Skip to content

Commit

Permalink
Merge pull request #2 from oat-sa/fix/case-sensitive-headers
Browse files Browse the repository at this point in the history
made headers case insensitive as per rfc7230
  • Loading branch information
Jérôme Bogaerts committed Mar 24, 2015
2 parents 558f482 + a960018 commit 33a5efa
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions core/Request.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,36 @@ class Request
protected $files;

public function __construct()
{
$this->parameters = array_merge($_GET, $_POST);
{
$this->parameters = array_merge($_GET, $_POST);
$this->rawParameters = $this->parameters;
$this->secureParameters();

if (function_exists('apache_request_headers')) {
// apache
$this->headers = apache_request_headers();
} else {
$this->headers = array();
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$this->headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
}
$this->secureParameters();

$this->files = $_FILES;

$this->method = $this->defineMethod();
if (function_exists('apache_request_headers')) {
// apache
$this->headers = array();
foreach (apache_request_headers() as $key => $value) {
$this->headers[strtolower($key)] = $value;
}
} else {
$this->headers = array();
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$this->headers[str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($name, 5))))] = $value;
}
}
}

$this->files = $_FILES;
$this->method = $this->defineMethod();
}

public function getParameter($name)
{
if (isset($this->headers[$name])) {
if (isset($this->headers[strtolower($name)])) {

$headerValues = explode(',', $this->headers[$name]);
return (count($headerValues)==1) ? ($this->headers[$name]) : $headerValues;
$headerValues = explode(',', $this->headers[strtolower($name)]);
return (count($headerValues)==1) ? reset($headerValues) : $headerValues;
}

//comapre $_POST[$string];
Expand All @@ -85,7 +85,7 @@ public function getParameter($name)

public function hasParameter($name)
{
return (isset($this->parameters[$name]) || isset($this->headers[$name]) || isset($this->files[$name]));
return (isset($this->parameters[$name]) || isset($this->headers[strtolower($name)]) || isset($this->files[$name]));
}

/**
Expand All @@ -107,7 +107,7 @@ public function getHeader($string)
{

//could be improved using the x- prefix
return isset($this->headers[$string]) ? $this->headers[$string] : false;
return isset($this->headers[strtolower($string)]) ? $this->headers[strtolower($string)] : false;
}

public function getHeaders()
Expand All @@ -117,7 +117,7 @@ public function getHeaders()

public function hasHeader($string)
{
return isset($this->headers[$string]);
return isset($this->headers[strtolower($string)]);
}

public function hasCookie($name)
Expand Down

0 comments on commit 33a5efa

Please sign in to comment.