net.httpserver: Allow response.body to be a non-string

Wed, 05 Aug 2009 03:07:45 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 05 Aug 2009 03:07:45 +0100
changeset 1632
4a70cbb0fad7
parent 1626
7f17d0d00fbb
child 1633
7812459eeed7

net.httpserver: Allow response.body to be a non-string

net/httpserver.lua file | annotate | diff | comparison | revisions
--- a/net/httpserver.lua	Mon Aug 03 21:48:51 2009 +0500
+++ b/net/httpserver.lua	Wed Aug 05 03:07:45 2009 +0100
@@ -37,6 +37,7 @@
 	-- Write status line
 	local resp;
 	if response.body then
+		local body = tostring(response.body);
 		log("debug", "Sending response to %s", request.id);
 		resp = { "HTTP/1.0 ", response.status or "200 OK", "\r\n"};
 		local h = response.headers;
@@ -48,15 +49,15 @@
 				t_insert(resp, "\r\n");
 			end
 		end
-		if response.body and not (h and h["Content-Length"]) then
+		if not (h and h["Content-Length"]) then
 			t_insert(resp, "Content-Length: ");
-			t_insert(resp, #response.body);
+			t_insert(resp, #body);
 			t_insert(resp, "\r\n");
 		end
 		t_insert(resp, "\r\n");
 		
-		if response.body and request.method ~= "HEAD" then
-			t_insert(resp, response.body);
+		if request.method ~= "HEAD" then
+			t_insert(resp, body);
 		end
 	else
 		-- Response we have is just a string (the body)

mercurial