From adf894d60c1abee0469ccf791dc94ed2b7f17be9 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 10 Apr 2020 01:15:29 +1200 Subject: [PATCH] Log request and response. --- lib/async/http/faraday/adapter.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/async/http/faraday/adapter.rb b/lib/async/http/faraday/adapter.rb index 070f897..3b3efd9 100644 --- a/lib/async/http/faraday/adapter.rb +++ b/lib/async/http/faraday/adapter.rb @@ -22,6 +22,7 @@ require 'faraday/adapter' require 'kernel/sync' require 'async/http/internet' +require 'async/clock' require_relative 'agent' @@ -61,16 +62,26 @@ def call(env) super parent = Async::Task.current? + response = nil Sync do with_timeout do + start = Async::Clock.now + Async.logger.info(self) {"#{env[:method]} -> #{env[:url]}"} response = @internet.call(env[:method].to_s.upcase, env[:url].to_s, env[:request_headers], env[:body] || []) save_response(env, response.status, response.read, response.headers) + Async.logger.info(self) {"#{env[:method]} <- #{env[:url]} (#{(Async::Clock.now - start).round(3)}s)"} end ensure # If we are the top level task, even if we are persistent, we must close the connection: if parent.nil? || !@persistent + # if response.connection.count == 1 + # puts "*" * 30 + # puts "#{env[:method]} #{env[:url]} #{response.connection.count}" + # puts caller + # end + @internet.close end end