-- Helper Functions function file_exists(path) local attr = lighty.stat(path) if (attr and attr["is_file"]) then return true else return false end end function removePrefix(str, prefix) return str:sub(1,#prefix+1) == prefix.."/" and str:sub(#prefix+2) end function string.starts(x,y) return string.sub(x,1,string.len(y)) == y end -- Set for subdirectory drupal installs. Example: "/drupal" local prefix = '' -- If this is not an existing file if (not file_exists(lighty.env["physical.path"])) then -- Set local variables local FINAL_PATH = "empty" local request_uri = removePrefix(lighty.env["uri.path"], prefix) -- none should be set to '/' local query_string = lighty.env["uri.query"] local cookies = lighty.request["Cookie"] or "NOCOOKIE" --print ("URI "..request_uri) -- filters for boost cache (anon+GET) to qualify boost caching local SERVE_CACHED_FLAG = (string.find(cookies, "DRUPAL_UID") == nil) and (lighty.env["request.method"] == "GET") local RESTRICTED_PATHS = (string.starts(request_uri, "/admin")) or (string.starts(request_uri, "/cache")) or (string.starts(request_uri, "/openid")) or (string.starts(request_uri, "/node/add")) or (string.starts(request_uri, "/user")) -- qualifies for boost cache type if (SERVE_CACHED_FLAG == true and RESTRICTED_PATHS == false) then -- Build filename based on URL for the boost cache local normal_boost_path_uribase = lighty.env["physical.doc-root"] .. prefix .. "/cache/normal/" .. lighty.request["Host"] .. "/" .. request_uri .. "_" local normal_gzip_boost_path_uribase = lighty.env["physical.doc-root"] .. prefix .. "/cache/normal/" .. lighty.request["Host"] .. "/" .. request_uri .. "_" local perm_boost_path_uribase = lighty.env["physical.doc-root"] .. prefix .. "/cache/perm/" .. lighty.request["Host"] .. "/" .. request_uri .. "_" local perm_gzip_boost_path_uribase = lighty.env["physical.doc-root"] .. prefix .. "/cache/perm/" .. lighty.request["Host"] .. "/" .. request_uri .. "_" if (query_string) then normal_boost_path_uribase = normal_boost_path_uribase .. query_string normal_gzip_boost_path_uribase = normal_gzip_boost_path_uribase .. query_string end -- Set Final Path, Content-Type & Content-Encoding if this file exists. if (string.find(lighty.request["Accept-Encoding"], "gzip") or string.find(cookies, "boost-gzip")) -- Try gzip first if (file_exists(normal_gzip_boost_path_uribase .. ".html.gz")) then FINAL_PATH = normal_gzip_boost_path_uribase .. ".html.gz" lighty.header["Content-Encoding"] = "gzip" lighty.header["Content-Type"] = "text/html" elseif (file_exists(perm_gzip_boost_path_uribase .. ".css.gz")) then FINAL_PATH = perm_gzip_boost_path_uribase .. ".css.gz" lighty.header["Content-Encoding"] = "gzip" lighty.header["Content-Type"] = "text/css" elseif (file_exists(perm_gzip_boost_path_uribase .. ".js.gz")) then FINAL_PATH = perm_gzip_boost_path_uribase .. ".js.gz" lighty.header["Content-Encoding"] = "gzip" lighty.header["Content-Type"] = "text/javascript" elseif (file_exists(normal_gzip_boost_path_uribase .. ".xml.gz")) then FINAL_PATH = normal_gzip_boost_path_uribase .. ".xml.gz" lighty.header["Content-Encoding"] = "gzip" lighty.header["Content-Type"] = "text/xml" elseif (file_exists(normal_gzip_boost_path_uribase .. ".json.gz")) then FINAL_PATH = normal_gzip_boost_path_uribase .. ".json.gz" lighty.header["Content-Encoding"] = "gzip" lighty.header["Content-Type"] = "text/javascript" end else if (file_exists(normal_boost_path_uribase .. ".html")) then FINAL_PATH = normal_boost_path_uribase .. ".html" lighty.header["Content-Type"] = "text/html" elseif (file_exists(perm_boost_path_uribase .. ".css")) then FINAL_PATH = perm_boost_path_uribase .. ".html" lighty.header["Content-Type"] = "text/css" elseif (file_exists(perm_boost_path_uribase .. ".js")) then FINAL_PATH = perm_boost_path_uribase .. ".html" lighty.header["Content-Type"] = "text/javascript" elseif (file_exists(normal_boost_path_uribase .. ".xml")) then FINAL_PATH = normal_boost_path_uribase .. ".html" lighty.header["Content-Type"] = "text/xml" elseif (file_exists(normal_boost_path_uribase .. ".json")) then FINAL_PATH = normal_boost_path_uribase .. ".html" lighty.header["Content-Type"] = "text/javascript" end -- Aggressive gzip cookie test elseif (request_uri == "/boost-gzip-cookie-test.html") then FINAL_PATH = lighty.env["physical.doc-root"] .. prefix .. "/cache/perm/boost-gzip-cookie-test.html.gz" lighty.header["Content-Encoding"] = "gzip" lighty.header["Content-Type"] = "text/html" end -- File not in cache. pass it to the fastcgi backend if (FINAL_PATH == "empty") then lighty.env["uri.path"] = prefix .. "/index.php" lighty.env["uri.query"] = query_string .. (query_string ~= "" and "&" or "") .. "q=" .. request_uri lighty.env["physical.rel-path"] = lighty.env["uri.path"] lighty.env["request.orig-uri"] = lighty.env["request.uri"] FINAL_PATH = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"] else -- Set Boost Headers lighty.header["X-Header"] = "Boost Citrus 1.7" lighty.header["Expires"] = "Sun, 19 Nov 1978 05:00:00 GMT" lighty.header["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0" end --print("Final Path Query "..lighty.env["uri.query"]) lighty.env["physical.path"] = FINAL_PATH end