Last active
October 3, 2017 06:16
-
-
Save darix/5025010490bb0ea70099 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- little helper function | |
function file_exists(path) | |
local attr = lighty.stat(path) | |
if (attr) then | |
return true | |
else | |
return false | |
end | |
end | |
-- the magic ;) | |
local original_attr = lighty.stat(lighty.env["physical.path"]) | |
if (original_attr) then | |
if (lighty.request["Accept-Encoding"]) then | |
if (lighty.request["Accept-Encoding"] ~= "gzip") then | |
local original_content_type = original_attr["content-type"] | |
local compressed_file = lighty.env["physical.path"] .. ".gz" | |
if (file_exists(compressed_file)) then | |
lighty.env["physical.path"] = compressed_file | |
lighty.header["Content-Encoding"] = "gzip" | |
lighty.header["Content-Type"] = original_content_type | |
end | |
end | |
end | |
end | |
-- fallthrough will put it back into the lighty request loop | |
-- that means we get the 304 handling for free. ;) |
lighty config snippet
magnet.attract-physical-path-to = ( conf_dir + "/sendcompressed.lua" )
awesome..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you :)