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

Commit 03d60fc

Browse filesBrowse files
[HttpClient] Always "buffer" empty responses
1 parent 3d39874 commit 03d60fc
Copy full SHA for 03d60fc

File tree

1 file changed

+10
-8
lines changed
Filter options

1 file changed

+10
-8
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/ResponseTrait.php
+10-8Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.