Preserve status code and headers in JSON responses

refs #12583
This commit is contained in:
Alexander A. Klimov 2016-09-27 13:26:20 +02:00
parent 7ed3acbbd8
commit 4d16656100
1 changed files with 20 additions and 2 deletions

View File

@ -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;
}
}