extend/cowboy — pull request #294 by betawaffle (2012-10-21 20:39:58+00:00)
Title: Add a step to cowboy_rest to support HTTP 429.

See [rfc6585] for an explaination of status code 429.

The callback for that example might look something like this:

```erlang
-define(RATE_LIMIT_MSG,
"I only allow 50 requests per hour "
"to this Web site per logged in user. "
"Try again soon.").

rate_limited(Req, State) ->
if
user_requests(Req, 3600) > 50 ->
Body = error_html(<<"Too Many Requests">>,
<>),
{ok, Req2} = cowboy:set_resp_body(Body, Req),
{{true, 3600}, Req2, State};
true ->
{false, Req, State}
end.

error_html(Title, Message) ->
<<""
"

"
"

", Title/binary, "

"
"

"
"

"
"

", Title/binary, "

"
"

", Message/binary, "

"
"

"
"">>.
```

Bring on the feedback!

[rfc6585]: http://tools.ietf.org/html/rfc6585#section-4