aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.59k stars 1.55k forks source link

fix: add string fallback for S3#Expires field when not a date-time #4577

Closed kuhe closed 8 months ago

kuhe commented 8 months ago

See https://github.com/aws/aws-sdk-js-v3/pull/5715.

Adds an S3-only model transform that adds an additional field ExpiresString: string where any operation output has Expires: Date as an output member. This field will contain the raw value from Expires response header in all cases.

If Expires response header is not a date format, this will no longer throw an exception. Users can access the ExpiresString field as a fallback, and Expires will be set to undefined in that case.

Checklist
kuhe commented 8 months ago

testing:

// in v2/workspace/s3 folder
import S3 from "../../clients/s3";

var s3 = new S3({
  region: 'us-west-2'
});

(async () => {
  // both Expires and ExpiresString will be set on the returned object.
  const get = await s3.getObject({
    Bucket: "...",
    Key: "goodexpires",
  }).promise();

  console.log("expires and expiresString", get.Expires, get.ExpiresString);

  // this emits a warning, but does not throw. Expires becomes undefined and only ExpiresString is set.
  const get2 = await s3.headObject({
    Bucket: "...",
    Key: "badexpires",
  }).promise();

  console.log("expires and expiresString", get2.Expires, get2.ExpiresString);
})();