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

chore(middleware-flexible-checksums): use RequestChecksumCalculation and ResponseChecksumValidation without interceptor middleware #6484

Closed
wants to merge 9 commits into from

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Sep 17, 2024

Issue

Internal JS-5396

Description

Uses values in RequestChecksumCalculation and ResponseChecksumValidation to decide flexible checksums algorithm.
Also deprecates MD5, and sets CRC32 as default.

Testing

Unit testing

Also, verified that checksums are computed by default

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

class CustomHandler extends NodeHttpHandler {
  constructor() {
    super();
  }

  async handle(request, options) {
    for (const [header, value] of Object.entries(request.headers)) {
      if (header.startsWith("x-amz-checksum-")) {
        console.log(`request['${header}']: '${value}'`);
      }
    }
    const response = await super.handle(request, options);
    for (const [header, value] of Object.entries(response.response.headers)) {
      if (header.startsWith("x-amz-checksum-")) {
        console.log(`response['${header}']: '${value}'`);
      }
    }
    return response;
  }
}

// WHEN_SUPPORTED is default.
const client = new S3({
  requestHandler: new CustomHandler(),
});

console.log("Put Object");
await client.putObject({
  Bucket: "test-flexible-checksums-v2",
  Key: "hello-world.txt",
  Body: "Hello World",
});

console.log("\nGet Object");
await client.getObject({
  Bucket: "test-flexible-checksums-v2",
  Key: "hello-world.txt",
});

Output

Put Object
request['x-amz-checksum-crc32']: 'ShexVg=='
response['x-amz-checksum-crc32']: 'ShexVg=='

Get Object
request['x-amz-checksum-mode']: 'ENABLED'
request['x-amz-checksum-crc32']: 'AAAAAA=='
response['x-amz-checksum-crc32']: 'ShexVg=='

An integration test will be added in S3 as a follow-up.


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 September 17, 2024 15:34
@trivikr trivikr requested a review from a team as a code owner September 17, 2024 15:34
@trivikr trivikr marked this pull request as draft September 17, 2024 20:34
@trivikr trivikr marked this pull request as ready for review September 17, 2024 21:14
@trivikr
Copy link
Member Author

trivikr commented Sep 18, 2024

Converting to draft, since this solution consumes the steam during validation

import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";

// WHEN_SUPPORTED is default.
const client = new S3({
  // responseChecksumValidation: "WHEN_REQUIRED",
});

const { Body } = await client.getObject({
  Bucket: "test-flexible-checksums-v2",
  Key: "hello-world.txt",
  // ChecksumMode: "ENABLED",
});

// Prints nothing in current setup.
// Prints "Hello World" when responseChecksumValidation is "WHEN_REQUIRED"
// Prints nothing when responseChecksumValidation is "WHEN_REQUIRED" and ChecksumMode is "ENABLED"
console.log(await Body.transformToString());

An alternative is being tested in #6492

@trivikr trivikr changed the title chore(middleware-flexible-checksums): use RequestChecksumCalculation and ResponseChecksumValidation chore(middleware-flexible-checksums): use RequestChecksumCalculation and ResponseChecksumValidation without interceptor middleware Sep 18, 2024
@trivikr
Copy link
Member Author

trivikr commented Sep 18, 2024

Superceded by #6492

@trivikr trivikr closed this Sep 18, 2024
@trivikr trivikr deleted the middleware-flexchecks branch September 18, 2024 16:51
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.

2 participants