Mercurial Hosting > luan
comparison http/src/luan/modules/http/Http.luan @ 500:ab9c2afefb47
add response.binary_writer
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 May 2015 20:59:30 -0600 |
parents | fa4af530697f |
children | 92c3d22745b8 |
comparison
equal
deleted
inserted
replaced
499:fa4af530697f | 500:ab9c2afefb47 |
---|---|
8 local url_encode = Html.url_encode | 8 local url_encode = Html.url_encode |
9 local HttpServicer = require "java:luan.modules.http.HttpServicer" | 9 local HttpServicer = require "java:luan.modules.http.HttpServicer" |
10 local IoLuan = require "java:luan.modules.IoLuan" | 10 local IoLuan = require "java:luan.modules.IoLuan" |
11 | 11 |
12 | 12 |
13 to_header_name = HttpServicer.toHeaderName | |
14 | |
15 | |
16 local singular_metatable = {} | 13 local singular_metatable = {} |
17 | 14 |
18 function singular_metatable.__index(table,key) | 15 function singular_metatable.__index(table,key) |
19 local list = table.__plural[key] | 16 local list = table.__plural[key] |
20 return list and list[1] | 17 return list and list[1] |
21 end | 18 end |
22 | 19 |
23 function singular_metatable.__new_index(table,key,value) | 20 function singular_metatable.__new_index(table,key,value) |
24 table.__plural[key] = {value} | 21 table.__plural[key] = value and {value} |
25 end | 22 end |
26 | 23 |
27 function singular_metatable.__pairs(table) | 24 function singular_metatable.__pairs(table) |
28 local iter = pairs(table.__plural) | 25 local iter = pairs(table.__plural) |
29 return function() | 26 return function() |
63 and_char = "&" | 60 and_char = "&" |
64 end | 61 end |
65 end | 62 end |
66 out.close() | 63 out.close() |
67 local s = string_uri.read_text() | 64 local s = string_uri.read_text() |
68 return s == "" and nil or s | 65 return s ~= "" and s or nil |
69 end | 66 end |
70 | 67 |
71 function this.url() | 68 function this.url() |
72 local url = this.scheme.."://"..this.header.host..this.path | 69 local url = this.scheme.."://"..this.header.host..this.path |
73 if this.method ~= "POST" then | 70 if this.method ~= "POST" then |
103 end | 100 end |
104 | 101 |
105 function this.text_writer() | 102 function this.text_writer() |
106 return IoLuan.textWriter(this.java.getWriter()) | 103 return IoLuan.textWriter(this.java.getWriter()) |
107 end | 104 end |
105 | |
106 function this.binary_writer() | |
107 return IoLuan.binaryWriter(this.java.getOutputStream()) | |
108 end | |
108 end | 109 end |
109 return this | 110 return this |
110 end | 111 end |
111 | 112 |
112 -- request = new_request{} -- filled in by HttpServicer | 113 -- request = new_request{} -- filled in by HttpServicer |
125 path = path .. test.welcome_file | 126 path = path .. test.welcome_file |
126 end | 127 end |
127 local old_out = Io.stdout | 128 local old_out = Io.stdout |
128 local mod = require("site:"..path) | 129 local mod = require("site:"..path) |
129 mod.respond() | 130 mod.respond() |
130 text_writer.close() | 131 test.text_writer.close() |
131 Io.stdout = old_out | 132 Io.stdout = old_out |
132 return result.read_text() | 133 return result.read_text() |
133 end | 134 end |
134 | 135 |
135 test.cookies = test.cookies or {} | 136 test.cookies = test.cookies or {} |
136 | 137 |
137 request = new_request{} | 138 request = new_request{} |
138 request.cookies = test.cookies | 139 request.cookies = test.cookies |
139 | 140 |
140 response = { | 141 response = new_response{ |
141 | 142 |
142 text_writer = function() | 143 text_writer = function() |
143 result = Io.uri "string:" | 144 result = Io.uri "string:" |
144 text_writer = result.text_writer() | 145 test.text_writer = result.text_writer() |
145 return text_writer | 146 return test.text_writer |
146 end; | 147 end; |
147 | 148 |
148 set_cookie = function(name,value) | 149 set_cookie = function(name,value) |
149 test.cookies[name] = value | 150 test.cookies[name] = value |
150 end; | 151 end; |
155 | 156 |
156 send_redirect = function(url) | 157 send_redirect = function(url) |
157 response.redirect = url | 158 response.redirect = url |
158 end; | 159 end; |
159 | 160 |
160 headers = {}; | |
161 | |
162 } | 161 } |
163 | 162 |
164 end | 163 end |