diff options
author | Loïc Hoguin <[email protected]> | 2018-11-04 11:51:35 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-11-04 11:58:59 +0100 |
commit | 8c9ad7bf078871295e391f416bfcb10c9156a35f (patch) | |
tree | f92cf4f4ff6f978405cf8171e86b44de27f91265 /test/handlers | |
parent | bf7ccc8623610d34cf3323db776b280a50275678 (diff) | |
download | cowboy-8c9ad7bf078871295e391f416bfcb10c9156a35f.tar.gz cowboy-8c9ad7bf078871295e391f416bfcb10c9156a35f.tar.bz2 cowboy-8c9ad7bf078871295e391f416bfcb10c9156a35f.zip |
Add the rate_limited/2 REST callback
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/rate_limited_h.erl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/handlers/rate_limited_h.erl b/test/handlers/rate_limited_h.erl new file mode 100644 index 0000000..e54249c --- /dev/null +++ b/test/handlers/rate_limited_h.erl @@ -0,0 +1,24 @@ +%% This module does rate limiting based on the query string value. + +-module(rate_limited_h). + +-export([init/2]). +-export([rate_limited/2]). +-export([content_types_provided/2]). +-export([get_text_plain/2]). + +init(Req, State) -> + {cowboy_rest, Req, State}. + +rate_limited(Req=#{qs := <<"false">>}, State) -> + {false, Req, State}; +rate_limited(Req=#{qs := <<"true-date">>}, State) -> + {{true, {{2222, 2, 22}, {11, 11, 11}}}, Req, State}; +rate_limited(Req=#{qs := <<"true">>}, State) -> + {{true, 3600}, Req, State}. + +content_types_provided(Req, State) -> + {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. + +get_text_plain(Req, State) -> + {<<"This is REST!">>, Req, State}. |