/** * @param \PSX\Http\ResponseInterface $response * @return string */ public static function buildStatusLine(ResponseInterface $response) { $protocol = $response->getProtocolVersion(); $code = $response->getStatusCode(); $phrase = $response->getReasonPhrase(); if (empty($code)) { throw new Exception('Status code not set'); } $protocol = !empty($protocol) ? $protocol : 'HTTP/1.1'; if (empty($phrase) && isset(Http::$codes[$code])) { $phrase = Http::$codes[$code]; } if (empty($phrase)) { throw new Exception('No reason phrase provided'); } return $protocol . ' ' . $code . ' ' . $phrase; }
/** * Method which checks whether this is an valid response from an google * server */ protected function assertGoogleResponse(ResponseInterface $response) { $this->assertTrue($response->getStatusCode() >= 200 && $response->getStatusCode() < 400); // google server always response with an Server header $this->assertTrue($response->hasHeader('Server')); // we assume that the response should be more the 128 bytes $this->assertTrue(strlen((string) $response->getBody()) > 128); }
protected function sendStatusLine(ResponseInterface $response) { $scheme = $response->getProtocolVersion(); if (empty($scheme)) { $scheme = 'HTTP/1.1'; } $code = $response->getStatusCode(); if (!isset(Http::$codes[$code])) { $code = 200; } $this->sendHeader($scheme . ' ' . $code . ' ' . Http::$codes[$code]); }
public static function createResponse(ResponseInterface $response) { return new PsrResponse($response->getBody(), $response->getStatusCode(), $response->getHeaders()); }