-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Add support for Req http client (draft) #846
Conversation
@requirements ["app.start"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this Req-specific change inside the test command but I left it like this for now because I wanted to get some general feedback first.
Details why this is needed: https://elixirforum.com/t/argumenterror-unknown-registry-req-finch-on-a-simple-http-request-using-req-library/64638/9
|> Req.merge(headers: headers) | ||
|
||
case Req.post(req) do | ||
{:ok, %{status: status, headers: headers, body: body}} = result -> {:ok, status, headers, body} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should pattern match when Req is available.
{:ok, %{status: status, headers: headers, body: body}} = result -> {:ok, status, headers, body} | |
{:ok, %Req.Response{status: status, headers: headers, body: body}} = result -> {:ok, status, headers, body} |
I transform the result into the Hackney-inspired form so everything else works.
|> Keyword.put(:decode_body, false) | ||
|> Keyword.put(:url, url) | ||
|> Keyword.put(:body, body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Req decodes responses automatically. I choose to disable body decoding so the users can make use of the json_library
option.
when is_integer(status) and status in 200..599 and is_list(resp_headers) and | ||
when is_integer(status) and status in 200..599 and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the is_list
guard because it's highly Hackney-specific (Req response headers are a Map).
@krns thanks for the PR, but I don't think this is the right approach. This SDK already supports the We are already looking at replacing the default Hackney-based client with one based on Finch (#758), but I’m not convinced this is worth it if Erlang/Elixir will ever get a stdlib HTTP client. We might opt for Mint instead if they don't, since it will be the lowest-level and hopefully most-widely-adopted-as-base client. Hopefully this all makes sense. Cheers! |
Hello, I would be happy if Req would be supported as http client lib. Here is a working proof of concept.
Since Hackney is the only HTTP client that is supported so far, I had to bend a little in some places. A few comments on this below.
One general question:
Because Req is not known in the Sentry library I get a few warning like:
Should I make use of
Code.ensure_loaded?(Req)
andApplication.ensure_all_started(:req)
?