pub struct AppState {
pub client: SearchClient,
pub started: Instant,
pub api_key: Option<String>,
pub max_results_limit: usize,
pub rate_limit_per_minute: u32,
pub max_body_bytes: u64,
pub trusted_proxies: Vec<IpAddr>,
/* private fields */
}Fields§
§client: SearchClient§started: Instant§api_key: Option<String>§max_results_limit: usizeUpper bound applied to max_results (from search.max_results_limit).
rate_limit_per_minute: u32Requests allowed per window per client; 0 disables the limiter.
max_body_bytes: u64Maximum accepted request body size in bytes.
trusted_proxies: Vec<IpAddr>Reverse-proxy IPs whose X-Forwarded-For header is trusted for
client IP extraction (see [client_ip]).
Implementations§
Source§impl AppState
impl AppState
pub fn new( client: SearchClient, api_key: Option<String>, max_results_limit: usize, rate_limit_per_minute: u32, max_body_bytes: u64, trusted_proxies: Vec<IpAddr>, ) -> Self
Constant-time API-key comparison: a configured key is only ever compared with XOR folds of equal-length byte buffers, never with early-exit string equality, so timing cannot leak key prefixes.
Sourcepub fn check_rate(&self, ip: Option<IpAddr>) -> bool
pub fn check_rate(&self, ip: Option<IpAddr>) -> bool
Fixed-window rate limit keyed on the client IP (falling back to a
single global bucket when the client address is unknown, e.g. in
unit tests). Returns true when the request is allowed.
Auto Trait Implementations§
impl !Freeze for AppState
impl !RefUnwindSafe for AppState
impl !UnwindSafe for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more