summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-03-12 10:19:40 +0100
committerVincent Petry <pvince81@owncloud.com>2014-03-12 10:19:40 +0100
commitce790119aea4a1cec2e8d8e8b493fec00b87693f (patch)
treef9fb969ea00f1b778459daf9f3947ff65db8325b /lib
parent942d5fcff3712da5f4bd085308a7a6e8fa93c44a (diff)
parent88f6dd7db1b3dc4cb68d3526a35108d196a5e5cb (diff)
downloadnextcloud-server-ce790119aea4a1cec2e8d8e8b493fec00b87693f.tar.gz
nextcloud-server-ce790119aea4a1cec2e8d8e8b493fec00b87693f.zip
Merge pull request #7683 from owncloud/proper-content-type-on-ocs-exceptions
set content-type on ocs exceptions
Diffstat (limited to 'lib')
-rw-r--r--lib/private/api.php33
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/private/api.php b/lib/private/api.php
index 1537cc11dd0..e8e54e375e9 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -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 setContentType() {
+ $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');
+ }
+
+
}