Mercurial Hosting > luan
comparison http/src/luan/modules/http/Dump_mod.luan @ 507:40e18d335da9
fix http/dump
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 May 2015 17:03:57 -0600 |
parents | http/src/luan/modules/http/dump.luan@ab9c2afefb47 |
children | ca169567ce07 |
comparison
equal
deleted
inserted
replaced
506:342964519194 | 507:40e18d335da9 |
---|---|
1 local Luan = require "luan:Luan" | |
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 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 |