diff options
author | Christian Schneider | 2023-08-22 16:12:24 +0200 |
---|---|---|
committer | Christian Schneider | 2023-08-22 16:12:24 +0200 |
commit | e70b53d3ef0991f3a09bc7fcaf070f27f2e4b83a (patch) | |
tree | 08378e881aa0de9455d5b5c9c5a737bbd812b258 /it_url.class | |
parent | 599fe205600c4d0634476a042c4b0c24d683ccb5 (diff) | |
download | itools-e70b53d3ef0991f3a09bc7fcaf070f27f2e4b83a.tar.gz itools-e70b53d3ef0991f3a09bc7fcaf070f27f2e4b83a.tar.bz2 itools-e70b53d3ef0991f3a09bc7fcaf070f27f2e4b83a.zip |
Add prefix to it_url::absolute() for OneDomain support, add tests for relative paths
Diffstat (limited to 'it_url.class')
-rw-r--r-- | it_url.class | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/it_url.class b/it_url.class index 1b2bfc7..05689c8 100644 --- a/it_url.class +++ b/it_url.class @@ -186,7 +186,7 @@ static function _default_headers($url, $p) 'Host' => $url->realhostname . $url->explicitport, 'User-Agent' => "Mozilla/5.0 (compatible; ITools; Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582)", 'Accept-Language' => $p['headers']['Accept-Language'] ?? ($search_subrequest ? T_defaultlang() : 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, + 'Referer' => it::match('([-\w]+\.\w+)$', $url->hostname) == it::match('([-\w]+\.\w+)$', $_SERVER['HTTP_HOST']) ? static::absolute(U($_GET)) : null, 'X-Ultra-Https' => $_SERVER['HTTPS'], ]); @@ -728,7 +728,7 @@ static function get_cache_contents($p) $result = self::_postprocess($result, $p); } else - $result = it::error((array)$p['it_error'] + ['title' => $p['safety'] === 0 ? false : "failed getting " . it_url::absolute($p['url']), 'body' => $p]); + $result = it::error((array)$p['it_error'] + ['title' => $p['safety'] === 0 ? false : "failed getting " . static::absolute($p['url']), 'body' => $p]); return $result; } @@ -845,10 +845,10 @@ static function _atomicwrite($path, $data) * @param $proto_force Optional protocol to enforce, default protocol of current request or http if in script context * @return absolute version of URL ( http[s]://host/bar.html ) */ -static function absolute($url = null, $proto_force = null) +static function absolute($url = null, $proto_force = null, $prefix = '') { if (!isset($url)) - $url = $_SERVER['PHP_SELF']; + $url = $prefix . $_SERVER['PHP_SELF']; if (list($proto_url, $urltmp) = it::match('^(\w+):(.*)$', $url)) { @@ -860,7 +860,7 @@ static function absolute($url = null, $proto_force = null) if (!preg_match('#^//#', $url)) { - $dir = preg_replace('#/[^/]*$#', '/', $_SERVER['PHP_SELF']); + $dir = preg_replace('#/[^/]*$#', '/', $prefix . $_SERVER['PHP_SELF']); $url = preg_match('#^/#', $url) ? $url : "$dir$url"; $url = "//" . $_SERVER['HTTP_HOST'] . $url; } |