summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/AppFramework/Http/Dispatcher.php8
-rw-r--r--lib/private/AppFramework/Middleware/OCSMiddleware.php2
-rw-r--r--lib/public/AppFramework/Controller.php7
-rw-r--r--lib/public/AppFramework/OCSController.php14
4 files changed, 25 insertions, 6 deletions
diff --git a/lib/private/AppFramework/Http/Dispatcher.php b/lib/private/AppFramework/Http/Dispatcher.php
index fdf99a57841..965d340fc77 100644
--- a/lib/private/AppFramework/Http/Dispatcher.php
+++ b/lib/private/AppFramework/Http/Dispatcher.php
@@ -167,10 +167,14 @@ class Dispatcher {
// if none is given try the first Accept header
if($format === null) {
$headers = $this->request->getHeader('Accept');
- $format = $controller->getResponderByHTTPHeader($headers);
+ $format = $controller->getResponderByHTTPHeader($headers, null);
}
- $response = $controller->buildResponse($response, $format);
+ if ($format !== null) {
+ $response = $controller->buildResponse($response, $format);
+ } else {
+ $response = $controller->buildResponse($response);
+ }
}
return $response;
diff --git a/lib/private/AppFramework/Middleware/OCSMiddleware.php b/lib/private/AppFramework/Middleware/OCSMiddleware.php
index 2c7d1167e7c..b21e8e05a90 100644
--- a/lib/private/AppFramework/Middleware/OCSMiddleware.php
+++ b/lib/private/AppFramework/Middleware/OCSMiddleware.php
@@ -72,7 +72,7 @@ class OCSMiddleware extends Middleware {
// if none is given try the first Accept header
if($format === null) {
$headers = $this->request->getHeader('Accept');
- $format = $controller->getResponderByHTTPHeader($headers);
+ $format = $controller->getResponderByHTTPHeader($headers, 'xml');
}
return $format;
diff --git a/lib/public/AppFramework/Controller.php b/lib/public/AppFramework/Controller.php
index daf6018cd12..c6baa5e30c1 100644
--- a/lib/public/AppFramework/Controller.php
+++ b/lib/public/AppFramework/Controller.php
@@ -104,8 +104,9 @@ abstract class Controller {
* @param string $acceptHeader
* @return string the responder type
* @since 7.0.0
+ * @since 9.1.0 Added default parameter
*/
- public function getResponderByHTTPHeader($acceptHeader) {
+ public function getResponderByHTTPHeader($acceptHeader, $default='json') {
$headers = explode(',', $acceptHeader);
// return the first matching responder
@@ -119,8 +120,8 @@ abstract class Controller {
}
}
- // no matching header defaults to json
- return 'json';
+ // no matching header return default
+ return $default;
}
diff --git a/lib/public/AppFramework/OCSController.php b/lib/public/AppFramework/OCSController.php
index e118b34250d..e67c0fc21ae 100644
--- a/lib/public/AppFramework/OCSController.php
+++ b/lib/public/AppFramework/OCSController.php
@@ -31,6 +31,7 @@ namespace OCP\AppFramework;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\OCSResponse;
+use OCP\AppFramework\Http\Response;
use OCP\IRequest;
@@ -69,6 +70,19 @@ abstract class OCSController extends ApiController {
});
}
+ /**
+ * Since the OCS endpoints default to XML we need to find out the format
+ * again
+ * @param mixed $response the value that was returned from a controller and
+ * is not a Response instance
+ * @param string $format the format for which a formatter has been registered
+ * @throws \DomainException if format does not match a registered formatter
+ * @return Response
+ * @since 9.1.0
+ */
+ public function buildResponse($response, $format = 'xml') {
+ return parent::buildResponse($response, $format);
+ }
/**
* Unwrap data and build ocs response