Comparison

net/http.lua @ 5488:0880a079d830

net.http: When HTTP request fails due to a network or SSL error, call the callback to let it know
author Matthew Wild <mwild1@gmail.com>
date Thu, 18 Apr 2013 00:08:58 +0100
parent 5466:e3b9dc9dd940
child 5505:0b6a99e6c1b1
comparison
equal deleted inserted replaced
5487:03ddf2375d48 5488:0880a079d830
64 end 64 end
65 65
66 function listener.ondisconnect(conn, err) 66 function listener.ondisconnect(conn, err)
67 local request = requests[conn]; 67 local request = requests[conn];
68 if request and request.conn then 68 if request and request.conn then
69 request:reader(nil); 69 request:reader(nil, err);
70 end 70 end
71 requests[conn] = nil; 71 requests[conn] = nil;
72 end 72 end
73 73
74 local function request_reader(request, data) 74 local function request_reader(request, data, err)
75 if not request.parser then 75 if not request.parser then
76 if not data then return; end 76 local function error_cb(reason)
77 local function success_cb(r)
78 if request.callback then 77 if request.callback then
79 request.callback(r.body, r.code, r, request); 78 request.callback(reason or "connection-closed", 0, request);
80 request.callback = nil; 79 request.callback = nil;
81 end 80 end
82 destroy_request(request); 81 destroy_request(request);
83 end 82 end
84 local function error_cb(r) 83
84 if not data then
85 error_cb(err);
86 return;
87 end
88
89 local function success_cb(r)
85 if request.callback then 90 if request.callback then
86 request.callback(r or "connection-closed", 0, request); 91 request.callback(r.body, r.code, r, request);
87 request.callback = nil; 92 request.callback = nil;
88 end 93 end
89 destroy_request(request); 94 destroy_request(request);
90 end 95 end
91 local function options_cb() 96 local function options_cb()