From 1002281dae6650684ba06d21abeba8ff8ba070d9 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 11 Jun 2014 00:54:25 +0200 Subject: handle http accept headers more gracefully --- lib/private/appframework/http/dispatcher.php | 29 +++++++++++----------------- 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'lib/private/appframework') diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php index 442e33ee726..c5ec345489a 100644 --- a/lib/private/appframework/http/dispatcher.php +++ b/lib/private/appframework/http/dispatcher.php @@ -75,7 +75,7 @@ class Dispatcher { $out = array(null, array(), null); try { - // prefill reflector with everything thats needed for the + // prefill reflector with everything thats needed for the // middlewares $this->reflector->reflect($controller, $methodName); @@ -132,14 +132,14 @@ class Dispatcher { // it to the type annotated in the @param annotation $value = $this->request->getParam($param, $default); $type = $this->reflector->getType($param); - - // if this is submitted using GET or a POST form, 'false' should be + + // if this is submitted using GET or a POST form, 'false' should be // converted to false if(($type === 'bool' || $type === 'boolean') && - $value === 'false' && + $value === 'false' && ( $this->request->method === 'GET' || - strpos($this->request->getHeader('Content-Type'), + strpos($this->request->getHeader('Content-Type'), 'application/x-www-form-urlencoded') !== false ) ) { @@ -148,7 +148,7 @@ class Dispatcher { } elseif(in_array($type, $types)) { settype($value, $type); } - + $arguments[] = $value; } @@ -156,22 +156,15 @@ class Dispatcher { // format response if not of type response if(!($response instanceof Response)) { - + // get format from the url format or request format parameter $format = $this->request->getParam('format'); - + // if none is given try the first Accept header if($format === null) { - $header = $this->request->getHeader('Accept'); - $formats = explode(',', $header); - - if($header !== null && count($formats) > 0) { - $accept = strtolower(trim($formats[0])); - $format = str_replace('application/', '', $accept); - } else { - $format = 'json'; - } - } + $headers = $this->request->getHeader('Accept'); + $format = $controller->getResponderByHTTPHeader($headers); + } $response = $controller->buildResponse($response, $format); } -- cgit v1.2.3 From 0252d39bb6b1e659b03840c5a1a599d90a92c291 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 11 Jun 2014 00:57:00 +0200 Subject: fix indention --- lib/private/appframework/http/dispatcher.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/private/appframework') diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php index c5ec345489a..fa8d3c47a8b 100644 --- a/lib/private/appframework/http/dispatcher.php +++ b/lib/private/appframework/http/dispatcher.php @@ -52,9 +52,9 @@ class Dispatcher { * @param IRequest $request the incoming request */ public function __construct(Http $protocol, - MiddlewareDispatcher $middlewareDispatcher, - ControllerMethodReflector $reflector, - IRequest $request) { + MiddlewareDispatcher $middlewareDispatcher, + ControllerMethodReflector $reflector, + IRequest $request) { $this->protocol = $protocol; $this->middlewareDispatcher = $middlewareDispatcher; $this->reflector = $reflector; @@ -162,9 +162,9 @@ class Dispatcher { // if none is given try the first Accept header if($format === null) { - $headers = $this->request->getHeader('Accept'); - $format = $controller->getResponderByHTTPHeader($headers); - } + $headers = $this->request->getHeader('Accept'); + $format = $controller->getResponderByHTTPHeader($headers); + } $response = $controller->buildResponse($response, $format); } -- cgit v1.2.3