systemprompt_extension/
frame_options.rs1use axum::extract::Request;
15use axum::middleware::Next;
16use axum::response::Response;
17use serde::{Deserialize, Serialize};
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
20pub enum FrameOptions {
21 #[serde(rename = "DENY")]
22 Deny,
23 #[serde(rename = "SAMEORIGIN")]
24 SameOrigin,
25 #[serde(rename = "ALLOWALL")]
26 AllowAll,
27}
28
29impl FrameOptions {
30 #[must_use]
31 pub const fn header_value(self) -> Option<&'static str> {
32 match self {
33 Self::Deny => Some("DENY"),
34 Self::SameOrigin => Some("SAMEORIGIN"),
35 Self::AllowAll => None,
36 }
37 }
38
39 #[must_use]
40 pub const fn frame_ancestors(self) -> &'static str {
41 match self {
42 Self::Deny => "'none'",
43 Self::SameOrigin => "'self'",
44 Self::AllowAll => "*",
45 }
46 }
47}
48
49#[derive(Debug, Clone, Copy)]
51pub struct FrameOptionsOverride(pub FrameOptions);
52
53pub async fn stamp_frame_options(
54 frame_options: FrameOptions,
55 request: Request,
56 next: Next,
57) -> Response {
58 let mut response = next.run(request).await;
59 response
60 .extensions_mut()
61 .insert(FrameOptionsOverride(frame_options));
62 response
63}