diff options
author | Christian Schneider | 2016-06-14 16:13:15 +0200 |
---|---|---|
committer | Christian Schneider | 2016-06-14 16:13:15 +0200 |
commit | bfa681350aac276bcf3b42670bfd54fa89bd3650 (patch) | |
tree | bb3572cbe39fe44532520250010bc35612f08050 /it_url.class | |
parent | f5c82c6bee3d02a5781c4e7f2933dd6fdf5f3405 (diff) | |
download | itools-bfa681350aac276bcf3b42670bfd54fa89bd3650.tar.gz itools-bfa681350aac276bcf3b42670bfd54fa89bd3650.tar.bz2 itools-bfa681350aac276bcf3b42670bfd54fa89bd3650.zip |
Refactor headers sent with subrequests copy/paste to common function
Diffstat (limited to 'it_url.class')
-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); |