[Pkg-owncloud-commits] [owncloud] 46/134: set content-type on ocs exceptions
David Prévot
taffit at moszumanska.debian.org
Fri Apr 18 21:43:59 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit 14b9eba4285c2af551af665577b1a286b3245f37
Author: Thomas Müller <thomas.mueller at tmit.eu>
Date: Wed Mar 12 00:35:19 2014 +0100
set content-type on ocs exceptions
---
lib/private/api.php | 33 ++++++++++++++++++++++++++++++---
ocs/v1.php | 3 +++
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/lib/private/api.php b/lib/private/api.php
index 857bc73..00f80b5 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();
}
@@ -347,4 +345,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');
+ }
+
+
}
diff --git a/ocs/v1.php b/ocs/v1.php
index 1c7d1c8..9d84f48 100644
--- a/ocs/v1.php
+++ b/ocs/v1.php
@@ -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);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list