]> source.dussan.org Git - nextcloud-server.git/commitdiff
set content-type on ocs exceptions
authorThomas Müller <thomas.mueller@tmit.eu>
Tue, 11 Mar 2014 23:35:19 +0000 (00:35 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 11 Mar 2014 23:35:19 +0000 (00:35 +0100)
lib/private/api.php
ocs/v1.php

index 1537cc11dd0fd7eba1373cade475c1d4f111ac1f..ccaccda97be4c3cb7ecd935057ca6e5cb1564179 100644 (file)
@@ -116,9 +116,7 @@ class OC_API {
                                );
                }
                $response = self::mergeResponses($responses);
-               $formats = array('json', 'xml');
-
-               $format = !empty($_GET['format']) && in_array($_GET['format'], $formats) ? $_GET['format'] : 'xml';
+               $format = self::requestedFormat();
                if (self::$logoutRequired) {
                        OC_User::logout();
                }
@@ -350,4 +348,33 @@ class OC_API {
                }
        }
 
+       /**
+        * @return string
+        */
+       public static function requestedFormat() {
+               $formats = array('json', 'xml');
+
+               $format = !empty($_GET['format']) && in_array($_GET['format'], $formats) ? $_GET['format'] : 'xml';
+               return $format;
+       }
+
+       /**
+        * Based on the requested format the response content type is set
+        */
+       public static function setOcsContentType() {
+               $format = \OC_API::requestedFormat();
+               if ($format === 'xml') {
+                       header('Content-type: text/xml; charset=UTF-8');
+                       return;
+               }
+
+               if ($format === 'json') {
+                       header('Content-Type: application/json; charset=utf-8');
+                       return;
+               }
+
+               header('Content-Type: application/octet-stream; charset=utf-8');
+       }
+
+
 }
index 1c7d1c8976824efe44dea0abe24a9f041b7df201..9d84f482ef7a7653316daf3d19bbf9f3206d9fcf 100644 (file)
@@ -28,8 +28,11 @@ use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 try {
        OC::getRouter()->match('/ocs'.OC_Request::getRawPathInfo());
 } catch (ResourceNotFoundException $e) {
+       OC_API::setContentType();
        OC_OCS::notFound();
 } catch (MethodNotAllowedException $e) {
+       setOcsContentType();
+       OC_API::setContentType();
        OC_Response::setStatus(405);
 }