diff options
author | Luca Favatella <[email protected]> | 2018-03-16 18:00:00 +0000 |
---|---|---|
committer | Luca Favatella <[email protected]> | 2018-03-23 17:02:53 +0000 |
commit | 9a19dc099198585bd4f019116663d5b8be506ce0 (patch) | |
tree | 742ef416e52af1c37f92814ccf2735f62a1674b8 /lib/inets/src/http_client/httpc_handler.erl | |
parent | cef626165bc62edcc78c3be0c2cb107ae961b805 (diff) | |
download | otp-9a19dc099198585bd4f019116663d5b8be506ce0.tar.gz otp-9a19dc099198585bd4f019116663d5b8be506ce0.tar.bz2 otp-9a19dc099198585bd4f019116663d5b8be506ce0.zip |
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.
Diffstat (limited to 'lib/inets/src/http_client/httpc_handler.erl')
-rw-r--r-- | lib/inets/src/http_client/httpc_handler.erl | 32 |
1 files changed, 23 insertions, 9 deletions
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 |