Skip to content
Permalink
Browse files

FIX HTTP Headers are case insensitive

  • Loading branch information...
dhensby committed Sep 13, 2017
1 parent c7c0ee3 commit 919831365846995e42b89de3fbb0920371f36bf0
Showing with 19 additions and 14 deletions.
  1. +11 −9 src/Control/HTTPRequest.php
  2. +8 −5 src/Control/HTTPResponse.php
@@ -349,12 +349,14 @@ public function isMedia()
/**
* Add a HTTP header to the response, replacing any header of the same name.
*
* @param string $header Example: "Content-Type"
* @param string $header Example: "content-type"
* @param string $value Example: "text/xml"
*/
public function addHeader($header, $value)
{
$header = strtolower($header);
$this->headers[$header] = $value;
return $this;
}
/**
@@ -373,6 +375,7 @@ public function getHeaders()
*/
public function getHeader($header)
{
$header = strtolower($header);
return (isset($this->headers[$header])) ? $this->headers[$header] : null;
}
@@ -385,9 +388,8 @@ public function getHeader($header)
*/
public function removeHeader($header)
{
if (isset($this->headers[$header])) {
unset($this->headers[$header]);
}
$header = strtolower($header);
unset($this->headers[$header]);
return $this;
}
@@ -428,7 +430,7 @@ public function isAjax()
{
return (
$this->requestVar('ajax') ||
$this->getHeader('X-Requested-With') === "XMLHttpRequest"
$this->getHeader('x-requested-with') === "XMLHttpRequest"
);
}
@@ -483,10 +485,10 @@ public static function send_file($fileData, $fileName, $mimeType = null)
$mimeType = HTTP::get_mime_type($fileName);
}
$response = new HTTPResponse($fileData);
$response->addHeader("Content-Type", "$mimeType; name=\"" . addslashes($fileName) . "\"");
$response->addHeader("content-type", "$mimeType; name=\"" . addslashes($fileName) . "\"");
// Note a IE-only fix that inspects this header in HTTP::add_cache_headers().
$response->addHeader("Content-Disposition", "attachment; filename=\"" . addslashes($fileName) . "\"");
$response->addHeader("Content-Length", strlen($fileData));
$response->addHeader("content-disposition", "attachment; filename=\"" . addslashes($fileName) . "\"");
$response->addHeader("content-length", strlen($fileData));
return $response;
}
@@ -809,7 +811,7 @@ public function setIP($ip)
public function getAcceptMimetypes($includeQuality = false)
{
$mimetypes = array();
$mimetypesWithQuality = preg_split('#\s*,\s*#', $this->getHeader('Accept'));
$mimetypesWithQuality = preg_split('#\s*,\s*#', $this->getHeader('accept'));
foreach ($mimetypesWithQuality as $mimetypeWithQuality) {
$mimetypes[] = ($includeQuality) ? $mimetypeWithQuality : preg_replace('/;.*/', '', $mimetypeWithQuality);
}
@@ -85,13 +85,13 @@ class HTTPResponse
protected $statusDescription = "OK";
/**
* HTTP Headers like "Content-Type: text/xml"
* HTTP Headers like "content-type: text/xml"
*
* @see http://en.wikipedia.org/wiki/List_of_HTTP_headers
* @var array
*/
protected $headers = array(
"Content-Type" => "text/html; charset=utf-8",
"content-type" => "text/html; charset=utf-8",
);
/**
@@ -200,12 +200,13 @@ public function getBody()
/**
* Add a HTTP header to the response, replacing any header of the same name.
*
* @param string $header Example: "Content-Type"
* @param string $header Example: "content-type"
* @param string $value Example: "text/xml"
* @return $this
*/
public function addHeader($header, $value)
{
$header = strtolower($header);
$this->headers[$header] = $value;
return $this;
}
@@ -218,6 +219,7 @@ public function addHeader($header, $value)
*/
public function getHeader($header)
{
$header = strtolower($header);
if (isset($this->headers[$header])) {
return $this->headers[$header];
}
@@ -241,6 +243,7 @@ public function getHeaders()
*/
public function removeHeader($header)
{
strtolower($header);
unset($this->headers[$header]);
return $this;
}
@@ -257,7 +260,7 @@ public function redirect($dest, $code = 302)
$code = 302;
}
$this->setStatusCode($code);
$this->addHeader('Location', $dest);
$this->addHeader('location', $dest);
return $this;
}
@@ -285,7 +288,7 @@ public function output()
protected function htmlRedirect()
{
$headersSent = headers_sent($file, $line);
$location = $this->getHeader('Location');
$location = $this->getHeader('location');
$url = Director::absoluteURL($location);
$urlATT = Convert::raw2htmlatt($url);
$urlJS = Convert::raw2js($url);

0 comments on commit 9198313

Please sign in to comment.
You can’t perform that action at this time.