X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=net%2Fhttpclient_listener.lua;h=dfa250623af523d18c4950608c42cfe043afd78f;hb=b61f92a28111e347d5b807e9329ac1ae2629fea4;hp=9c4f23f37a7bd08fc488c6b483a09fc92c0f1d50;hpb=aec516c79bb7467feadcf61e68e87e95de4ccede;p=prosody.git diff --git a/net/httpclient_listener.lua b/net/httpclient_listener.lua index 9c4f23f3..dfa25062 100644 --- a/net/httpclient_listener.lua +++ b/net/httpclient_listener.lua @@ -1,17 +1,25 @@ +-- Prosody IM +-- Copyright (C) 2008-2010 Matthew Wild +-- Copyright (C) 2008-2010 Waqas Hussain +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- -local connlisteners_register = require "net.connlisteners".register; +local log = require "util.logger".init("httpclient_listener"); +local connlisteners_register = require "net.connlisteners".register; local requests = {}; -- Open requests local buffers = {}; -- Buffers of partial lines local httpclient = { default_port = 80, default_mode = "*a" }; -function httpclient.listener(conn, data) +function httpclient.onincoming(conn, data) local request = requests[conn]; if not request then - print("NO REQUEST!! for "..tostring(conn)); + log("warn", "Received response from connection %s with no request attached!", tostring(conn)); return; end @@ -20,16 +28,16 @@ function httpclient.listener(conn, data) end end -function httpclient.disconnect(conn, err) +function httpclient.ondisconnect(conn, err) local request = requests[conn]; - if request then + if request and err ~= "closed" then request:reader(nil); end requests[conn] = nil; end function httpclient.register_request(conn, req) - print("Registering a request for "..tostring(conn)); + log("debug", "Attaching request %s to connection %s", tostring(req.id or req), tostring(conn)); requests[conn] = req; end