(no commit message)
[project/luci.git] / core / src / ffluci / sgi / webuci.lua
index f97b2445295081e7830919c886b10b08bb8aa194..5e17ab7935607a092593e613f67669cd58166a16 100644 (file)
@@ -5,7 +5,7 @@ Description:
 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>
@@ -25,10 +25,14 @@ limitations under the License.
 ]]--
 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
 
@@ -51,35 +55,29 @@ function ffluci.http.formvaluetable(prefix)
        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