[icinga-checkins] icinga.org: icingaweb2/master: Preserve status code and headers in JSON responses

git at icinga.org git at icinga.org
Tue Oct 11 10:46:40 CEST 2016


Module: icingaweb2
Branch: master
Commit: 4d16656100d74c81f6bf3783343d28643b4c7939
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=4d16656100d74c81f6bf3783343d28643b4c7939

Author: Alexander A. Klimov <alexander.klimov at netways.de>
Date:   Tue Sep 27 13:26:20 2016 +0200

Preserve status code and headers in JSON responses

refs #12583

---

 library/Icinga/Web/Response.php |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/library/Icinga/Web/Response.php b/library/Icinga/Web/Response.php
index 5fa5bc0..7e0b896 100644
--- a/library/Icinga/Web/Response.php
+++ b/library/Icinga/Web/Response.php
@@ -210,9 +210,11 @@ class Response extends Zend_Controller_Response_Http
      *
      * @return JsonResponse
      */
-    public static function json()
+    public function json()
     {
-        return new JsonResponse();
+        $response = new JsonResponse();
+        $response->setMetaDataFrom($this);
+        return $response;
     }
 
     /**
@@ -292,4 +294,20 @@ class Response extends Zend_Controller_Response_Http
         }
         return parent::sendHeaders();
     }
+
+    /**
+     * Copies non-body-related response data from $response
+     *
+     * @param   Response    $response
+     *
+     * @return  $this
+     */
+    protected function setMetaDataFrom(self $response)
+    {
+        $this->_headers = $response->_headers;
+        $this->_headersRaw = $response->_headersRaw;
+        $this->_httpResponseCode = $response->_httpResponseCode;
+        $this->headersSentThrowsException = $response->headersSentThrowsException;
+        return $this;
+    }
 }



More information about the icinga-checkins mailing list