diff options
-rw-r--r-- | it_url.class | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/it_url.class b/it_url.class index dffd805..b35a59f 100644 --- a/it_url.class +++ b/it_url.class @@ -159,6 +159,16 @@ function parse_http_header($header) } } +static function _default_headers($url, $p) +{ + return [ + 'Host' => $url->realhostname . $url->explicitport, + 'User-Agent' => "Mozilla/5.0 (compatible; MSIE 9.0; ITools)", + 'Accept-Language' => $p['headers']['Accept-Language'] ?: T_lang(), # can prevent loading of it_text + 'Referer' => it::match('([-\w]+\.\w+)$', $url->hostname) == it::match('([-\w]+\.\w+)$', $_SERVER['HTTP_HOST']) ? it_url::absolute(U($_GET)) : null, + ]; +} + function request($p=array()) { $p += array('totaltimeout' => "999999", 'timeout' => 5); @@ -181,12 +191,7 @@ function request($p=array()) else $data = $p['data']; - $p['headers'] = (array)$p['headers'] + array( - 'Host' => $url->realhostname . $url->explicitport, - 'User-Agent' => "Mozilla/5.0 (compatible; MSIE 9.0; ITools)", - 'Accept-Language' => $p['headers']['Accept-Language'] ?: T_lang(), # can prevent loading of it_text - 'Referer' => it::match('([-\w]+\.\w+)$', $url->hostname) == it::match('([-\w]+\.\w+)$', $_SERVER['HTTP_HOST']) ? it_url::absolute(U($_GET)) : null, - ); + $p['headers'] = (array)$p['headers'] + self::_default_headers($url, $p); if (is_int($p['filemtime'])) $p['headers']['If-Modified-Since'] = date("r", $p['filemtime']); @@ -321,13 +326,7 @@ function request_curl($p=array()) $this->it_url($p['url']); $url->headers = array(); - - $p['headers'] = (array)$p['headers'] + array( - 'Host' => $url->realhostname . $url->explicitport, - 'User-Agent' => "Mozilla/4.0 (compatible; MSIE 7.0; ITools)", - 'Accept-Language' => T_lang(), - ); - + $p['headers'] = (array)$p['headers'] + self::_default_headers($url, $p); $opts = array(CURLOPT_FOLLOWLOCATION => false, CURLOPT_HEADER => 1) + self::curl_opts($p); $curl = curl_init($url->rawurl); |