httpi
httpi copied to clipboard
Allow common `block` for all requests
As a suggestion, I often have the requirement to setup the adapter client for every request. For example, with the httpclient adapter I often need to do the following:
response = HTTPI.get(request) do |x|
x.ssl_config.set_default_paths
x.force_basic_auth = true
end
To save repeating myself, or otherwise creating my own "request" method, it would be nice if HTTPI allowed one to set a global block to be executed before each request to setup the client. Given that the adapter is set globally, it makes sense to allow an adapter-specific block to be set globally as well.
Something like this:
HTTPI.adapter = :httpclient
HTTPI.adapter_client_setup = proc do |x|
x.ssl_config.set_default_paths
x.force_basic_auth = true
end
When a request is made, this block would be executed before the request-specific block. In the following example, force_basic_auth
would be turned off for this particular request, but ssl_config.set_default_paths
would remain set.
HTTPI.adapter = :httpclient
HTTPI.adapter_client_setup = proc do |x|
x.ssl_config.set_default_paths
x.force_basic_auth = true
end
# ...
HTTPI.get(request) do |x|
x.force_basic_auth = false
end
Thoughts?
By the way, happy to send through a pull request.
Hi Tom @Wardrop
To save repeating myself, or otherwise creating my own "request" method, it would be nice if HTTPI allowed one to set a global block to be executed before each request to setup the client. Given that the adapter is set globally, it makes sense to allow an adapter-specific block to be set globally as well.
I like adapter_client_setup
block. 👍
Feel free to send a PR. I'm planning to merge #201 and #198 and release a 2.5.0 version. We can add this feature on 2.5.0 or 2.5.1. Ok?
No worries, pull request made.
Resolved in #237 / #203