Ticket #770 (defect)
Opened 7 months ago
Last modified 3 months ago
THttpResponse::StatusCode is not sent to the client
Status: closed (fixed)
| Reported by: | simon.lehmann | Assigned to: | xue |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1.2 |
| Component: | Prado Framework v3 | Version: | 3.1 |
| Severity: | minor | Keywords: | |
| Cc: |
The StatusCode? property of the THttpResponse class isn't sent to the client as one would expect.
As far as I can tell, the status code isn't used at all. Setting the HTTP header when a new status code is set could be easily achieved like this:
(in framework/Web/THttpResponse.php, version 3.1.1.r2290)
@@ -229,6 +229,7 @@
public function setStatusCode($status)
{
$this->_status=TPropertyValue::ensureInteger($status);
+ header("HTTP/1.0 $status");
}
/**
Attachments
Change History
01/16/2008 03:16:45 PM: Modified by xue
- milestone set to 3.1.2.
03/05/2008 09:06:44 AM: Modified by maddin
03/13/2008 08:19:38 AM: Modified by donkee
Yes, you're rigth but the instruction header must not be here but into the function writeFile.
Further more, there is some check that HTTP1.1 (rfc2616) that you need to do, but you don't :/
03/13/2008 08:43:19 AM: Modified by donkee
- attachment ticket.770.patch added.
For close this ticket
03/13/2008 08:44:28 AM: Modified by donkee
Only the last patch is good (filename: patch.770.patch) Sorry
04/08/2008 02:42:29 PM: Modified by tof06
Deleted your bad attachement.
Why do you put the header only in writeFile method ? This method is only used when user wants to send a file to the browser instead of the page.
I would put it in flushContent method ?
I never used the statusCode, anyone can give me an example where this can be useful ? Thanks.
04/21/2008 07:33:05 AM: Modified by tof06
- status changed from new to closed.
- resolution set to fixed.
Thanks

Nice when the name of the status is also send to the client. This can be done with the following code:
private $_statusNames = array( 100 => 'Continue', 'Switching Protocols', 200 => 'OK', 'Created', 'Accepted', 'Non-Authoritative Information', 'No Content', 'Reset Content', 'Partial Content', 300 => 'Multiple Choices', 'Moved Permanently', 'Found', 'See Other', 'Not Modified', 'Use Proxy', '', 'Temporary Redirect', 400 => 'Bad Request', 'Unauthorized', 'Payment Required', 'Forbidden', 'Not Found', 'Method Not Allowed', 'Not Acceptable', 'Proxy Authentication Required', 'Request Timeout', 'Conflict', 'Gone', 'Length Required', 'Precondition Failed', 'Request Entity Too Large', 'Request-URI Too Long', 'Unsupported Media Type', 'Requested Range Not Satisfiable', 'Expectation Failed', 500 => 'Internal Server Error', 'Not Implemented', 'Bad Gateway', 'Service Unavailable', 'Gateway Timeout', 'HTTP Version Not Supported' ); public function setStatusCode($status,$name=null) { if( $name===null ) $name = $this->_statusNames[$status]; $this->_status=TPropertyValue::ensureInteger($status); header("HTTP/1.1 $status $name"); }Also HTTP 1.1 should be sended!