Skip to content
Snippets Groups Projects
Commit 743addd1 authored by Thomas Müller's avatar Thomas Müller
Browse files

set content-type on ocs exceptions

parent 364e1f85
No related branches found
No related tags found
No related merge requests found
...@@ -116,9 +116,7 @@ class OC_API { ...@@ -116,9 +116,7 @@ class OC_API {
); );
} }
$response = self::mergeResponses($responses); $response = self::mergeResponses($responses);
$formats = array('json', 'xml'); $format = self::requestedFormat();
$format = !empty($_GET['format']) && in_array($_GET['format'], $formats) ? $_GET['format'] : 'xml';
if (self::$logoutRequired) { if (self::$logoutRequired) {
OC_User::logout(); OC_User::logout();
} }
...@@ -350,4 +348,33 @@ class OC_API { ...@@ -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');
}
} }
...@@ -28,8 +28,11 @@ use Symfony\Component\Routing\Exception\MethodNotAllowedException; ...@@ -28,8 +28,11 @@ use Symfony\Component\Routing\Exception\MethodNotAllowedException;
try { try {
OC::getRouter()->match('/ocs'.OC_Request::getRawPathInfo()); OC::getRouter()->match('/ocs'.OC_Request::getRawPathInfo());
} catch (ResourceNotFoundException $e) { } catch (ResourceNotFoundException $e) {
OC_API::setContentType();
OC_OCS::notFound(); OC_OCS::notFound();
} catch (MethodNotAllowedException $e) { } catch (MethodNotAllowedException $e) {
setOcsContentType();
OC_API::setContentType();
OC_Response::setStatus(405); OC_Response::setStatus(405);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment