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