lib/xmpp4r/httpbinding/client.rb in mad-p-xmpp4r-0.6.1 vs lib/xmpp4r/httpbinding/client.rb in mad-p-xmpp4r-0.6.2
- old
+ new
@@ -137,11 +137,11 @@
if host
req_body.attributes['route'] = "xmpp:#{host}:#{port}"
end
req_body.attributes['secure'] = 'true'
req_body.attributes['xmlns'] = 'http://jabber.org/protocol/httpbind'
- res_body = post(req_body)
+ res_body = post(req_body, "sid=new rid=#{@http_rid}")
unless res_body.name == 'body'
raise 'Response body is no <body/> element'
end
@streamid = res_body.attributes['authid']
@@ -190,11 +190,11 @@
req_body += "</body>"
current_rid = @http_rid
@pending_requests += 1
@last_send = Time.now
}
- res_body = post(req_body)
+ res_body = post(req_body, "terminate sid=#{@http_sid} rid=#{@http_rid}")
sleep(3)
Jabber::debuglog("Connection closed")
end
private
@@ -229,17 +229,17 @@
end
end
##
# Do a POST request
- def post(body)
+ def post(body, debug_info)
body = body.to_s
request = Net::HTTP::Post.new(@uri.path)
request.content_length = body.size
request.body = body
request['Content-Type'] = @http_content_type
- Jabber::debuglog("HTTP REQUEST (#{@pending_requests}/#{@http_requests}):\n#{request.body}")
+ Jabber::debuglog("HTTP REQUEST (#{@pending_requests}/#{@http_requests}) #{debug_info}:\n#{request.body}")
net_http_args = [@uri.host, @uri.port]
unless @proxy_args.empty?
unless no_proxy?(@uri)
net_http_args.concat @proxy_args
@@ -254,11 +254,11 @@
http.read_timeout = @http_wait * 1.1
response = http.start { |http|
http.request(request)
}
- Jabber::debuglog("HTTP RESPONSE (#{@pending_requests}/#{@http_requests}): #{response.class}\n#{response.body}")
+ Jabber::debuglog("HTTP RESPONSE (#{@pending_requests}/#{@http_requests}) #{debug_info}: #{response.class}\n#{response.body}")
unless response.kind_of? Net::HTTPSuccess
# Unfortunately, HTTPResponses aren't exceptions
# TODO: rescue'ing code should be able to distinguish
raise Net::HTTPBadResponse, "#{response.class}"
@@ -284,10 +284,11 @@
# Prepare data to POST and
# handle the result
def post_data(data, restart = false)
req_body = nil
current_rid = nil
+ debug_info = ''
begin
begin
@lock.synchronize {
# Do not send unneeded requests
@@ -304,16 +305,17 @@
req_body += " xml:lang='en' xmpp:restart='true' xmlns:xmpp='urn:xmpp:xbosh'" if restart
req_body += ">"
req_body += data unless restart
req_body += "</body>"
current_rid = @http_rid
+ debug_info = "sid=#{@http_sid} rid=#{current_rid}"
@pending_requests += 1
@last_send = Time.now
}
- res_body = post(req_body)
+ res_body = post(req_body, debug_info)
ensure
@lock.synchronize {
@pending_requests -= 1
}
@@ -327,21 +329,22 @@
Thread.new do
Thread.current.abort_on_exception = true
close; @exception_block.call(e, self, :parser)
end
else
- Jabber::debuglog "Exception caught when parsing HTTP response!"
+ Jabber::debuglog "Exception caught when parsing HTTP response! (#{debug_info})"
close
raise
end
rescue StandardError => e
- Jabber::debuglog("POST error (will retry): #{e.class}: #{e}")
+ Jabber::debuglog("POST error (will retry) #{debug_info}: #{e.class}: #{e}, #{e.backtrace}")
receive_elements_with_rid(current_rid, [])
# It's not good to resend on *any* exception,
# but there are too many cases (Timeout, 404, 502)
# where resending is appropriate
# TODO: recognize these conditions and act appropriate
+ # FIXME: resending the same data with a new rid is wrong. should resend with the same rid
send_data(data)
end
end
##