Comparison

net/http.lua @ 4351:3f414091a008

net.http: Whitespace fixes
author Matthew Wild <mwild1@gmail.com>
date Sat, 20 Aug 2011 15:08:54 -0400
parent 4350:0b9ed126286e
child 4352:912a49b1c4e3
comparison
equal deleted inserted replaced
4350:0b9ed126286e 4351:3f414091a008
3 -- Copyright (C) 2008-2010 Waqas Hussain 3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- 4 --
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8
9 8
10 local socket = require "socket" 9 local socket = require "socket"
11 local mime = require "mime" 10 local mime = require "mime"
12 local url = require "socket.url" 11 local url = require "socket.url"
13 local httpstream_new = require "util.httpstream".new; 12 local httpstream_new = require "util.httpstream".new;
103 102
104 103
105 if req.userinfo then 104 if req.userinfo then
106 default_headers["Authorization"] = "Basic "..mime.b64(req.userinfo); 105 default_headers["Authorization"] = "Basic "..mime.b64(req.userinfo);
107 end 106 end
108 107
109 if ex then 108 if ex then
110 custom_headers = ex.headers; 109 custom_headers = ex.headers;
111 req.onlystatus = ex.onlystatus; 110 req.onlystatus = ex.onlystatus;
112 body = ex.body; 111 body = ex.body;
113 if body then 112 if body then
114 req.method = "POST "; 113 req.method = "POST ";
115 default_headers["Content-Length"] = tostring(#body); 114 default_headers["Content-Length"] = tostring(#body);
116 default_headers["Content-Type"] = "application/x-www-form-urlencoded"; 115 default_headers["Content-Type"] = "application/x-www-form-urlencoded";
117 end 116 end
118 if ex.method then req.method = ex.method; end 117 if ex.method then method = ex.method; end
118 if ex.headers then
119 for k, v in pairs(ex.headers) do
120 headers[k] = v;
121 end
122 end
119 end 123 end
120 124
121 req.handler, req.conn = server.wrapclient(socket.tcp(), req.host, req.port or 80, listener, "*a"); 125 req.handler, req.conn = server.wrapclient(socket.tcp(), req.host, req.port or 80, listener, "*a");
122 req.write = function (...) return req.handler:write(...); end 126 req.write = function (...) return req.handler:write(...); end
123 req.conn:settimeout(0); 127 req.conn:settimeout(0);
156 end 160 end
157 161
158 req.callback = function (content, code, request) log("debug", "Calling callback, status %s", code or "---"); return select(2, xpcall(function () return callback(content, code, request) end, handleerr)); end 162 req.callback = function (content, code, request) log("debug", "Calling callback, status %s", code or "---"); return select(2, xpcall(function () return callback(content, code, request) end, handleerr)); end
159 req.reader = request_reader; 163 req.reader = request_reader;
160 req.state = "status"; 164 req.state = "status";
161 165
162 listener.register_request(req.handler, req); 166 listener.register_request(req.handler, req);
163 167
164 return req; 168 return req;
165 end 169 end
166 170