diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2008-06-28 02:05:48 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2008-06-28 02:05:48 +0000 |
commit | 7f56bf947599b20e2cf50018e160e602d5516e5f (patch) | |
tree | 45eade5287d340d2d6883aaa39e0fa3a1e57204e /libs/httpd/luasrc | |
parent | 3eefe8a8e2f9270ffc7b83744f692ee34852e4a1 (diff) |
* libs/http: prepare support for RFC2616 / 14.24 - 14.28
Diffstat (limited to 'libs/httpd/luasrc')
-rw-r--r-- | libs/httpd/luasrc/httpd/handler/file.lua | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/libs/httpd/luasrc/httpd/handler/file.lua b/libs/httpd/luasrc/httpd/handler/file.lua index e6311e839..f553e8292 100644 --- a/libs/httpd/luasrc/httpd/handler/file.lua +++ b/libs/httpd/luasrc/httpd/handler/file.lua @@ -18,6 +18,7 @@ module("luci.httpd.handler.file", package.seeall) require("luci.httpd.module") require("luci.http.protocol.date") require("luci.http.protocol.mime") +require("luci.http.protocol.conditionals") require("luci.fs") require("ltn12") @@ -39,28 +40,23 @@ function Simple.getfile(self, uri) return file, stat end - -function Simple._mk_etag(self, stat) - return string.format( "%x-%x-%x", stat.ino, stat.size, stat.mtime ) -end - -function Simple._cmp_etag(self, stat, etag) - return ( self:_mk_etag(stat) == etag ) -end - - function Simple.handle_get(self, request, sourcein, sinkerr) local file, stat = self:getfile(request.env.PATH_INFO) if stat then if stat.type == "regular" then + + -- Generate Entity Tag + local etag = luci.http.protocol.conditionals.mk_etag( stat ) + + -- Send Response return Response( 200, { ["Date"] = self.date.to_http( os.time() ); ["Last-Modified"] = self.date.to_http( stat.mtime ); ["Content-Type"] = self.mime.to_mime( file ); ["Content-Length"] = stat.size; - ["ETag"] = self:_mk_etag( stat ); + ["ETag"] = etag; } ), ltn12.source.file(io.open(file)) else |