diff --git a/lib/faraday/adapter/typhoeus.rb b/lib/faraday/adapter/typhoeus.rb index 8164b49..86304de 100644 --- a/lib/faraday/adapter/typhoeus.rb +++ b/lib/faraday/adapter/typhoeus.rb @@ -92,6 +92,12 @@ def request(env) end end + env[:typhoeus_timings] = %i[ + appconnect connect namelookup pretransfer redirect starttransfer total + ].to_h do |key| + [key, resp.public_send("#{key}_time")] + end + save_response(env, resp.code, resp.body, nil, resp.status_message) do |response_headers| response_headers.parse resp.response_headers end diff --git a/spec/faraday/adapter/typhoeus_spec.rb b/spec/faraday/adapter/typhoeus_spec.rb index d1c1c48..bc04de3 100644 --- a/spec/faraday/adapter/typhoeus_spec.rb +++ b/spec/faraday/adapter/typhoeus_spec.rb @@ -305,6 +305,20 @@ it 'succeeds' do expect(conn.get('/').status).to be(200) end + + it 'sets timings' do + response = conn.get('/') + # TODO: make these not-nil after https://github.com/bblimke/webmock/pull/1038 lands + expect(response.env.custom_members[:typhoeus_timings]).to eq({ + appconnect: nil, + connect: nil, + namelookup: nil, + pretransfer: nil, + redirect: nil, + starttransfer: nil, + total: nil + }) + end end context 'failed connection' do