<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpFoundation; /** * ServerBag is a container for HTTP headers from the $_SERVER variable. * * @author Fabien Potencier <fabien@symfony.com> * @author Bulat Shakirzyanov <mallluhuct@gmail.com> * @author Robert Kiss <kepten@gmail.com> */ class ServerBag extends ParameterBag { /** * Gets the HTTP headers. * * @return array */ public function getHeaders() { $headers = array(); $contentHeaders = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true); foreach ($this->parameters as $key => $value) { if (0 === strpos($key, 'HTTP_')) { $headers[substr($key, 5)] = $value; } // CONTENT_* are not prefixed with HTTP_ elseif (isset($contentHeaders[$key])) { $headers[$key] = $value; } } if (isset($this->parameters['PHP_AUTH_USER'])) { $headers['PHP_AUTH_USER'] = $this->parameters['PHP_AUTH_USER']; $headers['PHP_AUTH_PW'] = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] : ''; } else { /* * php-cgi under Apache does not pass HTTP Basic user/pass to PHP by default * For this workaround to work, add these lines to your .htaccess file: * RewriteCond %{HTTP:Authorization} ^(.+)$ * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] * * A sample .htaccess file: * RewriteEngine On * RewriteCond %{HTTP:Authorization} ^(.+)$ * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] * RewriteCond %{REQUEST_FILENAME} !-f * RewriteRule ^(.*)$ app.php [QSA,L] */ $authorizationHeader = null; if (isset($this->parameters['HTTP_AUTHORIZATION'])) { $authorizationHeader = $this->parameters['HTTP_AUTHORIZATION']; } elseif (isset($this->parameters['REDIRECT_HTTP_AUTHORIZATION'])) { $authorizationHeader = $this->parameters['REDIRECT_HTTP_AUTHORIZATION']; } if (null !== $authorizationHeader) { if (0 === stripos($authorizationHeader, 'basic ')) { // Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)), 2); if (2 == count($exploded)) { list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded; } } elseif (empty($this->parameters['PHP_AUTH_DIGEST']) && (0 === stripos($authorizationHeader, 'digest '))) { // In some circumstances PHP_AUTH_DIGEST needs to be set $headers['PHP_AUTH_DIGEST'] = $authorizationHeader; $this->parameters['PHP_AUTH_DIGEST'] = $authorizationHeader; } elseif (0 === stripos($authorizationHeader, 'bearer ')) { /* * XXX: Since there is no PHP_AUTH_BEARER in PHP predefined variables, * I'll just set $headers['AUTHORIZATION'] here. * http://php.net/manual/en/reserved.variables.server.php */ $headers['AUTHORIZATION'] = $authorizationHeader; } } } if (isset($headers['AUTHORIZATION'])) { return $headers; } // PHP_AUTH_USER/PHP_AUTH_PW if (isset($headers['PHP_AUTH_USER'])) { $headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']); } elseif (isset($headers['PHP_AUTH_DIGEST'])) { $headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST']; } return $headers; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Exception | Folder | 0755 |
|
|
File | Folder | 0755 |
|
|
Session | Folder | 0755 |
|
|
Tests | Folder | 0755 |
|
|
.gitignore | File | 34 B | 0644 |
|
AcceptHeader.php | File | 3.46 KB | 0644 |
|
AcceptHeaderItem.php | File | 4.58 KB | 0644 |
|
ApacheRequest.php | File | 930 B | 0644 |
|
BinaryFileResponse.php | File | 11.65 KB | 0644 |
|
CHANGELOG.md | File | 8.21 KB | 0644 |
|
Cookie.php | File | 7.87 KB | 0644 |
|
ExpressionRequestMatcher.php | File | 1.33 KB | 0644 |
|
FileBag.php | File | 3.91 KB | 0644 |
|
HeaderBag.php | File | 8.79 KB | 0644 |
|
IpUtils.php | File | 4.63 KB | 0644 |
|
JsonResponse.php | File | 7.2 KB | 0644 |
|
LICENSE | File | 1.04 KB | 0644 |
|
ParameterBag.php | File | 5.86 KB | 0644 |
|
README.md | File | 537 B | 0644 |
|
RedirectResponse.php | File | 2.89 KB | 0644 |
|
Request.php | File | 69.28 KB | 0644 |
|
RequestMatcher.php | File | 4.35 KB | 0644 |
|
RequestMatcherInterface.php | File | 687 B | 0644 |
|
RequestStack.php | File | 2.3 KB | 0644 |
|
Response.php | File | 37.02 KB | 0644 |
|
ResponseHeaderBag.php | File | 9.8 KB | 0644 |
|
ServerBag.php | File | 4.14 KB | 0644 |
|
StreamedResponse.php | File | 3.24 KB | 0644 |
|
composer.json | File | 958 B | 0644 |
|
phpunit.xml.dist | File | 892 B | 0644 |
|