aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2018-05-09 23:41:56 +0200
committerGitHub <noreply@github.com>2018-05-09 23:41:56 +0200
commit72dc01460ef16177b44a1ea8b89001da6436d1d9 (patch)
treeeaeef0447bf09c0a00fe26a18e8250b4a7dda35e
parent57ea4624741c36ed6e68f60c672ddddbfece628a (diff)
parentb4bacf46f3480cfb519917e73a921d0b61d0d447 (diff)
downloadnextcloud-server-72dc01460ef16177b44a1ea8b89001da6436d1d9.tar.gz
nextcloud-server-72dc01460ef16177b44a1ea8b89001da6436d1d9.zip
Merge pull request #9390 from nextcloud/bugfix/noid/no-body-for-no-content
Do not send a body for "No content", "Not modified" and others
-rw-r--r--lib/private/AppFramework/OCS/BaseResponse.php58
1 files changed, 55 insertions, 3 deletions
diff --git a/lib/private/AppFramework/OCS/BaseResponse.php b/lib/private/AppFramework/OCS/BaseResponse.php
index 59b8660a382..b27784cfcf2 100644
--- a/lib/private/AppFramework/OCS/BaseResponse.php
+++ b/lib/private/AppFramework/OCS/BaseResponse.php
@@ -22,6 +22,7 @@
*/
namespace OC\AppFramework\OCS;
+use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
use OCP\AppFramework\Http\Response;
@@ -85,9 +86,60 @@ abstract class BaseResponse extends Response {
* @param string[] $meta
* @return string
*/
- protected function renderResult($meta) {
- // TODO rewrite functions
- return \OC_API::renderResult($this->format, $meta, $this->data);
+ protected function renderResult(array $meta): string {
+ $status = $this->getStatus();
+ if ($status === Http::STATUS_NO_CONTENT ||
+ $status === Http::STATUS_NOT_MODIFIED ||
+ ($status >= 100 && $status <= 199)) {
+ // Those status codes are not supposed to have a body:
+ // https://stackoverflow.com/q/8628725
+ return '';
+ }
+
+ $response = [
+ 'ocs' => [
+ 'meta' => $meta,
+ 'data' => $this->data,
+ ],
+ ];
+
+ if ($this->format === 'json') {
+ return json_encode($response, JSON_HEX_TAG);
+ }
+
+ $writer = new \XMLWriter();
+ $writer->openMemory();
+ $writer->setIndent(true);
+ $writer->startDocument();
+ $this->toXML($response, $writer);
+ $writer->endDocument();
+ return $writer->outputMemory(true);
+
+ }
+
+ /**
+ * @param array $array
+ * @param \XMLWriter $writer
+ */
+ protected function toXML(array $array, \XMLWriter $writer) {
+ foreach ($array as $k => $v) {
+ if ($k[0] === '@') {
+ $writer->writeAttribute(substr($k, 1), $v);
+ continue;
+ }
+
+ if (\is_numeric($k)) {
+ $k = 'element';
+ }
+
+ if (\is_array($v)) {
+ $writer->startElement($k);
+ $this->toXML($v, $writer);
+ $writer->endElement();
+ } else {
+ $writer->writeElement($k, $v);
+ }
+ }
}
public function getOCSStatus() {