From 11a171bb2f7af24051c45cbb0d5701696c37f2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 17 Aug 2016 11:14:57 +0200 Subject: [PATCH] 204 and 304 must not have a body, see https://tools.ietf.org/html/rfc7230#section-3.3 --- lib/public/AppFramework/Http/JSONResponse.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/public/AppFramework/Http/JSONResponse.php b/lib/public/AppFramework/Http/JSONResponse.php index 1b8b676e6013c..aecefc9c4f508 100644 --- a/lib/public/AppFramework/Http/JSONResponse.php +++ b/lib/public/AppFramework/Http/JSONResponse.php @@ -61,15 +61,21 @@ public function __construct($data=array(), $statusCode=Http::STATUS_OK) { /** * 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;