Skip to content

Commit

Permalink
feat: add bearer token to header requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdockerty committed Aug 7, 2024
1 parent 5278aaf commit 9e1badf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/src/services/gcs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::time::Duration;
use backon::ExponentialBuilder;
use backon::Retryable;
use bytes::Bytes;
use http::header;
use http::header::CONTENT_LENGTH;
use http::header::CONTENT_TYPE;
use http::header::HOST;
Expand Down Expand Up @@ -53,6 +54,7 @@ pub struct GcsCore {
pub client: HttpClient,
pub signer: GoogleSigner,
pub token_loader: GoogleTokenLoader,
pub token: String,
pub credential_loader: GoogleCredentialLoader,

pub predefined_acl: Option<String>,
Expand Down Expand Up @@ -117,6 +119,12 @@ impl GcsCore {
}
let cred = self.load_token().await?;

if !self.token.is_empty() {
let header_value = format!("Bearer {}", self.token);
req.headers_mut()
.insert(header::AUTHORIZATION, header_value.parse().unwrap());
}

self.signer
.sign(req, &cred)
.map_err(new_request_sign_error)?;
Expand All @@ -141,6 +149,12 @@ impl GcsCore {
return Ok(());
}

if !self.token.is_empty() {
let header_value = format!("Bearer {}", self.token);
req.headers_mut()
.insert(header::AUTHORIZATION, header_value.parse().unwrap());
}

// Always remove host header, let users' client to set it based on HTTP
// version.
//
Expand Down

0 comments on commit 9e1badf

Please sign in to comment.