diff http/src/luan/modules/http/Http.luan @ 503:92c3d22745b8

make _ENV optional
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 May 2015 23:24:46 -0600
parents ab9c2afefb47
children dbdf4b8193a8
line wrap: on
line diff
--- a/http/src/luan/modules/http/Http.luan	Tue May 19 17:57:20 2015 -0600
+++ b/http/src/luan/modules/http/Http.luan	Wed May 20 23:24:46 2015 -0600
@@ -9,6 +9,7 @@
 local HttpServicer = require "java:luan.modules.http.HttpServicer"
 local IoLuan = require "java:luan.modules.IoLuan"
 
+local M = {}
 
 local singular_metatable = {}
 
@@ -39,7 +40,7 @@
 end
 
 
-function new_request(this)
+function M.new_request(this)
 	this = new_common(this)
 	this.method = "GET"  -- default
 	-- this.path
@@ -79,12 +80,13 @@
 	return this
 end
 
-STATUS = {
+local STATUS = {
 	OK = 200;
 	-- add more as needed
 }
+M.STATUS = STATUS
 
-function new_response(this)
+function M.new_response(this)
 	this = new_common(this)
 	this.status = STATUS.OK
 	if this.java ~= nil then
@@ -92,11 +94,11 @@
 		this.send_error = this.java.sendError
 
 		function this.set_cookie(name,value,is_persistent,domain)
-			HttpServicer.setCookie(this.java,response.java,name,value,is_persistent,domain)
+			HttpServicer.setCookie(this.java,M.response.java,name,value,is_persistent,domain)
 		end
 
 		function this.remove_cookie(name,domain)
-			HttpServicer.removeCookie(this.java,response.java,name,domain)
+			HttpServicer.removeCookie(this.java,M.response.java,name,domain)
 		end
 
 		function this.text_writer()
@@ -113,51 +115,4 @@
 -- request = new_request{}  -- filled in by HttpServicer
 -- response = new_response{}  -- filled in by HttpServicer
 
-
-
-function init_for_test()
-
-	test = test or {}
-
-	test.welcome_file = "index.html"
-
-	function get_page(path)
-		if test.welcome_file ~= nil and path.matches ".*/" then
-			path = path .. test.welcome_file
-		end
-		local old_out = Io.stdout
-		local mod = require("site:"..path)
-		mod.respond()
-		test.text_writer.close()
-		Io.stdout = old_out
-		return result.read_text()
-	end
-
-	test.cookies = test.cookies or {}
-
-	request = new_request{}
-	request.cookies = test.cookies
-
-	response = new_response{
-
-		text_writer = function()
-			result = Io.uri "string:"
-			test.text_writer = result.text_writer()
-			return test.text_writer
-		end;
-
-		set_cookie = function(name,value)
-			test.cookies[name] = value
-		end;
-
-		remove_cookie = function(name)
-			test.cookies[name] = nil
-		end;
-
-		send_redirect = function(url)
-			response.redirect = url
-		end;
-
-	}
-
-end
+return M