Skip to content

Commit d181301

Browse files
authored
Merge pull request #508 from nextcloud/stable10_ocs_appframework_xml
[Stable10] AppFramework do not get default response
2 parents 750644a + 2abd832 commit d181301

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

lib/private/AppFramework/Http/Dispatcher.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,14 @@ private function executeController($controller, $methodName) {
168168
// if none is given try the first Accept header
169169
if($format === null) {
170170
$headers = $this->request->getHeader('Accept');
171-
$format = $controller->getResponderByHTTPHeader($headers);
171+
$format = $controller->getResponderByHTTPHeader($headers, null);
172172
}
173173

174-
$response = $controller->buildResponse($response, $format);
174+
if ($format !== null) {
175+
$response = $controller->buildResponse($response, $format);
176+
} else {
177+
$response = $controller->buildResponse($response);
178+
}
175179
}
176180

177181
return $response;

lib/private/AppFramework/Middleware/OCSMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private function getFormat($controller) {
7373
// if none is given try the first Accept header
7474
if($format === null) {
7575
$headers = $this->request->getHeader('Accept');
76-
$format = $controller->getResponderByHTTPHeader($headers);
76+
$format = $controller->getResponderByHTTPHeader($headers, 'xml');
7777
}
7878

7979
return $format;

lib/public/AppFramework/Controller.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ public function __construct($appName,
105105
* @param string $acceptHeader
106106
* @return string the responder type
107107
* @since 7.0.0
108+
* @since 9.1.0 Added default parameter
108109
*/
109-
public function getResponderByHTTPHeader($acceptHeader) {
110+
public function getResponderByHTTPHeader($acceptHeader, $default='json') {
110111
$headers = explode(',', $acceptHeader);
111112

112113
// return the first matching responder
@@ -120,8 +121,8 @@ public function getResponderByHTTPHeader($acceptHeader) {
120121
}
121122
}
122123

123-
// no matching header defaults to json
124-
return 'json';
124+
// no matching header return default
125+
return $default;
125126
}
126127

127128

lib/public/AppFramework/OCSController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
use OCP\AppFramework\Http\DataResponse;
3434
use OCP\AppFramework\Http\OCSResponse;
35+
use OCP\AppFramework\Http\Response;
3536
use OCP\IRequest;
3637

3738

@@ -70,6 +71,19 @@ public function __construct($appName,
7071
});
7172
}
7273

74+
/**
75+
* Since the OCS endpoints default to XML we need to find out the format
76+
* again
77+
* @param mixed $response the value that was returned from a controller and
78+
* is not a Response instance
79+
* @param string $format the format for which a formatter has been registered
80+
* @throws \DomainException if format does not match a registered formatter
81+
* @return Response
82+
* @since 9.1.0
83+
*/
84+
public function buildResponse($response, $format = 'xml') {
85+
return parent::buildResponse($response, $format);
86+
}
7387

7488
/**
7589
* Unwrap data and build ocs response

0 commit comments

Comments
 (0)