comparison src/luan/modules/http/tools/Dump_mod.luan @ 1150:0842b9b570f8

change http headers interface
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 04 Feb 2018 18:03:37 -0700
parents 3bf5190b3c77
children 4beabb087be6
comparison
equal deleted inserted replaced
1149:1b7c20e20ca7 1150:0842b9b570f8
2 local error = Luan.error 2 local error = Luan.error
3 local pairs = Luan.pairs or error() 3 local pairs = Luan.pairs or error()
4 local ipairs = Luan.ipairs or error() 4 local ipairs = Luan.ipairs or error()
5 local Io = require "luan:Io.luan" 5 local Io = require "luan:Io.luan"
6 local Http = require "luan:http/Http.luan" 6 local Http = require "luan:http/Http.luan"
7 java() 7
8 local Implementation = require "luan:http/Implementation.luan"
9 local HttpServicer = require(Implementation.java.."HttpServicer")
10 8
11 local Dump_mod = {} 9 local Dump_mod = {}
12 10
13 local to_http_header_name = HttpServicer.toHttpHeaderName
14 Dump_mod.to_http_header_name = to_http_header_name
15
16 function Dump_mod.respond() 11 function Dump_mod.respond()
17 Http.response.header.content_type = "text/plain" 12 Http.response.headers["content-type"] = "text/plain"
18 Io.stdout = Http.response.text_writer() 13 Io.stdout = Http.response.text_writer()
19 14
20 local method = Http.request.method 15 local method = Http.request.method
21 local path = Http.request.path 16 local path = Http.request.path
22 local query = Http.request.query_string() 17 local query = Http.request.query_string()
38 end 33 end
39 34
40 35
41 function Dump_mod.dump_headers(headers) 36 function Dump_mod.dump_headers(headers)
42 for name, values in pairs(headers) do 37 for name, values in pairs(headers) do
43 local header_name = to_http_header_name(name)
44 for _, value in ipairs(values) do 38 for _, value in ipairs(values) do
45 %> 39 %>
46 <%=header_name%>: <%=value%> 40 <%=name%>: <%=value%>
47 <% 41 <%
48 end 42 end
49 end 43 end
50 end 44 end
51 45