Skip to content

Conversation

@trivikr
Copy link
Member

@trivikr trivikr commented Dec 17, 2024

Issue

Fixes #6744

Description

Skips checksum computation if user provided one in the call

Testing

Test code for printing headers

import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { NodeHttpHandler } from "../aws-sdk-js-v3/node_modules/@smithy/node-http-handler/dist-cjs/index.js";

// Prints checksum headers for request and response.
class CustomHandler extends NodeHttpHandler {
  constructor() {
    super();
  }

  printChecksumHeaders(prefix, headers) {
    for (const [header, value] of Object.entries(headers)) {
      if (
        header.startsWith("x-amz-checksum-") ||
        header.startsWith("x-amz-sdk-checksum-")
      ) {
        console.log(`${prefix}['${header}']: '${value}'`);
      }
    }
  }

  async handle(request, options) {
    this.printChecksumHeaders("request", request.headers);
    const response = await super.handle(request, options);
    this.printChecksumHeaders("response", response.response.headers);
    return response;
  }
}

const client = new S3({ requestHandler: new CustomHandler() });

Passes user provided checksum value in header

const Bucket = "test-flexible-checksums"; // Replace with your test bucket name.
const Body = "Hello world";
const Key = "helloworld.txt";
const ChecksumCRC32 = "i9aeUg==";

await client.putObject({ Bucket, Key, Body, ChecksumCRC32 });
request['x-amz-checksum-crc32']: 'i9aeUg=='
response['x-amz-checksum-crc32']: 'i9aeUg=='
response['x-amz-checksum-type']: 'FULL_OBJECT'

Passes user provided checksum in header

const Bucket = "test-flexible-checksums"; // Replace with your test bucket name.
const Body = "Hello world";
const Key = "helloworld.txt";
const ChecksumAlgorithm = "CRC32";
const ChecksumCRC32 = "i9aeUg==";

await client.putObject({ Bucket, Key, Body, ChecksumAlgorithm, ChecksumCRC32 });
request['x-amz-sdk-checksum-algorithm']: 'CRC32'
request['x-amz-checksum-crc32']: 'i9aeUg=='
response['x-amz-checksum-crc32']: 'i9aeUg=='
response['x-amz-checksum-type']: 'FULL_OBJECT'

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr marked this pull request as ready for review December 17, 2024 16:30
@trivikr trivikr requested a review from a team as a code owner December 17, 2024 16:30
@trivikr trivikr merged commit e1678f8 into aws:main Dec 17, 2024
4 checks passed
@github-actions
Copy link

github-actions bot commented Jan 2, 2025

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK computes the checksum even if one is passed by application

2 participants