Skip to content
Permalink
Browse files

Added `protocolRelative` option to `buildUrl()` method.

  • Loading branch information...
robertpustulka committed Sep 13, 2017
1 parent 1feffe8 commit fef1ebfdd183eb0ea4cd3b494dc361d781f60bf6
Showing with 18 additions and 4 deletions.
  1. +4 −2 src/Http/Client.php
  2. +14 −2 tests/TestCase/Http/ClientTest.php
@@ -402,7 +402,8 @@ public function send(Request $request, $options = [])
$locationUrl = $this->buildUrl($location, [], [
'host' => $url->getHost(),
'port' => $url->getPort(),
'scheme' => $url->getScheme()
'scheme' => $url->getScheme(),
'protocolRelative' => true
]);
$request = $request->withUri(new Uri($locationUrl));
@@ -452,10 +453,11 @@ public function buildUrl($url, $query = [], $options = [])
'host' => null,
'port' => null,
'scheme' => 'http',
'protocolRelative' => false
];
$options += $defaults;
if (preg_match('#^//#', $url)) {
if ($options['protocolRelative'] && preg_match('#^//#', $url)) {
$url = $options['scheme'] . ':' . $url;
}
if (preg_match('#^https?://#', $url)) {
@@ -137,14 +137,26 @@ public static function urlProvider()
[],
'query string data with some already on the url.'
],
[
'http://example.com/test.html',
'//test.html',
[],
[
'scheme' => 'http',
'host' => 'example.com',
'protocolRelative' => false
],
'url with a double slash',
],
[
'http://example.com/test.html',
'//example.com/test.html',
[],
[
'scheme' => 'http'
'scheme' => 'http',
'protocolRelative' => true
],
'url without a scheme',
'protocol relative url',
],
];
}

0 comments on commit fef1ebf

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