Merge pull request #508 from nextcloud/stable10_ocs_appframework_xml
[Stable10] AppFramework do not get default response
This commit is contained in:
commit
d181301699
|
@ -168,10 +168,14 @@ class Dispatcher {
|
||||||
// if none is given try the first Accept header
|
// if none is given try the first Accept header
|
||||||
if($format === null) {
|
if($format === null) {
|
||||||
$headers = $this->request->getHeader('Accept');
|
$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;
|
return $response;
|
||||||
|
|
|
@ -73,7 +73,7 @@ class OCSMiddleware extends Middleware {
|
||||||
// if none is given try the first Accept header
|
// if none is given try the first Accept header
|
||||||
if($format === null) {
|
if($format === null) {
|
||||||
$headers = $this->request->getHeader('Accept');
|
$headers = $this->request->getHeader('Accept');
|
||||||
$format = $controller->getResponderByHTTPHeader($headers);
|
$format = $controller->getResponderByHTTPHeader($headers, 'xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $format;
|
return $format;
|
||||||
|
|
|
@ -105,8 +105,9 @@ abstract class Controller {
|
||||||
* @param string $acceptHeader
|
* @param string $acceptHeader
|
||||||
* @return string the responder type
|
* @return string the responder type
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @since 9.1.0 Added default parameter
|
||||||
*/
|
*/
|
||||||
public function getResponderByHTTPHeader($acceptHeader) {
|
public function getResponderByHTTPHeader($acceptHeader, $default='json') {
|
||||||
$headers = explode(',', $acceptHeader);
|
$headers = explode(',', $acceptHeader);
|
||||||
|
|
||||||
// return the first matching responder
|
// return the first matching responder
|
||||||
|
@ -120,8 +121,8 @@ abstract class Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// no matching header defaults to json
|
// no matching header return default
|
||||||
return 'json';
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace OCP\AppFramework;
|
||||||
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\AppFramework\Http\OCSResponse;
|
use OCP\AppFramework\Http\OCSResponse;
|
||||||
|
use OCP\AppFramework\Http\Response;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,6 +71,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
|
* Unwrap data and build ocs response
|
||||||
|
|
Loading…
Reference in New Issue