8000 bug #38388 [HttpClient] Always "buffer" empty responses (nicolas-grekas) · symfony/symfony@b3a20e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b3a20e4

Browse files
bug #38388 [HttpClient] Always "buffer" empty responses (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Always "buffer" empty responses | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 03d60fc [HttpClient] Always "buffer" empty responses
2 parents 3d39874 + 03d60fc commit b3a20e4

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ public function getContent(bool $throw = true): string
115115
return $content;
116116
}
117117

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

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

377375
$chunk = new ErrorChunk($response->offset, $e);
378376
} else {
377+
if (0 === $response->offset && null === $response->content) {
378+
$response->content = fopen('php://memory', 'w+');
379+
}
380+
379381
$chunk = new LastChunk($response->offset);
380382
}
381383
} elseif ($chunk instanceof ErrorChunk) {

0 commit comments

Comments
 (0)
0