From 8978289e9e617ef961c3073755fdb630e725151b Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Wed, 3 Aug 2022 21:34:42 +1200 Subject: [PATCH] WIP: elp --- rebar.config | 17 +++++++++++++++-- rebar.lock | 13 +++++++++---- src/katipo.erl | 36 ++++++++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/rebar.config b/rebar.config index b5517ea..f062b3e 100644 --- a/rebar.config +++ b/rebar.config @@ -5,8 +5,13 @@ {minimum_otp_vsn, "23.0"}. {deps, [ - {worker_pool, "6.0.0"}, - {metrics, "2.5.0"} + {worker_pool, "6.0.1"}, + {metrics, "2.5.0"}, + {eqwalizer_support, + {git_subdir, + "git@github.com:whatsapp/eqwalizer.git", + {branch, "main"}, + "eqwalizer_support"}} ]}. {profiles, @@ -47,3 +52,11 @@ {coveralls_service_name, "travis-ci"}. {hex, [{doc, #{provider => edoc}}]}. + +{project_plugins, [ + {eqwalizer_rebar3, + {git_subdir, + "git@github.com:whatsapp/eqwalizer.git", + {branch, "main"}, + "eqwalizer_rebar3"}} +]}. diff --git a/rebar.lock b/rebar.lock index 8d827e3..5580202 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,11 +1,16 @@ {"1.2.0", -[{<<"metrics">>,{pkg,<<"metrics">>,<<"2.5.0">>},0}, - {<<"worker_pool">>,{pkg,<<"worker_pool">>,<<"6.0.0">>},0}]}. +[{<<"eqwalizer_support">>, + {git_subdir,"git@github.com:whatsapp/eqwalizer.git", + {ref,"c76956d720add1cd7eefebba945a5e17a4b5b0a9"}, + "eqwalizer_support"}, + 0}, + {<<"metrics">>,{pkg,<<"metrics">>,<<"2.5.0">>},0}, + {<<"worker_pool">>,{pkg,<<"worker_pool">>,<<"6.0.1">>},0}]}. [ {pkg_hash,[ {<<"metrics">>, <<"268D218D56529CB5F070D74BBFC3AF64C668379B5B18FAFDA88959442F790C57">>}, - {<<"worker_pool">>, <<"F7B442B30121EED6D8C828833533E5C15DB61E4AB2EF343C8B67824267656822">>}]}, + {<<"worker_pool">>, <<"CA262C2DFB3B4AF661B206C82065D86F83922B7227508AA6E0BC34D3E5AE5135">>}]}, {pkg_hash_ext,[ {<<"metrics">>, <<"AE061938C8C3BDE97D17BE9A792B63E15C1E1EFFE16598AB87A62384F5F3714B">>}, - {<<"worker_pool">>, <<"F9D95B85E80C5C27B7AB2E60BF780DA70A5E26DD9E6D30BE45032742FC039CC5">>}]} + {<<"worker_pool">>, <<"772E12CCB26909EA7F804B52E86E733DF66BB8150F683B591B0A762196494C74">>}]} ]. diff --git a/src/katipo.erl b/src/katipo.erl index 2650f7f..3cdafbd 100644 --- a/src/katipo.erl +++ b/src/katipo.erl @@ -244,10 +244,11 @@ -type status() :: pos_integer(). -type header() :: {binary(), iodata()}. -type headers() :: [header()]. +-type req_headers() :: [binary()]. -opaque cookiejar() :: [binary()]. -type qs_vals() :: [{unicode:chardata(), unicode:chardata() | true}]. -type req_body() :: iodata() | qs_vals(). --type body() :: binary(). +-type body() :: iodata(). -type connecttimeout_ms() :: pos_integer(). %% See [https://curl.haxx.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html] -type ssl_verifyhost() :: boolean(). @@ -349,6 +350,21 @@ curl_http_version_2_0 | curl_http_version_2tls | curl_http_version_2_prior_knowledge. + +-define(CURL_HTTP_VERSION_NONE, 0). +-define(CURL_HTTP_VERSION_1_0, 1). +-define(CURL_HTTP_VERSION_1_1, 2). +-define(CURL_HTTP_VERSION_2_0, 3). +-define(CURL_HTTP_VERSION_2TLS, 4). +-define(CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE, 5). + +-type curlopt_http_version_int() :: ?CURL_HTTP_VERSION_NONE | + ?CURL_HTTP_VERSION_1_0 | + ?CURL_HTTP_VERSION_1_1 | + ?CURL_HTTP_VERSION_2_0 | + ?CURL_HTTP_VERSION_2TLS | + ?CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE. + %% HTTP protocol version to use %% see [https://curl.se/libcurl/c/CURLOPT_HTTP_VERSION.html] -type curlmopts() :: [{max_pipeline_length, non_neg_integer()} | @@ -386,7 +402,7 @@ -record(req, { method = ?GET :: method_int(), url :: undefined | binary(), - headers = [] :: headers(), + headers = [] :: req_headers(), cookiejar = [] :: cookiejar(), body = <<>> :: body(), connecttimeout_ms = ?DEFAULT_REQ_TIMEOUT :: pos_integer(), @@ -409,7 +425,7 @@ lock_data_ssl_session = ?LOCK_DATA_SSL_SESSION_FALSE :: ?LOCK_DATA_SSL_SESSION_FALSE | ?LOCK_DATA_SSL_SESSION_TRUE, doh_url = undefined :: undefined | doh_url(), - http_version = curl_http_version_none :: curlopt_http_version(), + http_version = ?CURL_HTTP_VERSION_NONE :: curlopt_http_version_int(), verbose = ?VERBOSE_FALSE :: ?VERBOSE_FALSE | ?VERBOSE_TRUE, sslcert = undefined :: undefined | binary() | file:name_all(), sslkey = undefined :: undefined | binary() | file:name_all(), @@ -705,7 +721,7 @@ get_mopts(Opts) -> {error, {bad_opts, Opts}} end. --spec mopt_supported({curlmopt(), any()}) -> false | {true, any()}. +-spec mopt_supported({curlmopt(), any()}) -> false | {true, string()}. mopt_supported({max_pipeline_length, Val}) when is_integer(Val) andalso Val >= 0 -> {true, "--max-pipeline-length " ++ integer_to_list(Val)}; @@ -805,17 +821,17 @@ opt(lock_data_ssl_session, false, {Req, Errors}) -> opt(doh_url, DOHURL, {Req, Errors}) when ?DOH_URL_AVAILABLE andalso is_binary(DOHURL) -> {Req#req{doh_url=DOHURL}, Errors}; opt(http_version, curl_http_version_none, {Req, Errors}) -> - {Req#req{http_version=0}, Errors}; + {Req#req{http_version=?CURL_HTTP_VERSION_NONE}, Errors}; opt(http_version, curl_http_version_1_0, {Req, Errors}) -> - {Req#req{http_version=1}, Errors}; + {Req#req{http_version=?CURL_HTTP_VERSION_1_0}, Errors}; opt(http_version, curl_http_version_1_1, {Req, Errors}) -> - {Req#req{http_version=2}, Errors}; + {Req#req{http_version=?CURL_HTTP_VERSION_1_1}, Errors}; opt(http_version, curl_http_version_2_0, {Req, Errors}) -> - {Req#req{http_version=3}, Errors}; + {Req#req{http_version=?CURL_HTTP_VERSION_2_0}, Errors}; opt(http_version, curl_http_version_2tls, {Req, Errors}) -> - {Req#req{http_version=4}, Errors}; + {Req#req{http_version=?CURL_HTTP_VERSION_2TLS}, Errors}; opt(http_version, curl_http_version_2_prior_knowledge, {Req, Errors}) -> - {Req#req{http_version=5}, Errors}; + {Req#req{http_version=?CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE}, Errors}; opt(verbose, true, {Req, Errors}) -> {Req#req{verbose=?VERBOSE_TRUE}, Errors}; opt(verbose, false, {Req, Errors}) ->