From 13e2bfbe9c4f9ac8583ef49da6bdcf6fe86aa755 Mon Sep 17 00:00:00 2001 From: Hazar Karabay Date: Sat, 29 Aug 2015 15:30:37 +0300 Subject: [PATCH] Use gzipped file if exists If foo.html is requested and not found, foo.html.gz is checked and if exists, will served. --- httpserver.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/httpserver.lua b/httpserver.lua index 8435178..b48ef2a 100644 --- a/httpserver.lua +++ b/httpserver.lua @@ -23,8 +23,21 @@ return function (port) fileServeFunction = dofile("httpserver-error.lc") else local fileExists = file.open(uri.file, "r") + file.close() + + if not fileExists then + -- gzip check + fileExists = file.open(uri.file .. ".gz", "r") file.close() - if not fileExists then + + if fileExists then + print("gzip variant exists, serving that one") + uri.file = uri.file .. ".gz" + uri.ext = uri.ext .. ".gz" + end + end + + if not fileExists then uri.args = {code = 404, errorString = "Not Found"} fileServeFunction = dofile("httpserver-error.lc") elseif uri.isScript then