aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/src/http_client/httpc_request.erl
diff options
context:
space:
mode:
authorPéter Dimitrov <[email protected]>2018-10-02 17:03:00 +0200
committerPéter Dimitrov <[email protected]>2018-10-02 17:03:00 +0200
commitd95cfc3b4a8ea1bbd8ad6c90f1e00b0150a87d7e (patch)
treeb030571c4a5579d24b3d9fec4ca10a9df3eaae72 /lib/inets/src/http_client/httpc_request.erl
parent0edd7ee4d575656f6da6558e40d6993f41a4be38 (diff)
downloadotp-d95cfc3b4a8ea1bbd8ad6c90f1e00b0150a87d7e.tar.gz
otp-d95cfc3b4a8ea1bbd8ad6c90f1e00b0150a87d7e.tar.bz2
otp-d95cfc3b4a8ea1bbd8ad6c90f1e00b0150a87d7e.zip
inets: Fix handling of 'Content-Type' (httpc)
'Content-Type' is sent when it is explicitly set as a header or there is a non-empty body in the request. Former implementation dropped the explicit 'Content-Type' when the request had an empty body. Change-Id: I00a9e4a5011f9d28c04c0dfc5fe1561b1ab7eb09
Diffstat (limited to 'lib/inets/src/http_client/httpc_request.erl')
-rw-r--r--lib/inets/src/http_client/httpc_request.erl12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/inets/src/http_client/httpc_request.erl b/lib/inets/src/http_client/httpc_request.erl
index 9b81bd7a80..4cb2d57b14 100644
--- a/lib/inets/src/http_client/httpc_request.erl
+++ b/lib/inets/src/http_client/httpc_request.erl
@@ -213,9 +213,11 @@ update_body(Headers, Body) ->
update_headers(Headers, ContentType, Body, []) ->
case Body of
[] ->
- Headers#http_request_h{'content-length' = "0"};
+ Headers1 = Headers#http_request_h{'content-length' = "0"},
+ handle_content_type(Headers1, ContentType);
<<>> ->
- Headers#http_request_h{'content-length' = "0"};
+ Headers1 = Headers#http_request_h{'content-length' = "0"},
+ handle_content_type(Headers1, ContentType);
{Fun, _Acc} when is_function(Fun, 1) ->
%% A client MUST NOT generate a 100-continue expectation in a request
%% that does not include a message body. This implies that either the
@@ -236,6 +238,12 @@ body_length(Body) when is_binary(Body) ->
body_length(Body) when is_list(Body) ->
integer_to_list(length(Body)).
+%% Set 'Content-Type' when it is explicitly set.
+handle_content_type(Headers, "") ->
+ Headers;
+handle_content_type(Headers, ContentType) ->
+ Headers#http_request_h{'content-type' = ContentType}.
+
method(Method) ->
http_util:to_upper(atom_to_list(Method)).