Skip to content

[HttpClient] Always "buffer" empty responses #38388

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 2, 2020
Merged
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
18 changes: 10 additions & 8 deletions src/Symfony/Component/HttpClient/Response/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,13 @@ public function getContent(bool $throw = true): string
return $content;
}

if ('HEAD' === $this->info['http_method'] || \in_array($this->info['http_code'], [204, 304], true)) {
return '';
if (null === $this->content) {
throw new TransportException('Cannot get the content of the response twice: buffering is disabled.');
}
} else {
foreach (self::stream([$this]) as $chunk) {
// Chunks are buffered in $this->content already
}

throw new TransportException('Cannot get the content of the response twice: buffering is disabled.');
}

foreach (self::stream([$this]) as $chunk) {
// Chunks are buffered in $this->content already
}

rewind($this->content);
Expand Down Expand Up @@ -376,6 +374,10 @@ public static function stream(iterable $responses, float $timeout = null): \Gene

$chunk = new ErrorChunk($response->offset, $e);
} else {
if (0 === $response->offset && null === $response->content) {
$response->content = fopen('php://memory', 'w+');
}

$chunk = new LastChunk($response->offset);
}
} elseif ($chunk instanceof ErrorChunk) {
Expand Down