[HttpClient] fix buffering AsyncResponse with no passthru
This commit is contained in:
parent
901e938da3
commit
1ffeba3f09
@ -209,6 +209,10 @@ final class AsyncResponse implements ResponseInterface, StreamableInterface
|
||||
if (!$r->passthru) {
|
||||
if (null !== $chunk->getError() || $chunk->isLast()) {
|
||||
unset($asyncMap[$response]);
|
||||
} elseif (null !== $r->content && '' !== ($content = $chunk->getContent()) && \strlen($content) !== fwrite($r->content, $content)) {
|
||||
$chunk = new ErrorChunk($r->offset, new TransportException(sprintf('Failed writing %d bytes to the response buffer.', \strlen($content))));
|
||||
$r->info['error'] = $chunk->getError();
|
||||
$r->response->cancel();
|
||||
}
|
||||
|
||||
yield $r => $chunk;
|
||||
|
@ -182,4 +182,18 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
|
||||
|
||||
$this->assertTrue($lastChunk->isLast());
|
||||
}
|
||||
|
||||
public function testBufferPurePassthru()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {
|
||||
$context->passthru();
|
||||
|
||||
yield $chunk;
|
||||
});
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057/');
|
||||
|
||||
$this->assertStringContainsString('SERVER_PROTOCOL', $response->getContent());
|
||||
$this->assertStringContainsString('HTTP_HOST', $response->getContent());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user