/** * @test */ public function createCookieFromRawSetsHttpOnlyIfPresent() { $cookie = Cookie::createFromRawSetCookieHeader('ckName=someValue; HttpOnly; more=nothing'); $this->assertTrue($cookie->isHttpOnly()); }
/** * Creates a response from the given raw, that is plain text, HTTP response. * * @param string $rawResponse * @param \TYPO3\Flow\Http\Response $parentResponse Parent response, if called recursively * * @throws \InvalidArgumentException * @return \TYPO3\Flow\Http\Response */ public static function createFromRaw($rawResponse, Response $parentResponse = NULL) { $response = new static($parentResponse); $lines = explode(chr(10), $rawResponse); $firstLine = array_shift($lines); if (substr($firstLine, 0, 5) !== 'HTTP/') { throw new \InvalidArgumentException('The given raw HTTP message is not a valid response.', 1335175601); } list(, $statusCode, $statusMessage) = explode(' ', $firstLine, 3); $response->setStatus((int) $statusCode, trim($statusMessage)); $parsingHeader = TRUE; $contentLines = array(); $headers = new Headers(); foreach ($lines as $line) { if ($parsingHeader) { if (trim($line) === '') { $parsingHeader = FALSE; continue; } $fieldName = trim(substr($line, 0, strpos($line, ':'))); $fieldValue = trim(substr($line, strlen($fieldName) + 1)); if (strtoupper(substr($fieldName, 0, 10)) === 'SET-COOKIE') { $cookie = Cookie::createFromRawSetCookieHeader($fieldValue); if ($cookie !== NULL) { $headers->setCookie($cookie); } } else { $headers->set($fieldName, $fieldValue, FALSE); } } else { $contentLines[] = $line; } } $content = implode(chr(10), $contentLines); $response->setHeaders($headers); $response->setContent($content); return $response; }