fix(OCS): Add IRequest::getFormat to determine the response Content-Type the same way everywhere#54627
Conversation
|
While a good and nice fix, I fear this could break current clients working around the problem since years. So I'd suggest to delay it until after the branch off? |
So the issue is known and was manually handled by some clients? 🙈 I'm fine with waiting, I just found this while fuzzing the API and it has been broken this way since forever, so fixing it is not that urgent. |
|
It would make sense to add a method to IRequest to get requested format, maybe? |
…ype the same way everywhere Signed-off-by: provokateurin <[email protected]>
714a976 to
aab11d3
Compare
|
I have too many questions about the code I saw 🙈 |
| return \is_array($trustedProxies) && $this->isTrustedProxy($trustedProxies, $remoteAddress); | ||
| } | ||
|
|
||
| public function getFormat(): ?string { |
There was a problem hiding this comment.
Should have upstreamed https://github.com/nextcloud/spreed/blob/38e56a3fe460f07e128c49be2759362592728a22/lib/Controller/AEnvironmentAwareOCSController.php#L60-L75 before it was cool :D
| $header = strtolower(trim($header)); | ||
|
|
||
| if (str_starts_with($header, $prefix)) { | ||
| return substr($header, strlen($prefix)); |
There was a problem hiding this comment.
Opposed to Controller::getResponderByHTTPHeader() which was used before, this here no longer checks if there is a responder registered and does not fall back to the default type correctly.
E.g. When you create a share for a file that can not have a preview (e.g. PDF without PDF being enabled), instead of having a proper 404, the response now is:
Technische Details
Entfernte Adresse: ::1
Anfragekennung: 3RuRvo3TEr52XxYi3pq6
Typ: DomainException
Code: 0
Nachricht: No responder registered for format xhtml+xml!
Datei: /home/nickv/Nextcloud/33/server/lib/public/AppFramework/Controller.php
Zeile: 139
Trace
#0 /home/nickv/Nextcloud/33/server/lib/private/AppFramework/Http/Dispatcher.php(227): OCP\AppFramework\Controller->buildResponse(Object(OCP\AppFramework\Http\DataResponse), '...')
#1 /home/nickv/Nextcloud/33/server/lib/private/AppFramework/Http/Dispatcher.php(118): OC\AppFramework\Http\Dispatcher->executeController(Object(OCA\Files_Sharing\Controller\PublicPreviewController), '...')
#2 /home/nickv/Nextcloud/33/server/lib/private/AppFramework/App.php(153): OC\AppFramework\Http\Dispatcher->dispatch(Object(OCA\Files_Sharing\Controller\PublicPreviewController), '...')
#3 /home/nickv/Nextcloud/33/server/lib/private/Route/Router.php(321): OC\AppFramework\App::main('...', '...', Object(OC\AppFramework\DependencyInjection\DIContainer), Array)
#4 /home/nickv/Nextcloud/33/server/lib/base.php(1096): OC\Route\Router->match('...')
#5 /home/nickv/Nextcloud/33/server/index.php(25): OC::handleRequest()
#6 {main}
This works properly until Nextcloud 31.
The OCSMiddleware handles the
?format=jsonquery parameter andAccept: application/jsonrequest header, butocs/v1.phpusesApiHelper::respondwhich only handles?format=jsonso far.