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
-------
03d60fce47
[HttpClient] Always "buffer" empty responses
This commit is contained in:
commit
b3a20e4065
@ -115,15 +115,13 @@ trait ResponseTrait
|
|||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('HEAD' === $this->info['http_method'] || \in_array($this->info['http_code'], [204, 304], true)) {
|
if (null === $this->content) {
|
||||||
return '';
|
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);
|
rewind($this->content);
|
||||||
@ -376,6 +374,10 @@ trait ResponseTrait
|
|||||||
|
|
||||||
$chunk = new ErrorChunk($response->offset, $e);
|
$chunk = new ErrorChunk($response->offset, $e);
|
||||||
} else {
|
} else {
|
||||||
|
if (0 === $response->offset && null === $response->content) {
|
||||||
|
$response->content = fopen('php://memory', 'w+');
|
||||||
|
}
|
||||||
|
|
||||||
$chunk = new LastChunk($response->offset);
|
$chunk = new LastChunk($response->offset);
|
||||||
}
|
}
|
||||||
} elseif ($chunk instanceof ErrorChunk) {
|
} elseif ($chunk instanceof ErrorChunk) {
|
||||||
|
Reference in New Issue
Block a user