summaryrefslogtreecommitdiff
path: root/lib/inets/test/httpc_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/inets/test/httpc_SUITE.erl')
-rw-r--r--lib/inets/test/httpc_SUITE.erl138
1 files changed, 124 insertions, 14 deletions
diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl
index b755c2ebef..f7eff5822d 100644
--- a/lib/inets/test/httpc_SUITE.erl
+++ b/lib/inets/test/httpc_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2004-2018. All Rights Reserved.
+%% Copyright Ericsson AB 2004-2021. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -98,6 +98,30 @@ real_requests()->
emulate_lower_versions,
headers,
headers_as_is,
+ header_type_0,
+ header_type_1,
+ header_type_2,
+ header_type_3,
+ header_type_4,
+ header_type_5,
+ header_type_6,
+ header_type_7,
+ header_type_8,
+ header_type_9,
+ header_type_10,
+ header_type_11,
+ header_type_12,
+ header_type_13,
+ header_type_14,
+ header_type_15,
+ header_type_16,
+ header_type_17,
+ header_type_18,
+ header_type_19,
+ header_type_20,
+ header_type_21,
+ header_type_22,
+ header_type_23,
empty_body,
stream,
stream_to_pid,
@@ -105,8 +129,11 @@ real_requests()->
stream_through_mfa,
streaming_error,
inet_opts,
- invalid_headers,
+ invalid_headers_key,
+ invalid_headers_value,
invalid_body,
+ invalid_body_fun,
+ invalid_method,
no_scheme,
invalid_uri,
undefined_port,
@@ -1217,23 +1244,106 @@ headers_conflict_chunked_with_length(Config) when is_list(Config) ->
%%-------------------------------------------------------------------------
-invalid_headers(Config) ->
- Request = {url(group_name(Config), "/dummy.html", Config), [{"cookie", undefined}]},
- {error, _} = httpc:request(get, Request, [], []).
+
+invalid_headers_key(Config) ->
+ Request = {url(group_name(Config), "/dummy.html", Config),
+ [{cookie, "valid cookie"}]},
+ {error, {headers_error, invalid_field}} =
+ httpc:request(get, Request, [], []).
+
+invalid_headers_value(Config) ->
+ Request = {url(group_name(Config), "/dummy.html", Config),
+ [{"cookie", atom_value}]},
+ {error, {headers_error, invalid_value}} =
+ httpc:request(get, Request, [], []).
%%-------------------------------------------------------------------------
-invalid_body(Config) ->
+%% Doc not generated, but we can live without that. It should be
+%% [{doc, "Header type test"}].
+-define(HDR_TYPE_TEST(Name, Method, Value),
+ Name(Config) when is_list(Config) ->
+ test_header_type(Config, Method, Value)).
+
+?HDR_TYPE_TEST(header_type_0, get, "stringheader").
+?HDR_TYPE_TEST(header_type_1, get, <<"binary">>).
+?HDR_TYPE_TEST(header_type_2, get, ["an", <<"iolist">>]).
+?HDR_TYPE_TEST(header_type_3, head, "stringheader").
+?HDR_TYPE_TEST(header_type_4, head, <<"binary">>).
+?HDR_TYPE_TEST(header_type_5, head, ["an", <<"iolist">>]).
+?HDR_TYPE_TEST(header_type_6, post, "stringheader").
+?HDR_TYPE_TEST(header_type_7, post, <<"binary">>).
+?HDR_TYPE_TEST(header_type_8, post, ["an", <<"iolist">>]).
+?HDR_TYPE_TEST(header_type_9, put, "stringheader").
+?HDR_TYPE_TEST(header_type_10, put, <<"binary">>).
+?HDR_TYPE_TEST(header_type_11, put, ["an", <<"iolist">>]).
+?HDR_TYPE_TEST(header_type_12, delete, "stringheader").
+?HDR_TYPE_TEST(header_type_13, delete, <<"binary">>).
+?HDR_TYPE_TEST(header_type_14, delete, ["an", <<"iolist">>]).
+?HDR_TYPE_TEST(header_type_15, trace, "stringheader").
+?HDR_TYPE_TEST(header_type_16, trace, <<"binary">>).
+?HDR_TYPE_TEST(header_type_17, trace, ["an", <<"iolist">>]).
+?HDR_TYPE_TEST(header_type_18, patch, "stringheader").
+?HDR_TYPE_TEST(header_type_19, patch, <<"binary">>).
+?HDR_TYPE_TEST(header_type_20, patch, ["an", <<"iolist">>]).
+?HDR_TYPE_TEST(header_type_21, options, "stringheader").
+?HDR_TYPE_TEST(header_type_22, options, <<"binary">>).
+?HDR_TYPE_TEST(header_type_23, options, ["an", <<"iolist">>]).
+
+test_header_type(Config, Method, Value) ->
+ {Method, Value, {ok, _Data}} =
+ {Method, Value,
+ httpc:request(Method,
+ make_request(Config, Method, Value),
+ [],
+ [])}.
+
+make_request(Config, Method, Value) ->
URL = url(group_name(Config), "/dummy.html", Config),
- try
- httpc:request(post, {URL, [], <<"text/plain">>, "foobar"},
- [], []),
- ct:fail(accepted_invalid_input)
- catch
- error:function_clause ->
- ok
+ Headers = [{"other-header", Value},
+ {"user-agent", Value}],
+ %% Generate request with or without body, depending on method.
+ case method_type(Method) of
+ read ->
+ {URL, Headers};
+ write ->
+ {URL, Headers, "text/plain", ""}
end.
+method_type(Method) ->
+ case Method of
+ get -> read;
+ head -> read;
+ options -> read;
+ trace -> read;
+ post -> write;
+ put -> write;
+ delete -> write;
+ patch -> write
+ end.
+
+%%-------------------------------------------------------------------------
+
+invalid_body(Config) ->
+ URL = url(group_name(Config), "/dummy.html", Config),
+ {error, invalid_request} =
+ httpc:request(post, {URL, [], <<"text/plain">>, "foobar"},
+ [], []).
+
+invalid_body_fun(Config) ->
+ URL = url(group_name(Config), "/dummy.html", Config),
+ BodyFun = fun() -> body_part end,
+ {error, {bad_body_generator, _}} =
+ httpc:request(post, {URL, [], "text/plain", {BodyFun, init}},
+ [], []).
+
+
+invalid_method(Config) ->
+ URL = url(group_name(Config), "/dummy.html", Config),
+ {error, invalid_method} =
+ httpc:request(past, {URL, [], <<"text/plain">>, "foobar"},
+ [], []).
+
%%-------------------------------------------------------------------------
binary_url(Config) ->
@@ -1948,7 +2058,7 @@ setup_server_dirs(ServerRoot, DocRoot, DataDir) ->
"cgi_echo"
end,
- inets_test_lib:copy_file(Cgi, DataDir, CgiDir),
+ {ok, _} = inets_test_lib:copy_file(Cgi, DataDir, CgiDir),
AbsCgi = filename:join([CgiDir, Cgi]),
{ok, FileInfo} = file:read_file_info(AbsCgi),
ok = file:write_file_info(AbsCgi, FileInfo#file_info{mode = 8#00755}).