New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support protocol relative URL in HTTP Client. #11163

Merged
merged 2 commits into from Sep 14, 2017
Jump to file or symbol
Failed to load files and symbols.
+32 −4
Diff settings

Always

Just for now

View
@@ -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));
@@ -448,15 +449,21 @@ 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',
'protocolRelative' => false
];
$options += $defaults;
if ($options['protocolRelative'] && preg_match('#^//#', $url)) {
$url = $options['scheme'] . ':' . $url;
}
if (preg_match('#^https?://#', $url)) {
return $url;
}
$defaultPorts = [
'http' => 80,
'https' => 443
@@ -137,6 +137,27 @@ 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',
'protocolRelative' => true
],
'protocol relative url',
],
];
}
ProTip! Use n and p to navigate between commits in a pull request.