Merge pull request 1661 from 'sime/fallback-content-type' to master.

This commit is contained in:
mark_story 2013-10-01 15:11:57 -04:00
commit b1ea2d3a2b
2 changed files with 13 additions and 0 deletions

View file

@ -518,6 +518,9 @@ class RequestHandlerComponent extends Component {
} }
list($contentType) = explode(';', env('CONTENT_TYPE')); list($contentType) = explode(';', env('CONTENT_TYPE'));
if ($contentType === '') {
list($contentType) = explode(';', CakeRequest::header('CONTENT_TYPE'));
}
if (!$type) { if (!$type) {
return $this->mapType($contentType); return $this->mapType($contentType);
} }

View file

@ -603,6 +603,16 @@ class RequestHandlerComponentTest extends CakeTestCase {
$result = $this->RequestHandler->requestedWith(array('rss', 'atom')); $result = $this->RequestHandler->requestedWith(array('rss', 'atom'));
$this->assertFalse($result); $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,*/*'; $_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
$this->assertTrue($this->RequestHandler->isXml()); $this->assertTrue($this->RequestHandler->isXml());
$this->assertFalse($this->RequestHandler->isAtom()); $this->assertFalse($this->RequestHandler->isAtom());