Skip to content

Commit 1afb900

Browse files
author
Ian Barber
committed
Fix handling for 204 with no content
1 parent e5d1d21 commit 1afb900

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

examples/batch.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
************************************************/
3636
$client = new Google_Client();
3737
$client->setApplicationName("Client_Library_Examples");
38-
$apiKey = "<YOUR_API_KEY>";
38+
$apiKey = "<YOUR_API_KEY>"; // Change to your API key.
39+
// Warn if the API key isn't changed!
3940
if ($apiKey == '<YOUR_API_KEY>') {
4041
echo missingApiKeyWarning();
4142
} else {

examples/simple-query.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
************************************************/
3838
$client = new Google_Client();
3939
$client->setApplicationName("Client_Library_Examples");
40-
$apiKey = "<YOUR_API_KEY>";
40+
$apiKey = "<YOUR_API_KEY>"; // Change this line.
41+
// Warn if the API key isn't changed.
4142
if ($apiKey == '<YOUR_API_KEY>') {
4243
echo missingApiKeyWarning();
4344
}

src/Google/IO/Abstract.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ public function parseHttpResponse($respData, $headerSize)
271271
$responseBody = substr($respData, $headerSize);
272272
$responseHeaders = substr($respData, 0, $headerSize);
273273
} else {
274-
list($responseHeaders, $responseBody) = explode("\r\n\r\n", $respData, 2);
274+
$responseSegments = explode("\r\n\r\n", $respData, 2);
275+
$responseHeaders = $responseSegments[0];
276+
$responseBody = isset($responseSegments[1]) ? $responseSegments[1] :
277+
null;
275278
}
276279

277280
$responseHeaders = $this->getHttpResponseHeaders($responseHeaders);

tests/general/IoTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ public function responseChecker($io)
236236
$this->assertEquals(3, sizeof($headers));
237237
$this->assertEquals(null, json_decode($body, true));
238238

239+
// Test no content.
240+
$rawerHeaders = "HTTP/1.1 204 No Content\r\n"
241+
. "Date: Fri, 19 Sep 2014 15:52:14 GMT";
242+
list($headers, $body) = $io->parseHttpResponse($rawerHeaders, 0);
243+
$this->assertEquals(1, sizeof($headers));
244+
$this->assertEquals(null, json_decode($body, true));
245+
239246
// Test transforms from proxies.
240247
$connection_established_headers = array(
241248
"HTTP/1.0 200 Connection established\r\n\r\n",

0 commit comments

Comments
 (0)