/**
  * Constructs a new Request object based on the given environment data.
  *
  * @param array $get Data similar to that which is typically provided by $_GET
  * @param array $post Data similar to that which is typically provided by $_POST
  * @param array $files Data similar to that which is typically provided by $_FILES
  * @param array $server Data similar to that which is typically provided by $_SERVER
  * @see create()
  * @see createFromEnvironment()
  * @api
  */
 public function __construct(array $get, array $post, array $files, array $server)
 {
     $this->headers = Headers::createFromServer($server);
     $method = isset($server['REQUEST_METHOD']) ? $server['REQUEST_METHOD'] : 'GET';
     if ($method === 'POST') {
         if (isset($post['__method'])) {
             $method = $post['__method'];
         } elseif (isset($server['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
             $method = $server['HTTP_X_HTTP_METHOD_OVERRIDE'];
         } elseif (isset($server['HTTP_X_HTTP_METHOD'])) {
             $method = $server['HTTP_X_HTTP_METHOD'];
         }
     }
     $this->setMethod($method);
     if ($this->headers->has('X-Forwarded-Proto')) {
         $protocol = $this->headers->get('X-Forwarded-Proto');
     } else {
         $protocol = isset($server['SSL_SESSION_ID']) || isset($server['HTTPS']) && ($server['HTTPS'] === 'on' || strcmp($server['HTTPS'], '1') === 0) ? 'https' : 'http';
     }
     $host = isset($server['HTTP_HOST']) ? $server['HTTP_HOST'] : 'localhost';
     $requestUri = isset($server['REQUEST_URI']) ? $server['REQUEST_URI'] : '/';
     if (substr($requestUri, 0, 10) === '/index.php') {
         $requestUri = '/' . ltrim(substr($requestUri, 10), '/');
     }
     $this->uri = new Uri($protocol . '://' . $host . $requestUri);
     if ($this->headers->has('X-Forwarded-Port')) {
         $this->uri->setPort($this->headers->get('X-Forwarded-Port'));
     } elseif ($this->headers->has('X-Forwarded-Proto')) {
         $this->uri->setPort($protocol === 'https' ? 443 : 80);
     } elseif (isset($server['SERVER_PORT'])) {
         $this->uri->setPort($server['SERVER_PORT']);
     }
     $this->server = $server;
     $this->arguments = $this->buildUnifiedArguments($get, $post, $files);
 }
 /**
  * Sends a prepared request and returns the respective response.
  *
  * @param \TYPO3\Flow\Http\Request $request
  * @return \TYPO3\Flow\Http\Response
  * @api
  */
 public function sendRequest(Request $request)
 {
     foreach ($this->automaticRequestHeaders->getAll() as $name => $values) {
         $request->setHeader($name, $values);
     }
     $this->lastRequest = $request;
     $this->lastResponse = $this->requestEngine->sendRequest($request);
     return $this->lastResponse;
 }
 /**
  * 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);
     $statusLine = array_shift($lines);
     if (substr($statusLine, 0, 5) !== 'HTTP/') {
         throw new \InvalidArgumentException('The given raw HTTP message is not a valid response.', 1335175601);
     }
     list($version, $statusCode, $reasonPhrase) = explode(' ', $statusLine, 3);
     $response->setVersion($version);
     $response->setStatus((int) $statusCode, trim($reasonPhrase));
     $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;
 }
 /**
  * Removes the specified cookie from the headers of this message, if it exists
  *
  * This is a shortcut for $message->getHeaders()->removeCookie($name);
  *
  * Note: This will remove the cookie object from this Headers container. If you
  *       intend to remove a cookie in the user agent (browser), you should call
  *       the cookie's expire() method and _not_ remove the cookie from the Headers
  *       container.
  *
  * @param string $name Name of the cookie to remove
  * @return void
  * @api
  */
 public function removeCookie($name)
 {
     $this->headers->removeCookie($name);
 }
 /**
  * @dataProvider cacheDirectivesAndExampleValues
  * @test
  */
 public function getCacheControlDirectiveReturnsTheSpecifiedDirectiveValueIfPresent($name, $value)
 {
     $headers = new Headers();
     $this->assertNull($headers->getCacheControlDirective($name));
     if ($value === TRUE) {
         $headers->setCacheControlDirective($name);
     } else {
         $headers->setCacheControlDirective($name, $value);
     }
     $this->assertEquals($value, $headers->getCacheControlDirective($name));
 }