예제 #1
0
 public function testParseHttpResponseBody()
 {
     $io = new apiCurlIO();
     $rawHeaders = "HTTP/1.1 200 OK\r\n" . "Expires: Sun, 22 Jan 2012 09:00:56 GMT\r\n" . "Date: Sun, 22 Jan 2012 09:00:56 GMT\r\n" . "Content-Type: application/json; charset=UTF-8\r\n";
     $size = strlen($rawHeaders);
     $rawBody = "{}";
     $rawResponse = "{$rawHeaders}\r\n{$rawBody}";
     list($headers, $body) = $io->parseHttpResponseBody($rawResponse, $size);
     $this->assertEquals(3, sizeof($headers));
     $this->assertEquals(array(), json_decode($body, true));
     // Test empty bodies.
     $rawResponse = $rawHeaders . "\r\n";
     list($headers, $body) = $io->parseHttpResponseBody($rawResponse, $size);
     $this->assertEquals(3, sizeof($headers));
     $this->assertEquals(null, json_decode($body, true));
     // Test transforms from proxies.
     $rawHeaders = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n";
     $size = strlen($rawHeaders);
     $rawBody = "{}";
     $rawResponse = apiCurlIO::CONNECTION_ESTABLISHED . "{$rawHeaders}\r\n{$rawBody}";
     list($headers, $body) = $io->parseHttpResponseBody($rawResponse, $size);
     $this->assertEquals(1, sizeof($headers));
     $this->assertEquals(array(), json_decode($body, true));
 }