This repository was archived by the owner on Jan 13, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -295,8 +295,11 @@ private function getHeaderSize()
295
295
// This corrects a Curl bug where header size does not account
296
296
// for additional Proxy headers.
297
297
if ( self ::needsCurlProxyFix () ) {
298
- if ( stripos ($ this ->rawResponse , self ::CONNECTION_ESTABLISHED ) !== false ) {
299
- $ headerSize += mb_strlen (self ::CONNECTION_ESTABLISHED );
298
+ // Additional way to calculate the request body size.
299
+ if (preg_match ('/Content-Length: (\d+)/ ' , $ this ->rawResponse , $ m )) {
300
+ $ headerSize = mb_strlen ($ this ->rawResponse ) - $ m [1 ];
301
+ } elseif (stripos ($ this ->rawResponse , self ::CONNECTION_ESTABLISHED ) !== false ) {
302
+ $ headerSize += mb_strlen (self ::CONNECTION_ESTABLISHED );
300
303
}
301
304
}
302
305
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ abstract class AbstractTestHttpClient extends PHPUnit_Framework_TestCase
7
7
Content-Type: text/html; charset=utf-8
8
8
Location: https://foobar.com/ \r\n\r\n" ;
9
9
protected $ fakeRawProxyHeader = "HTTP/1.0 200 Connection established \r\n\r\n" ;
10
+ protected $ fakeRawProxyHeader2 = "HTTP/1.0 200 Connection established
11
+ Proxy-agent: Kerio Control/7.1.1 build 1971 \r\n\r\n" ;
10
12
protected $ fakeRawHeader = "HTTP/1.1 200 OK
11
13
Etag: \"9d86b21aa74d74e574bbb35ba13524a52deb96e3 \"
12
14
Content-Type: text/javascript; charset=UTF-8
Original file line number Diff line number Diff line change @@ -298,6 +298,34 @@ public function testProperlyHandlesProxyHeadersWithCurlBug()
298
298
$ this ->assertEquals ($ headers , $ this ->fakeHeadersAsArray );
299
299
}
300
300
301
+ public function testProperlyHandlesProxyHeadersWithCurlBug2 ()
302
+ {
303
+ $ rawHeader = $ this ->fakeRawProxyHeader2 . $ this ->fakeRawHeader ;
304
+ $ this ->curlMock
305
+ ->shouldReceive ('getinfo ' )
306
+ ->with (CURLINFO_HEADER_SIZE )
307
+ ->once ()
308
+ ->andReturn (mb_strlen ($ this ->fakeRawHeader )); // Mimic bug that doesn't count proxy header
309
+ $ this ->curlMock
310
+ ->shouldReceive ('version ' )
311
+ ->once ()
312
+ ->andReturn (array ('version_number ' => self ::CURL_VERSION_BUGGY ));
313
+ $ this ->curlMock
314
+ ->shouldReceive ('exec ' )
315
+ ->once ()
316
+ ->andReturn ($ rawHeader . $ this ->fakeRawBody );
317
+
318
+ $ this ->curlClient ->sendRequest ();
319
+ list ($ rawHeaders , $ rawBody ) = $ this ->curlClient ->extractResponseHeadersAndBody ();
320
+
321
+ $ this ->assertEquals ($ rawHeaders , trim ($ rawHeader ));
322
+ $ this ->assertEquals ($ rawBody , $ this ->fakeRawBody );
323
+
324
+ $ headers = FacebookCurlHttpClient::headersToArray ($ rawHeaders );
325
+
326
+ $ this ->assertEquals ($ headers , $ this ->fakeHeadersAsArray );
327
+ }
328
+
301
329
public function testProperlyHandlesRedirectHeaders ()
302
330
{
303
331
$ rawHeader = $ this ->fakeRawRedirectHeader . $ this ->fakeRawHeader ;
You can’t perform that action at this time.
0 commit comments