/** * * @expectedException HTTP_Request2_MessageException */ public function testParseStatusLine() { $response = new HTTP_Request2_Response('HTTP/1.1 200 OK'); $this->assertEquals('1.1', $response->getVersion()); $this->assertEquals(200, $response->getStatus()); $this->assertEquals('OK', $response->getReasonPhrase()); $response2 = new HTTP_Request2_Response('HTTP/1.2 222 Nishtyak!'); $this->assertEquals('1.2', $response2->getVersion()); $this->assertEquals(222, $response2->getStatus()); $this->assertEquals('Nishtyak!', $response2->getReasonPhrase()); $response3 = new HTTP_Request2_Response('Invalid status line'); }
public function testParseStatusLine() { $response = new HTTP_Request2_Response('HTTP/1.1 200 OK'); $this->assertEquals('1.1', $response->getVersion()); $this->assertEquals(200, $response->getStatus()); $this->assertEquals('OK', $response->getReasonPhrase()); $response2 = new HTTP_Request2_Response('HTTP/1.2 222 Nishtyak!'); $this->assertEquals('1.2', $response2->getVersion()); $this->assertEquals(222, $response2->getStatus()); $this->assertEquals('Nishtyak!', $response2->getReasonPhrase()); try { $response3 = new HTTP_Request2_Response('Invalid status line'); } catch (HTTP_Request2_Exception $e) { return; } $this->fail('Expected HTTP_Request2_Exception was not thrown'); }
/** * Checks whether current connection may be reused or should be closed * * @param boolean whether connection could be persistent * in the first place * @param HTTP_Request2_Response response object to check * @return boolean */ protected function canKeepAlive($requestKeepAlive, HTTP_Request2_Response $response) { // Do not close socket on successful CONNECT request if (HTTP_Request2::METHOD_CONNECT == $this->request->getMethod() && 200 <= $response->getStatus() && 300 > $response->getStatus()) { return true; } $lengthKnown = 'chunked' == strtolower($response->getHeader('transfer-encoding')) || null !== $response->getHeader('content-length') || HTTP_Request2::METHOD_HEAD == $this->request->getMethod() || in_array($response->getStatus(), array(204, 304)); $persistent = 'keep-alive' == strtolower($response->getHeader('connection')) || null === $response->getHeader('connection') && '1.1' == $response->getVersion(); return $requestKeepAlive && $lengthKnown && $persistent; }