comparison src/luan/modules/http/Http_test.luan @ 1088:bae2d0c2576c

change module naming convention
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 26 Dec 2016 22:29:36 -0700
parents 9c13a15a4002
children 1f4da56abd4f
comparison
equal deleted inserted replaced
1087:4aab4dd3ac9c 1088:bae2d0c2576c
7 local String = require "luan:String.luan" 7 local String = require "luan:String.luan"
8 local matches = String.matches or error() 8 local matches = String.matches or error()
9 local Http = require "luan:http/Http.luan" 9 local Http = require "luan:http/Http.luan"
10 10
11 11
12 local M = {} 12 local Http_test = {}
13 13
14 M.welcome_file = "index.html" 14 Http_test.welcome_file = "index.html"
15 M.cookie = {} 15 Http_test.cookie = {}
16 16
17 function M.get_page(path) 17 function Http_test.get_page(path)
18 Http.request.path = path 18 Http.request.path = path
19 if M.welcome_file ~= nil and matches(path,"/$") then 19 if Http_test.welcome_file ~= nil and matches(path,"/$") then
20 path = path .. M.welcome_file 20 path = path .. Http_test.welcome_file
21 end 21 end
22 local old_out = Io.stdout 22 local old_out = Io.stdout
23 try { 23 try {
24 function() 24 function()
25 local mod = Package.load("site:"..path..".luan") 25 local mod = Package.load("site:"..path..".luan")
28 else 28 else
29 local not_found = Package.load("site:/not_found.luan") 29 local not_found = Package.load("site:/not_found.luan")
30 not_found or error(path.." not found") 30 not_found or error(path.." not found")
31 not_found() 31 not_found()
32 end 32 end
33 M.text_writer.close() 33 Http_test.text_writer.close()
34 end 34 end
35 finally = function() 35 finally = function()
36 Io.stdout = old_out 36 Io.stdout = old_out
37 end 37 end
38 } 38 }
39 return M.result.read_text() 39 return Http_test.result.read_text()
40 end 40 end
41 41
42 function M.init() 42 function Http_test.init()
43 Http.request = Http.new_request{} 43 Http.request = Http.new_request{}
44 Http.request.cookie = M.cookie 44 Http.request.cookie = Http_test.cookie
45 45
46 Http.response = Http.new_response{ 46 Http.response = Http.new_response{
47 47
48 text_writer = function() 48 text_writer = function()
49 Http.sent_headers(Http.response.headers) 49 Http.sent_headers(Http.response.headers)
50 M.result = Io.uri "string:" 50 Http_test.result = Io.uri "string:"
51 M.text_writer = M.result.text_writer() 51 Http_test.text_writer = Http_test.result.text_writer()
52 return M.text_writer 52 return Http_test.text_writer
53 end 53 end
54 54
55 set_cookie = function(name,value) 55 set_cookie = function(name,value)
56 M.cookie[name] = value 56 Http_test.cookie[name] = value
57 end 57 end
58 58
59 remove_cookie = function(name) 59 remove_cookie = function(name)
60 M.cookie[name] = nil 60 Http_test.cookie[name] = nil
61 end 61 end
62 62
63 send_redirect = function(url) 63 send_redirect = function(url)
64 Http.response.redirect = url 64 Http.response.redirect = url
65 end 65 end
70 70
71 } 71 }
72 72
73 end 73 end
74 74
75 return M 75 return Http_test