Skip to content

Instantly share code, notes, and snippets.

@darix
Last active Oct 3, 2017
Embed
What would you like to do?
-- 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. ;)
@polyzen

This comment has been minimized.

Copy link

@polyzen polyzen commented Sep 3, 2015

thank you :)

@darix

This comment has been minimized.

Copy link
Owner Author

@darix darix commented Sep 3, 2015

lighty config snippet

magnet.attract-physical-path-to = ( conf_dir + "/sendcompressed.lua" )
@polyzen

This comment has been minimized.

Copy link

@polyzen polyzen commented Sep 3, 2015

awesome..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment