Repository navigation
Conversation
sendRequest() read the body with getContents(), which starts at the current position of the stream, so a body that had been written or read without rewinding was sent empty. empty() also dropped the body "0". Transport failures were thrown as plain RuntimeExceptions, which PSR-18 consumers cannot catch through the PSR interfaces. Wrap them in a new NetworkException that implements NetworkExceptionInterface and still extends RuntimeException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary of Changes
Two problems in
Http::sendRequest(), the PSR-18 entry point. They are in one PR because both change the same few lines.The body was read from the current stream position.
$request->getBody()->getContents()returns what follows the stream pointer, so a body stream that had been written to (Diactoros leaves the pointer at the end) or already read was sent empty.empty($data)additionally treated the body"0"as "no body". The body is now read with(string) $request->getBody(), which rewinds first, and only an empty string counts as no data.Transport failures did not implement the PSR-18 exception interfaces. Connection failures came out of
sendRequest()as plain\RuntimeException, so code typed against PSR-18 could not catch them withNetworkExceptionInterface/ClientExceptionInterface. They are now wrapped in the newJoomla\Http\Exception\NetworkException, which implementsNetworkExceptionInterface(withgetRequest()), keeps message, code and the original asgetPrevious(), and still extends\RuntimeException, so existingcatch (\RuntimeException $e)blocks are unaffected. Exceptions that already implementClientExceptionInterface(InvalidResponseCodeException,UnexpectedResponseException) pass through unchanged. The native API (get(),post(), …) is not changed.Not done: passing the request's protocol version to the transport. Transports read
protocolVersionfrom their own options, set at construction, andTransportInterface::request()has no parameter for it, so this needs an interface change (5.x). The docs now say that the transport's option decides.Testing Instructions
Tests/HttpSendRequestTest.php(new, with a mocked transport, no server needed):''before);"0"is sent (was dropped);null;RuntimeExceptionfrom the transport becomes aNetworkExceptionwith the request, message, code and previous exception;InvalidResponseCodeExceptionis rethrown as is.Documentation Changes Required
docs/classes/Http.md: new section "Sending a PSR-7 request" on the body handling, the protocol version and the exceptions.🤖 Generated with Claude Code