From b9a2da76f0a4d84b749c4ac6ef8d269994385593 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Mon, 19 Mar 2018 10:36:18 +0000 Subject: inets: Delete obsolete comment in httpc_response:result --- lib/inets/src/http_client/httpc_response.erl | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/inets/src') diff --git a/lib/inets/src/http_client/httpc_response.erl b/lib/inets/src/http_client/httpc_response.erl index 58ab9144df..92dc9b0e02 100644 --- a/lib/inets/src/http_client/httpc_response.erl +++ b/lib/inets/src/http_client/httpc_response.erl @@ -83,7 +83,6 @@ whole_body(Body, Length) -> %% result(Response, Request) -> %% Response - {StatusLine, Headers, Body} %% Request - #request{} -%% Session - #tcp_session{} %% %% Description: Checks the status code ... %%------------------------------------------------------------------------- -- cgit v1.2.3 From 2591eddc8db45c89e01ceefa009537aaf660ac82 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Fri, 16 Mar 2018 21:03:19 +0000 Subject: inets: Remove httpc dead code re init error ... i.e. references to `connect_failed` and `send_failed`, unused since 5d32eaf750 . --- lib/inets/src/http_client/httpc_handler.erl | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'lib/inets/src') diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl index 9b09832eb8..327aec4baa 100644 --- a/lib/inets/src/http_client/httpc_handler.erl +++ b/lib/inets/src/http_client/httpc_handler.erl @@ -48,12 +48,10 @@ queue_timer :: reference() | 'undefined' }). --type session_failed() :: {'connect_failed',term()} | {'send_failed',term()}. - -record(state, { request :: request() | 'undefined', - session :: session() | session_failed() | 'undefined', + session :: session() | 'undefined', status_line, % {Version, StatusCode, ReasonPharse} headers :: http_response_h() | 'undefined', body :: binary() | 'undefined', @@ -295,23 +293,6 @@ handle_info(Info, State) -> %% Description: Shutdown the httpc_handler %%-------------------------------------------------------------------- -%% Init error there is no socket to be closed. -terminate(normal, - #state{request = Request, - session = {send_failed, _} = Reason} = State) -> - maybe_send_answer(Request, - httpc_response:error(Request, Reason), - State), - ok; - -terminate(normal, - #state{request = Request, - session = {connect_failed, _} = Reason} = State) -> - maybe_send_answer(Request, - httpc_response:error(Request, Reason), - State), - ok; - terminate(normal, #state{session = undefined}) -> ok; -- cgit v1.2.3 From 4868c38d1653ee9389ec024214509661818baf2a Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Fri, 16 Mar 2018 21:26:53 +0000 Subject: inets: Enable stronger Dialyzer checks in httpc_handler --- lib/inets/src/http_client/httpc_handler.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/inets/src') diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl index 327aec4baa..8311d1ed76 100644 --- a/lib/inets/src/http_client/httpc_handler.erl +++ b/lib/inets/src/http_client/httpc_handler.erl @@ -58,7 +58,7 @@ mfa, % {Module, Function, Args} pipeline = queue:new() :: queue:queue(), keep_alive = queue:new() :: queue:queue(), - status, % undefined | new | pipeline | keep_alive | close | {ssl_tunnel, Request} + status :: undefined | new | pipeline | keep_alive | close | {ssl_tunnel, request()}, canceled = [], % [RequestId] max_header_size = nolimit :: nolimit | integer(), max_body_size = nolimit :: nolimit | integer(), -- cgit v1.2.3 From c061eb5f8b6b0fdf3468945d8f6eea818ac4f478 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Mon, 19 Mar 2018 19:16:29 +0000 Subject: inets: Make httpc error reason more informative for unexpected errors --- lib/inets/src/http_client/httpc_handler.erl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'lib/inets/src') diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl index 8311d1ed76..0ca8155054 100644 --- a/lib/inets/src/http_client/httpc_handler.erl +++ b/lib/inets/src/http_client/httpc_handler.erl @@ -253,8 +253,9 @@ handle_call(Request, From, State) -> Result -> Result catch - _:Reason -> - {stop, {shutdown, Reason} , State} + Class:Reason -> + ST = erlang:get_stacktrace(), + {stop, {shutdown, {{Class, Reason}, ST}}, State} end. @@ -269,8 +270,9 @@ handle_cast(Msg, State) -> Result -> Result catch - _:Reason -> - {stop, {shutdown, Reason} , State} + Class:Reason -> + ST = erlang:get_stacktrace(), + {stop, {shutdown, {{Class, Reason}, ST}}, State} end. %%-------------------------------------------------------------------- @@ -284,8 +286,9 @@ handle_info(Info, State) -> Result -> Result catch - _:Reason -> - {stop, {shutdown, Reason} , State} + Class:Reason -> + ST = erlang:get_stacktrace(), + {stop, {shutdown, {{Class, Reason}, ST}}, State} end. %%-------------------------------------------------------------------- @@ -569,11 +572,12 @@ do_handle_info({Proto, _Socket, Data}, activate_once(Session), {noreply, State#state{mfa = NewMFA}} catch - _:Reason -> + Class:Reason -> + ST = erlang:get_stacktrace(), ClientReason = {could_not_parse_as_http, Data}, ClientErrMsg = httpc_response:error(Request, ClientReason), NewState = answer_request(Request, ClientErrMsg, State), - {stop, {shutdown, Reason}, NewState} + {stop, {shutdown, {{Class, Reason}, ST}}, NewState} end; do_handle_info({Proto, Socket, Data}, -- cgit v1.2.3 From 9a19dc099198585bd4f019116663d5b8be506ce0 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Fri, 16 Mar 2018 18:00:00 +0000 Subject: inets: Teach httpc to honour `Connection: close` from server From https://tools.ietf.org/html/rfc7230#section-6.6 > A client that receives a "close" connection option MUST cease sending requests on that connection and close the connection after reading the response message containing the "close"; if additional pipelined requests had been sent on the connection, the client SHOULD NOT assume that they will be processed by the server. Notes on tests: * The new tests are added only in group sim_http and not sim_https because the same test approach appears to be not valid because when processing the first response the server already sent data (> 0) for the TLS/SSL handshake; * The order of tests is relevant as it appears some test cases leave reusable sessions behind. --- lib/inets/src/http_client/httpc_handler.erl | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'lib/inets/src') diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl index 0ca8155054..ca29523f84 100644 --- a/lib/inets/src/http_client/httpc_handler.erl +++ b/lib/inets/src/http_client/httpc_handler.erl @@ -1043,15 +1043,29 @@ handle_response(#state{status = new} = State) -> ?hcrd("handle response - status = new", []), handle_response(try_to_enable_pipeline_or_keep_alive(State)); -handle_response(#state{request = Request, - status = Status, - session = Session, - status_line = StatusLine, - headers = Headers, - body = Body, - options = Options, - profile_name = ProfileName} = State) - when Status =/= new -> +handle_response(#state{status = Status0} = State0) when Status0 =/= new -> + Status = + case Status0 of + close -> close; + _ -> + case State0#state.headers of + undefined -> Status0; + _ -> + case httpc_response:is_server_closing( + State0#state.headers) of + true -> close; + false -> Status0 + end + end + end, + State = State0#state{status = Status}, + #state{request = Request, + session = Session, + status_line = StatusLine, + headers = Headers, + body = Body, + options = Options, + profile_name = ProfileName} = State, handle_cookies(Headers, Request, Options, ProfileName), case httpc_response:result({StatusLine, Headers, Body}, Request) of %% 100-continue -- cgit v1.2.3 From 2f7731260c4624cd5a324cb7c6ea9c124cf9ea4a Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Thu, 5 Apr 2018 15:02:43 +0100 Subject: inets: Avoid `erlang:get_stacktrace/0` deprecated in OTP 21 --- lib/inets/src/http_client/httpc_handler.erl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'lib/inets/src') diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl index ca29523f84..945b1b94b6 100644 --- a/lib/inets/src/http_client/httpc_handler.erl +++ b/lib/inets/src/http_client/httpc_handler.erl @@ -253,8 +253,7 @@ handle_call(Request, From, State) -> Result -> Result catch - Class:Reason -> - ST = erlang:get_stacktrace(), + Class:Reason:ST -> {stop, {shutdown, {{Class, Reason}, ST}}, State} end. @@ -270,8 +269,7 @@ handle_cast(Msg, State) -> Result -> Result catch - Class:Reason -> - ST = erlang:get_stacktrace(), + Class:Reason:ST -> {stop, {shutdown, {{Class, Reason}, ST}}, State} end. @@ -286,8 +284,7 @@ handle_info(Info, State) -> Result -> Result catch - Class:Reason -> - ST = erlang:get_stacktrace(), + Class:Reason:ST -> {stop, {shutdown, {{Class, Reason}, ST}}, State} end. @@ -572,8 +569,7 @@ do_handle_info({Proto, _Socket, Data}, activate_once(Session), {noreply, State#state{mfa = NewMFA}} catch - Class:Reason -> - ST = erlang:get_stacktrace(), + Class:Reason:ST -> ClientReason = {could_not_parse_as_http, Data}, ClientErrMsg = httpc_response:error(Request, ClientReason), NewState = answer_request(Request, ClientErrMsg, State), -- cgit v1.2.3 From d9d40dd446d7e7783ceaff62f0bc5f74e556d119 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Fri, 6 Apr 2018 10:45:28 +0100 Subject: inets: Improve readability of handling of server `Connection: close` Addresses https://github.com/erlang/otp/pull/1752#discussion_r177970060 --- lib/inets/src/http_client/httpc_handler.erl | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'lib/inets/src') diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl index 945b1b94b6..eeb08ce0ee 100644 --- a/lib/inets/src/http_client/httpc_handler.erl +++ b/lib/inets/src/http_client/httpc_handler.erl @@ -1040,21 +1040,7 @@ handle_response(#state{status = new} = State) -> handle_response(try_to_enable_pipeline_or_keep_alive(State)); handle_response(#state{status = Status0} = State0) when Status0 =/= new -> - Status = - case Status0 of - close -> close; - _ -> - case State0#state.headers of - undefined -> Status0; - _ -> - case httpc_response:is_server_closing( - State0#state.headers) of - true -> close; - false -> Status0 - end - end - end, - State = State0#state{status = Status}, + State = handle_server_closing(State0), #state{request = Request, session = Session, status_line = StatusLine, @@ -1325,6 +1311,14 @@ try_to_enable_pipeline_or_keep_alive( State#state{status = close} end. +handle_server_closing(State = #state{status = close}) -> State; +handle_server_closing(State = #state{headers = undefined}) -> State; +handle_server_closing(State = #state{headers = Headers}) -> + case httpc_response:is_server_closing(Headers) of + true -> State#state{status = close}; + false -> State + end. + answer_request(#request{id = RequestId, from = From} = Request, Msg, #state{session = Session, timers = Timers, -- cgit v1.2.3