diff options
author | Péter Dimitrov <[email protected]> | 2018-10-02 16:26:59 +0200 |
---|---|---|
committer | Péter Dimitrov <[email protected]> | 2018-10-02 16:26:59 +0200 |
commit | bb5ba03ac8ada0b05c95c7cde295e61fe3faca5c (patch) | |
tree | d6662eda32de291d0b6296cfdf53d252c92abfac /lib/inets/src/http_client | |
parent | 0edd7ee4d575656f6da6558e40d6993f41a4be38 (diff) | |
download | otp-bb5ba03ac8ada0b05c95c7cde295e61fe3faca5c.tar.gz otp-bb5ba03ac8ada0b05c95c7cde295e61fe3faca5c.tar.bz2 otp-bb5ba03ac8ada0b05c95c7cde295e61fe3faca5c.zip |
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
Diffstat (limited to 'lib/inets/src/http_client')
-rw-r--r-- | lib/inets/src/http_client/httpc_request.erl | 11 |
1 files changed, 10 insertions, 1 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)); |