getHeaders() public method

public getHeaders ( )
Beispiel #1
0
 /**
  * information about case sensitivity:
  * @link http://stackoverflow.com/questions/7718476/are-http-headers-content-type-c-case-sensitive
  * @return array
  */
 private function getHeaders()
 {
     $headers = [];
     foreach ($this->serverBag->getHeaders() as $key => $value) {
         $key = str_replace(' ', '-', str_replace('_', ' ', $key));
         $headers[] = '-H \'' . $key . ': ' . $value . '\'';
     }
     return $headers;
 }
Beispiel #2
0
 /**
  * Sets the parameters for this request.
  *
  * This method also re-initializes all properties.
  *
  * @param array  $query      The GET parameters
  * @param array  $request    The POST parameters
  * @param array  $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
  * @param array  $cookies    The COOKIE parameters
  * @param array  $files      The FILES parameters
  * @param array  $server     The SERVER parameters
  * @param string $content    The raw body data
  *
  * @api
  */
 public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
 {
     $this->request = new ParameterBag($request);
     $this->query = new ParameterBag($query);
     $this->attributes = new ParameterBag($attributes);
     $this->cookies = new ParameterBag($cookies);
     $this->files = new FileBag($files);
     $this->server = new ServerBag($server);
     $this->headers = new HeaderBag($this->server->getHeaders());
     $this->content = $content;
     $this->languages = null;
     $this->charsets = null;
     $this->acceptableContentTypes = null;
     $this->pathInfo = null;
     $this->requestUri = null;
     $this->baseUrl = null;
     $this->basePath = null;
     $this->method = null;
     $this->format = null;
 }
 public function testHttpPasswordIsOptional()
 {
     $bag = new ServerBag(array('PHP_AUTH_USER' => 'foo'));
     $this->assertEquals(array('AUTHORIZATION' => 'Basic ' . base64_encode('foo:')), $bag->getHeaders());
 }
Beispiel #4
0
 public function testOAuthBearerAuth()
 {
     $headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
     $bag = new ServerBag(array('HTTP_AUTHORIZATION' => $headerContent));
     $this->assertEquals(array('AUTHORIZATION' => $headerContent), $bag->getHeaders());
 }
Beispiel #5
0
 /**
  * @see https://github.com/symfony/symfony/issues/17345
  */
 public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet()
 {
     $headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
     $bag = new ServerBag(array('PHP_AUTH_USER' => 'foo', 'HTTP_AUTHORIZATION' => $headerContent));
     $this->assertEquals(array('AUTHORIZATION' => $headerContent, 'PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => ''), $bag->getHeaders());
 }
Beispiel #6
0
    public function testHttpBasicAuthWithPhpCgiEmptyPassword()
    {
        $bag = new ServerBag(array('HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:')));

        $this->assertEquals(array(
            'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),
            'PHP_AUTH_USER' => 'foo',
            'PHP_AUTH_PW' => ''
        ), $bag->getHeaders());
    }
 public function testShouldExtractHeadersFromServerArray()
 {
     $server = array('SOME_SERVER_VARIABLE' => 'value', 'SOME_SERVER_VARIABLE2' => 'value', 'ROOT' => 'value', 'HTTP_CONTENT_TYPE' => 'text/html', 'HTTP_CONTENT_LENGTH' => '0', 'HTTP_ETAG' => 'asdf');
     $bag = new ServerBag($server);
     $this->assertEquals(array('CONTENT_TYPE' => 'text/html', 'CONTENT_LENGTH' => '0', 'ETAG' => 'asdf'), $bag->getHeaders());
 }