diff src/luan/modules/http/Dump_mod.luan @ 775:1a68fc55a80c

simplify dir structure
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 14:36:40 -0600
parents http/src/luan/modules/http/Dump_mod.luan@ca169567ce07
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/modules/http/Dump_mod.luan	Fri Aug 26 14:36:40 2016 -0600
@@ -0,0 +1,50 @@
+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 HttpServicer = require "java:luan.modules.http.HttpServicer"
+
+local M = {}
+
+local to_http_header_name = HttpServicer.toHttpHeaderName
+M.to_http_header_name = to_http_header_name
+
+function M.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%> 
+<%
+	M.dump_headers(Http.request.headers)
+%>
+
+<%
+	if method == "POST" and query ~= nil then
+%>
+<%=query%>
+<%
+	end
+end
+
+
+function M.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 M