Mercurial Hosting > luan
comparison http/src/luan/modules/http/dump.luan @ 500:ab9c2afefb47
add response.binary_writer
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 May 2015 20:59:30 -0600 |
parents | fa4af530697f |
children | 40e18d335da9 |
comparison
equal
deleted
inserted
replaced
499:fa4af530697f | 500:ab9c2afefb47 |
---|---|
1 local Luan = require "luan:Luan" | 1 local Luan = require "luan:Luan" |
2 local pairs = Luan.pairs | 2 local pairs = Luan.pairs |
3 local ipairs = Luan.ipairs | 3 local ipairs = Luan.ipairs |
4 local Io = require "luan:Io" | 4 local Io = require "luan:Io" |
5 local Http = require "luan:http/Http" | 5 local Http = require "luan:http/Http" |
6 java() | |
7 local HttpServicer = require "java:luan.modules.http.HttpServicer" | |
6 | 8 |
9 | |
10 to_http_header_name = HttpServicer.toHttpHeaderName | |
7 | 11 |
8 function respond() | 12 function respond() |
9 Http.response.header.content_type = "text/plain" | 13 Http.response.header.content_type = "text/plain" |
10 Io.stdout = Http.response.text_writer() | 14 Io.stdout = Http.response.text_writer() |
11 | 15 |
16 path = path.."?"..query | 20 path = path.."?"..query |
17 end | 21 end |
18 %> | 22 %> |
19 <%=method%> <%=path%> <%=Http.request.protocol%> | 23 <%=method%> <%=path%> <%=Http.request.protocol%> |
20 <% | 24 <% |
21 for name, values in pairs(Http.request.headers) do | 25 dump_headers(Http.request.headers) |
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 %> | 26 %> |
30 | 27 |
31 <% | 28 <% |
32 if method == "POST" and query ~= nil then | 29 if method == "POST" and query ~= nil then |
33 %> | 30 %> |
34 <%=query%> | 31 <%=query%> |
35 <% | 32 <% |
36 end | 33 end |
37 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 |