Server Gateway Interface for Haserl
FileId:
-$Id: haserl.lua 2004 2008-05-05 19:56:14Z Cyrus $
+$Id$
License:
Copyright 2008 Steven Barth <steven@midlink.org>
]]--
module("ffluci.sgi.webuci", package.seeall)
--- HTTP interface
+-- Environment Table
+ffluci.http.env = webuci.env
+
+
+local status_set = false
-- Returns a table of all COOKIE, GET and POST Parameters
-function ffluci.http.formvalues(prefix)
+function ffluci.http.formvalues()
return webuci.vars
end
return vals
end
-
--- Returns the User's IP
-function ffluci.http.get_remote_addr()
- return os.getenv("REMOTE_ADDR")
+-- Sends a custom HTTP-Header
+function ffluci.http.header(key, value)
+ print(key .. ": " .. value)
end
--- Returns the script name
-function ffluci.http.get_script_name()
- return os.getenv("SCRIPT_NAME")
-end
-
-
--- Asks the browser to redirect to "url"
-function ffluci.http.redirect(url, qs)
- if qs then
- url = url .. "?" .. qs
+-- Set Content-Type
+function ffluci.http.prepare_content(type)
+ if not status_set then
+ ffluci.http.status(200, "OK")
end
- ffluci.http.set_status(302, "Found")
- print("Location: " .. url .. "\n")
+ print("Content-Type: "..type.."\n")
end
-
--- Set Content-Type
-function ffluci.http.set_content_type(type)
- print("Content-Type: "..type.."\n")
+-- Asks the browser to redirect to "url"
+function ffluci.http.redirect(url)
+ ffluci.http.status(302, "Found")
+ ffluci.http.header("Location", url)
+ print()
end
-- Sets HTTP-Status-Header
-function ffluci.http.set_status(code, message)
- print("Status: " .. tostring(code) .. " " .. message)
+function ffluci.http.status(code, message)
+ print(webuci.env.SERVER_PROTOCOL .. " " .. tostring(code) .. " " .. message)
+ status_set = true
end