I'm trying to block all access using Basic HTTP Authentication, but wish to avoid accidentally forgetting any routes.
I thought that perhaps it could be implemented through a Fairing
, but I cannot see how that would work given that "Fairings cannot respond to an incoming request directly."
I saw that I can get an Outcome
from a request guard, but I do not see how it could be used.
#[rocket::async_trait]
impl Fairing for TheFairing {
fn info(&self) -> Info {
Info {
name: "TheFairing",
kind: Kind::Request | Kind::Response,
}
}
async fn on_request(&self, request: &mut Request<'_>, _: &mut Data<'_>) {
let outcome = request.guard::<BasicAuthentication>().await;
}
}
I also know that it's possible to block data by modifying the response in on_response
with something like response.set_status(Status::Unauthorized)
but this still generates a response, requires erasing its content and more generally, seems like it would cause unintended consequences.
I am using v0.5-rc
.