Fastly Compute C++ SDK
Loading...
Searching...
No Matches
erl.cpp
#include "fastly/sdk.h"
// Note that this example will return "Welcome!" unconditionally on Viceroy; to
// see the expected behavior, you need to run it on a Compute service.
int main() {
auto client = req.get_client_ip_addr().value();
fastly::erl::RateCounter rate_counter("mycounter");
fastly::erl::PenaltyBox penalty_box("mypenaltybox");
auto erl = fastly::erl::ERL(rate_counter, penalty_box);
auto check_result = erl.check_rate(
client, // Use the client IP address as the entry to check in the rate
// counter
1, // How many requests to count this as
fastly::erl::RateWindow::SixtySecs, // The window to check the rate over
5, // The maximum allowed rate for the client over the window
std::chrono::minutes(
1)); // The duration to penalize the client if they exceed the rate
if (check_result.has_value() && *check_result) {
} else {
std::string message = "Welcome! Your current rate is ";
message += std::to_string(
.value());
}
}
int main()
Definition async_reqs.cpp:10
static Request from_client()
static Response from_body(Body body)
Create a new Response with the given value as the body.
Definition erl.h:78
Definition erl.h:25
Definition erl.h:60
tl::expected< std::uint32_t, ERLError > lookup_rate(std::string_view entry, RateWindow window) const
Lookup the current rate for entry in the rate counter for a window.
@ SixtySecs
Definition erl.h:55