Mercurial Hosting > luan
annotate src/luan/modules/http/tools/Dump_mod.luan @ 1136:d30d400fd43d
add http/jetty
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 29 Jan 2018 17:50:49 -0700 |
parents | bae2d0c2576c |
children | 3bf5190b3c77 |
rev | line source |
---|---|
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
507
diff
changeset
|
1 local Luan = require "luan:Luan.luan" |
499 | 2 local pairs = Luan.pairs |
3 local ipairs = Luan.ipairs | |
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
507
diff
changeset
|
4 local Io = require "luan:Io.luan" |
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
507
diff
changeset
|
5 local Http = require "luan:http/Http.luan" |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
6 java() |
1136 | 7 local Implementation = require "luan:http/Implementation.luan" |
8 local HttpServicer = require(Implementation.java.."HttpServicer") | |
499 | 9 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
10 local Dump_mod = {} |
499 | 11 |
507 | 12 local to_http_header_name = HttpServicer.toHttpHeaderName |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
13 Dump_mod.to_http_header_name = to_http_header_name |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
14 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
15 function Dump_mod.respond() |
499 | 16 Http.response.header.content_type = "text/plain" |
17 Io.stdout = Http.response.text_writer() | |
18 | |
19 local method = Http.request.method | |
20 local path = Http.request.path | |
21 local query = Http.request.query_string() | |
22 if method ~= "POST" and query ~= nil then | |
23 path = path.."?"..query | |
24 end | |
25 %> | |
26 <%=method%> <%=path%> <%=Http.request.protocol%> | |
27 <% | |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
28 Dump_mod.dump_headers(Http.request.headers) |
499 | 29 %> |
30 | |
31 <% | |
32 if method == "POST" and query ~= nil then | |
33 %> | |
34 <%=query%> | |
35 <% | |
36 end | |
37 end | |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
38 |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
39 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
40 function Dump_mod.dump_headers(headers) |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
41 for name, values in pairs(headers) do |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
42 local header_name = to_http_header_name(name) |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
43 for _, value in ipairs(values) do |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
44 %> |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
45 <%=header_name%>: <%=value%> |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
46 <% |
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 |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
49 end |
507 | 50 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
51 return Dump_mod |