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] 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
[HttpClient] Always "buffer" empty responses
  • Loading branch information
nicolas-grekas committed Oct 2, 2020
commit 03d60fce47f89446d6a6725ce8659911278b4a88
18 changes: 10 additions & 8 deletions 18 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.