/**
  * 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;
 }
 /**
  * Sets the given cookie to in the headers of this message.
  *
  * This is a shortcut for $message->getHeaders()->setCookie($cookie);
  *
  * @param \TYPO3\Flow\Http\Cookie $cookie The cookie to set
  * @return void
  * @api
  */
 public function setCookie(Cookie $cookie)
 {
     $this->headers->setCookie($cookie);
 }
 /**
  * @test
  */
 public function getCookiesReturnsAllCookies()
 {
     $cookies = array('Dark-Chocolate-Chip' => new Cookie('Dark-Chocolate-Chip'), 'Pecan-Maple-Choc' => new Cookie('Pecan-Maple-Choc'), 'Coffee-Fudge-Mess' => new Cookie('Coffee-Fudge-Mess'));
     $headers = new Headers();
     $headers->setCookie($cookies['Dark-Chocolate-Chip']);
     $headers->setCookie($cookies['Pecan-Maple-Choc']);
     $headers->setCookie($cookies['Coffee-Fudge-Mess']);
     $headers->eatCookie('Coffee-Fudge-Mess');
     unset($cookies['Coffee-Fudge-Mess']);
     $this->assertEquals($cookies, $headers->getCookies());
 }