public function testResponse() { $testBody = 'TestBodyWith<strong>special</strong>Chäräctörs'; $testHeader = HeadersParser::parse(['Header1' => 'Test Header']); $testStatus = 200; $testUri = new Uri('http://smoke.phmlabs.com'); $testRequest = new Request($testUri); $stream = fopen('data://text/plain,' . $testBody, 'r'); $response = new Response($stream, $testStatus, array(), ['request' => $testRequest]); $this->assertEquals($testBody, $response->getBody()); $this->assertEquals([], $response->getHeader('Test Header')); $this->assertEquals($testStatus, $response->getStatus()); $this->assertEmpty($response->getContentType()); $this->assertEquals($testRequest, $response->getRequest()); }
/** * Normalizes the headers. * * @param string|array $headers The headers. * @param boolean $associative TRUE if the headers should be an associative array else FALSE. * * @return array The normalized headers. */ public static function normalize($headers, $associative = true) { $normalizedHeaders = array(); if (!$associative) { $headers = self::normalize($headers); } foreach (HeadersParser::parse($headers) as $name => $value) { if (strpos($value, 'HTTP/') === 0) { continue; } list($name, $value) = explode(':', $value, 2); $name = self::normalizeHeaderName($name); $value = self::normalizeHeaderValue($value); if (!$associative) { $normalizedHeaders[] = $name . ': ' . $value; } else { $normalizedHeaders[$name] = isset($normalizedHeaders[$name]) ? $normalizedHeaders[$name] . ', ' . $value : $value; } } return $normalizedHeaders; }
/** * Extracts the status line. * * @param array|string $headers The headers. * * @return string The extracted status line. */ public static function extract($headers) { $headers = HeadersParser::parse($headers); return $headers[0]; }