Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(middleware-flexible-checksums): skip checksum computation if provided #6745

Merged
merged 1 commit into from
Dec 17, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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