[Pkg-owncloud-commits] [owncloud] 32/223: also handle lowercase headers

David Prévot taffit at moszumanska.debian.org
Sun Jun 22 01:54:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 93169eca1e754bf9a91599f7a7a84e461cfd974f
Author: Bernhard Posselt <dev at bernhard-posselt.com>
Date:   Wed Jun 11 01:20:09 2014 +0200

    also handle lowercase headers
---
 lib/public/appframework/controller.php             | 44 +++++++++++-----------
 .../lib/appframework/controller/ControllerTest.php |  9 +++++
 2 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/lib/public/appframework/controller.php b/lib/public/appframework/controller.php
index b3bff5e..b22eb73 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);
-
-        // 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';
+	}
 
 
 	/**
diff --git a/tests/lib/appframework/controller/ControllerTest.php b/tests/lib/appframework/controller/ControllerTest.php
index 1a09925..e97ec54 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);
+	}
+
+
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list