Skip to content

Commit

Permalink
fix(middleware-sdk-s3): remove error name check to allow for region r…
Browse files Browse the repository at this point in the history
…edirect for HEAD operations (#5425)
  • Loading branch information
siddsriv authored Oct 31, 2023
1 parent f9841f0 commit eed5dcc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("S3 Global Client Test", () => {
bucketNames = regionConfigs.map((config) => `${callerID.Account}-${randId}-redirect-${config.region}`);
await Promise.all(bucketNames.map((bucketName, index) => deleteBucket(s3Clients[index], bucketName)));
await Promise.all(bucketNames.map((bucketName, index) => s3Clients[index].createBucket({ Bucket: bucketName })));
await Promise.all(bucketNames.map((bucketName, index) => s3Clients[index].headBucket({ Bucket: bucketName })));
});

afterAll(async () => {
Expand All @@ -48,6 +49,7 @@ describe("S3 Global Client Test", () => {
for (const bucketName of bucketNames) {
for (const s3Client of s3Clients) {
const objKey = `object-from-${await s3Client.config.region()}-client`;
await s3Client.headObject({ Bucket: bucketName, Key: objKey });
const { Body } = await s3Client.getObject({ Bucket: bucketName, Key: objKey });
const data = await Body?.transformToString();
expect(data).toEqual(testValue);
Expand Down
3 changes: 1 addition & 2 deletions packages/middleware-sdk-s3/src/region-redirect-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ export function regionRedirectMiddleware(clientConfig: PreviouslyResolved): Init
try {
return await next(args);
} catch (err) {
// console.log("Region Redirect", clientConfig.followRegionRedirects, err.name, err.$metadata.httpStatusCode);
if (
clientConfig.followRegionRedirects &&
err.name === "PermanentRedirect" &&
// err.name === "PermanentRedirect" && --> removing the error name check, as that allows for HEAD operations (which have the 301 status code, but not the same error name) to be covered for region redirection as well
err.$metadata.httpStatusCode === 301
) {
try {
Expand Down

0 comments on commit eed5dcc

Please sign in to comment.