Skip to content

Commit

Permalink
fix(middleware-sdk-s3): only check tail bytes in s3-200-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Jul 1, 2024
1 parent bceac19 commit ed0bec0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 3 additions & 7 deletions packages/middleware-sdk-s3/src/throw-200-exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const throw200ExceptionsMiddleware =
return result;
}

const bodyBytes = await collectBody(body, config);
const bodyString = await collectBodyString(bodyBytes, config);
const bodyBytes: Uint8Array = await collectBody(body, config);
const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));

// Throw on 200 response with empty body, legacy behavior allowlist.
if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName!]) {
Expand All @@ -51,7 +51,7 @@ export const throw200ExceptionsMiddleware =
throw err;
}
// Generalized throw-on-200 for top level Error element and non-streaming response.
if (bodyString && bodyString.endsWith("</Error>")) {
if (bodyStringTail && bodyStringTail.endsWith("</Error>")) {
// Set the error code to 4XX so that error deserializer can parse them
response.statusCode = 400;
}
Expand All @@ -70,10 +70,6 @@ const collectBody = (streamBody: any = new Uint8Array(), context: PreviouslyReso
return context.streamCollector(streamBody) || Promise.resolve(new Uint8Array());
};

// Encode Uint8Array data into string with utf-8.
const collectBodyString = (streamBody: any, context: PreviouslyResolved): Promise<string> =>
collectBody(streamBody, context).then((body) => context.utf8Encoder(body));

/**
* @internal
*/
Expand Down
6 changes: 5 additions & 1 deletion scripts/copy-smithy-dist-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ const smithyPackages = path.join(aws, "smithy-typescript", "packages");
const node_modules = path.join(__dirname, "..", "node_modules");

const localSmithyPkgs = fs.readdirSync(path.join(node_modules, "@smithy"));
const adjacentSmithyPkgs = fs.readdirSync(smithyPackages);

(async () => {
for (const smithyPkg of localSmithyPkgs) {
for (const smithyPkg of [...localSmithyPkgs, ...adjacentSmithyPkgs]) {
if (!fs.existsSync(path.join(smithyPackages, smithyPkg, "dist-cjs"))) {
continue;
}
await Promise.all([
spawnProcess("cp", [
"-r",
Expand Down

0 comments on commit ed0bec0

Please sign in to comment.