Skip to content

Commit

Permalink
Fix rps
Browse files Browse the repository at this point in the history
  • Loading branch information
fulltimemike committed Sep 24, 2024
1 parent 2349f3e commit 25f7a76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions node/rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,21 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {

// Prepare the rate limiting setup.
let governor_config = Box::new(
GovernorConfigBuilder::default()
.per_second(1)
.burst_size(rest_rps)
.error_handler(|error| Response::new(error.to_string().into()))
.finish()
.expect("Couldn't set up rate limiting for the REST server!"),
GovernorConfigBuilder::default()
.per_nanosecond((1_000_000_000 / rest_rps) as u64)
.burst_size(rest_rps)
.error_handler(|error| {
// Properly return a 429 Too Many Requests error
let error_message = error.to_string();
let mut response = Response::new(error_message.clone().into());
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
if error_message.contains("Too Many Requests") {
*response.status_mut() = StatusCode::TOO_MANY_REQUESTS;
}
response
})
.finish()
.expect("Couldn't set up rate limiting for the REST server!"),
);

// Get the network being used.
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.76.0
1.81.0

0 comments on commit 25f7a76

Please sign in to comment.