Mercurial Hosting > luan
annotate 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 |
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" |
1143
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
1136
diff
changeset
|
2 local error = Luan.error |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
1136
diff
changeset
|
3 local pairs = Luan.pairs or error() |
3bf5190b3c77
webserver - handle GET params
Franklin Schmidt <fschmidt@gmail.com>
parents:
1136
diff
changeset
|
4 local ipairs = Luan.ipairs or error() |
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
507
diff
changeset
|
5 local Io = require "luan:Io.luan" |
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
507
diff
changeset
|
6 local Http = require "luan:http/Http.luan" |
1150
0842b9b570f8
change http headers interface
Franklin Schmidt <fschmidt@gmail.com>
parents:
1143
diff
changeset
|
7 |
499 | 8 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
9 local Dump_mod = {} |
499 | 10 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
11 function Dump_mod.respond() |
1150
0842b9b570f8
change http headers interface
Franklin Schmidt <fschmidt@gmail.com>
parents:
1143
diff
changeset
|
12 Http.response.headers["content-type"] = "text/plain" |
499 | 13 Io.stdout = Http.response.text_writer() |
14 | |
15 local method = Http.request.method | |
16 local path = Http.request.path | |
17 local query = Http.request.query_string() | |
18 if method ~= "POST" and query ~= nil then | |
19 path = path.."?"..query | |
20 end | |
21 %> | |
22 <%=method%> <%=path%> <%=Http.request.protocol%> | |
23 <% | |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
24 Dump_mod.dump_headers(Http.request.headers) |
499 | 25 %> |
26 | |
27 <% | |
28 if method == "POST" and query ~= nil then | |
29 %> | |
30 <%=query%> | |
31 <% | |
32 end | |
33 end | |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
34 |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
35 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
36 function Dump_mod.dump_headers(headers) |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
37 for name, values in pairs(headers) do |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
38 for _, value in ipairs(values) do |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
39 %> |
1150
0842b9b570f8
change http headers interface
Franklin Schmidt <fschmidt@gmail.com>
parents:
1143
diff
changeset
|
40 <%=name%>: <%=value%> |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
41 <% |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
42 end |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
43 end |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
44 end |
507 | 45 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
46 return Dump_mod |