Repository navigation
Conversation
The transports took the first run of three digits anywhere in the first header line as the status code, so a response without a status line got a code made up from its first header, and the stream and socket transports read $matches[0] without checking the match, which raised PHP deprecations and "Undefined array key" warnings before the intended InvalidResponseCodeException. Parse the status line with an anchored pattern in a shared AbstractTransport::parseStatusCode() and throw when it does not match. 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
All three transports read the status code with
preg_match('/[0-9]{3}/', array_shift($headers), $matches):Content-Length: 12345got the status code123, andHTTP/1.1 2000 OKbecame200;$matches[0]without checking the match. With no headers at allarray_shift()returnsnull, so PHP 8.1+ raised apreg_match()null deprecation and then "Undefined array key 0", before the intendedInvalidResponseCodeException.A new protected
AbstractTransport::parseStatusCode()matches^HTTP/<version> <3 digits>(alsoHTTP/2 200) and throwsInvalidResponseCodeException('No HTTP response code found.')when the line does not match. The three transports use it.Testing Instructions
Tests/Transport/StatusLineTest.php(new, no server needed) calls each transport'sgetResponse():HTTP/1.1 404 Not Found,HTTP/1.0 200 OKandHTTP/2 201give 404, 200 and 201;InvalidResponseCodeExceptionwithout any PHP warning or deprecation. Before the change all ten cases fail: a made-up code is returned, or PHP errors are raised first.Documentation Changes Required
docs/classes/TransportInterface.md: a paragraph onparseStatusCode()and the exception.Related to #82 (stream redirects) and #86 (another
AbstractTransporthelper); they touch other lines of the same files.🤖 Generated with Claude Code