From 743addd1e317c760e8b1e4ad7dc149476e4ad282 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 12 Mar 2014 00:35:19 +0100 Subject: set content-type on ocs exceptions --- lib/private/api.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/private/api.php b/lib/private/api.php index 1537cc11dd0..ccaccda97be 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 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'); + } + + } -- cgit v1.2.3 From 88f6dd7db1b3dc4cb68d3526a35108d196a5e5cb Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 12 Mar 2014 10:00:22 +0100 Subject: fixing method names --- lib/private/api.php | 2 +- ocs/v1.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/private/api.php b/lib/private/api.php index ccaccda97be..e8e54e375e9 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -361,7 +361,7 @@ class OC_API { /** * Based on the requested format the response content type is set */ - public static function setOcsContentType() { + public static function setContentType() { $format = \OC_API::requestedFormat(); if ($format === 'xml') { header('Content-type: text/xml; charset=UTF-8'); diff --git a/ocs/v1.php b/ocs/v1.php index 9d84f482ef7..4cbc857bbcf 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -31,7 +31,6 @@ try { OC_API::setContentType(); OC_OCS::notFound(); } catch (MethodNotAllowedException $e) { - setOcsContentType(); OC_API::setContentType(); OC_Response::setStatus(405); } -- cgit v1.2.3