Skip to content

Commit c150697

Browse files
committed
Document ResourceStream close behavior
The underlying PHP resource is shared between the ResourceStream and the PSR-7 stream, so closing one closes the other. Document this and suggest copying the stream when reuse is needed.
1 parent 27a1835 commit c150697

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

docs/transports.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ This package contains some frequently used encoders / decoders for you:
4141
| `RawEncoder` | `EncoderInterface<string>` | Adds raw string as request body |
4242
| `ResourceStreamDecoder` | `DecoderInterface<ResourceStream>` | Returns `phpro/resource-stream` from response body |
4343
| `ResourceStreamEncoder` | `EncoderInterface<ResourceStream>` | Adds `phpro/resource-stream` as request body |
44+
45+
> **Note:** The `ResourceStreamEncoder` passes the underlying PHP resource to a PSR-7 stream.
46+
> PSR-7's `StreamInterface::close()` will close this resource, which also closes the original `ResourceStream`.
47+
> If you need to reuse the resource after sending a request, pass a copy of the stream (e.g. via `$stream->copyTo(MemoryStream::create())`) to the encoder instead.
48+
4449
| `ResponseDecoder` | `DecoderInterface<ResponseInterface>` | Returns the received PSR-7 response as result |
4550
| `StreamDecoder` | `DecoderInterface<StreamInterface>` | Returns the PSR-7 Stream as response result |
4651
| `StreamEncoder` | `EncoderInterface<StreamInterface>` | Adds PSR-7 Stream as request body |

0 commit comments

Comments
 (0)