Mercurial Hosting > luan
diff http/src/luan/modules/http/dump.luan @ 499:fa4af530697f
add http/dump
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 May 2015 14:24:50 -0600 |
parents | |
children | ab9c2afefb47 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/http/src/luan/modules/http/dump.luan Mon May 18 14:24:50 2015 -0600 @@ -0,0 +1,37 @@ +local Luan = require "luan:Luan" +local pairs = Luan.pairs +local ipairs = Luan.ipairs +local Io = require "luan:Io" +local Http = require "luan:http/Http" + + +function 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%> +<% + for name, values in pairs(Http.request.headers) do + local header_name = Http.to_header_name(name) + for _, value in ipairs(values) do +%> +<%=header_name%>: <%=value%> +<% + end + end +%> + +<% + if method == "POST" and query ~= nil then +%> +<%=query%> +<% + end +end