Mercurial Hosting > luan
view 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 |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local pairs = Luan.pairs local ipairs = Luan.ipairs local Io = require "luan:Io.luan" local Http = require "luan:http/Http.luan" java() local Implementation = require "luan:http/Implementation.luan" local HttpServicer = require(Implementation.java.."HttpServicer") local Dump_mod = {} local to_http_header_name = HttpServicer.toHttpHeaderName Dump_mod.to_http_header_name = to_http_header_name function Dump_mod.respond() Http.response.header.content_type = "text/plain" Io.stdout = Http.response.text_writer() local method = Http.request.method local path = Http.request.path local query = Http.request.query_string() if method ~= "POST" and query ~= nil then path = path.."?"..query end %> <%=method%> <%=path%> <%=Http.request.protocol%> <% Dump_mod.dump_headers(Http.request.headers) %> <% if method == "POST" and query ~= nil then %> <%=query%> <% end end function Dump_mod.dump_headers(headers) for name, values in pairs(headers) do local header_name = to_http_header_name(name) for _, value in ipairs(values) do %> <%=header_name%>: <%=value%> <% end end end return Dump_mod