Skip to content

Commit c06d69c

Browse files
committed
Revert to HTTP 1.0 for socket request/response
Looks like the endpoint is returning chunked responses and it's going to take a little more code to handle that. Instead, we can just request HTTP 1.0 and get the full response back in one.
1 parent 2ccff6a commit c06d69c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/ReCaptcha/RequestMethod/SocketPost.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function submit(RequestParameters $params)
8181

8282
$content = $params->toQueryString();
8383

84-
$request = "POST " . $urlParsed['path'] . " HTTP/1.1\r\n";
84+
$request = "POST " . $urlParsed['path'] . " HTTP/1.0\r\n";
8585
$request .= "Host: " . $urlParsed['host'] . "\r\n";
8686
$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
8787
$request .= "Content-length: " . strlen($content) . "\r\n";
@@ -97,7 +97,7 @@ public function submit(RequestParameters $params)
9797

9898
$this->socket->fclose();
9999

100-
if (0 !== strpos($response, 'HTTP/1.1 200 OK')) {
100+
if (0 !== strpos($response, 'HTTP/1.0 200 OK')) {
101101
return '{"success": false, "error-codes": ["'.ReCaptcha::E_BAD_RESPONSE.'"]}';
102102
}
103103

tests/ReCaptcha/RequestMethod/SocketPostTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testSubmitSuccess()
5353
->method('fwrite');
5454
$socket->expects($this->once())
5555
->method('fgets')
56-
->willReturn("HTTP/1.1 200 OK\n\nRESPONSEBODY");
56+
->willReturn("HTTP/1.0 200 OK\n\nRESPONSEBODY");
5757
$socket->expects($this->exactly(2))
5858
->method('feof')
5959
->will($this->onConsecutiveCalls(false, true));
@@ -81,7 +81,7 @@ public function testOverrideSiteVerifyUrl()
8181
->with($this->matchesRegularExpression('/^POST \/some\/path.*Host: over\.ride/s'));
8282
$socket->expects($this->once())
8383
->method('fgets')
84-
->willReturn("HTTP/1.1 200 OK\n\nRESPONSEBODY");
84+
->willReturn("HTTP/1.0 200 OK\n\nRESPONSEBODY");
8585
$socket->expects($this->exactly(2))
8686
->method('feof')
8787
->will($this->onConsecutiveCalls(false, true));
@@ -107,7 +107,7 @@ public function testSubmitBadResponse()
107107
->method('fwrite');
108108
$socket->expects($this->once())
109109
->method('fgets')
110-
->willReturn("HTTP/1.1 500 NOPEn\\nBOBBINS");
110+
->willReturn("HTTP/1.0 500 NOPEn\\nBOBBINS");
111111
$socket->expects($this->exactly(2))
112112
->method('feof')
113113
->will($this->onConsecutiveCalls(false, true));

0 commit comments

Comments
 (0)