-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add
new_momento_cli
to use in Momento CLI and add agent
me…
…tadata for SDK (#39)
- Loading branch information
1 parent
97c379d
commit fa6fe5b
Showing
5 changed files
with
120 additions
and
56 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
use std::collections::HashMap; | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
||
const AUTHORIZATION: &str = "authorization"; | ||
const AGENT: &str = "agent"; | ||
|
||
#[derive(Clone)] | ||
pub struct HeaderInterceptor { | ||
pub header: HashMap<String, String>, | ||
} | ||
|
||
impl tonic::service::Interceptor for HeaderInterceptor { | ||
fn call( | ||
&mut self, | ||
mut request: tonic::Request<()>, | ||
) -> Result<tonic::Request<()>, tonic::Status> { | ||
static ARE_ONLY_ONCE_HEADER_SENT: AtomicBool = AtomicBool::new(false); | ||
for (key, value) in self.header.iter() { | ||
if *key == *AUTHORIZATION { | ||
request.metadata_mut().insert( | ||
tonic::metadata::AsciiMetadataKey::from_static(AUTHORIZATION), | ||
tonic::metadata::AsciiMetadataValue::from_str(value).unwrap(), | ||
); | ||
} | ||
if !ARE_ONLY_ONCE_HEADER_SENT.load(Ordering::Relaxed) && *key == *AGENT { | ||
request.metadata_mut().insert( | ||
tonic::metadata::AsciiMetadataKey::from_static(AGENT), | ||
tonic::metadata::AsciiMetadataValue::from_str(value).unwrap(), | ||
); | ||
ARE_ONLY_ONCE_HEADER_SENT.store(true, Ordering::Relaxed); | ||
} | ||
} | ||
Ok(request) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
pub mod auth_header_interceptor; | ||
pub mod cache_header_interceptor; | ||
pub mod header_interceptor; |
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