Mercurial Hosting > luan
annotate src/luan/modules/http/tools/Dump_mod.luan @ 1165:668f29bc52ea
clean up content-type
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 07 Feb 2018 23:16:12 -0700 |
parents | 4beabb087be6 |
children |
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() |
1165
668f29bc52ea
clean up content-type
Franklin Schmidt <fschmidt@gmail.com>
parents:
1160
diff
changeset
|
12 Http.response.headers["content-type"] = "text/plain; charset=utf-8" |
499 | 13 Io.stdout = Http.response.text_writer() |
14 | |
15 local method = Http.request.method | |
1160 | 16 local path = Http.request.full_path() |
499 | 17 %> |
18 <%=method%> <%=path%> <%=Http.request.protocol%> | |
19 <% | |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
20 Dump_mod.dump_headers(Http.request.headers) |
499 | 21 %> |
22 | |
23 <% | |
1160 | 24 if method == "POST" then |
499 | 25 %> |
1160 | 26 <%=Io.repr(Http.request.parameters)%> |
499 | 27 <% |
28 end | |
29 end | |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
30 |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
31 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
32 function Dump_mod.dump_headers(headers) |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
33 for name, values in pairs(headers) do |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
34 for _, value in ipairs(values) do |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
35 %> |
1150
0842b9b570f8
change http headers interface
Franklin Schmidt <fschmidt@gmail.com>
parents:
1143
diff
changeset
|
36 <%=name%>: <%=value%> |
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 end |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
39 end |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
40 end |
507 | 41 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
789
diff
changeset
|
42 return Dump_mod |