Prefer apache_request_headers when reading request headers.
Apache does not pass the Authorization header through to PHP as $_SERVER["HTTP_AUTHORIZATION"], so reading from $_SERVER is not viable with Apache.
This commit is contained in:
parent
46f11b2b9b
commit
512897effd
|
|
@ -1,5 +1,3 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="5.3.0" />
|
||||
</project>
|
||||
<project version="4" />
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,11 @@ class Request extends Message implements RequestInterface
|
|||
*/
|
||||
public static function getRequestHeaders()
|
||||
{
|
||||
// Prefer apache_request_headers is available.
|
||||
if (function_exists('apache_request_headers')) {
|
||||
return apache_request_headers();
|
||||
}
|
||||
|
||||
// http://www.php.net/manual/en/function.getallheaders.php#84262
|
||||
$headers = array();
|
||||
foreach ($_SERVER as $name => $value) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
// This file must be in the global namespace to add apache_request_headers
|
||||
|
||||
use pjdietz\WellRESTed\Request;
|
||||
|
||||
class ApacheRequestHeadersTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testReadApacheRequestHeaders()
|
||||
{
|
||||
if (!function_exists('apache_request_headers')) {
|
||||
function apache_request_headers() {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
$headers = Request::getRequestHeaders();
|
||||
$this->assertNotNull($headers);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue