Skip to content

Commit 3152617

Browse files
[HttpClient] Fix catching some invalid Location headers
1 parent c83c46a commit 3152617

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

CurlHttpClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ private static function createRedirectResolver(array $options, string $host): \C
425425
try {
426426
$locationHasHost = false;
427427
$location = self::parseUrl($location);
428+
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));
429+
$url = self::resolveUrl($location, $url);
428430
} catch (InvalidArgumentException $e) {
429431
return null;
430432
}
@@ -446,9 +448,6 @@ private static function createRedirectResolver(array $options, string $host): \C
446448
curl_setopt($ch, \CURLOPT_HTTPHEADER, $redirectHeaders['with_auth']);
447449
}
448450

449-
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));
450-
$url = self::resolveUrl($location, $url);
451-
452451
curl_setopt($ch, \CURLOPT_PROXY, self::getProxyUrl($options['proxy'], $url));
453452

454453
return implode('', $url);

NativeHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,14 @@ private static function createRedirectResolver(array $options, string $host, ?ar
383383

384384
try {
385385
$url = self::parseUrl($location);
386+
$locationHasHost = isset($url['authority']);
387+
$url = self::resolveUrl($url, $info['url']);
386388
} catch (InvalidArgumentException $e) {
387389
$info['redirect_url'] = null;
388390

389391
return null;
390392
}
391393

392-
$locationHasHost = isset($url['authority']);
393-
$url = self::resolveUrl($url, $info['url']);
394394
$info['redirect_url'] = implode('', $url);
395395

396396
if ($info['redirect_count'] >= $maxRedirects) {

Tests/HttpClientTestCase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,11 @@ public function testNoRedirectWithInvalidLocation()
494494
{
495495
$client = $this->getHttpClient(__FUNCTION__);
496496

497-
$response = $client->request('GET', 'http://localhost:8057/302-no-scheme');
497+
$response = $client->request('GET', 'http://localhost:8057/302?location=localhost:8067');
498+
499+
$this->assertSame(302, $response->getStatusCode());
500+
501+
$response = $client->request('GET', 'http://localhost:8057/302?location=http:localhost');
498502

499503
$this->assertSame(302, $response->getStatusCode());
500504
}

0 commit comments

Comments
 (0)