Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] fix handling of 3xx with no Location header - ignore Content-Length when no body is expected #34154

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

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions 7 src/Symfony/Component/HttpClient/Response/CurlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &

if (200 > $statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE)) {
$multi->handlesActivity[$id][] = new InformationalChunk($statusCode, $headers);
$location = null;

return \strlen($data);
}
Expand All @@ -346,9 +347,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
}
}

$location = null;

if ($statusCode < 300 || 400 <= $statusCode || curl_getinfo($ch, CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
if ($statusCode < 300 || 400 <= $statusCode || null === $location || curl_getinfo($ch, CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
// Headers and redirects completed, time to get the response's body
$multi->handlesActivity[$id][] = new FirstChunk();

Expand All @@ -361,6 +360,8 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
$logger->info(sprintf('Redirecting: "%s %s"', $info['http_code'], $info['redirect_url']));
}

$location = null;

return \strlen($data);
}
}
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/HttpClient/Response/MockResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private static function readResponse(self $response, array $options, ResponseInt
$info = $mock->getInfo() ?: [];
$response->info['http_code'] = ($info['http_code'] ?? 0) ?: $mock->getStatusCode() ?: 200;
$response->addResponseHeaders($info['response_headers'] ?? [], $response->info, $response->headers);
$dlSize = isset($response->headers['content-encoding']) ? 0 : (int) ($response->headers['content-length'][0] ?? 0);
$dlSize = isset($response->headers['content-encoding']) || 'HEAD' === $response->info['http_method'] || \in_array($response->info['http_code'], [204, 304], true) ? 0 : (int) ($response->headers['content-length'][0] ?? 0);

$response->info = [
'start_time' => $response->info['start_time'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private function open(): void

$this->multi->handlesActivity[$this->id] = [new FirstChunk()];

if ('HEAD' === $context['http']['method']) {
if ('HEAD' === $context['http']['method'] || \in_array($this->info['http_code'], [204, 304], true)) {
$this->multi->handlesActivity[$this->id][] = null;
$this->multi->handlesActivity[$this->id][] = null;

Expand Down
5 changes: 5 additions & 0 deletions 5 src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
header('Location: ..', true, 302);
break;

case '/304':
header('Content-Length: 10', true, 304);
echo '12345';
return;

case '/307':
header('Location: http://localhost:8057/post', true, 307);
break;
Expand Down
11 changes: 11 additions & 0 deletions 11 src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ public function testBadRequestBody()
$response->getStatusCode();
}

public function test304()
{
$client = $this->getHttpClient(__FUNCTION__);
$response = $client->request('GET', 'http://localhost:8057/304', [
'headers' => ['If-Match' => '"abc"'],
]);

$this->assertSame(304, $response->getStatusCode());
$this->assertSame('', $response->getContent(false));
}

public function testRedirects()
{
$client = $this->getHttpClient(__FUNCTION__);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.