Closed
Description
Q | A |
---|---|
Bug? | yes |
New Feature? | no |
Version | 1.7.0 |
I am working on a 3rd party integration for my library that uses HTTplug and this library. When I integrated my library to Drupal 8 that has its own Guzzle client wrapper I faced with an interesting problem. By using the \Http\Client\Common\Plugin\DecoderPlugin
sometimes I got back an empty string instead of the JSON that API has actually returned.
I think this is the combination of two possible issues:
- If something reads the content of the full response body before the
\Http\Client\Common\Plugin\DecoderPlugin
plugin can do that then when it starts processing the response (ex.: with the\Http\Message\Encoding\DechunkStream
) it does not rewinds the stream, therefore when the\Http\Message\Encoding\FilteredStream::getContents()
is being called the while loop does not do anything because the wrapped (underlying) stream has already in the end.
Maybe this can be solved by adding this condition to the constructor of the FilteredStream class.
if ($this->stream->isSeekable()) {
$this->stream->rewind();
}
- If the wrapped stream was being closed then any of the
\Http\Message\Encoding\FilteredStream
implementations could not read the content of the stream again. It means that if I use the\Http\Client\Common\Plugin\DecoderPlugin
on my client an try to get the body of the response multiple times like this:(string) $response->getBody()
then after the first call I always get back an empty string. (Or if we add the suggested condition to the FilteredStream class' constructor an exception, because the read() method tries to read on a closed stream after the first(string) $response->getBody()
). If I remove the plugin then the originally wrapped\GuzzleHttp\Psr7\Stream
object inside an instance of\GuzzleHttp\Psr7\Response
can always return the same response body (string) multiple times.
Metadata
Metadata
Assignees
Labels
No labels