Chaining defaults

21 views
Skip to first unread message

Scott Wright

unread,
Mar 20, 2021, 7:58:09 AM3/20/21
to htt...@googlegroups.com
I am building a client with which I intend to make several requests. I do not need or want a persistent connection because there will be long intervals between my requests. The code to do this is pretty straightforward:
client = HTTP.auth(“Bearer #{my_token}”).headers(accept: “application/json”)
And then I can make requests with the client object I just created.
What I would like to do is then modify the client object conditionally based on parameters I send when building the client (such as logging and proxy)
I have tried to modify client right after creating it:
client = client..use(logging: {logger: Logger.new("log/http.log")})
Or
client = client.via(“localhost”, 9090)

But these do not seem to modify client for future requests.
Any ideas on how I might accomplish this?

Thanks,

Scott

Scott Wright

unread,
Mar 21, 2021, 5:36:31 AM3/21/21
to htt...@googlegroups.com
After further investigation this works as expected:
client = client.via(“localhost”, 9090)
Does add the proxy to client for all future requests.
> --
> You received this message because you are subscribed to the Google Groups "http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to httprb+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/httprb/39B778C9-A50F-4F39-A1D4-FA43196D6B8D%40wrightzone.com.

Reply all
Reply to author
Forward
0 new messages