mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 04:10:24 +00:00
Detect invalid content_types_provided return values earlier
Before this change invalid return values would be detected via unhelpful error messages such as [1] and the closing of the connection. [1] Bad value on output port 'tcp_inet'
This commit is contained in:
parent
fbd680f0f6
commit
72b57a846d
3 changed files with 25 additions and 4 deletions
|
@ -11,9 +11,14 @@
|
|||
init(Req, Opts) ->
|
||||
{cowboy_rest, Req, Opts}.
|
||||
|
||||
content_types_provided(Req=#{qs := <<"invalid-type">>}, State) ->
|
||||
ct_helper:ignore(cowboy_rest, normalize_content_types, 2),
|
||||
{[{{'*', '*', '*'}, get_text_plain}], Req, State};
|
||||
content_types_provided(Req=#{qs := <<"wildcard-param">>}, State) ->
|
||||
{[{{<<"text">>, <<"plain">>, '*'}, get_text_plain}], Req, State}.
|
||||
|
||||
get_text_plain(Req=#{qs := <<"invalid-type">>}, State) ->
|
||||
{<<"invalid-type">>, Req, State};
|
||||
get_text_plain(Req=#{qs := <<"wildcard-param">>}, State) ->
|
||||
{_, _, Param} = maps:get(media_type, Req),
|
||||
Body = if
|
||||
|
|
|
@ -404,6 +404,18 @@ content_types_accepted_wildcard_param_content_type_with_param(Config) ->
|
|||
{response, fin, 204, _} = gun:await(ConnPid, Ref),
|
||||
ok.
|
||||
|
||||
content_types_provided_invalid_type(Config) ->
|
||||
doc("When an invalid type is returned from the "
|
||||
"content_types_provided callback, the "
|
||||
"resource is incorrect and a 500 response is expected."),
|
||||
ConnPid = gun_open(Config),
|
||||
Ref = gun:get(ConnPid, "/content_types_provided?invalid-type", [
|
||||
{<<"accept">>, <<"*/*">>},
|
||||
{<<"accept-encoding">>, <<"gzip">>}
|
||||
]),
|
||||
{response, _, 500, _} = do_maybe_h3_error(gun:await(ConnPid, Ref)),
|
||||
ok.
|
||||
|
||||
content_types_provided_wildcard_param_no_accept_param(Config) ->
|
||||
doc("When a wildcard is returned for parameters from the "
|
||||
"content_types_provided callback, an accept header "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue