[Pkg-owncloud-commits] [owncloud] 16/55: set content-type on ocs exceptions

David Prévot taffit at moszumanska.debian.org
Wed Apr 23 19:51:58 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag v5.0.16RC1
in repository owncloud.

commit a440b360d01632d1209629d4ee7eb248adccbe03
Author: Thomas Müller <thomas.mueller at tmit.eu>
Date:   Wed Mar 12 00:35:19 2014 +0100

    set content-type on ocs exceptions
    
    Conflicts:
    	lib/api.php
---
 lib/api.php | 33 ++++++++++++++++++++++++++++++---
 ocs/v1.php  |  3 +++
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/lib/api.php b/lib/api.php
index fc76836..b23e94f 100644
--- a/lib/api.php
+++ b/lib/api.php
@@ -110,9 +110,8 @@ 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();
 		OC_User::logout();
 
 		self::respond($response, $format);
@@ -287,5 +286,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 af83a56..2aa40b2 100644
--- a/ocs/v1.php
+++ b/ocs/v1.php
@@ -28,8 +28,11 @@ use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 try {
 	OC::getRouter()->match('/ocs'.$_SERVER['PATH_INFO']);
 } 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