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:
PJ Dietz 2014-07-28 12:43:29 -04:00
parent 46f11b2b9b
commit 512897effd
3 changed files with 30 additions and 3 deletions

View File

@ -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" />

View File

@ -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) {

View File

@ -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);
}
}