Skip to content

Commit

Permalink
Don't compute checksum if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Apr 16, 2024
1 parent b6bab19 commit 7f482d8
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions object_store/src/aws/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,27 +337,25 @@ impl<'a> Request<'a> {
Self { builder, ..self }
}

pub fn with_payload(self, payload: PutPayload) -> Self {
let mut builder = self.builder;

let mut sha256 = Context::new(&digest::SHA256);
payload.iter().for_each(|x| sha256.update(x));
let payload_sha256 = sha256.finish();

if let Some(Checksum::SHA256) = self.config.checksum {
builder = builder.header(
"x-amz-checksum-sha256",
BASE64_STANDARD.encode(payload_sha256),
);
pub fn with_payload(mut self, payload: PutPayload) -> Self {
if !self.config.skip_signature || self.config.checksum.is_some() {
let mut sha256 = Context::new(&digest::SHA256);
payload.iter().for_each(|x| sha256.update(x));
let payload_sha256 = sha256.finish();

if let Some(Checksum::SHA256) = self.config.checksum {
self.builder = self.builder.header(
"x-amz-checksum-sha256",
BASE64_STANDARD.encode(payload_sha256),
);
}
self.payload_sha256 = Some(payload_sha256);
}
builder = builder.header(CONTENT_LENGTH, payload.content_length());

Self {
builder,
payload: Some(payload),
payload_sha256: Some(payload_sha256),
..self
}
let content_length = payload.content_length();
self.builder = self.builder.header(CONTENT_LENGTH, content_length);
self.payload = Some(payload);
self
}

pub async fn send(self) -> Result<Response, RequestError> {
Expand Down

0 comments on commit 7f482d8

Please sign in to comment.