Software /
code /
prosody
Changeset
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 |
parents | 5487:03ddf2375d48 |
children | 5489:421c7830eccc 5491:55faa2fd5549 |
files | net/http.lua |
diffstat | 1 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/net/http.lua Wed Apr 17 15:28:20 2013 -0400 +++ b/net/http.lua Thu Apr 18 00:08:58 2013 +0100 @@ -66,24 +66,29 @@ function listener.ondisconnect(conn, err) local request = requests[conn]; if request and request.conn then - request:reader(nil); + request:reader(nil, err); end requests[conn] = nil; end -local function request_reader(request, data) +local function request_reader(request, data, err) if not request.parser then - if not data then return; end - local function success_cb(r) + local function error_cb(reason) if request.callback then - request.callback(r.body, r.code, r, request); + request.callback(reason or "connection-closed", 0, request); request.callback = nil; end destroy_request(request); end - local function error_cb(r) + + if not data then + error_cb(err); + return; + end + + local function success_cb(r) if request.callback then - request.callback(r or "connection-closed", 0, request); + request.callback(r.body, r.code, r, request); request.callback = nil; end destroy_request(request);