Created
March 24, 2023 18:12
-
-
Save deadbaed/7df747a71cd357fcc86d81ef2c751bd8 to your computer and use it in GitHub Desktop.
fairing example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct MyFairing {} | |
#[rocket::async_trait] | |
impl Fairing for MyFairing { | |
fn info(&self) -> fairing::Info { | |
fairing::Info { | |
name: "MyFairing", | |
kind: Kind::Request | Kind::Response, | |
} | |
} | |
async fn on_request(&self, request: &mut Request<'_>, _: &mut rocket::Data<'_>) { | |
println!("MyFairing: on_request"); | |
} | |
async fn on_response<'r>(&self, request: &'r Request<'_>, response: &mut rocket::Response<'r>) { | |
println!("MyFairing: on_response"); | |
response.set_header(Header::new("MyHeader", format!("MyContent"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment