pub trait Checkpoint:
Send
+ Sync
+ 'static {
// Required method
fn check(&self, env: &Envelope, at: Stage) -> Verdict;
}Expand description
Revocation in flight: a ban, a revoked session, or a lockdown that arrives while a request is being handled. serve-net’s own checkpoint covers admission and the moment before the reply leaves; this one covers the points in between that only web-net knows.
A checkpoint backed by remote state fails closed (denies) when the remote cannot be reached.
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use serve_net::testing::respond;
use serve_net::{Envelope, Verdict};
use web_net::{App, Checkpoint, Stage, get};
#[derive(Default)]
struct Lockdown(AtomicBool);
impl Checkpoint for Lockdown {
fn check(&self, _: &Envelope, _: Stage) -> Verdict {
if self.0.load(Ordering::Relaxed) { Verdict::Deny { status: 503 } } else { Verdict::Pass }
}
}
let lockdown = Arc::new(Lockdown::default());
let app = App::builder().checkpoint(Arc::clone(&lockdown)).route(get("/", |cx| cx.text(200, "hi"))).build()?;
let req = b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n";
assert_eq!(respond(&app, req).status, 200);
lockdown.0.store(true, Ordering::Relaxed);
assert_eq!(respond(&app, req).status, 503);Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T: Checkpoint + ?Sized> Checkpoint for Arc<T>
A checkpoint shared with the code that revokes.
impl<T: Checkpoint + ?Sized> Checkpoint for Arc<T>
A checkpoint shared with the code that revokes.