Skip to content
Snippets Groups Projects
Commit 93169eca authored by Bernhard Posselt's avatar Bernhard Posselt
Browse files

also handle lowercase headers

parent 0252d39b
No related branches found
No related tags found
No related merge requests found
......@@ -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);
// return the first matching responder
foreach ($headers as $header) {
$header = trim($header);
$responder = str_replace('application/', '', $header);
if (array_key_exists($responder, $this->responders)) {
return $responder;
}
}
// no matching header defaults to json
return 'json';
}
/**
* 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 = strtolower(trim($header));
$responder = str_replace('application/', '', $header);
if (array_key_exists($responder, $this->responders)) {
return $responder;
}
}
// no matching header defaults to json
return 'json';
}
/**
......
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment