8000 [HttpClient] fix proxied redirects in curl client · symfony/symfony@ca2d0f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ca2d0f6

Browse files
committed
[HttpClient] fix proxied redirects in curl client
1 parent 6ae4ac9 commit ca2d0f6

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/Symfony/Component/HttpClient/CurlHttpClient.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,6 @@ private static function createRedirectResolver(array $options, string $host): \C
436436
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));
437437
$url = self::resolveUrl($location, $url);
438438

439-
curl_setopt($ch, \CURLOPT_PROXY, $options['proxy']
440-
?? ('https:' === $url['scheme'] ? $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? null : null)
441-
// Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
442-
?? $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null : null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null
443-
);
444-
445439
return implode('', $url);
446440
};
447441
}

src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
header('Location: //?foo=bar', true, 301);
8787
break;
8888

89+
case '/301/proxy':
90+
case 'http://localhost:8057/301/proxy':
91+
case 'http://127.0.0.1:8057/301/proxy':
92+
header('Location: http://localhost:8057/', true, 301);
93+
break;
94+
8995
case '/302':
9096
if (!isset($vars['HTTP_AUTHORIZATION'])) {
9197
header('Location: http://localhost:8057/', true, 302);

src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,14 @@ public function testProxy()
969969
} finally {
970970
unset($_SERVER['http_proxy']);
971971
}
972+
973+
$response = $client->request('GET', 'http://localhost:8057/301/proxy', [
974+
'proxy' => 'http://localhost:8057',
975+
]);
976+
977+
$body = $response->toArray();
978+
$this->assertSame('localhost:8057', $body['HTTP_HOST']);
979+
$this->assertMatchesRegularExpression('#^http://(localhost|127\.0\.0\.1):8057/$#', $body['REQUEST_URI']);
972980
}
973981

974982
public function testNoProxy()

0 commit comments

Comments
 (0)
0