diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-06-11 00:54:25 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-06-11 00:54:25 +0200 |
commit | 1002281dae6650684ba06d21abeba8ff8ba070d9 (patch) | |
tree | a817c33678ccf52526c15e0027f16836a293b968 /lib/public | |
parent | 077a542d59ea5c992ebb1b3ac0e6117f6289582c (diff) | |
download | nextcloud-server-1002281dae6650684ba06d21abeba8ff8ba070d9.tar.gz nextcloud-server-1002281dae6650684ba06d21abeba8ff8ba070d9.zip |
handle http accept headers more gracefully
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/appframework/controller.php | 24 |
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 |