def request action, &b
headers = { 'content-type' => 'text/xml; charset=utf-8', 'SOAPAction' => action }
headers['cookie'] = @cookie if @cookie
body = soap_envelope(&b).target!
if @debug
$stderr.puts "Request:"
$stderr.puts body
$stderr.puts
end
start_time = Time.now
response = @lock.synchronize do
begin
@http.request_post(@opts[:path], body, headers)
rescue Exception
restart_http
raise
end
end
end_time = Time.now
@cookie = response['set-cookie'] if response.key? 'set-cookie'
nk = Nokogiri(response.body)
if @debug
$stderr.puts "Response (in #{'%.3f' % (end_time - start_time)} s)"
$stderr.puts nk
$stderr.puts
end
nk.xpath('//soapenv:Body/*').select(&:element?).first
end