mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
fix(AppFramework): Check for responder existence
Signed-off-by: provokateurin <kate@provokateurin.de>
This commit is contained in:
parent
b3fd79fff3
commit
f720925b06
3 changed files with 13 additions and 6 deletions
|
|
@ -222,8 +222,7 @@ class Dispatcher {
|
|||
// format response
|
||||
if ($response instanceof DataResponse || !($response instanceof Response)) {
|
||||
$format = $this->request->getFormat();
|
||||
|
||||
if ($format !== null) {
|
||||
if ($format !== null && $controller->isResponderRegistered($format)) {
|
||||
$response = $controller->buildResponse($response, $format);
|
||||
} else {
|
||||
$response = $controller->buildResponse($response);
|
||||
|
|
|
|||
|
|
@ -110,7 +110,10 @@ class OCSMiddleware extends Middleware {
|
|||
* @return V1Response|V2Response
|
||||
*/
|
||||
private function buildNewResponse(Controller $controller, $code, $message) {
|
||||
$format = $this->request->getFormat() ?? 'xml';
|
||||
$format = $this->request->getFormat();
|
||||
if ($format === null || !$controller->isResponderRegistered($format)) {
|
||||
$format = 'xml';
|
||||
}
|
||||
|
||||
$data = new DataResponse();
|
||||
$data->setStatus($code);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
namespace OCP\AppFramework;
|
||||
|
||||
use Closure;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
|
|
@ -32,7 +33,7 @@ abstract class Controller {
|
|||
protected $request;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var array<string, Closure>
|
||||
* @since 7.0.0
|
||||
*/
|
||||
private $responders;
|
||||
|
|
@ -113,10 +114,10 @@ abstract class Controller {
|
|||
/**
|
||||
* Registers a formatter for a type
|
||||
* @param string $format
|
||||
* @param \Closure $responder
|
||||
* @param Closure $responder
|
||||
* @since 7.0.0
|
||||
*/
|
||||
protected function registerResponder($format, \Closure $responder) {
|
||||
protected function registerResponder($format, Closure $responder) {
|
||||
$this->responders[$format] = $responder;
|
||||
}
|
||||
|
||||
|
|
@ -139,4 +140,8 @@ abstract class Controller {
|
|||
throw new \DomainException('No responder registered for format '
|
||||
. $format . '!');
|
||||
}
|
||||
|
||||
public function isResponderRegistered(string $responder): bool {
|
||||
return isset($this->responders[$responder]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue