Permalink
Browse files

Do not assume CONTENT_TYPE is available.

In some server environments notably the CLI server, _SERVER['CONTENT_TYPE'] is not available.
In these cases, fall back to the HTTP_CONTENT_TYPE header.

Refs #GH-1661
  • Loading branch information...
1 parent ad1b806 commit c998888fe71248512b40c3d6213c019619a4a33e @sime sime committed with markstory Sep 20, 2013
@@ -518,6 +518,9 @@ public function requestedWith($type = null) {
}
list($contentType) = explode(';', env('CONTENT_TYPE'));
+ if ($contentType === '') {
+ list($contentType) = explode(';', CakeRequest::header('CONTENT_TYPE'));
+ }
if (!$type) {
return $this->mapType($contentType);
}
@@ -603,6 +603,16 @@ public function testRequestContentTypes() {
$result = $this->RequestHandler->requestedWith(array('rss', 'atom'));
$this->assertFalse($result);
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ unset($_SERVER['CONTENT_TYPE']);
+ $_SERVER['HTTP_CONTENT_TYPE'] = 'application/json';
+
+ $result = $this->RequestHandler->requestedWith(array('json', 'xml'));
+ $this->assertEquals('json', $result);
+
+ $result = $this->RequestHandler->requestedWith(array('rss', 'atom'));
+ $this->assertFalse($result);
+
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
$this->assertTrue($this->RequestHandler->isXml());
$this->assertFalse($this->RequestHandler->isAtom());

0 comments on commit c998888

Please sign in to comment.