changeset 507:40e18d335da9

fix http/dump
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 May 2015 17:03:57 -0600
parents 342964519194
children 9218f9cf45d3
files http/src/luan/modules/http/Dump_mod.luan http/src/luan/modules/http/dump.luan scripts/test.luan
diffstat 3 files changed, 54 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
diff -r 342964519194 -r 40e18d335da9 http/src/luan/modules/http/Dump_mod.luan
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/http/src/luan/modules/http/Dump_mod.luan	Thu May 21 17:03:57 2015 -0600
@@ -0,0 +1,50 @@
+local Luan = require "luan:Luan"
+local pairs = Luan.pairs
+local ipairs = Luan.ipairs
+local Io = require "luan:Io"
+local Http = require "luan:http/Http"
+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
diff -r 342964519194 -r 40e18d335da9 http/src/luan/modules/http/dump.luan
--- a/http/src/luan/modules/http/dump.luan	Thu May 21 12:15:44 2015 -0600
+++ b/http/src/luan/modules/http/dump.luan	Thu May 21 17:03:57 2015 -0600
@@ -1,46 +1,1 @@
-local Luan = require "luan:Luan"
-local pairs = Luan.pairs
-local ipairs = Luan.ipairs
-local Io = require "luan:Io"
-local Http = require "luan:http/Http"
-java()
-local HttpServicer = require "java:luan.modules.http.HttpServicer"
-
-
-to_http_header_name = HttpServicer.toHttpHeaderName
-
-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%> 
-<%
-	dump_headers(Http.request.headers)
-%>
-
-<%
-	if method == "POST" and query ~= nil then
-%>
-<%=query%>
-<%
-	end
-end
-
-
-function 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 require("luan:http/Dump_mod").respond
diff -r 342964519194 -r 40e18d335da9 scripts/test.luan
--- a/scripts/test.luan	Thu May 21 12:15:44 2015 -0600
+++ b/scripts/test.luan	Thu May 21 17:03:57 2015 -0600
@@ -44,6 +44,9 @@
 page = get_page "/shell"
 page.find "abcd" or error "failed"
 
+init()
+page = get_page "/dump"
+
 
 -- lucene