From 633d554c289e378ef23b5795cd627346d3e130dd Mon Sep 17 00:00:00 2001 From: James Brown Date: Thu, 12 Oct 2023 10:13:13 -0700 Subject: [PATCH 1/4] expose libcurl timings in the faraday env --- lib/faraday/adapter/typhoeus.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/faraday/adapter/typhoeus.rb b/lib/faraday/adapter/typhoeus.rb index 8164b49..6601a2f 100644 --- a/lib/faraday/adapter/typhoeus.rb +++ b/lib/faraday/adapter/typhoeus.rb @@ -92,6 +92,10 @@ def request(env) end end + env[:typhoeus_timings] = %w[appconnect connect namelookup pretransfer redirect starttransfer total].map do |key| + [key, resp.send("#{key}_time")] + end.to_h + save_response(env, resp.code, resp.body, nil, resp.status_message) do |response_headers| response_headers.parse resp.response_headers end From 70eaf20d05d64e6afa19db9bf6872c28adaa4020 Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 13 Oct 2023 17:13:41 -0700 Subject: [PATCH 2/4] make Rubocop happy --- lib/faraday/adapter/typhoeus.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/faraday/adapter/typhoeus.rb b/lib/faraday/adapter/typhoeus.rb index 6601a2f..5b563ba 100644 --- a/lib/faraday/adapter/typhoeus.rb +++ b/lib/faraday/adapter/typhoeus.rb @@ -92,9 +92,11 @@ def request(env) end end - env[:typhoeus_timings] = %w[appconnect connect namelookup pretransfer redirect starttransfer total].map do |key| - [key, resp.send("#{key}_time")] - end.to_h + env[:typhoeus_timings] = %w[ + appconnect connect namelookup pretransfer redirect starttransfer total + ].to_h do |key| + [key.to_sym, 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 From 3b8c7162f99cfe28705bd39592a21da9cc896cad Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 13 Oct 2023 17:28:17 -0700 Subject: [PATCH 3/4] add smoke test --- spec/faraday/adapter/typhoeus_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 From abd7df84b987deed4ae2ef9f7e0a041b7e85400d Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 13 Oct 2023 17:29:51 -0700 Subject: [PATCH 4/4] ...that was a silly way to make something a symbol --- lib/faraday/adapter/typhoeus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/faraday/adapter/typhoeus.rb b/lib/faraday/adapter/typhoeus.rb index 5b563ba..86304de 100644 --- a/lib/faraday/adapter/typhoeus.rb +++ b/lib/faraday/adapter/typhoeus.rb @@ -92,10 +92,10 @@ def request(env) end end - env[:typhoeus_timings] = %w[ + env[:typhoeus_timings] = %i[ appconnect connect namelookup pretransfer redirect starttransfer total ].to_h do |key| - [key.to_sym, resp.public_send("#{key}_time")] + [key, resp.public_send("#{key}_time")] end save_response(env, resp.code, resp.body, nil, resp.status_message) do |response_headers|