Mercurial Hosting > luan
annotate http/src/luan/modules/http/dump.luan @ 500:ab9c2afefb47
add response.binary_writer
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 May 2015 20:59:30 -0600 |
parents | fa4af530697f |
children | 40e18d335da9 |
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 |
9 | |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
10 to_http_header_name = HttpServicer.toHttpHeaderName |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
11 |
499 | 12 function respond() |
13 Http.response.header.content_type = "text/plain" | |
14 Io.stdout = Http.response.text_writer() | |
15 | |
16 local method = Http.request.method | |
17 local path = Http.request.path | |
18 local query = Http.request.query_string() | |
19 if method ~= "POST" and query ~= nil then | |
20 path = path.."?"..query | |
21 end | |
22 %> | |
23 <%=method%> <%=path%> <%=Http.request.protocol%> | |
24 <% | |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
25 dump_headers(Http.request.headers) |
499 | 26 %> |
27 | |
28 <% | |
29 if method == "POST" and query ~= nil then | |
30 %> | |
31 <%=query%> | |
32 <% | |
33 end | |
34 end | |
500
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
35 |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
36 |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
37 function dump_headers(headers) |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
38 for name, values in pairs(headers) do |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
39 local header_name = to_http_header_name(name) |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
40 for _, value in ipairs(values) do |
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 <%=header_name%>: <%=value%> |
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 end |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
45 end |
ab9c2afefb47
add response.binary_writer
Franklin Schmidt <fschmidt@gmail.com>
parents:
499
diff
changeset
|
46 end |