-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require direct pass to get backend IP and port
- Loading branch information
Showing
5 changed files
with
128 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::wiggle_abi::types::CacheOverrideTag; | ||
use http::HeaderValue; | ||
|
||
/// Optional override for response caching behavior. | ||
#[derive(Clone, Debug, Default)] | ||
pub enum CacheOverride { | ||
/// Do not override the behavior specified in the origin response's cache control headers. | ||
#[default] | ||
None, | ||
/// Do not cache the response to this request, regardless of the origin response's headers. | ||
Pass, | ||
/// Override particular cache control settings. | ||
/// | ||
/// The origin response's cache control headers will be used for ttl and stale_while_revalidate if `None`. | ||
Override { | ||
ttl: Option<u32>, | ||
stale_while_revalidate: Option<u32>, | ||
pci: bool, | ||
surrogate_key: Option<HeaderValue>, | ||
}, | ||
} | ||
|
||
impl CacheOverride { | ||
pub fn is_pass(&self) -> bool { | ||
if let Self::Pass = self { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
/// Convert from the representation suitable for passing across the ABI boundary. | ||
/// | ||
/// Returns `None` if the tag is not recognized. Depending on the tag, some of the values may be | ||
/// ignored. | ||
pub fn from_abi( | ||
tag: u32, | ||
ttl: u32, | ||
swr: u32, | ||
surrogate_key: Option<HeaderValue>, | ||
) -> Option<Self> { | ||
CacheOverrideTag::from_bits(tag).map(|tag| { | ||
if tag.contains(CacheOverrideTag::PASS) { | ||
return CacheOverride::Pass; | ||
} | ||
if tag.is_empty() && surrogate_key.is_none() { | ||
return CacheOverride::None; | ||
} | ||
let ttl = if tag.contains(CacheOverrideTag::TTL) { | ||
Some(ttl) | ||
} else { | ||
None | ||
}; | ||
let stale_while_revalidate = if tag.contains(CacheOverrideTag::STALE_WHILE_REVALIDATE) { | ||
Some(swr) | ||
} else { | ||
None | ||
}; | ||
let pci = tag.contains(CacheOverrideTag::PCI); | ||
CacheOverride::Override { | ||
ttl, | ||
stale_while_revalidate, | ||
pci, | ||
surrogate_key, | ||
} | ||
}) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
pub mod adapt; | ||
pub mod body; | ||
pub mod cache; | ||
pub mod config; | ||
pub mod error; | ||
pub mod logging; | ||
|
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
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
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