From 0785ded49f29cfda71907bd91d3d6677f4ad8117 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Tue, 7 Apr 2026 10:22:11 +0200 Subject: [PATCH] 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. --- docs/transports.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/transports.md b/docs/transports.md index dd8f803..de51440 100644 --- a/docs/transports.md +++ b/docs/transports.md @@ -45,6 +45,10 @@ This package contains some frequently used encoders / decoders for you: | `StreamDecoder` | `DecoderInterface` | Returns the PSR-7 Stream as response result | | `StreamEncoder` | `EncoderInterface` | Adds PSR-7 Stream as request body | +> **Note:** The `ResourceStreamEncoder` passes the underlying PHP resource to a PSR-7 stream. +> PSR-7's `StreamInterface::close()` will close this resource, which also closes the original `ResourceStream`. +> 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. + ## Built-in transport presets: We've composed some of the encodings above into pre-configured transports: