Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/private/AppFramework/Http/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ private function executeController(Controller $controller, string $methodName):
// 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);
Expand Down
5 changes: 4 additions & 1 deletion lib/private/AppFramework/Middleware/OCSMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ public function afterController($controller, $methodName, Response $response) {
* @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);
Expand Down
11 changes: 8 additions & 3 deletions lib/public/AppFramework/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OCP\AppFramework;

use Closure;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
Expand All @@ -32,7 +33,7 @@ abstract class Controller {
protected $request;

/**
* @var array
* @var array<string, Closure>
* @since 7.0.0
*/
private $responders;
Expand Down Expand Up @@ -113,10 +114,10 @@ public function getResponderByHTTPHeader($acceptHeader, $default = 'json') {
/**
* Registers a formatter for a type
* @param string $format
* @param \Closure $responder
* @param Closure $responder
Comment on lines 116 to +117
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both can be removed

* @since 7.0.0
*/
protected function registerResponder($format, \Closure $responder) {
protected function registerResponder($format, Closure $responder) {
$this->responders[$format] = $responder;
}

Expand All @@ -139,4 +140,8 @@ public function buildResponse($response, $format = 'json') {
throw new \DomainException('No responder registered for format '
. $format . '!');
}

public function isResponderRegistered(string $responder): bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SInCE is missing. Did we not have a check for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh yes 🤔

return isset($this->responders[$responder]);
}
}
Loading