fix: Accept HTTP/1.1 responses in SocketPost to support proxies#616
Merged
rowan-m merged 3 commits intogoogle:mainfrom Mar 26, 2026
Merged
fix: Accept HTTP/1.1 responses in SocketPost to support proxies#616rowan-m merged 3 commits intogoogle:mainfrom
rowan-m merged 3 commits intogoogle:mainfrom
Conversation
Contributor
|
Can you resolve the conflicts here as I had made some changes to the |
Contributor
Author
Of course, no problem. I was waiting until you finished so I could pull all the changes along with the fixes. #DONE |
Proxies and certain hosting environments may convert outbound HTTP/1.0 requests and respond with HTTP/1.1 200 OK. The previous strict check (strpos for 'HTTP/1.0 200 OK') caused false E_BAD_RESPONSE errors for these users. Replace the strpos check with a regex that accepts both HTTP/1.0 and HTTP/1.1 200 OK response headers. Add a dedicated test to verify HTTP/1.1 responses are handled correctly.
029ec01 to
df61d9d
Compare
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
Fixes false
E_BAD_RESPONSEerrors for users behind HTTP proxies or on hosting environments that rewrite outboundHTTP/1.0traffic toHTTP/1.1.The Problem
SocketPost::submit()sends anHTTP/1.0POST request to the reCAPTCHA API. When the response arrives, it checks the status line with a strictstrpos()comparison:Some proxies, reverse proxies, and hosting environments transparently upgrade the connection and respond with
HTTP/1.1 200 OK. This causes a false-positive failure — the reCAPTCHA verification was actually successful, but the library rejects the response.The Fix
Replace the rigid
strpos()check with a regex that securely accepts both HTTP versions:This regex:
^)HTTP/1.0orHTTP/1.1(no other versions likeHTTP/2)200 OK(non-200 statuses are still correctly rejected)Test Coverage
Added a new test testSubmitReturnsResponseWhenHttp11() that explicitly mocks an
HTTP/1.1 200 OKresponse and asserts the body is returned correctly. The existingHTTP/1.0tests remain unchanged and continue to pass.Verification