From 730d09f874bc9ef46540ab548e5b702259d303c2 Mon Sep 17 00:00:00 2001 From: tigercl Date: Fri, 29 Jan 2021 09:35:08 +0800 Subject: [PATCH] fix(http): upgrade ehttpc to 0.1.2 (#4093) For fix the connection closed by keepalive --- apps/emqx_auth_http/rebar.config | 2 +- apps/emqx_web_hook/etc/emqx_web_hook.conf | 2 +- apps/emqx_web_hook/priv/emqx_web_hook.schema | 2 +- apps/emqx_web_hook/rebar.config | 3 +- .../src/emqx_web_hook_actions.erl | 30 +++++++++---------- apps/emqx_web_hook/src/emqx_web_hook_app.erl | 4 +-- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/apps/emqx_auth_http/rebar.config b/apps/emqx_auth_http/rebar.config index 1e9f04a08..d159825ee 100644 --- a/apps/emqx_auth_http/rebar.config +++ b/apps/emqx_auth_http/rebar.config @@ -1,5 +1,5 @@ {deps, - [{ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.1.1"}}} + [{ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.1.2"}}} ]}. {edoc_opts, [{preprocess, true}]}. diff --git a/apps/emqx_web_hook/etc/emqx_web_hook.conf b/apps/emqx_web_hook/etc/emqx_web_hook.conf index ae3eaa854..159769394 100644 --- a/apps/emqx_web_hook/etc/emqx_web_hook.conf +++ b/apps/emqx_web_hook/etc/emqx_web_hook.conf @@ -41,7 +41,7 @@ web.hook.body.encoding_of_payload_field = plain ## Turn on peer certificate verification ## ## Value: true | false -## web.hook.ssl.verify = true +## web.hook.ssl.verify = false ## Connection process pool size ## diff --git a/apps/emqx_web_hook/priv/emqx_web_hook.schema b/apps/emqx_web_hook/priv/emqx_web_hook.schema index 62ad804e3..9610ae094 100644 --- a/apps/emqx_web_hook/priv/emqx_web_hook.schema +++ b/apps/emqx_web_hook/priv/emqx_web_hook.schema @@ -27,7 +27,7 @@ ]}. {mapping, "web.hook.ssl.verify", "emqx_web_hook.verify", [ - {default, true}, + {default, false}, {datatype, {enum, [true, false]}} ]}. diff --git a/apps/emqx_web_hook/rebar.config b/apps/emqx_web_hook/rebar.config index a1caccf57..3684b78b0 100644 --- a/apps/emqx_web_hook/rebar.config +++ b/apps/emqx_web_hook/rebar.config @@ -1,8 +1,7 @@ {plugins, [rebar3_proper]}. {deps, - [{ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.1.1"}}}, - {emqx_rule_engine, {git, "https://github.com/emqx/emqx-rule-engine"}} + [{ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.1.2"}}} ]}. {edoc_opts, [{preprocess, true}]}. diff --git a/apps/emqx_web_hook/src/emqx_web_hook_actions.erl b/apps/emqx_web_hook/src/emqx_web_hook_actions.erl index 7e7a901c9..725a08406 100644 --- a/apps/emqx_web_hook/src/emqx_web_hook_actions.erl +++ b/apps/emqx_web_hook/src/emqx_web_hook_actions.erl @@ -32,7 +32,7 @@ title => #{en => <<"URL">>, zh => <<"URL"/utf8>>}, description => #{en => <<"The URL of the server that will receive the Webhook requests.">>, - zh => <<"用于接收 Webhook 请求的服务器的 URL。"/utf8>>} + zh => <<"用于接收 Webhook 请求的服务器的 URL。"/utf8>>} }, connect_timeout => #{ order => 2, @@ -40,7 +40,7 @@ default => 5, title => #{en => <<"Connect Timeout">>, zh => <<"连接超时时间"/utf8>>}, - description => #{en => <<"Connect Timeout In Seconds">>, + description => #{en => <<"Connect timeout in seconds">>, zh => <<"连接超时时间,单位秒"/utf8>>}}, request_timeout => #{ order => 3, @@ -48,7 +48,7 @@ default => 5, title => #{en => <<"Request Timeout">>, zh => <<"请求超时时间时间"/utf8>>}, - description => #{en => <<"Request Timeout In Seconds">>, + description => #{en => <<"Request timeout in seconds">>, zh => <<"请求超时时间,单位秒"/utf8>>}}, cacertfile => #{ order => 4, @@ -56,7 +56,7 @@ default => <<>>, title => #{en => <<"CA Certificate File">>, zh => <<"CA 证书文件"/utf8>>}, - description => #{en => <<"CA Certificate File.">>, + description => #{en => <<"CA certificate file.">>, zh => <<"CA 证书文件。"/utf8>>} }, certfile => #{ @@ -65,7 +65,7 @@ default => <<>>, title => #{en => <<"Certificate File">>, zh => <<"证书文件"/utf8>>}, - description => #{en => <<"Certificate File.">>, + description => #{en => <<"Certificate file.">>, zh => <<"证书文件。"/utf8>>} }, keyfile => #{ @@ -80,7 +80,7 @@ verify => #{ order => 7, type => boolean, - default => true, + default => false, title => #{en => <<"Verify">>, zh => <<"Verify"/utf8>>}, description => #{en => <<"Turn on peer certificate verification.">>, @@ -92,8 +92,8 @@ default => 32, title => #{en => <<"Pool Size">>, zh => <<"连接池大小"/utf8>>}, - description => #{en => <<"Pool Size for HTTP Server.">>, - zh => <<"HTTP Server 连接池大小。"/utf8>>} + description => #{en => <<"Pool size for HTTP server.">>, + zh => <<"HTTP server 连接池大小。"/utf8>>} } }). @@ -112,7 +112,7 @@ method => #{ order => 1, type => string, - enum => [<<"POST">>,<<"DELETE">>,<<"PUT">>,<<"GET">>], + enum => [<<"POST">>, <<"DELETE">>, <<"PUT">>, <<"GET">>], default => <<"POST">>, title => #{en => <<"Method">>, zh => <<"Method"/utf8>>}, @@ -263,15 +263,15 @@ on_action_data_to_webserver(Selected, _Envs = Req = create_req(Method, NPath, Headers, NBody), case ehttpc:request(ehttpc_pool:pick_worker(Pool, ClientID), Method, Req, RequestTimeout) of {ok, StatusCode, _} when StatusCode >= 200 andalso StatusCode < 300 -> - ok; + emqx_rule_metrics:inc_actions_success(Id); {ok, StatusCode, _, _} when StatusCode >= 200 andalso StatusCode < 300 -> - ok; + emqx_rule_metrics:inc_actions_success(Id); {ok, StatusCode, _} -> ?LOG(warning, "[WebHook Action] HTTP request failed with status code: ~p", [StatusCode]), - ok; + emqx_rule_metrics:inc_actions_error(Id); {ok, StatusCode, _, _} -> ?LOG(warning, "[WebHook Action] HTTP request failed with status code: ~p", [StatusCode]), - ok; + emqx_rule_metrics:inc_actions_error(Id); {error, Reason} -> ?LOG(error, "[WebHook Action] HTTP request error: ~p", [Reason]), emqx_rule_metrics:inc_actions_error(Id) @@ -357,7 +357,7 @@ pool_opts(Params = #{<<"url">> := URL}) -> (_) -> true end, [{keyfile, KeyFile}, {certfile, CertFile}, {cacertfile, CACertFile}]), - TlsVers = ['tlsv1.2','tlsv1.1',tlsv1], + TlsVers = ['tlsv1.2', 'tlsv1.1', tlsv1], NTLSOpts = [{verify, VerifyType}, {versions, TlsVers}, {ciphers, lists:foldl(fun(TlsVer, Ciphers) -> @@ -385,4 +385,4 @@ parse_host(Host) -> {ok, _} -> {inet6, Host}; {error, _} -> {inet, Host} end - end. + end. \ No newline at end of file diff --git a/apps/emqx_web_hook/src/emqx_web_hook_app.erl b/apps/emqx_web_hook/src/emqx_web_hook_app.erl index 431cb5792..c8083e195 100644 --- a/apps/emqx_web_hook/src/emqx_web_hook_app.erl +++ b/apps/emqx_web_hook/src/emqx_web_hook_app.erl @@ -52,10 +52,10 @@ translate_env() -> {ok, URL} = application:get_env(?APP, url), #{host := Host0, path := Path0, - scheme := Scheme} = URIMap = uri_string:parse(add_default_scheme(URL)), + scheme := Scheme} = URIMap = uri_string:parse(add_default_scheme(uri_string:normalize(URL))), Port = maps:get(port, URIMap, case Scheme of "https" -> 443; - _ -> 80 + "http" -> 80 end), Path = path(Path0), {Inet, Host} = parse_host(Host0),