Browse Source

Add an additional test to the static test suite

Loïc Hoguin 6 years ago
parent
commit
ae96aa6e49
2 changed files with 7 additions and 1 deletions
  1. 1 1
      src/cowboy_static.erl
  2. 6 0
      test/static_handler_SUITE.erl

+ 1 - 1
src/cowboy_static.erl

@@ -340,7 +340,7 @@ charsets_provided(Req, State={Path, _, Extra}) ->
 			no_call;
 			no_call;
 		{charset, Module, Function} ->
 		{charset, Module, Function} ->
 			{[Module:Function(Path)], Req, State};
 			{[Module:Function(Path)], Req, State};
-		{charset, Charset} ->
+		{charset, Charset} when is_binary(Charset) ->
 			{[Charset], Req, State}
 			{[Charset], Req, State}
 	end.
 	end.
 
 

+ 6 - 0
test/static_handler_SUITE.erl

@@ -195,6 +195,7 @@ execute(Req=#{path := Path}, Env) ->
 		<<"/bad/options">> -> ct_helper:ignore(cowboy_static, content_types_provided, 2);
 		<<"/bad/options">> -> ct_helper:ignore(cowboy_static, content_types_provided, 2);
 		<<"/bad/options/mime">> -> ct_helper:ignore(cowboy_rest, set_content_type, 2);
 		<<"/bad/options/mime">> -> ct_helper:ignore(cowboy_rest, set_content_type, 2);
 		<<"/bad/options/etag">> -> ct_helper:ignore(cowboy_static, generate_etag, 2);
 		<<"/bad/options/etag">> -> ct_helper:ignore(cowboy_static, generate_etag, 2);
+		<<"/bad/options/charset">> -> ct_helper:ignore(cowboy_static, charsets_provided, 2);
 		_ -> ok
 		_ -> ok
 	end,
 	end,
 	{ok, Req, Env}.
 	{ok, Req, Env}.
@@ -279,6 +280,11 @@ bad_options(Config) ->
 	{500, _, _} = do_get("/bad/options", Config),
 	{500, _, _} = do_get("/bad/options", Config),
 	ok.
 	ok.
 
 
+bad_options_charset(Config) ->
+	doc("Bad cowboy_static extra options: invalid charset option."),
+	{500, _, _} = do_get("/bad/options/charset", Config),
+	ok.
+
 bad_options_etag(Config) ->
 bad_options_etag(Config) ->
 	doc("Bad cowboy_static extra options: invalid etag option."),
 	doc("Bad cowboy_static extra options: invalid etag option."),
 	{500, _, _} = do_get("/bad/options/etag", Config),
 	{500, _, _} = do_get("/bad/options/etag", Config),