Skip to content

Commit 5e48c1e

Browse files
Merge branch '5.1'
* 5.1: [HttpClient] Always "buffer" empty responses
2 parents 700462f + c453c3d commit 5e48c1e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Symfony/Component/HttpClient/Response/CommonResponseTrait.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@ public function getContent(bool $throw = true): string
6161
return $content;
6262
}
6363

64-
if ('HEAD' === $this->getInfo('http_method') || \in_array($this->getInfo('http_code'), [204, 304], true)) {
65-
return '';
64+
if (null === $this->content) {
65+
throw new TransportException('Cannot get the content of the response twice: buffering is disabled.');
66+
}
67+
} else {
68+
foreach (self::stream([$this]) as $chunk) {
69+
// Chunks are buffered in $this->content already
6670
}
67-
68-
throw new TransportException('Cannot get the content of the response twice: buffering is disabled.');
69-
}
70-
71-
foreach (self::stream([$this]) as $chunk) {
72-
// Chunks are buffered in $this->content already
7371
}
7472

7573
rewind($this->content);

src/Symfony/Component/HttpClient/Response/TransportResponseTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ public static function stream(iterable $responses, float $timeout = null): \Gene
207207

208208
$chunk = new ErrorChunk($response->offset, $e);
209209
} else {
210+
if (0 === $response->offset && null === $response->content) {
211+
$response->content = fopen('php://memory', 'w+');
212+
}
213+
210214
$chunk = new LastChunk($response->offset);
211215
}
212216
} elseif ($chunk instanceof ErrorChunk) {

0 commit comments

Comments
 (0)