Skip to content

Use Req instead of HTTPoison#151

Open
randycoulman wants to merge 5 commits into
mainfrom
convert-to-req
Open

Use Req instead of HTTPoison#151
randycoulman wants to merge 5 commits into
mainfrom
convert-to-req

Conversation

@randycoulman

Copy link
Copy Markdown
Collaborator

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.Base behaviour. To avoid having to significantly refactor the tests, we convert ConfigCat.API to a mockable behaviour and provide ConfigCat.API.ReqAPI as 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_proxy option. 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)

  • I have covered the applied changes with automated tests.
  • I have executed the full automated test set against my changes.
  • I have validated my changes against all supported platform versions.
  • I have read and accepted the contribution agreement.

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.
@randycoulman
randycoulman requested a review from a team as a code owner July 15, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant