Skip to content

Commit e002ea8

Browse files
committed
Merge pull request googleapis#270 from danielzhme/master
Remove HTTP/1.1 proxy header
2 parents 5675d9a + d7252c3 commit e002ea8

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/Google/IO/Abstract.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ abstract class Google_IO_Abstract
2828
{
2929
const UNKNOWN_CODE = 0;
3030
const FORM_URLENCODED = 'application/x-www-form-urlencoded';
31-
const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n";
31+
private static $CONNECTION_ESTABLISHED_HEADERS = array(
32+
"HTTP/1.0 200 Connection established\r\n\r\n",
33+
"HTTP/1.1 200 Connection established\r\n\r\n",
34+
);
3235
private static $ENTITY_HTTP_METHODS = array("POST" => null, "PUT" => null);
3336

3437
/** @var Google_Client */
@@ -249,14 +252,18 @@ protected function updateCachedRequest($cached, $responseHeaders)
249252
*/
250253
public function parseHttpResponse($respData, $headerSize)
251254
{
252-
if (stripos($respData, self::CONNECTION_ESTABLISHED) !== false) {
253-
$respData = str_ireplace(self::CONNECTION_ESTABLISHED, '', $respData);
254-
255-
// Subtract the proxy header size unless the cURL bug prior to 7.30.0
256-
// is present which prevented the proxy header size from being taken into
257-
// account.
258-
if (!$this->needsQuirk()) {
259-
$headerSize -= strlen(self::CONNECTION_ESTABLISHED);
255+
// check proxy header
256+
foreach (self::$CONNECTION_ESTABLISHED_HEADERS as $established_header) {
257+
if (stripos($respData, $established_header) !== false) {
258+
// existed, remove it
259+
$respData = str_ireplace($established_header, '', $respData);
260+
// Subtract the proxy header size unless the cURL bug prior to 7.30.0
261+
// is present which prevented the proxy header size from being taken into
262+
// account.
263+
if (!$this->needsQuirk()) {
264+
$headerSize -= strlen($established_header);
265+
}
266+
break;
260267
}
261268
}
262269

tests/general/IoTest.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,25 @@ public function responseChecker($io)
237237
$this->assertEquals(null, json_decode($body, true));
238238

239239
// Test transforms from proxies.
240-
$rawHeaders = Google_IO_Abstract::CONNECTION_ESTABLISHED
241-
. "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n";
242-
$headersSize = strlen($rawHeaders);
243-
// If we have a broken cURL version we have to simulate it to get the
244-
// correct test result.
245-
if ($hasQuirk && get_class($io) === 'Google_IO_Curl') {
246-
$headersSize -= strlen(Google_IO_Abstract::CONNECTION_ESTABLISHED);
240+
$connection_established_headers = array(
241+
"HTTP/1.0 200 Connection established\r\n\r\n",
242+
"HTTP/1.1 200 Connection established\r\n\r\n",
243+
);
244+
foreach ($connection_established_headers as $established_header) {
245+
$rawHeaders = "{$established_header}HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n";
246+
$headersSize = strlen($rawHeaders);
247+
// If we have a broken cURL version we have to simulate it to get the
248+
// correct test result.
249+
if ($hasQuirk && get_class($io) === 'Google_IO_Curl') {
250+
$headersSize -= strlen($established_header);
251+
}
252+
$rawBody = "{}";
253+
254+
$rawResponse = "$rawHeaders\r\n$rawBody";
255+
list($headers, $body) = $io->parseHttpResponse($rawResponse, $headersSize);
256+
$this->assertEquals(1, sizeof($headers));
257+
$this->assertEquals(array(), json_decode($body, true));
247258
}
248-
$rawBody = "{}";
249-
250-
$rawResponse = "$rawHeaders\r\n$rawBody";
251-
list($headers, $body) = $io->parseHttpResponse($rawResponse, $headersSize);
252-
$this->assertEquals(1, sizeof($headers));
253-
$this->assertEquals(array(), json_decode($body, true));
254259
}
255260

256261
public function processEntityRequest($io, $client)

0 commit comments

Comments
 (0)