Mercurial Hosting > luan
annotate http/src/luan/modules/http/Http_test.luan @ 528:a24abf172f8f 0.9
Removed tag 0.9
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 27 May 2015 03:29:35 -0600 |
parents | 9218f9cf45d3 |
children | 473e456444ff |
rev | line source |
---|---|
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" | |
508 | 7 M.cookie = {} |
503 | 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) | |
505
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
15 mod() |
503 | 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{} | |
508 | 23 Http.request.cookie = M.cookie |
503 | 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) | |
508 | 34 M.cookie[name] = value |
503 | 35 end; |
36 | |
37 remove_cookie = function(name) | |
508 | 38 M.cookie[name] = nil |
503 | 39 end; |
40 | |
41 send_redirect = function(url) | |
42 Http.response.redirect = url | |
43 end; | |
44 | |
45 } | |
46 | |
47 end | |
48 | |
49 return M |