firebase-ruby icon indicating copy to clipboard operation
firebase-ruby copied to clipboard

Convert from HTTPClient to Faraday

Open halostatue opened this issue 5 years ago • 4 comments

We’re switching from a Hurley/Faraday-based mechanism to the firebase-ruby gem because it provides a REALLY nice interface for the new auth mechanism without me actually having to do a lot of heavy lifting. At least until I got it to one of our production-like test environments, when it failed because it does not support HTTPS proxies (https_proxy), which our previous mechanism did handle. I traced this to the use of httpclient.

Unfortunately, Nahi’s HTTPClient has not been modified in two years and I see no open PRs for https proxy support, something that is supported in Net::HTTP (which is all we use in Hurley and Faraday).

This PR is to provide all of the changes necessary to switch from httpclient to Faraday using the default adapter. For a variety of reasons, I had to make a few more changes than I would have liked to, and I consider this an incomplete change overall. There are a couple of things that I normally wouldn’t do on behalf of a maintainer (like updating the VERSION), but I’m stuck in a situation where I needed to deploy this to our private gem server. I am also in the middle of our live tests for this, so there may be further changes, but it looks good so far in local testing (just like last time).

The existing behaviour can be more-or-less maintained by changing from Faraday.default_adapter to :http_client, but I see no reason to do that since Net::HTTP is under active development on Ruby.

The dinosaurs test is failing on master, BTW, so I’ve at least got this part all green.

halostatue avatar Dec 14 '18 04:12 halostatue

Something I discovered: there is a transitive dependency on Faraday in any case (using the default adapter) via the googleauth gem. I wasn't paying attention to what it was doing, and in fact, if you have a forward proxy like squid, both of these will be required:

proxy_uri = Rails.configuration.https_proxy_uri
Faraday.default_connection.proxy = proxy_uri
# or wherever your proxy URI is configured
firebase = Firebase.new(uri, auth)
firebase.request.proxy = proxy_uri

Otherwise, the request made by the googleauth gem will be blocked for lack of proxy.

halostatue avatar Dec 14 '18 05:12 halostatue

Thank you for this PR. This is going to sound really shitty, but would you consider doing this with http-rb instead? While Faraday is great, I would prefer not to introduce a middleware-based HTTP library into so small a library like firebase-ruby. http-rb achieves a lot of the same pure-ruby niceness of HTTPClient but is much better maintained these days.

vincentwoo avatar Dec 17 '18 14:12 vincentwoo

I haven’t used http-rb and therefore have no clue whether it supports HTTPS proxies…and I’m not adding it as another HTTP client dependency to our application, sorry. I chose Faraday because it’s an already existing dependency for our application and it is well-known to have support for HTTPS proxies. The only middleware I needed to add because it’s not provided by default was the follow-redirects middleware.

As I mentioned, whether you want to or not, firebase-ruby already has faraday as a once-removed dependency because of googleauth (although googleauth uses the default Faraday client), so your clients already have this as a dependency.

halostatue avatar Dec 17 '18 16:12 halostatue

I've created this gem for my own use with the same purpose firebase_faraday_client

leanhdaovn avatar Jan 17 '19 02:01 leanhdaovn