diff options
author | Matthew Wild <mwild1@gmail.com> | 2013-04-18 00:08:58 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2013-04-18 00:08:58 +0100 |
commit | 5fea8c600e8382a58995f48936d5b61f64a79712 (patch) | |
tree | 0604a6d66c0c755bf29a09127cce1c4ce854f6ac | |
parent | eab907d95b55f3153183d38255c3fff573eede5a (diff) | |
download | prosody-5fea8c600e8382a58995f48936d5b61f64a79712.tar.gz prosody-5fea8c600e8382a58995f48936d5b61f64a79712.zip |
net.http: When HTTP request fails due to a network or SSL error, call the callback to let it know
-rw-r--r-- | net/http.lua | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/net/http.lua b/net/http.lua index 4eb4a2ac..639ecf6a 100644 --- a/net/http.lua +++ b/net/http.lua @@ -66,24 +66,29 @@ end 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); |