fix for empty response body when debugging unseekable streams#537
Open
JonPurvis wants to merge 3 commits intosaloonphp:v3from
Open
fix for empty response body when debugging unseekable streams#537JonPurvis wants to merge 3 commits intosaloonphp:v3from
JonPurvis wants to merge 3 commits intosaloonphp:v3from
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #447
When debug mode is on, the default response debugger calls
$response->body()to dump the response. If the PSR-7 body stream is unseekable (e.g. many LLM/OpenAI APIs), that first read consumes the stream and it is never rewound, so later calls tobody()orjson()return empty.This change:
Response::withBufferedBody(string $body): staticReturns a new Response with the same metadata but the body replaced by a seekable stream containing the given string (using
ResponseInterface::withBody()andGuzzleHttp\Psr7\Utils::streamFor()).HasDebugging::debugResponse()In the response middleware: if the PSR body stream is not seekable, we read the body once, build a replacement response via
withBufferedBody(), run the debug callback on that response (so the dump still shows the full body), and return the replacement response from the middleware so the rest of the pipeline and the caller receive a response whose body can still be read. If the stream is seekable, behavior is unchanged (same response, no buffering).