Skip to content

Commit 14cd5f6

Browse files
committed
check otp version
1 parent 348fcd8 commit 14cd5f6

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

lib/tesla/adapter/httpc.ex

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ defmodule Tesla.Adapter.Httpc do
88
consistency between adapters
99
"""
1010

11+
# current_otp_version = List.to_integer(:erlang.system_info(:otp_release))
12+
1113
@behaviour Tesla.Adapter
1214
import Tesla.Adapter.Shared, only: [stream_to_fun: 1, next_chunk: 1]
1315
alias Tesla.Multipart
@@ -18,28 +20,42 @@ defmodule Tesla.Adapter.Httpc do
1820
@impl Tesla.Adapter
1921
def call(env, opts) do
2022
opts = Tesla.Adapter.opts(@override_defaults, env, opts)
21-
# opts = Tesla.Adapter.opts(default_ssl_opt(), env, opts)
23+
opts = add_default_ssl_opt(env, opts)
2224

2325
with {:ok, {status, headers, body}} <- request(env, opts) do
2426
{:ok, format_response(env, status, headers, body)}
2527
end
2628
end
2729

28-
defp format_response(env, {_, status, _}, headers, body) do
29-
%{env | status: status, headers: format_headers(headers), body: format_body(body)}
30-
end
31-
32-
defp default_ssl_opt do
30+
# TODO: remove this once OTP 26+ is required
31+
# if current_otp_version <= 26 do
32+
def add_default_ssl_opt(env, opts) do
3333
# TODO: verify that requires OTP 25+
3434
# TODO: verify that does not require any Elixir version
3535
# TODO: maybe use Castore for now? cacertfile: CAStore.file_path(),
36-
[
37-
verify: :verify_peer,
38-
cacerts: :public_key.cacerts_get(),
39-
customize_hostname_check: [
40-
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
36+
37+
# https://github.com/erlang/otp/blob/33d99c5f50988c4bf124974ce3340bf18dbf0d08/lib/inets/src/http_client/httpc.erl#L461-L476
38+
default_ssl_opt = [
39+
ssl: [
40+
verify: :verify_peer,
41+
cacerts: :public_key.cacerts_get()
42+
# customize_hostname_check: [
43+
# match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
44+
# ]
4145
]
4246
]
47+
48+
Tesla.Adapter.opts(default_ssl_opt, env, opts)
49+
end
50+
51+
# else
52+
# def add_default_ssl_opt(_env, opts) do
53+
# opts
54+
# end
55+
# end
56+
57+
defp format_response(env, {_, status, _}, headers, body) do
58+
%{env | status: status, headers: format_headers(headers), body: format_body(body)}
4359
end
4460

4561
# from http://erlang.org/doc/man/httpc.html

0 commit comments

Comments
 (0)