comparison src/luan/modules/http/Dump_mod.luan @ 775:1a68fc55a80c

simplify dir structure
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 14:36:40 -0600
parents http/src/luan/modules/http/Dump_mod.luan@ca169567ce07
children
comparison
equal deleted inserted replaced
774:3e30cf310e56 775:1a68fc55a80c
1 local Luan = require "luan:Luan.luan"
2 local pairs = Luan.pairs
3 local ipairs = Luan.ipairs
4 local Io = require "luan:Io.luan"
5 local Http = require "luan:http/Http.luan"
6 java()
7 local HttpServicer = require "java:luan.modules.http.HttpServicer"
8
9 local M = {}
10
11 local to_http_header_name = HttpServicer.toHttpHeaderName
12 M.to_http_header_name = to_http_header_name
13
14 function M.respond()
15 Http.response.header.content_type = "text/plain"
16 Io.stdout = Http.response.text_writer()
17
18 local method = Http.request.method
19 local path = Http.request.path
20 local query = Http.request.query_string()
21 if method ~= "POST" and query ~= nil then
22 path = path.."?"..query
23 end
24 %>
25 <%=method%> <%=path%> <%=Http.request.protocol%>
26 <%
27 M.dump_headers(Http.request.headers)
28 %>
29
30 <%
31 if method == "POST" and query ~= nil then
32 %>
33 <%=query%>
34 <%
35 end
36 end
37
38
39 function M.dump_headers(headers)
40 for name, values in pairs(headers) do
41 local header_name = to_http_header_name(name)
42 for _, value in ipairs(values) do
43 %>
44 <%=header_name%>: <%=value%>
45 <%
46 end
47 end
48 end
49
50 return M