]> source.dussan.org Git - nextcloud-server.git/commitdiff
204 and 304 must not have a body, see https://tools.ietf.org/html/rfc7230#section-3.3
authorJörn Friedrich Dreyer <jfd@butonic.de>
Wed, 17 Aug 2016 09:28:29 +0000 (11:28 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Wed, 17 Aug 2016 09:28:29 +0000 (11:28 +0200)
lib/public/appframework/http/jsonresponse.php

index 89433fd23e5ee36d71276ecb2d15ecffda9f0f85..0683e22a0290a04677c87bdef4613791cc375098 100644 (file)
@@ -60,15 +60,21 @@ class JSONResponse extends Response {
 
        /**
         * Returns the rendered json
-        * @return string the rendered json
+        * @return string|null the rendered json
         * @since 6.0.0
         * @throws \Exception If data could not get encoded
         */
        public function render() {
-               $response = json_encode($this->data, JSON_HEX_TAG);
-               if($response === false) {
-                       throw new \Exception(sprintf('Could not json_encode due to invalid ' .
-                               'non UTF-8 characters in the array: %s', var_export($this->data, true)));
+               if ($this->getStatus() === Http::STATUS_NO_CONTENT
+                       || $this->getStatus() === Http::STATUS_NOT_MODIFIED
+               ) {
+                       $response = null;
+               } else {
+                       $response = json_encode($this->data, JSON_HEX_TAG);
+                       if ($response === false) {
+                               throw new \Exception(sprintf('Could not json_encode due to invalid ' .
+                                       'non UTF-8 characters in the array: %s', var_export($this->data, true)));
+                       }
                }
 
                return $response;