Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-06-11 02:54:25 +0400
committerBernhard Posselt <dev@bernhard-posselt.com>2014-06-11 02:54:25 +0400
commit1002281dae6650684ba06d21abeba8ff8ba070d9 (patch)
treea817c33678ccf52526c15e0027f16836a293b968 /lib/public
parent077a542d59ea5c992ebb1b3ac0e6117f6289582c (diff)
handle http accept headers more gracefully
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/appframework/controller.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/public/appframework/controller.php b/lib/public/appframework/controller.php
index 79491902bfd..b3bff5e05f5 100644
--- a/lib/public/appframework/controller.php
+++ b/lib/public/appframework/controller.php
@@ -70,6 +70,30 @@ 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';
+ }
+
+
/**
* Registers a formatter for a type
* @param string $format