Fixed issue with 304 caching. Fixed PHP 5.3 compatibility.

pull/55/merge
Mike Cao 12 years ago
parent 000b1db3be
commit b4a9d6f70e

@ -75,6 +75,7 @@ class Engine {
*/
public function init() {
static $initialized = false;
$self = $this;
if ($initialized) {
$this->vars = array();
@ -86,8 +87,8 @@ class Engine {
$this->loader->register('request', '\flight\net\Request');
$this->loader->register('response', '\flight\net\Response');
$this->loader->register('router', '\flight\net\Router');
$this->loader->register('view', '\flight\template\View', array(), function($view) {
$view->path = $this->get('flight.views.path');
$this->loader->register('view', '\flight\template\View', array(), function($view) use ($self) {
$view->path = $self->get('flight.views.path');
});
// Register framework methods
@ -320,12 +321,13 @@ class Engine {
*
* @param int $code HTTP status code
* @param string $message Response message
* @param bool $cache Cache response
*/
public function _halt($code = 200, $message = '') {
public function _halt($code = 200, $message = '', $cache = false) {
$this->response(false)
->status($code)
->write($message)
->cache(false)
->cache($cache)
->send();
}
@ -438,7 +440,7 @@ class Engine {
$this->response()->header('ETag', $id);
if ($id === getenv('HTTP_IF_NONE_MATCH')) {
$this->halt(304);
$this->halt(304, '', true);
}
}
@ -451,7 +453,7 @@ class Engine {
$this->response()->header('Last-Modified', date(DATE_RFC1123, $time));
if ($time === strtotime(getenv('HTTP_IF_MODIFIED_SINCE'))) {
$this->halt(304);
$this->halt(304, '', true);
}
}
}

@ -151,6 +151,7 @@ class Response {
* @return object Self reference
*/
public function cache($expires) {
if ($expires !== true) {
if ($expires === false) {
$this->headers['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
$this->headers['Cache-Control'] = array(
@ -165,6 +166,7 @@ class Response {
$this->headers['Expires'] = gmdate('D, d M Y H:i:s', $expires) . ' GMT';
$this->headers['Cache-Control'] = 'max-age='.($expires - time());
}
}
return $this;
}

Loading…
Cancel
Save