File 0294-inets-Fix-handling-of-Content-Length-httpc.patch of Package erlang
From bb5ba03ac8ada0b05c95c7cde295e61fe3faca5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A9ter=20Dimitrov?= <peterdmv@erlang.org>
Date: Tue, 2 Oct 2018 16:26:59 +0200
Subject: [PATCH] inets: Fix handling of 'Content-Length' (httpc)
RFC7230 3.3.2
A sender MUST NOT send a 'Content-Length' header field in any message
that contains a 'Transfer-Encoding' header field.
Change-Id: I568fc65cafe3ab30baad56c002459ff74e4dbb28
---
lib/inets/src/http_client/httpc_request.erl | 11 ++++-
lib/inets/test/httpc_SUITE.erl | 75 ++++++++++++++++++++++++-----
2 files changed, 73 insertions(+), 13 deletions(-)
diff --git a/lib/inets/src/http_client/httpc_request.erl b/lib/inets/src/http_client/httpc_request.erl
index 9b81bd7a80..9db961cf9e 100644
--- a/lib/inets/src/http_client/httpc_request.erl
+++ b/lib/inets/src/http_client/httpc_request.erl
@@ -221,7 +221,8 @@ update_headers(Headers, ContentType, Body, []) ->
%% that does not include a message body. This implies that either the
%% Content-Length or the Transfer-Encoding header MUST be present.
%% DO NOT send content-type when Body is empty.
- Headers#http_request_h{'content-type' = ContentType};
+ Headers1 = Headers#http_request_h{'content-type' = ContentType},
+ handle_transfer_encoding(Headers1);
_ ->
Headers#http_request_h{
'content-length' = body_length(Body),
@@ -230,6 +231,14 @@ update_headers(Headers, ContentType, Body, []) ->
update_headers(_, _, _, HeadersAsIs) ->
HeadersAsIs.
+handle_transfer_encoding(Headers = #http_request_h{'transfer-encoding' = undefined}) ->
+ Headers;
+handle_transfer_encoding(Headers) ->
+ %% RFC7230 3.3.2
+ %% A sender MUST NOT send a 'Content-Length' header field in any message
+ %% that contains a 'Transfer-Encoding' header field.
+ Headers#http_request_h{'content-length' = undefined}.
+
body_length(Body) when is_binary(Body) ->
integer_to_list(size(Body));
--
2.16.4