comparison http/src/luan/modules/http/Http.luan @ 580:1e69d9c21461

add Table.clear(); add Http.response.reset(); fix http/run;
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 21 Jul 2015 14:56:41 -0600
parents f1601a4ce1aa
children 1368ca798ccc
comparison
equal deleted inserted replaced
579:f22a09e98b04 580:1e69d9c21461
5 local pairs = Luan.pairs or error() 5 local pairs = Luan.pairs or error()
6 local set_metatable = Luan.set_metatable or error() 6 local set_metatable = Luan.set_metatable or error()
7 local Io = require "luan:Io" 7 local Io = require "luan:Io"
8 local Html = require "luan:Html" 8 local Html = require "luan:Html"
9 local url_encode = Html.url_encode or error() 9 local url_encode = Html.url_encode or error()
10 local Table = require "luan:Table"
11 local clear = Table.clear or error()
10 local HttpServicer = require "java:luan.modules.http.HttpServicer" 12 local HttpServicer = require "java:luan.modules.http.HttpServicer"
11 local IoLuan = require "java:luan.modules.IoLuan" 13 local IoLuan = require "java:luan.modules.IoLuan"
12 14
13 local M = {} 15 local M = {}
14 16
33 35
34 local function sent_error() 36 local function sent_error()
35 error "headers are not accessible after you start writing content" 37 error "headers are not accessible after you start writing content"
36 end 38 end
37 39
38 M.sent_error_metatable = { __index=sent_error, __new_index=sent_error } 40 local sent_error_metatable = { __index=sent_error, __new_index=sent_error }
39 41
42 function M.sent_headers(headers)
43 clear(headers)
44 set_metatable(headers,sent_error_metatable)
45 end
40 46
41 47
42 local function new_common(this) 48 local function new_common(this)
43 this = this or {} 49 this = this or {}
44 this.headers = {} 50 this.headers = {}
109 HttpServicer.removeCookie(M.request.java,this.java,name,domain) 115 HttpServicer.removeCookie(M.request.java,this.java,name,domain)
110 end 116 end
111 117
112 function this.set() 118 function this.set()
113 HttpServicer.setResponse(this,this.java) 119 HttpServicer.setResponse(this,this.java)
114 set_metatable(this.headers,M.sent_error_metatable) 120 M.sent_headers(this.headers)
115 end 121 end
116 122
117 function this.text_writer() 123 function this.text_writer()
118 this.set() 124 this.set()
119 return IoLuan.textWriter(this.java.getWriter()) 125 return IoLuan.textWriter(this.java.getWriter())
120 end 126 end
121 127
122 function this.binary_writer() 128 function this.binary_writer()
123 this.set() 129 this.set()
124 return IoLuan.binaryWriter(this.java.getOutputStream()) 130 return IoLuan.binaryWriter(this.java.getOutputStream())
131 end
132
133 function this.reset()
134 this.java.reset()
135 set_metatable(this.headers,nil)
125 end 136 end
126 end 137 end
127 return this 138 return this
128 end 139 end
129 140