net/http.lua

changeset 719
b1eb112478b8
parent 714
ab3c47f4fe1d
child 720
8f22e9fb2291
equal deleted inserted replaced
718:aa78dfb26593 719:b1eb112478b8
140 local ok, err = req.conn:connect(req.host, req.port or 80); 140 local ok, err = req.conn:connect(req.host, req.port or 80);
141 if not ok and err ~= "timeout" then 141 if not ok and err ~= "timeout" then
142 return nil, err; 142 return nil, err;
143 end 143 end
144 144
145 req.write((req.method or "GET ")..req.path.." HTTP/1.0\r\n"); 145 local request_line = { req.method or "GET", " ", req.path, " HTTP/1.1\r\n" };
146
147 if req.query then
148 t_insert(request_line, 4, "?");
149 t_insert(request_line, 5, req.query);
150 end
151
152 req.write(t_concat(request_line));
146 local t = { [2] = ": ", [4] = "\r\n" }; 153 local t = { [2] = ": ", [4] = "\r\n" };
147 if custom_headers then 154 if custom_headers then
148 for k, v in pairs(custom_headers) do 155 for k, v in pairs(custom_headers) do
149 t[1], t[3] = k, v; 156 t[1], t[3] = k, v;
150 req.write(t_concat(t)); 157 req.write(t_concat(t));

mercurial