From e86e0f6853ad5b21304ccd796d81d212acab5617 Mon Sep 17 00:00:00 2001 From: Tiago Cardoso Date: Mon, 13 Jul 2026 15:37:32 +0100 Subject: [PATCH] feat: allow setting the faraday adapter to use The application I work on uses httpclient and relies on its persistent connection feature and request hedging to keep p99 google storage uploads to a minimum. v1 changed to faraday, which is understandable, but the default faraday adapter uses net-http, which does not do persistent requests, and would severely limit our ability to seamlessly upgrade. This patch introduces a new client option, `:adapter`, which allows setting a default adapter (faraday has several) which supports persistent connections via: ```ruby Google::Apis::ClientOptions.default.adapter = :httpx # or :net_http_persistent ``` --- google-apis-core/lib/google/apis/core/base_service.rb | 1 + google-apis-core/lib/google/apis/options.rb | 3 +++ 2 files changed, 4 insertions(+) diff --git a/google-apis-core/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb index 38723fc4d07..a366e5f8432 100644 --- a/google-apis-core/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -557,6 +557,7 @@ def new_client Faraday.new options do |faraday| faraday.response :logger, Google::Apis.logger if client_options.log_http_requests faraday.response :follow_redirects_google_apis_core, limit: 5 + faraday.adapter client_options.adapter if client_options.adapter end end diff --git a/google-apis-core/lib/google/apis/options.rb b/google-apis-core/lib/google/apis/options.rb index 4445f7e90c4..9f8d79be288 100644 --- a/google-apis-core/lib/google/apis/options.rb +++ b/google-apis-core/lib/google/apis/options.rb @@ -18,6 +18,7 @@ module Apis ClientOptions = Struct.new( :application_name, :application_version, + :adapter, :proxy_url, :open_timeout_sec, :read_timeout_sec, @@ -50,6 +51,8 @@ class ClientOptions # @return [String] Name of the application, for identification in the User-Agent header # @!attribute [rw] application_version # @return [String] Version of the application, for identification in the User-Agent header + # @!attribute [rw] adapter + # @return [Symbol, Class] Faraday adapter to use # @!attribute [rw] proxy_url # @return [String] URL of a proxy server # @!attribute [rw] log_http_requests