X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Fluci-base%2Fluasrc%2Fhttp%2Fprotocol%2Fconditionals.lua;fp=modules%2Fluci-base%2Fluasrc%2Fhttp%2Fprotocol%2Fconditionals.lua;h=d31a4e38a4f3eb2ed260d3fad5441f1c05271a43;hp=1d40425ff90eae8eccabe97ed0f9c2c16493ccb0;hb=84346cd178ca0740817edc6f81d8f90e7bc6e00c;hpb=cf7e2695cc676dff02561a1a45d6de8140170b17 diff --git a/modules/luci-base/luasrc/http/protocol/conditionals.lua b/modules/luci-base/luasrc/http/protocol/conditionals.lua index 1d40425ff..d31a4e38a 100644 --- a/modules/luci-base/luasrc/http/protocol/conditionals.lua +++ b/modules/luci-base/luasrc/http/protocol/conditionals.lua @@ -1,7 +1,6 @@ -- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich -- Licensed to the public under the Apache License 2.0. ---- LuCI http protocol implementation - HTTP/1.1 bits. -- This class provides basic ETag handling and implements most of the -- conditional HTTP/1.1 headers specified in RFC2616 Sct. 14.24 - 14.28 . module("luci.http.protocol.conditionals", package.seeall) @@ -9,22 +8,14 @@ module("luci.http.protocol.conditionals", package.seeall) local date = require("luci.http.protocol.date") ---- Implement 14.19 / ETag. --- @param stat A file.stat structure --- @return String containing the generated tag suitable for ETag headers function mk_etag( stat ) if stat ~= nil then return string.format( '"%x-%x-%x"', stat.ino, stat.size, stat.mtime ) end end ---- 14.24 / If-Match -- Test whether the given message object contains an "If-Match" header and -- compare it against the given stat object. --- @param req HTTP request message object --- @param stat A file.stat object --- @return Boolean indicating whether the precondition is ok --- @return Alternative status code if the precondition failed function if_match( req, stat ) local h = req.headers local etag = mk_etag( stat ) @@ -43,14 +34,8 @@ function if_match( req, stat ) return true end ---- 14.25 / If-Modified-Since -- Test whether the given message object contains an "If-Modified-Since" header -- and compare it against the given stat object. --- @param req HTTP request message object --- @param stat A file.stat object --- @return Boolean indicating whether the precondition is ok --- @return Alternative status code if the precondition failed --- @return Table containing extra HTTP headers if the precondition failed function if_modified_since( req, stat ) local h = req.headers @@ -72,14 +57,8 @@ function if_modified_since( req, stat ) return true end ---- 14.26 / If-None-Match -- Test whether the given message object contains an "If-None-Match" header and -- compare it against the given stat object. --- @param req HTTP request message object --- @param stat A file.stat object --- @return Boolean indicating whether the precondition is ok --- @return Alternative status code if the precondition failed --- @return Table containing extra HTTP headers if the precondition failed function if_none_match( req, stat ) local h = req.headers local etag = mk_etag( stat ) @@ -105,26 +84,16 @@ function if_none_match( req, stat ) return true end ---- 14.27 / If-Range -- The If-Range header is currently not implemented due to the lack of general -- byte range stuff in luci.http.protocol . This function will always return -- false, 412 to indicate a failed precondition. --- @param req HTTP request message object --- @param stat A file.stat object --- @return Boolean indicating whether the precondition is ok --- @return Alternative status code if the precondition failed function if_range( req, stat ) -- Sorry, no subranges (yet) return false, 412 end ---- 14.28 / If-Unmodified-Since -- Test whether the given message object contains an "If-Unmodified-Since" -- header and compare it against the given stat object. --- @param req HTTP request message object --- @param stat A file.stat object --- @return Boolean indicating whether the precondition is ok --- @return Alternative status code if the precondition failed function if_unmodified_since( req, stat ) local h = req.headers