Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  [HttpClient] Always "buffer" empty responses
  • Loading branch information
nicolas-grekas committed Oct 2, 2020
2 parents 6db1a7d + b1cb966 commit df75799
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Response/ResponseTrait.php
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

0 comments on commit df75799

Please sign in to comment.