Skip to content

Commit

Permalink
neater
Browse files Browse the repository at this point in the history
  • Loading branch information
shikhar committed Nov 20, 2024
1 parent 28e1da5 commit 99208b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,9 @@ impl ClientInner {

async fn send<T: ServiceRequest>(&self, service_req: T) -> Result<T::Response, ClientError> {
let basin_header = match (&self.kind, &self.config.endpoints.basin) {
(ClientKind::Basin(basin), BasinEndpoint::CellKnown(_)) => Some((
AsciiMetadataKey::from_static("S2-Basin"),
AsciiMetadataValue::from_str(&basin).expect("valid"),
)),
(ClientKind::Basin(basin), BasinEndpoint::CellKnown(_)) => {
Some((AsciiMetadataValue::from_str(&basin).expect("valid"),))
}
_ => None,
};
send_request(service_req, &self.config.token, basin_header).await
Expand Down
9 changes: 5 additions & 4 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{client::ClientError, types};
pub async fn send_request<T: ServiceRequest>(
mut service: T,
token: &SecretString,
basin_header: Option<(AsciiMetadataKey, AsciiMetadataValue)>,
basin_header: Option<AsciiMetadataValue>,
) -> Result<T::Response, ClientError> {
let req = prepare_request(&mut service, token, basin_header)?;
match service.send(req).await {
Expand All @@ -29,12 +29,13 @@ pub async fn send_request<T: ServiceRequest>(
fn prepare_request<T: ServiceRequest>(
service: &mut T,
token: &SecretString,
basin_header: Option<(AsciiMetadataKey, AsciiMetadataValue)>,
basin_header: Option<AsciiMetadataValue>,
) -> Result<tonic::Request<T::ApiRequest>, types::ConvertError> {
let mut req = service.prepare_request()?;
add_authorization_header(req.metadata_mut(), token)?;
if let Some((key, value)) = basin_header {
req.metadata_mut().insert(key, value);
if let Some(basin) = basin_header {
req.metadata_mut()
.insert(AsciiMetadataKey::from_static("s2-basin"), basin);
}
Ok(req)
}
Expand Down

0 comments on commit 99208b9

Please sign in to comment.