|
1 |
|
2 local connlisteners_register = require "net.connlisteners".register; |
|
3 |
|
4 |
|
5 local requests = {}; -- Open requests |
|
6 local buffers = {}; -- Buffers of partial lines |
|
7 |
|
8 local httpclient = { default_port = 80, default_mode = "*a" }; |
|
9 |
|
10 function httpclient.listener(conn, data) |
|
11 local request = requests[conn]; |
|
12 |
|
13 if not request then |
|
14 print("NO REQUEST!! for "..tostring(conn)); |
|
15 return; |
|
16 end |
|
17 |
|
18 if data and request.reader then |
|
19 request:reader(data); |
|
20 end |
|
21 end |
|
22 |
|
23 function httpclient.disconnect(conn, err) |
|
24 local request = requests[conn]; |
|
25 if request then |
|
26 request:reader(nil); |
|
27 end |
|
28 --requests[conn] = nil; |
|
29 end |
|
30 |
|
31 function httpclient.register_request(conn, req) |
|
32 print("Registering a request for "..tostring(conn)); |
|
33 requests[conn] = req; |
|
34 end |
|
35 |
|
36 connlisteners_register("httpclient", httpclient); |