diff http/src/luan/modules/http/Http_test.luan @ 506:342964519194

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 May 2015 12:15:44 -0600
parents http/src/luan/modules/http/HttpTest.luan@7bc63886d4f2
children 9218f9cf45d3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/http/src/luan/modules/http/Http_test.luan	Thu May 21 12:15:44 2015 -0600
@@ -0,0 +1,49 @@
+local Io = require "luan:Io"
+local Http = require "luan:http/Http"
+
+local M = {}
+
+M.welcome_file = "index.html"
+M.cookies = {}
+
+function M.get_page(path)
+	if M.welcome_file ~= nil and path.matches ".*/" then
+		path = path .. M.welcome_file
+	end
+	local old_out = Io.stdout
+	local mod = require("site:"..path)
+	mod()
+	M.text_writer.close()
+	Io.stdout = old_out
+	return M.result.read_text()
+end
+
+function M.init()
+	Http.request = Http.new_request{}
+	Http.request.cookies = M.cookies
+
+	Http.response = Http.new_response{
+
+		text_writer = function()
+			M.result = Io.uri "string:"
+			M.text_writer = M.result.text_writer()
+			return M.text_writer
+		end;
+
+		set_cookie = function(name,value)
+			M.cookies[name] = value
+		end;
+
+		remove_cookie = function(name)
+			M.cookies[name] = nil
+		end;
+
+		send_redirect = function(url)
+			Http.response.redirect = url
+		end;
+
+	}
+
+end
+
+return M