503
|
1 local Io = require "luan:Io"
|
|
2 local Http = require "luan:http/Http"
|
|
3
|
|
4 local M = {}
|
|
5
|
|
6 M.welcome_file = "index.html"
|
|
7 M.cookies = {}
|
|
8
|
|
9 function M.get_page(path)
|
|
10 if M.welcome_file ~= nil and path.matches ".*/" then
|
|
11 path = path .. M.welcome_file
|
|
12 end
|
|
13 local old_out = Io.stdout
|
|
14 local mod = require("site:"..path)
|
|
15 mod.respond()
|
|
16 M.text_writer.close()
|
|
17 Io.stdout = old_out
|
|
18 return M.result.read_text()
|
|
19 end
|
|
20
|
|
21 function M.init()
|
|
22 Http.request = Http.new_request{}
|
|
23 Http.request.cookies = M.cookies
|
|
24
|
|
25 Http.response = Http.new_response{
|
|
26
|
|
27 text_writer = function()
|
|
28 M.result = Io.uri "string:"
|
|
29 M.text_writer = M.result.text_writer()
|
|
30 return M.text_writer
|
|
31 end;
|
|
32
|
|
33 set_cookie = function(name,value)
|
|
34 M.cookies[name] = value
|
|
35 end;
|
|
36
|
|
37 remove_cookie = function(name)
|
|
38 M.cookies[name] = nil
|
|
39 end;
|
|
40
|
|
41 send_redirect = function(url)
|
|
42 Http.response.redirect = url
|
|
43 end;
|
|
44
|
|
45 }
|
|
46
|
|
47 end
|
|
48
|
|
49 return M
|