From 93169eca1e754bf9a91599f7a7a84e461cfd974f Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 11 Jun 2014 01:20:09 +0200 Subject: [PATCH] also handle lowercase headers --- lib/public/appframework/controller.php | 36 +++++++++---------- .../controller/ControllerTest.php | 9 +++++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/public/appframework/controller.php b/lib/public/appframework/controller.php index b3bff5e05f..b22eb73343 100644 --- a/lib/public/appframework/controller.php +++ b/lib/public/appframework/controller.php @@ -70,28 +70,28 @@ abstract class Controller { } - /** - * Parses an HTTP accept header and returns the supported responder type - * @param string $acceptHeader - * @return string the responder type - */ - public function getResponderByHTTPHeader($acceptHeader) { - $headers = explode(',', $acceptHeader); + /** + * Parses an HTTP accept header and returns the supported responder type + * @param string $acceptHeader + * @return string the responder type + */ + public function getResponderByHTTPHeader($acceptHeader) { + $headers = explode(',', $acceptHeader); - // return the first matching responder - foreach ($headers as $header) { - $header = trim($header); + // return the first matching responder + foreach ($headers as $header) { + $header = strtolower(trim($header)); - $responder = str_replace('application/', '', $header); + $responder = str_replace('application/', '', $header); - if (array_key_exists($responder, $this->responders)) { - return $responder; - } - } + if (array_key_exists($responder, $this->responders)) { + return $responder; + } + } - // no matching header defaults to json - return 'json'; - } + // no matching header defaults to json + return 'json'; + } /** diff --git a/tests/lib/appframework/controller/ControllerTest.php b/tests/lib/appframework/controller/ControllerTest.php index 1a09925ef6..e97ec54893 100644 --- a/tests/lib/appframework/controller/ControllerTest.php +++ b/tests/lib/appframework/controller/ControllerTest.php @@ -185,4 +185,13 @@ class ControllerTest extends \PHPUnit_Framework_TestCase { } + public function testResponderAcceptHeaderParsedUpperCase() { + $responder = $this->controller->getResponderByHTTPHeader( + '*/*, apPlication/ToM, application/json' + ); + + $this->assertEquals('tom', $responder); + } + + }