0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20: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:
Loïc Hoguin 2025-02-09 23:34:55 +01:00
parent fbd680f0f6
commit 72b57a846d
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
3 changed files with 25 additions and 4 deletions

View file

@ -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