aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/test/httpc_SUITE.erl
diff options
context:
space:
mode:
authorPéter Dimitrov <[email protected]>2018-04-06 12:02:20 +0200
committerPéter Dimitrov <[email protected]>2018-04-06 12:02:20 +0200
commitfd2af907bc854e5dc92fbd71efdab096be572573 (patch)
treef7e0ef1181fefbabdc84d63ad2b8af26a3497ccc /lib/inets/test/httpc_SUITE.erl
parenta5dc5af3fe3b1e25f0596d71d3ac36291b0099dc (diff)
downloadotp-fd2af907bc854e5dc92fbd71efdab096be572573.tar.gz
otp-fd2af907bc854e5dc92fbd71efdab096be572573.tar.bz2
otp-fd2af907bc854e5dc92fbd71efdab096be572573.zip
inets: Fix broken handling of header Content-Type
Strict REST APIs does not accept HTTP requests that have no body but still include a 'Content-Type' header. RFC7231 does not forbid this corner case but as it causes interoperatbility problems in client software we opt to not send the 'Content-Type' header when the body is not present. Change-Id: I36c43225fd156fb1b651037fcbe69b448665ec23
Diffstat (limited to 'lib/inets/test/httpc_SUITE.erl')
-rw-r--r--lib/inets/test/httpc_SUITE.erl29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl
index 38705372c9..38903f560c 100644
--- a/lib/inets/test/httpc_SUITE.erl
+++ b/lib/inets/test/httpc_SUITE.erl
@@ -151,6 +151,7 @@ only_simulated() ->
relaxed,
multipart_chunks,
get_space,
+ delete_no_body,
stream_fun_server_close
].
@@ -1304,7 +1305,16 @@ unix_domain_socket(Config) when is_list(Config) ->
= httpc:request(put, {URL, [], [], ""}, [], []),
{ok, {{_,200,_}, [_ | _], _}}
= httpc:request(get, {URL, []}, [], []).
-
+%%-------------------------------------------------------------------------
+delete_no_body(doc) ->
+ ["Test that a DELETE request without Body does not send a Content-Type header - Solves ERL-536"];
+delete_no_body(Config) when is_list(Config) ->
+ URL = url(group_name(Config), "/delete_no_body.html", Config),
+ %% Simulated server replies 500 if 'Content-Type' header is present
+ {ok, {{_,200,_}, _, _}} =
+ httpc:request(delete, {URL, []}, [], []),
+ {ok, {{_,500,_}, _, _}} =
+ httpc:request(delete, {URL, [], "text/plain", "TEST"}, [], []).
%%--------------------------------------------------------------------
@@ -1811,6 +1821,13 @@ auth_header([{"authorization", Value} | _]) ->
auth_header([_ | Tail]) ->
auth_header(Tail).
+content_type_header([]) ->
+ not_found;
+content_type_header([{"content-type", Value}|_]) ->
+ {ok, string:strip(Value)};
+content_type_header([_|T]) ->
+ content_type_header(T).
+
handle_auth("Basic " ++ UserInfo, Challange, DefaultResponse) ->
case string:tokens(base64:decode_to_string(UserInfo), ":") of
["alladin", "sesame"] = Auth ->
@@ -2232,7 +2249,15 @@ handle_uri("GET","/v1/kv/foo",_,_,_,_) ->
"Content-Length: 24\r\n" ++
"Content-Type: application/json\r\n\r\n" ++
"[{\"Value\": \"aGVsbG8=\"}]\n";
-
+handle_uri(_,"/delete_no_body.html", _,Headers,_, DefaultResponse) ->
+ Error = "HTTP/1.1 500 Internal Server Error\r\n" ++
+ "Content-Length:0\r\n\r\n",
+ case content_type_header(Headers) of
+ {ok, _} ->
+ Error;
+ not_found ->
+ DefaultResponse
+ end;
handle_uri(_,_,_,_,_,DefaultResponse) ->
DefaultResponse.