diff http/src/luan/modules/http/Http.luan @ 498:ee55be414a34

Http.response is now mostly luan
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 May 2015 00:25:35 -0600
parents 55f9f74f1e55
children fa4af530697f
line wrap: on
line diff
--- a/http/src/luan/modules/http/Http.luan	Sun May 17 19:25:47 2015 -0600
+++ b/http/src/luan/modules/http/Http.luan	Mon May 18 00:25:35 2015 -0600
@@ -1,3 +1,4 @@
+java()
 local Luan = require "luan:Luan"
 local ipairs = Luan.ipairs
 local pairs = Luan.pairs
@@ -5,6 +6,8 @@
 local Io = require "luan:Io"
 local Html = require "luan:Html"
 local url_encode = Html.url_encode
+local HttpServicer = require "java:luan.modules.http.HttpServicer"
+local IoLuan = require "java:luan.modules.IoLuan"
 
 
 local singular_metatable = {}
@@ -69,6 +72,33 @@
 	return this
 end
 
+STATUS = {
+	OK = 200;
+	-- add more as needed
+}
+
+function new_response(this)
+	this = new_common(this)
+	this.status = STATUS.OK
+	if this.java ~= nil then
+		this.send_redirect = this.java.sendRedirect
+		this.send_error = this.java.sendError
+
+		function this.set_cookie(name,value,is_persistent,domain)
+			HttpServicer.setCookie(this.java,response.java,name,value,is_persistent,domain)
+		end
+
+		function this.remove_cookie(name,domain)
+			HttpServicer.removeCookie(this.java,response.java,name,domain)
+		end
+
+		function this.text_writer()
+			return IoLuan.textWriter(this.java.getWriter())
+		end
+	end
+	return this
+end
+
 -- request = new_request{}  -- filled in by HttpServicer