@@ -421,19 +421,26 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
421
421
throw new AdapterException \RuntimeException ("Error in cURL request: " . curl_error ($ this ->curl ));
422
422
}
423
423
424
+ // separating header from body because it is dangerous to accidentially replace strings in the body
425
+ $ responseHeaderSize = curl_getinfo ($ this ->curl , CURLINFO_HEADER_SIZE );
426
+ $ responseHeaders = substr ($ this ->response , 0 , $ responseHeaderSize );
427
+
424
428
// cURL automatically decodes chunked-messages, this means we have to disallow the Zend\Http\Response to do it again
425
- if (stripos ($ this ->response , "Transfer-Encoding: chunked \r\n" )) {
426
- $ this ->response = str_ireplace ("Transfer-Encoding: chunked \r\n" , '' , $ this ->response );
427
- }
429
+ $ responseHeaders = preg_replace ("/Transfer-Encoding:\s*chunked \\r \\n/ " , "" , $ responseHeaders );
428
430
429
431
// cURL can automatically handle content encoding; prevent double-decoding from occurring
430
432
if (isset ($ this ->config ['curloptions ' ][CURLOPT_ENCODING ])
431
433
&& '' == $ this ->config ['curloptions ' ][CURLOPT_ENCODING ]
432
- && stripos ($ this ->response , "Content-Encoding: gzip \r\n" )
433
434
) {
434
- $ this -> response = str_ireplace ( " Content-Encoding: gzip \r\n " , '' , $ this -> response );
435
+ $ responseHeaders = preg_replace ( " / Content-Encoding:\s* gzip \\ r \\ n/ " , "" , $ responseHeaders );
435
436
}
436
437
438
+ // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
439
+ $ responseHeaders = preg_replace ("/HTTP\/1.0\s*200\s*Connection\s*established \\r \\n \\r \\n/ " , "" , $ responseHeaders );
440
+
441
+ // replace old header with new, cleaned up, header
442
+ $ this ->response = substr_replace ($ this ->response , $ responseHeaders , 0 , $ responseHeaderSize );
443
+
437
444
// Eliminate multiple HTTP responses.
438
445
do {
439
446
$ parts = preg_split ('|(?:\r?\n){2}|m ' , $ this ->response , 2 );
@@ -445,11 +452,6 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
445
452
}
446
453
} while ($ again );
447
454
448
- // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
449
- if (stripos ($ this ->response , "HTTP/1.0 200 Connection established \r\n\r\n" ) !== false ) {
450
- $ this ->response = str_ireplace ("HTTP/1.0 200 Connection established \r\n\r\n" , '' , $ this ->response );
451
- }
452
-
453
455
return $ request ;
454
456
}
455
457
0 commit comments