mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
rest: reject incorrect content-type header
This commit is contained in:
parent
fa31c82595
commit
180143f9b2
2 changed files with 17 additions and 3 deletions
|
@ -776,9 +776,12 @@ accept_resource(Req, State, OnTrue) ->
|
||||||
{CTA, Req2, HandlerState} ->
|
{CTA, Req2, HandlerState} ->
|
||||||
CTA2 = [normalize_content_types(P) || P <- CTA],
|
CTA2 = [normalize_content_types(P) || P <- CTA],
|
||||||
State2 = State#state{handler_state=HandlerState},
|
State2 = State#state{handler_state=HandlerState},
|
||||||
{ok, ContentType, Req3}
|
case cowboy_req:parse_header(<<"content-type">>, Req2) of
|
||||||
= cowboy_req:parse_header(<<"content-type">>, Req2),
|
{ok, ContentType, Req3} ->
|
||||||
choose_content_type(Req3, State2, OnTrue, ContentType, CTA2)
|
choose_content_type(Req3, State2, OnTrue, ContentType, CTA2);
|
||||||
|
{error, badarg} ->
|
||||||
|
respond(Req2, State2, 415)
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% The special content type '*' will always match. It can be used as a
|
%% The special content type '*' will always match. It can be used as a
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
-export([pipeline/1]).
|
-export([pipeline/1]).
|
||||||
-export([pipeline_long_polling/1]).
|
-export([pipeline_long_polling/1]).
|
||||||
-export([rest_bad_accept/1]).
|
-export([rest_bad_accept/1]).
|
||||||
|
-export([rest_bad_content_type/1]).
|
||||||
-export([rest_expires/1]).
|
-export([rest_expires/1]).
|
||||||
-export([rest_keepalive/1]).
|
-export([rest_keepalive/1]).
|
||||||
-export([rest_keepalive_post/1]).
|
-export([rest_keepalive_post/1]).
|
||||||
|
@ -123,6 +124,7 @@ groups() ->
|
||||||
pipeline,
|
pipeline,
|
||||||
pipeline_long_polling,
|
pipeline_long_polling,
|
||||||
rest_bad_accept,
|
rest_bad_accept,
|
||||||
|
rest_bad_content_type,
|
||||||
rest_expires,
|
rest_expires,
|
||||||
rest_keepalive,
|
rest_keepalive,
|
||||||
rest_keepalive_post,
|
rest_keepalive_post,
|
||||||
|
@ -355,6 +357,7 @@ init_dispatch(Config) ->
|
||||||
{"/echo/body_qs", http_handler_body_qs, []},
|
{"/echo/body_qs", http_handler_body_qs, []},
|
||||||
{"/param_all", rest_param_all, []},
|
{"/param_all", rest_param_all, []},
|
||||||
{"/bad_accept", rest_simple_resource, []},
|
{"/bad_accept", rest_simple_resource, []},
|
||||||
|
{"/bad_content_type", rest_patch_resource, []},
|
||||||
{"/simple", rest_simple_resource, []},
|
{"/simple", rest_simple_resource, []},
|
||||||
{"/forbidden_post", rest_forbidden_resource, [true]},
|
{"/forbidden_post", rest_forbidden_resource, [true]},
|
||||||
{"/simple_post", rest_forbidden_resource, [false]},
|
{"/simple_post", rest_forbidden_resource, [false]},
|
||||||
|
@ -879,6 +882,14 @@ rest_bad_accept(Config) ->
|
||||||
Client),
|
Client),
|
||||||
{ok, 400, _, _} = cowboy_client:response(Client2).
|
{ok, 400, _, _} = cowboy_client:response(Client2).
|
||||||
|
|
||||||
|
rest_bad_content_type(Config) ->
|
||||||
|
Client = ?config(client, Config),
|
||||||
|
{ok, Client2} = cowboy_client:request(<<"PATCH">>,
|
||||||
|
build_url("/bad_content_type", Config),
|
||||||
|
[{<<"content-type">>, <<"text/plain, text/html">>}],
|
||||||
|
<<"Whatever">>, Client),
|
||||||
|
{ok, 415, _, _} = cowboy_client:response(Client2).
|
||||||
|
|
||||||
rest_expires(Config) ->
|
rest_expires(Config) ->
|
||||||
Client = ?config(client, Config),
|
Client = ?config(client, Config),
|
||||||
{ok, Client2} = cowboy_client:request(<<"GET">>,
|
{ok, Client2} = cowboy_client:request(<<"GET">>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue