| 1 |
%% This module does rate limiting based on the query string value. |
| 2 |
|
| 3 |
-module(rate_limited_h). |
| 4 |
|
| 5 |
-export([init/2]). |
| 6 |
-export([rate_limited/2]). |
| 7 |
-export([content_types_provided/2]). |
| 8 |
-export([get_text_plain/2]). |
| 9 |
|
| 10 |
init(Req, State) -> |
| 11 |
{cowboy_rest, Req, State}. |
| 12 |
|
| 13 |
rate_limited(Req=#{qs := <<"false">>}, State) -> |
| 14 |
{false, Req, State}; |
| 15 |
rate_limited(Req=#{qs := <<"true-date">>}, State) -> |
| 16 |
{{true, {{2222, 2, 22}, {11, 11, 11}}}, Req, State}; |
| 17 |
rate_limited(Req=#{qs := <<"true">>}, State) -> |
| 18 |
{{true, 3600}, Req, State}. |
| 19 |
|
| 20 |
content_types_provided(Req, State) -> |
| 21 |
{[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. |
| 22 |
|
| 23 |
get_text_plain(Req, State) -> |
| 24 |
{<<"This is REST!">>, Req, State}. |