-
Notifications
You must be signed in to change notification settings - Fork 634
fix(middleware-sdk-s3): handle cross-region redirects for HeadBucket with 400 status #7313
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
Conversation
if ( | ||
err?.$metadata?.httpStatusCode === 301 || | ||
// 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 === 400 && err?.name === "IllegalLocationConstraintException") | ||
(err?.$metadata?.httpStatusCode === 400 && err?.name === "IllegalLocationConstraintException") || | ||
(err?.$metadata?.httpStatusCode === 400 && | ||
context.commandName === "HeadBucketCommand" && | ||
err?.$response?.headers?.["x-amz-bucket-region"]) | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify this using variable names and combining the two 400 checks?
const statusCode = err?.$metadata?.httpStatusCode;
const isHeadBucket = context.commandName === "HeadBucketCommand";
const hasBucketRegionHeader = err?.$response?.headers?.["x-amz-bucket-region"];
if (
statusCode === 301 ||
(statusCode === 400 && (
err?.name === "IllegalLocationConstraintException" ||
(isHeadBucket && hasBucketRegionHeader)
))
)
(err?.name === "IllegalLocationConstraintException" || (isHeadBucket && hasBucketRegionHeader))) | ||
) { | ||
try { | ||
const actualRegion = err.$response.headers["x-amz-bucket-region"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reuse the value from hasBucketRegionHeader
. Since it isn't a boolean it should simply be called bucketRegionHeader
.
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. |
Issue
#7304
Description
Fixes HeadBucket cross-region redirects for 400 responses for newer regions with
x-amz-bucket-region
headerTesting
Locally
Checklist
*.integ.spec.ts
).@public
tag and enable doc generation on the package?By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.