Overview
ShopifyAPI::Clients::HttpClient internally uses HTTParty to perform HTTP requests, but there is currently no way to pass through any HTTParty options (e.g. timeout, open_timeout, read_timeout, etc.). HttpClient#request hardcodes only headers, query, and body when calling HTTParty.send(...).
|
res = T.cast(HTTParty.send( |
|
request.http_method, |
|
parsed_uri.to_s, |
|
headers: headers, |
|
query: request.query, |
|
body: request.body.class == Hash ? T.unsafe(request.body).to_json : request.body, |
|
), HTTParty::Response) |
It would be helpful if HttpClient allowed passing an arbitrary set of HTTParty options, rather than only supporting specific ones, so that users can configure whichever options they need without waiting for the gem to add explicit support for each one.
Problem
Because none of HTTParty's other options are exposed, users of this gem have no way to bound request latency with timeout / open_timeout / read_timeout (e.g. for background jobs or requests with strict SLAs). Currently the only workaround is monkey-patching HttpClient, which is fragile across gem upgrades.
Proposed Solution
Rather than adding support for a single option like timeout, it may be more flexible to allow passing an arbitrary options hash that gets merged into the HTTParty call, e.g.:
sig { params(base_path: String, session: T.nilable(Auth::Session), httparty_options: T::Hash[Symbol, T.untyped]).void }
def initialize(base_path:, session: nil, httparty_options: {})
@httparty_options = httparty_options
# ...
end
# in #request
res = T.cast(HTTParty.send(
request.http_method,
parsed_uri.to_s,
**@httparty_options.merge(
headers: headers,
query: request.query,
body: ...,
),
), HTTParty::Response)
This would let users pass timeout:, open_timeout:, read_timeout:, or any other HTTParty-supported option, without the gem needing to explicitly enumerate and support each one individually.
Alternatives Considered
- Adding a dedicated
timeout: argument only — simpler, but doesn't generalize to other HTTParty options users may need.
- Monkey-patching
HttpClient — works today but fragile across gem upgrades.
Overview
ShopifyAPI::Clients::HttpClientinternally uses HTTParty to perform HTTP requests, but there is currently no way to pass through any HTTParty options (e.g.timeout,open_timeout,read_timeout, etc.).HttpClient#requesthardcodes onlyheaders,query, andbodywhen callingHTTParty.send(...).shopify-api-ruby/lib/shopify_api/clients/http_client.rb
Lines 51 to 57 in 8c72cd2
It would be helpful if
HttpClientallowed passing an arbitrary set of HTTParty options, rather than only supporting specific ones, so that users can configure whichever options they need without waiting for the gem to add explicit support for each one.Problem
Because none of HTTParty's other options are exposed, users of this gem have no way to bound request latency with
timeout/open_timeout/read_timeout(e.g. for background jobs or requests with strict SLAs). Currently the only workaround is monkey-patchingHttpClient, which is fragile across gem upgrades.Proposed Solution
Rather than adding support for a single option like
timeout, it may be more flexible to allow passing an arbitrary options hash that gets merged into the HTTParty call, e.g.:This would let users pass
timeout:,open_timeout:,read_timeout:, or any other HTTParty-supported option, without the gem needing to explicitly enumerate and support each one individually.Alternatives Considered
timeout:argument only — simpler, but doesn't generalize to other HTTParty options users may need.HttpClient— works today but fragile across gem upgrades.