Software /
code /
prosody
Comparison
net/httpclient_listener.lua @ 1227:6a587ca99109
httpclient_listener: Don't use print()...
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 29 May 2009 22:04:57 +0100 |
parent | 737:ade262a8da7f |
child | 1522:569d58d21612 |
comparison
equal
deleted
inserted
replaced
1226:3b5f9dac2045 | 1227:6a587ca99109 |
---|---|
1 local log = require "util.logger".init("httpclient_listener"); | |
1 | 2 |
2 local connlisteners_register = require "net.connlisteners".register; | 3 local connlisteners_register = require "net.connlisteners".register; |
3 | |
4 | 4 |
5 local requests = {}; -- Open requests | 5 local requests = {}; -- Open requests |
6 local buffers = {}; -- Buffers of partial lines | 6 local buffers = {}; -- Buffers of partial lines |
7 | 7 |
8 local httpclient = { default_port = 80, default_mode = "*a" }; | 8 local httpclient = { default_port = 80, default_mode = "*a" }; |
9 | 9 |
10 function httpclient.listener(conn, data) | 10 function httpclient.listener(conn, data) |
11 local request = requests[conn]; | 11 local request = requests[conn]; |
12 | 12 |
13 if not request then | 13 if not request then |
14 print("NO REQUEST!! for "..tostring(conn)); | 14 log("warn", "Received response from connection %s with no request attached!", tostring(conn)); |
15 return; | 15 return; |
16 end | 16 end |
17 | 17 |
18 if data and request.reader then | 18 if data and request.reader then |
19 request:reader(data); | 19 request:reader(data); |
27 end | 27 end |
28 requests[conn] = nil; | 28 requests[conn] = nil; |
29 end | 29 end |
30 | 30 |
31 function httpclient.register_request(conn, req) | 31 function httpclient.register_request(conn, req) |
32 print("Registering a request for "..tostring(conn)); | 32 log("debug", "Attaching request %s to connection %s", tostring(req.id or req), tostring(conn)); |
33 requests[conn] = req; | 33 requests[conn] = req; |
34 end | 34 end |
35 | 35 |
36 connlisteners_register("httpclient", httpclient); | 36 connlisteners_register("httpclient", httpclient); |