-
Notifications
You must be signed in to change notification settings - Fork 346
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
Mint adapter #297
Mint adapter #297
Conversation
Codecov Report
@@ Coverage Diff @@
## master #297 +/- ##
==========================================
+ Coverage 95.43% 95.51% +0.08%
==========================================
Files 23 24 +1
Lines 460 513 +53
==========================================
+ Hits 439 490 +51
- Misses 21 23 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #297 +/- ##
==========================================
- Coverage 95.43% 95.11% -0.32%
==========================================
Files 23 24 +1
Lines 460 512 +52
==========================================
+ Hits 439 487 +48
- Misses 21 25 +4
Continue to review full report at Codecov.
|
Wow! 👏 @ericmj would you mind taking a look at mint usage? |
If I have not overlooked anything, this implementation will create a new connection for every request and there will be no way to reuse it. The question is how fast will it work in comparison to other adapters. |
I know, but given #301 I think this is a good starting point. |
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.
Could you explain why do we need this You explained that already, 🤦♂get_default_ca
at all? Is this for production use or for tests only?
Let me see if I can find any other non-hackish way to do this
config/config.exs
Outdated
@@ -19,5 +19,5 @@ if Mix.env() == :test do | |||
|
|||
config :tesla, MockClient, adapter: Tesla.Mock | |||
|
|||
config :tesla, cacert: ["./deps/httparrot/priv/ssl/server-ca.crt"] | |||
config :tesla, Mint, cacert: ["./deps/httparrot/priv/ssl/server-ca.crt"] |
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'd use
config :tesla, Tesla.Adapter.Mint, cacert: ["./deps/httparrot/priv/ssl/server-ca.crt"]
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.
There are performance downsides to this adapter. It starts a new connection for each request, unlike with for example hackney that uses a pool connection. Because of this, clients that use pools will likely be faster.
Since the connection is never reused you may want to set the connection: close
header and explicitly close the connection. Otherwise you are likely to leak messages since you may still be getting messages from the socket after the request is finished.
lib/tesla/adapter/mint.ex
Outdated
|
||
defp get_default_ca() do | ||
env = Application.get_env(:tesla, Mint) | ||
Keyword.get(env, :cacert) |
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.
Not sure how this works, but make sure the CA store Mint uses is not removed if a user does not explicitly the :cacert
config.
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.
There should be either some error reporting or some default, this will blow if Application.get_env(:tesla, Tesla.Adapter.Mint)
returns nil
I have opened an issue to support chunked encoding for the request: elixir-mint/mint#174. |
Thank you @ericmj and @teamon ! |
Codecov Report
@@ Coverage Diff @@
## master #297 +/- ##
==========================================
+ Coverage 95.19% 95.28% +0.09%
==========================================
Files 25 26 +1
Lines 520 573 +53
==========================================
+ Hits 495 546 +51
- Misses 25 27 +2
Continue to review full report at Codecov.
|
And for the checks, I don't know how to fix the codecov. Some of the paths cannot be simply tested by HTTParrot. |
@@ -18,4 +18,7 @@ if Mix.env() == :test do | |||
sasl_error_logger: false | |||
|
|||
config :tesla, MockClient, adapter: Tesla.Mock | |||
|
|||
config :tesla, Tesla.Adapter.Mint, | |||
cacert: ["./deps/httparrot/priv/ssl/server-ca.crt"] |
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.
@ericmj This config won't end up in production builds, right? I mean, it will be nil
by default so it should be safe to reference httparrot here.
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 think it will be nil
by default.
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.
Correct, config.exs
is not used from dependencies. So the Tesla.Adapter.Mint
key will not be set.
lib/tesla/adapter/mint.ex
Outdated
|
||
defp get_default_ca() do | ||
env = Application.get_env(:tesla, Mint) | ||
Keyword.get(env, :cacert) |
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.
There should be either some error reporting or some default, this will blow if Application.get_env(:tesla, Tesla.Adapter.Mint)
returns nil
46ed476
to
9fd478f
Compare
I have done a simple research on the build issue. Ref: https://travis-ci.community/t/erlang-18-3-couldnt-be-pulled/3836 |
@RyanSiu1995 please rebase on recent master that contains fixes for otp 18 |
Co-Authored-By: Alexander Strizhakov <[email protected]>
8d3e6e6
to
b1e5c11
Compare
Regarding issue #282,
sorry for misopen of PR without verifying the build last time.
Several problems for mint integration
badarg
if the user uses SSL options in TCP. So I do not useconfig :tesla, Mint, xxxxx
to let user to have a global adapter configuration for Mint.config :tesla, :cacert, [xxxx]
for passing the unit test. I don't like the hacky way I do in the pr. Any idea on making this much more precise and concise?Welcome to have any kinds of comments. Thank you!!!!