summaryrefslogtreecommitdiff
path: root/it_url.class
diff options
context:
space:
mode:
authorChristian Schneider2016-06-14 16:13:15 +0200
committerChristian Schneider2016-06-14 16:13:15 +0200
commitbfa681350aac276bcf3b42670bfd54fa89bd3650 (patch)
treebb3572cbe39fe44532520250010bc35612f08050 /it_url.class
parentf5c82c6bee3d02a5781c4e7f2933dd6fdf5f3405 (diff)
downloaditools-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.class25
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);