Mercurial Hosting > luan
view http/src/luan/modules/http/Http_test.luan @ 629:35dde32c02ab 0.15
change String.matches()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 Jan 2016 23:07:52 -0700 |
parents | 1e69d9c21461 |
children | ca169567ce07 |
line wrap: on
line source
local Luan = require "luan:Luan" local error = Luan.error local set_metatable = Luan.set_metatable or error() local Io = require "luan:Io" local String = require "luan:String" local matches = String.matches or error() local Http = require "luan:http/Http" local M = {} M.welcome_file = "index.html" M.cookie = {} function M.get_page(path) if M.welcome_file ~= nil and matches(path,"/$") 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.cookie = M.cookie Http.response = Http.new_response{ text_writer = function() Http.sent_headers(Http.response.headers) M.result = Io.uri "string:" M.text_writer = M.result.text_writer() return M.text_writer end; set_cookie = function(name,value) M.cookie[name] = value end; remove_cookie = function(name) M.cookie[name] = nil end; send_redirect = function(url) Http.response.redirect = url end; } end return M