Skip to content

Commit 0785ded

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 0785ded

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

docs/transports.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ This package contains some frequently used encoders / decoders for you:
4545
| `StreamDecoder` | `DecoderInterface<StreamInterface>` | Returns the PSR-7 Stream as response result |
4646
| `StreamEncoder` | `EncoderInterface<StreamInterface>` | Adds PSR-7 Stream as request body |
4747

48+
> **Note:** The `ResourceStreamEncoder` passes the underlying PHP resource to a PSR-7 stream.
49+
> PSR-7's `StreamInterface::close()` will close this resource, which also closes the original `ResourceStream`.
50+
> 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.
51+
4852
## Built-in transport presets:
4953

5054
We've composed some of the encodings above into pre-configured transports:

0 commit comments

Comments
 (0)