diff http/src/luan/modules/http/Http.luan @ 499:fa4af530697f

add http/dump
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 May 2015 14:24:50 -0600
parents ee55be414a34
children ab9c2afefb47
line wrap: on
line diff
--- a/http/src/luan/modules/http/Http.luan	Mon May 18 00:25:35 2015 -0600
+++ b/http/src/luan/modules/http/Http.luan	Mon May 18 14:24:50 2015 -0600
@@ -10,6 +10,9 @@
 local IoLuan = require "java:luan.modules.IoLuan"
 
 
+to_header_name = HttpServicer.toHeaderName
+
+
 local singular_metatable = {}
 
 function singular_metatable.__index(table,key)
@@ -50,23 +53,30 @@
 	set_metatable(this.parameter,singular_metatable)
 	this.cookie = {}
 
-	function this.url()
+	function this.query_string()
 		local string_uri = Io.uri "string:"
 		local out = string_uri.text_writer()
-
-		out.write( this.scheme, "://", this.header.host, this.path )
-		if this.method ~= "POST" then
-			local and_char = "?"
-			for name, values in pairs(this.parameters) do
-				for _, value in ipairs(values) do
-					out.write( and_char, url_encode(name), "=", url_encode(value) )
-					and_char = "&"
-				end
+		local and_char = ""
+		for name, values in pairs(this.parameters) do
+			for _, value in ipairs(values) do
+				out.write( and_char, url_encode(name), "=", url_encode(value) )
+				and_char = "&"
 			end
 		end
+		out.close()
+		local s = string_uri.read_text()
+		return s == "" and nil or s
+	end
 
-		out.close()
-		return string_uri.read_text()
+	function this.url()
+		local url = this.scheme.."://"..this.header.host..this.path
+		if this.method ~= "POST" then
+			local query = this.query_string()
+			if query ~= nil then
+				url = url.."?"..query
+			end
+		end
+		return url
 	end
 
 	return this
@@ -100,6 +110,7 @@
 end
 
 -- request = new_request{}  -- filled in by HttpServicer
+-- response = new_response{}  -- filled in by HttpServicer