0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Add cowboy_req:read_and_match_urlencoded_body/2,3

This commit is contained in:
Loïc Hoguin 2018-09-07 13:56:12 +02:00
parent dcc6f9326f
commit 4b385749f2
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
9 changed files with 218 additions and 2 deletions

View file

@ -54,7 +54,8 @@
-export([read_body/2]).
-export([read_urlencoded_body/1]).
-export([read_urlencoded_body/2]).
%% @todo read_and_match_urlencoded_body?
-export([read_and_match_urlencoded_body/2]).
-export([read_and_match_urlencoded_body/3]).
%% Multipart.
-export([read_part/1]).
@ -513,6 +514,23 @@ read_urlencoded_body(Req0, Opts) ->
end
end.
-spec read_and_match_urlencoded_body(cowboy:fields(), Req)
-> {ok, map(), Req} when Req::req().
read_and_match_urlencoded_body(Fields, Req) ->
read_and_match_urlencoded_body(Fields, Req, #{length => 64000, period => 5000}).
-spec read_and_match_urlencoded_body(cowboy:fields(), Req, read_body_opts())
-> {ok, map(), Req} when Req::req().
read_and_match_urlencoded_body(Fields, Req0, Opts) ->
{ok, Qs, Req} = read_urlencoded_body(Req0, Opts),
case filter(Fields, kvlist_to_map(Fields, Qs)) of
{ok, Map} ->
{ok, Map, Req};
{error, Errors} ->
exit({request_error, {read_and_match_urlencoded_body, Errors},
'Urlencoded request body validation constraints failed for the reasons provided.'})
end.
%% Multipart.
-spec read_part(Req)