From 45c83c5025313b88f0e26e91555b10b66bf60386 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 13 Apr 2013 17:53:50 +1000 Subject: [PATCH] Allow for etag caching --- application/classes/HTTP/Exception/404.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/application/classes/HTTP/Exception/404.php b/application/classes/HTTP/Exception/404.php index c2a3997..9651d3d 100644 --- a/application/classes/HTTP/Exception/404.php +++ b/application/classes/HTTP/Exception/404.php @@ -43,13 +43,24 @@ class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 { } elseif (preg_match('/^file:\/\/(.*)$/',$redirect,$matches) AND file_exists($matches[1])) { $response->status(200); - $response->headers('Content-Type', Kohana_Exception::$error_view_content_type.'; charset='.Kohana::$charset); $response->body(file_get_contents($redirect)); + + HTTP::check_cache($this->request(),$response,sha1($response->body())); + + $response->headers('Content-Type',File::mime_by_ext(pathinfo($matches[1],PATHINFO_EXTENSION))); + $response->headers('Content-Length',(string)$response->content_length()); + $response->headers('Last-Modified',date('r',$matches[1] ? filemtime($matches[1]) : time())); } return $response; } catch (Exception $e) { + // Incase we are thrown in this exception. + if ($e instanceof HTTP_Exception AND $e->getCode() != 404) { + $x = new $e; + return $x->get_response(); + } + return parent::get_response(); } }