Exception
2 years ago
File
1 year ago
RateLimiter
2 years ago
Session
1 year ago
Test
1 year ago
AcceptHeader.php
1 year ago
AcceptHeaderItem.php
2 years ago
BinaryFileResponse.php
1 year ago
Cookie.php
1 year ago
ExpressionRequestMatcher.php
2 years ago
FileBag.php
1 year ago
HeaderBag.php
1 year ago
HeaderUtils.php
1 year ago
InputBag.php
2 years ago
IpUtils.php
1 year ago
JsonResponse.php
1 year ago
LICENSE
2 years ago
ParameterBag.php
1 year ago
README.md
2 years ago
RedirectResponse.php
2 years ago
Request.php
1 year ago
RequestMatcher.php
1 year ago
RequestMatcherInterface.php
2 years ago
RequestStack.php
2 years ago
Response.php
1 year ago
ResponseHeaderBag.php
1 year ago
ServerBag.php
1 year ago
StreamedResponse.php
1 year ago
UrlHelper.php
2 years ago
ServerBag.php
93 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace Matomo\Dependencies\Symfony\Component\HttpFoundation; |
| 12 | |
| 13 | /** |
| 14 | * ServerBag is a container for HTTP headers from the $_SERVER variable. |
| 15 | * |
| 16 | * @author Fabien Potencier <fabien@symfony.com> |
| 17 | * @author Bulat Shakirzyanov <mallluhuct@gmail.com> |
| 18 | * @author Robert Kiss <kepten@gmail.com> |
| 19 | */ |
| 20 | class ServerBag extends ParameterBag |
| 21 | { |
| 22 | /** |
| 23 | * Gets the HTTP headers. |
| 24 | * |
| 25 | * @return array |
| 26 | */ |
| 27 | public function getHeaders() |
| 28 | { |
| 29 | $headers = []; |
| 30 | foreach ($this->parameters as $key => $value) { |
| 31 | if (str_starts_with($key, 'HTTP_')) { |
| 32 | $headers[substr($key, 5)] = $value; |
| 33 | } elseif (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], \true) && '' !== $value) { |
| 34 | $headers[$key] = $value; |
| 35 | } |
| 36 | } |
| 37 | if (isset($this->parameters['PHP_AUTH_USER'])) { |
| 38 | $headers['PHP_AUTH_USER'] = $this->parameters['PHP_AUTH_USER']; |
| 39 | $headers['PHP_AUTH_PW'] = $this->parameters['PHP_AUTH_PW'] ?? ''; |
| 40 | } else { |
| 41 | /* |
| 42 | * php-cgi under Apache does not pass HTTP Basic user/pass to PHP by default |
| 43 | * For this workaround to work, add these lines to your .htaccess file: |
| 44 | * RewriteCond %{HTTP:Authorization} .+ |
| 45 | * RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0] |
| 46 | * |
| 47 | * A sample .htaccess file: |
| 48 | * RewriteEngine On |
| 49 | * RewriteCond %{HTTP:Authorization} .+ |
| 50 | * RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0] |
| 51 | * RewriteCond %{REQUEST_FILENAME} !-f |
| 52 | * RewriteRule ^(.*)$ index.php [QSA,L] |
| 53 | */ |
| 54 | $authorizationHeader = null; |
| 55 | if (isset($this->parameters['HTTP_AUTHORIZATION'])) { |
| 56 | $authorizationHeader = $this->parameters['HTTP_AUTHORIZATION']; |
| 57 | } elseif (isset($this->parameters['REDIRECT_HTTP_AUTHORIZATION'])) { |
| 58 | $authorizationHeader = $this->parameters['REDIRECT_HTTP_AUTHORIZATION']; |
| 59 | } |
| 60 | if (null !== $authorizationHeader) { |
| 61 | if (0 === stripos($authorizationHeader, 'basic ')) { |
| 62 | // Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic |
| 63 | $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)), 2); |
| 64 | if (2 == \count($exploded)) { |
| 65 | [$headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']] = $exploded; |
| 66 | } |
| 67 | } elseif (empty($this->parameters['PHP_AUTH_DIGEST']) && 0 === stripos($authorizationHeader, 'digest ')) { |
| 68 | // In some circumstances PHP_AUTH_DIGEST needs to be set |
| 69 | $headers['PHP_AUTH_DIGEST'] = $authorizationHeader; |
| 70 | $this->parameters['PHP_AUTH_DIGEST'] = $authorizationHeader; |
| 71 | } elseif (0 === stripos($authorizationHeader, 'bearer ')) { |
| 72 | /* |
| 73 | * XXX: Since there is no PHP_AUTH_BEARER in PHP predefined variables, |
| 74 | * I'll just set $headers['AUTHORIZATION'] here. |
| 75 | * https://php.net/reserved.variables.server |
| 76 | */ |
| 77 | $headers['AUTHORIZATION'] = $authorizationHeader; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | if (isset($headers['AUTHORIZATION'])) { |
| 82 | return $headers; |
| 83 | } |
| 84 | // PHP_AUTH_USER/PHP_AUTH_PW |
| 85 | if (isset($headers['PHP_AUTH_USER'])) { |
| 86 | $headers['AUTHORIZATION'] = 'Basic ' . base64_encode($headers['PHP_AUTH_USER'] . ':' . ($headers['PHP_AUTH_PW'] ?? '')); |
| 87 | } elseif (isset($headers['PHP_AUTH_DIGEST'])) { |
| 88 | $headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST']; |
| 89 | } |
| 90 | return $headers; |
| 91 | } |
| 92 | } |
| 93 |