File 0950-inets-bug-fix-handle-message-body-of-response-with-1.patch of Package erlang
From d984ad4231303045ef450fc28a656be53aca9417 Mon Sep 17 00:00:00 2001
From: Ao Song <andy@erlang.org>
Date: Fri, 3 Jul 2020 12:36:56 +0200
Subject: [PATCH] inets: bug fix, handle message body of response with 1XX code
as next http message
Change-Id: I537134e39e7e026fdd00ae624cfdc812429b3c18
---
lib/inets/src/http_client/httpc_handler.erl | 8 ++++----
lib/inets/src/http_client/httpc_response.erl | 10 ++++++++--
2 files 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 1f8806d1d8..dd16240814 100644
--- a/lib/inets/src/http_client/httpc_handler.erl
+++ b/lib/inets/src/http_client/httpc_handler.erl
@@ -965,16 +965,16 @@ handle_http_body(_, #state{status = {ssl_tunnel, Request},
%% terminated by the first empty line after the header fields.
%% This implies that chunked encoding MUST NOT be used for these
%% status codes.
-handle_http_body(<<>>, #state{headers = Headers,
+handle_http_body(Body, #state{headers = Headers,
status_line = {_,StatusCode, _}} = State)
when Headers#http_response_h.'transfer-encoding' =/= "chunked" andalso
(StatusCode =:= 204 orelse %% No Content
StatusCode =:= 304 orelse %% Not Modified
100 =< StatusCode andalso StatusCode =< 199) -> %% Informational
- handle_response(State#state{body = <<>>});
-
+ handle_response(State#state{body = Body});
-handle_http_body(<<>>, #state{request = #request{method = head}} = State) ->
+%% Ignore the body of response to a HEAD method
+handle_http_body(_Body, #state{request = #request{method = head}} = State) ->
handle_response(State#state{body = <<>>});
handle_http_body(Body, #state{headers = Headers,
diff --git a/lib/inets/src/http_client/httpc_response.erl b/lib/inets/src/http_client/httpc_response.erl
index bb6b76da89..538cdd0e87 100644
--- a/lib/inets/src/http_client/httpc_response.erl
+++ b/lib/inets/src/http_client/httpc_response.erl
@@ -91,7 +91,13 @@ result(Response = {{_, Code,_}, _, _},
when ((Code =:= 200) orelse (Code =:= 206)) andalso (Stream =/= none) ->
stream_end(Response, Request);
-result(Response = {{_,100,_}, _, _}, Request) ->
+%% Ignore the body of response with status code 204 or 304
+result({{_, Code, _} = StatusLine, Headers, _Body}, Request)
+ when Code =:= 204 orelse Code =:= 304 ->
+ transparent({StatusLine, Headers, <<>>}, Request);
+
+result(Response = {{_, Code, _}, _, _}, Request)
+ when (100 =< Code andalso Code =< 199) ->
status_continue(Response, Request);
%% In redirect loop
@@ -356,7 +362,7 @@ status_continue(_, #request{headers =
status_continue({_,_, Data}, _) ->
%% The data in the body in this case is actually part of the real
- %% response sent after the "fake" 100-continue.
+ %% response.
{ignore, Data}.
status_service_unavailable(Response = {_, Headers, _}, Request) ->
--
2.26.2