AppFramework do not get default response

The OCSResponse differs from other responses in that it defaults to
XML. However we fell back to json by default.

This makes sure that if nothing is set we don't pass anything.
Which defaults then to the controllers default (which is often 'json')
but in the case of the OCSResponse 'xml'.
This commit is contained in:
Roeland Jago Douma 2016-07-20 21:30:39 +02:00
parent b4c7eb5326
commit 2abd83212e
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
4 changed files with 25 additions and 6 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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