Skip to content
Permalink
Browse files

Support protocol relative URL in HTTP Client.

Some servers set //example.com as a Location header. `buildUrl()` needs
to support that in order to build absolute urls.
  • Loading branch information...
robertpustulka committed Sep 7, 2017
1 parent 6d25953 commit 1feffe862db9861b7a39cfff199a48ef85ac29d3
Showing with 17 additions and 3 deletions.
  1. +8 −3 src/Http/Client.php
  2. +9 −0 tests/TestCase/Http/ClientTest.php
@@ -448,15 +448,20 @@ public function buildUrl($url, $query = [], $options = [])
$url .= $q;
$url .= is_string($query) ? $query : http_build_query($query);
}
if (preg_match('#^https?://#', $url)) {
return $url;
}
$defaults = [
'host' => null,
'port' => null,
'scheme' => 'http',
];
$options += $defaults;
if (preg_match('#^//#', $url)) {
$url = $options['scheme'] . ':' . $url;
}
if (preg_match('#^https?://#', $url)) {
return $url;
}
$defaultPorts = [
'http' => 80,
'https' => 443
@@ -137,6 +137,15 @@ public static function urlProvider()
[],
'query string data with some already on the url.'
],
[
'http://example.com/test.html',
'//example.com/test.html',
[],
[
'scheme' => 'http'
],
'url without a scheme',
],
];
}

0 comments on commit 1feffe8

Please sign in to comment.
You can’t perform that action at this time.