-
-
Notifications
You must be signed in to change notification settings - Fork 207
Add support for Req http client (draft) #846
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||
| defmodule Sentry.ReqClient do | ||||||
| @behaviour Sentry.HTTPClient | ||||||
|
|
||||||
| @moduledoc """ | ||||||
| The built-in HTTP client. | ||||||
| This client implements the `Sentry.HTTPClient` behaviour. | ||||||
| It's based on the [Req](https://github.com/wojtekmach/req) HTTP client, | ||||||
| which is an *optional dependency* of this library. If you wish to use another | ||||||
| HTTP client, you'll have to implement your own `Sentry.HTTPClient`. See the | ||||||
| documentation for `Sentry.HTTPClient` for more information. | ||||||
| """ | ||||||
|
|
||||||
| @impl true | ||||||
| def post(url, headers, body) do | ||||||
| opts = | ||||||
| Sentry.Config.req_opts() | ||||||
| |> Keyword.put(:decode_body, false) | ||||||
| |> Keyword.put(:url, url) | ||||||
| |> Keyword.put(:body, body) | ||||||
|
Comment on lines
+19
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
|
|
||||||
| req = | ||||||
| Req.new(opts) | ||||||
| |> 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 commentThe reason will be displayed to describe this comment to others. Learn more. We should pattern match when Req is available.
Suggested change
I transform the result into the Hackney-inspired form so everything else works. |
||||||
| {:error, _reason} = error -> error | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,7 +125,7 @@ defmodule Sentry.Transport do | |
| defp client_post_and_validate_return_value(client, endpoint, headers, body) do | ||
| case client.post(endpoint, headers, body) do | ||
| {:ok, status, resp_headers, resp_body} | ||
| 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the |
||
| is_binary(resp_body) -> | ||
| {:ok, status, resp_headers, resp_body} | ||
|
|
||
|
|
@@ -152,8 +152,8 @@ defmodule Sentry.Transport do | |
| |> Enum.map_join(", ", fn {name, value} -> "#{name}=#{value}" end) | ||
|
|
||
| auth_headers = [ | ||
| {"User-Agent", @sentry_client}, | ||
| {"X-Sentry-Auth", "Sentry " <> auth_query} | ||
| {"user-agent", @sentry_client}, | ||
| {"x-sentry-auth", "Sentry " <> auth_query} | ||
| ] | ||
|
|
||
| {dsn.endpoint_uri, auth_headers} | ||
|
|
||
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