Example #1
0
 /**
  * Constructor.
  *
  * @param string $baseUrl
  * @param string $basePath
  * @param array  $request
  * @param array  $server
  */
 public function __construct($baseUrl, $basePath, array $request = array(), array $server = array())
 {
     $this->baseUrl = $baseUrl;
     $this->basePath = $basePath;
     $this->attributes = new ParameterBag();
     $this->request = new ParameterBag($request ?: $_REQUEST);
     $this->server = new ServerBag($server ?: $_SERVER);
     $this->headers = new HeaderBag($this->server->getHeaders());
     // decode json content type
     if (stripos($this->headers->get('CONTENT_TYPE'), 'application/json') !== false) {
         if ($json = json_decode(@file_get_contents('php://input'), true)) {
             $this->request->add($json);
         }
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     parent::remove($key);
     if ('cache-control' === strtr(strtolower($key), '_', '-')) {
         $this->computedCacheControl = array();
     }
 }
Example #3
0
 private function parseHeader(HeaderBag $headerBag)
 {
     try {
         $vars = $this->consumeRegexp('/(' . self::TOKEN_HEADER_NAME . '): ?/');
         $headerName = $vars[1];
         $value = $this->consumeTo("\n");
         $this->consume("\n");
         while ($this->expects(" ") || $this->expects("\t")) {
             $value .= $this->consumeTo("\n");
             $this->consume("\n");
         }
         $headerBag->set($headerName, $value);
     } catch (\InvalidArgumentException $e) {
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * Parses an article from a string.
  */
 public static function parse(string $data) : self
 {
     $separator = strpos($data, "\r\n\r\n");
     if ($separator === false) {
         throw new FormatException('Invalid article format');
     }
     $headers = HeaderBag::parse(substr($data, 0, $separator + 2));
     $body = substr($data, $separator + 4);
     return new self($body, $headers);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     parent::remove($key);
     $uniqueKey = str_replace('_', '-', strtolower($key));
     unset($this->headerNames[$uniqueKey]);
     if ('cache-control' === $uniqueKey) {
         $this->computedCacheControl = array();
     }
 }
Example #6
0
 /**
  * Gets the HTTP method.
  *
  * @return string
  */
 public function getMethod()
 {
     $method = $this->server->get('REQUEST_METHOD', 'GET');
     $method = $this->headers->get('X-HTTP-Method-Override', $method);
     return strtoupper($method);
 }
 public function testCacheControlDirectiveOverrideWithReplace()
 {
     $bag = new HeaderBag(array('cache-control' => 'private, max-age=100'));
     $bag->replace(array('cache-control' => 'public, max-age=10'));
     $this->assertTrue($bag->hasCacheControlDirective('public'));
     $this->assertTrue($bag->getCacheControlDirective('public'));
     $this->assertTrue($bag->hasCacheControlDirective('max-age'));
     $this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
 }
Example #8
0
 /**
  * @param string $key
  */
 public function remove($key)
 {
     parent::remove($key);
     $uniqueKey = strtr(strtolower($key), '_', '-');
     unset($this->headerNames[$uniqueKey]);
     if ('cache-control' === $uniqueKey) {
         $this->computedCacheControl = [];
     }
 }
Example #9
0
 private function headerToBinary(HeaderBag $header) : string
 {
     $data = '';
     $data .= pack('n', $header->get('id'));
     $flags = 0x0;
     $flags = $flags << 1 | $header->get('qr');
     $flags = $flags << 4 | $header->get('opcode');
     $flags = $flags << 1 | $header->get('aa');
     $flags = $flags << 1 | $header->get('tc');
     $flags = $flags << 1 | $header->get('rd');
     $flags = $flags << 1 | $header->get('ra');
     $flags = $flags << 3 | $header->get('z');
     $flags = $flags << 4 | $header->get('rcode');
     $data .= pack('n', $flags);
     $data .= pack('n', $header->get('qdCount'));
     $data .= pack('n', $header->get('anCount'));
     $data .= pack('n', $header->get('nsCount'));
     $data .= pack('n', $header->get('arCount'));
     return $data;
 }
Example #10
0
 public function prepare()
 {
     $this->header->populateCounts($this);
 }
Example #11
0
 protected function prepareRequestUri()
 {
     $requestUri = '';
     if ($this->headers->has('X_ORIGINAL_URL')) {
         // IIS with Microsoft Rewrite Module
         $requestUri = $this->headers->get('X_ORIGINAL_URL');
         $this->headers->remove('X_ORIGINAL_URL');
         $this->server->remove('HTTP_X_ORIGINAL_URL');
         $this->server->remove('UNENCODED_URL');
         $this->server->remove('IIS_WasUrlRewritten');
     } elseif ($this->headers->has('X_REWRITE_URL')) {
         // IIS with ISAPI_Rewrite
         $requestUri = $this->headers->get('X_REWRITE_URL');
         $this->headers->remove('X_REWRITE_URL');
     } elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
         // IIS7 with URL Rewrite: make sure we get the unencoded URL (double slash problem)
         $requestUri = $this->server->get('UNENCODED_URL');
         $this->server->remove('UNENCODED_URL');
         $this->server->remove('IIS_WasUrlRewritten');
     } elseif ($this->server->has('REQUEST_URI')) {
         $requestUri = $this->server->get('REQUEST_URI');
         // HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path, only use URL path
         $schemeAndHttpHost = $this->getSchemeAndHttpHost();
         if (strpos($requestUri, $schemeAndHttpHost) === 0) {
             $requestUri = substr($requestUri, strlen($schemeAndHttpHost));
         }
     } elseif ($this->server->has('ORIG_PATH_INFO')) {
         // IIS 5.0, PHP as CGI
         $requestUri = $this->server->get('ORIG_PATH_INFO');
         if ('' != $this->server->get('QUERY_STRING')) {
             $requestUri .= '?' . $this->server->get('QUERY_STRING');
         }
         $this->server->remove('ORIG_PATH_INFO');
     }
     // normalize the request URI to ease creating sub-requests from this request
     $this->server->set('REQUEST_URI', $requestUri);
     return $requestUri;
 }