]> source.dussan.org Git - nextcloud-server.git/commitdiff
also handle lowercase headers
authorBernhard Posselt <dev@bernhard-posselt.com>
Tue, 10 Jun 2014 23:20:09 +0000 (01:20 +0200)
committerBernhard Posselt <dev@bernhard-posselt.com>
Tue, 10 Jun 2014 23:20:09 +0000 (01:20 +0200)
lib/public/appframework/controller.php
tests/lib/appframework/controller/ControllerTest.php

index b3bff5e05f5124bdf4d77a2775f7de22daa04a50..b22eb73343ac8e45343556e391942d26e37995a1 100644 (file)
@@ -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';
+       }
 
 
        /**
index 1a09925ef697d4c98d73be085ee6ef5a65505ad3..e97ec548939d4b8307ef650fca78900230c0fdcc 100644 (file)
@@ -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);
+       }
+
+
 }