Mercurial Hosting > luan
annotate 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 |
rev | line source |
---|---|
499 | 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" | |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
6 java() |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
7 local HttpServicer = require "java:luan.modules.http.HttpServicer" |
499 | 8 |
507 | 9 local M = {} |
499 | 10 |
507 | 11 local to_http_header_name = HttpServicer.toHttpHeaderName |
12 M.to_http_header_name = to_http_header_name | |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
13 |
507 | 14 function M.respond() |
499 | 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 <% | |
507 | 27 M.dump_headers(Http.request.headers) |
499 | 28 %> |
29 | |
30 <% | |
31 if method == "POST" and query ~= nil then | |
32 %> | |
33 <%=query%> | |
34 <% | |
35 end | |
36 end | |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
37 |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
38 |
507 | 39 function M.dump_headers(headers) |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
40 for name, values in pairs(headers) do |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
41 local header_name = to_http_header_name(name) |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
42 for _, value in ipairs(values) do |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
43 %> |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
44 <%=header_name%>: <%=value%> |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
45 <% |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
46 end |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
47 end |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
48 end |
507 | 49 |
50 return M |