Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow common block for all requests #202

Closed
Wardrop opened this issue Apr 23, 2019 · 4 comments
Closed

Allow common block for all requests #202

Wardrop opened this issue Apr 23, 2019 · 4 comments
Labels

Comments

@Wardrop
Copy link

Wardrop commented Apr 23, 2019

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?

@Wardrop
Copy link
Author

Wardrop commented Apr 23, 2019

By the way, happy to send through a pull request.

@rogerleite
Copy link
Member

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?

@Wardrop
Copy link
Author

Wardrop commented Apr 29, 2019

No worries, pull request made.

@pcai
Copy link
Member

pcai commented Oct 1, 2022

Resolved in #237 / #203

@pcai pcai closed this as completed Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants