File 0952-inets-ERL-1239-fix-to-return-an-error-if-http-server.patch of Package erlang
From e214929d93308cbbaeb7367bf832a16d1de65fe3 Mon Sep 17 00:00:00 2001
From: Ao Song <andy@erlang.org>
Date: Mon, 20 Jul 2020 21:36:49 +0200
Subject: [PATCH] inets: ERL-1239, fix to return an error if http server closes
in the middle of streaming response.
Change-Id: I9a8c9631d9419ac979c285e029d329e9fb0bcb9d
---
lib/inets/src/http_client/httpc_handler.erl | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl
index dd16240814..9135935567 100644
--- a/lib/inets/src/http_client/httpc_handler.erl
+++ b/lib/inets/src/http_client/httpc_handler.erl
@@ -602,12 +602,18 @@ do_handle_info({Proto, Socket, Data},
{noreply, State};
%% The Server may close the connection to indicate that the
-%% whole body is now sent instead of sending an length
-%% indicator.
-do_handle_info({tcp_closed, _}, State = #state{mfa = {_, whole_body, Args}}) ->
- handle_response(State#state{body = hd(Args)});
-do_handle_info({ssl_closed, _}, State = #state{mfa = {_, whole_body, Args}}) ->
- handle_response(State#state{body = hd(Args)});
+%% whole body is now sent instead of sending a lengh
+%% indicator. In this case the lengh indicator will be
+%% -1.
+do_handle_info({Info, _}, State = #state{mfa = {_, whole_body, Args}})
+ when Info =:= tcp_closed orelse
+ Info =:= ssl_closed ->
+ case lists:last(Args) of
+ Length when Length =< 0 ->
+ handle_response(State#state{body = hd(Args)});
+ _Else ->
+ {stop, {shutdown, server_closed}, State}
+ end;
%%% Server closes idle pipeline
do_handle_info({tcp_closed, _}, State = #state{request = undefined}) ->
--
2.26.2