Use Req instead of HTTPoison#151
Open
randycoulman wants to merge 5 commits into
Open
Conversation
In order to prepare for the conversion to Req, we introduce a new API behaviour to replace HTTPoison.Base as well as a default implementation that delegates to an HTTPoison implementation. This uses an extra module because `use HTTPoison.Base` causes us to implement the `HTTPoison.Base` behaviour, and Elixir doesn't allow us to implement both that and ConfigCat.API when they both define the same callback.
There is some simplification/refactoring we can do, but this does the basic conversion. We also need to do some testing around how we configure the Req struct from the various options to make sure we're doing that right.
Use Req's `get_header` function to extract the etag. This caused some tests to fail due to Req's different internal representation of headers, so switch all response creation to use `Response.new` and `Response.put_header`.
Found and fixed bugs in the initial implementation.
Rather than mapping option names to the old HTTPoison/Hackney names in ConfigFetcher, pass the options as-is to the API and let it figure out what to do with them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the purpose of your pull request
HTTPoison (and its main dependency, hackney) have had some recent security issues and seem to have somewhat fallen out of favor in the Elixir community. In addition, the latest HTTPoison no longer supports Elixir 1.16, even that version is still officially supported by the Elixir core team.
Given that, we migrate our internal HTTP requests to use Req instead, which is a commonly used HTTP client library that allows pluggable backend adapters.
For testing, we previously relied on mocking the
HTTPoison.Basebehaviour. To avoid having to significantly refactor the tests, we convertConfigCat.APIto a mockable behaviour and provideConfigCat.API.ReqAPIas its default implementation.NOTE: We do not (yet) expose any of Req's pluggable configuration to clients, though we can do so if there is a need.
Related issues (only if applicable)
This can be considered an alternative to #149
How to test? (only if applicable)
The config fetching was affected, so we can test by running any sample application with the new version of the library.
Of note, Req takes the HTTP connection options in a different format than HTTPoison did. I'm reasonably confident in the connect/read timeout options, but didn't have a way to test the
http_proxyoption. I followed Req's (and the underling Finch/Mint) docs a best I could, but if there's a way to test proxying, let me know.Security (only if applicable)
There should be no new security issues arising from this change. In fact, Req/Finch/Mint seem to have fewer security issues overall than HTTPoison/hackney, so this should be an improvement in our security posture.
Requirement checklist (only if applicable)