Mercurial Hosting > luan
annotate http/src/luan/modules/http/Http_test.luan @ 539:473e456444ff
Remove object-oriented primitive methods for string and binary
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 01 Jun 2015 17:53:55 -0600 |
parents | 9218f9cf45d3 |
children | cd944b010f25 |
rev | line source |
---|---|
503 | 1 local Io = require "luan:Io" |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
508
diff
changeset
|
2 local String = require "luan:String" |
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
508
diff
changeset
|
3 local matches = String.matches |
503 | 4 local Http = require "luan:http/Http" |
5 | |
6 local M = {} | |
7 | |
8 M.welcome_file = "index.html" | |
508 | 9 M.cookie = {} |
503 | 10 |
11 function M.get_page(path) | |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
508
diff
changeset
|
12 if M.welcome_file ~= nil and matches(path,".*/") then |
503 | 13 path = path .. M.welcome_file |
14 end | |
15 local old_out = Io.stdout | |
16 local mod = require("site:"..path) | |
505
7bc63886d4f2
web page modules now return a function
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
17 mod() |
503 | 18 M.text_writer.close() |
19 Io.stdout = old_out | |
20 return M.result.read_text() | |
21 end | |
22 | |
23 function M.init() | |
24 Http.request = Http.new_request{} | |
508 | 25 Http.request.cookie = M.cookie |
503 | 26 |
27 Http.response = Http.new_response{ | |
28 | |
29 text_writer = function() | |
30 M.result = Io.uri "string:" | |
31 M.text_writer = M.result.text_writer() | |
32 return M.text_writer | |
33 end; | |
34 | |
35 set_cookie = function(name,value) | |
508 | 36 M.cookie[name] = value |
503 | 37 end; |
38 | |
39 remove_cookie = function(name) | |
508 | 40 M.cookie[name] = nil |
503 | 41 end; |
42 | |
43 send_redirect = function(url) | |
44 Http.response.redirect = url | |
45 end; | |
46 | |
47 } | |
48 | |
49 end | |
50 | |
51 return M |