diff options
author | Péter Dimitrov <[email protected]> | 2018-10-08 15:06:25 +0200 |
---|---|---|
committer | Péter Dimitrov <[email protected]> | 2018-10-08 15:06:25 +0200 |
commit | 89aa002c83e490ea59606a472f190e75ed1af5a2 (patch) | |
tree | cc0a2d14753de6ca8cbd50956fbd55c7dbef22af /lib/inets/src/http_client | |
parent | f4c8e878fe335afd4b5036c6f1991ba671bfa8dc (diff) | |
parent | bb5ba03ac8ada0b05c95c7cde295e61fe3faca5c (diff) | |
download | otp-89aa002c83e490ea59606a472f190e75ed1af5a2.tar.gz otp-89aa002c83e490ea59606a472f190e75ed1af5a2.tar.bz2 otp-89aa002c83e490ea59606a472f190e75ed1af5a2.zip |
Merge branch 'peterdmv/inets/httpc-content-length/ERL-733/OTP-15338' into maint
* peterdmv/inets/httpc-content-length/ERL-733/OTP-15338:
inets: Fix handling of 'Content-Length' (httpc)
Change-Id: I3281949d47d2494dc8d6f3af3e93b46cdbbc24b9
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)); |