diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2014-10-23 22:35:19 +0200 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2014-10-23 22:35:19 +0200 |
commit | 6258436ce62988d1178c7c394d5093dbac52056f (patch) | |
tree | f45955e528cdcdd7eec362ee6e27f84fbe83c589 /framework | |
parent | a95129eca0c513b4090c76656a068805b3b5281f (diff) |
Fix #539
TErrorHandler: let THttpResponse handle http status codes
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Exceptions/TErrorHandler.php | 14 | ||||
-rw-r--r-- | framework/Web/THttpResponse.php | 13 |
2 files changed, 10 insertions, 17 deletions
diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php index ad5fe662..8337f3be 100644 --- a/framework/Exceptions/TErrorHandler.php +++ b/framework/Exceptions/TErrorHandler.php @@ -199,19 +199,7 @@ class TErrorHandler extends TModule '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time()) ); - $CGI=substr(php_sapi_name(), 0, 3) == 'cgi'; // FastCGI / IIS - if($isDebug) - { - if ($CGI) - header("Status: $statusCode ".$exception->getMessage(), true, TPropertyValue::ensureInteger($statusCode)); - else - header("HTTP/1.0 $statusCode ".$exception->getMessage(), true, TPropertyValue::ensureInteger($statusCode)); - } else { - if ($CGI) - header("Status: $statusCode", true, TPropertyValue::ensureInteger($statusCode)); - else - header("HTTP/1.0 $statusCode", true, TPropertyValue::ensureInteger($statusCode)); - } + $this->getApplication()->getResponse()->setStatusCode($statusCode, $isDebug ? $exception->getMessage() : null); echo strtr($content,$tokens); } diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index 75563ef9..7e1afcc6 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -512,10 +512,15 @@ class THttpResponse extends TModule implements ITextWriter */ protected function sendHttpHeader() { - if (($version=$this->getRequest()->getHttpProtocolVersion())==='') - header (' ', true, $this->_status); - else - header($version.' '.$this->_status.' '.$this->_reason, true, $this->_status); + $protocol=$this->getRequest()->getHttpProtocolVersion(); + if($this->getRequest()->getHttpProtocolVersion() === null) + $protocol='HTTP/1.1'; + + $phpSapiName = substr(php_sapi_name(), 0, 3); + $cgi = $phpSapiName == 'cgi' || $phpSapiName == 'fpm'; + + header(($cgi ? 'Status:' : $protocol).' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status)); + $this->_httpHeaderSent = true; } |