comparison http/src/luan/modules/http/dump.luan @ 499:fa4af530697f

add http/dump
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 May 2015 14:24:50 -0600
parents
children ab9c2afefb47
comparison
equal deleted inserted replaced
498:ee55be414a34 499:fa4af530697f
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
7
8 function respond()
9 Http.response.header.content_type = "text/plain"
10 Io.stdout = Http.response.text_writer()
11
12 local method = Http.request.method
13 local path = Http.request.path
14 local query = Http.request.query_string()
15 if method ~= "POST" and query ~= nil then
16 path = path.."?"..query
17 end
18 %>
19 <%=method%> <%=path%> <%=Http.request.protocol%>
20 <%
21 for name, values in pairs(Http.request.headers) do
22 local header_name = Http.to_header_name(name)
23 for _, value in ipairs(values) do
24 %>
25 <%=header_name%>: <%=value%>
26 <%
27 end
28 end
29 %>
30
31 <%
32 if method == "POST" and query ~= nil then
33 %>
34 <%=query%>
35 <%
36 end
37 end