From e08b97565f2a2dfeb482be0f061bfefa93d32556 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 28 Jun 2008 16:12:37 +0000 Subject: * libs/http: fix header handling in conditionals.lua * libs/httpd: add support for RFC2616 / 14.24 - 14.28 in file handler, add Date and Expires headers to luci handler --- libs/http/luasrc/http/protocol.lua | 6 ++++-- libs/http/luasrc/http/protocol/conditionals.lua | 15 +++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'libs/http') diff --git a/libs/http/luasrc/http/protocol.lua b/libs/http/luasrc/http/protocol.lua index 205869a2d..67b425857 100644 --- a/libs/http/luasrc/http/protocol.lua +++ b/libs/http/luasrc/http/protocol.lua @@ -160,7 +160,7 @@ process_states['magic'] = function( msg, chunk, err ) end end end - + -- Can't handle it return nil, "Invalid HTTP message magic" end @@ -533,7 +533,7 @@ function header_source( sock ) local chunk, err, part = sock:receive("*l") -- Line too long - if chunk == nil then + if chunk == nil then if err ~= "timeout" then return nil, part and "Line exceeds maximum allowed length["..part.."]" @@ -779,11 +779,13 @@ end -- Status codes statusmsg = { [200] = "OK", + [304] = "Not Modified", [400] = "Bad Request", [403] = "Forbidden", [404] = "Not Found", [405] = "Method Not Allowed", [411] = "Length Required", + [412] = "Precondition Failed", [500] = "Internal Server Error", [503] = "Server Unavailable", } diff --git a/libs/http/luasrc/http/protocol/conditionals.lua b/libs/http/luasrc/http/protocol/conditionals.lua index 0bff274cd..36f323a6e 100644 --- a/libs/http/luasrc/http/protocol/conditionals.lua +++ b/libs/http/luasrc/http/protocol/conditionals.lua @@ -21,7 +21,7 @@ local date = require("luci.http.protocol.date") -- 14.19 / ETag function mk_etag( stat ) if stat ~= nil then - return string.format( "%x-%x-%x", stat.ino, stat.size, stat.mtime ) + return string.format( '"%x-%x-%x"', stat.ino, stat.size, stat.mtime ) end end @@ -56,7 +56,10 @@ function if_modified_since( req, stat ) return true end - return false, 304 + return false, 304, { + ["ETag"] = mk_etag( stat ); + ["Last-Modified"] = date.to_http( stat.mtime ) + } end return true @@ -74,10 +77,10 @@ function if_none_match( req, stat ) if req.request_method == "get" or req.request_method == "head" then - h['ETag'] = mk_etag( stat ) - h['Last-Modified'] = date.to_http( stat.mtime ) - - return false, 304 + return false, 304, { + ["ETag"] = mk_etag( stat ); + ["Last-Modified"] = date.to_http( stat.mtime ) + } else return false, 412 end -- cgit v1.2.3