HTTP_download -If-Modified-Since (->304) does not work
| From: | Andreas Korthaus | Date: | Fri, 19 Dec 2003 16:39:55 +0000 |
| Subject: | HTTP_download -If-Modified-Since (->304) does not work | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-24545@lists.php.net to get a copy of this message | ||
Hi!
The following code is from HTTP_download and HTTP_header, latest CVS.
(http://cvs.php.net/co.php/pear/HTTP_Download/Download.php?r=1.12)
function _processRequest() {
[...]
/**
* Don't send data if cached - "HTTP/1.x 304 Not Modified"
*/
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] ==
$this->_last_modified ) {
// Not Modified
$this->sendStatusCode(HTTP_HEADER_STATUS_304);
return PEAR::raiseError(
'HTTP Cached: ' . HTTP_HEADER_STATUS_304
);
}
}
The "sendStatusCode()" looks like that:
/**
* Send out the given HTTP-Status code.
* Use this for example when you want to tell the client this page is
* cached, then you would call sendStatusCode(304),
* see HTTP_Header_Cache::exitIfCached() for example usage.
*
* @param int the status code to be sent, i.e. 404, 304, 200, etc.
*/
function sendStatusCode( $code)
{
if (defined('HTTP_HEADER_STATUS_' .$code)) {
$status_msg = constant('HTTP_HEADER_STATUS_' .$code);
header( 'HTTP/'.$this->_httpVersion. ' ' .$code. ' '
.$status_msg);
} else {
return false;
}
}
Why is there no "exit;" after sending the header? Because if there is no
exit, the code above will raise an error and my scripts will stop and
sending HTML-Output(error-message). If I use this code as it is in CVS, I
get a PEAR Error if the Client sends IF_MODIFIED_SINCE.
Is this a bug? Or my mistake?
kind regards,
Andreas