comparison http/src/luan/modules/http/dump.luan @ 507:40e18d335da9

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