Skip to content

Commit b6a96c0

Browse files
authored
fix(util-create-request): fix creating undefined request (#803)
* fix(util-create-request): fix creating undefined request Use command.resolveMiddleware() to generate request instead of concatenating middleware stacks manually. This fixes gh issue also include `build` stage to creating request. Because build stage sometimes contains necessary middleware to build a correct request. For example, S3's bucket endpoint middleware is located in build stage. Host header is also necessary, if users want to sign the generated request directly. * fix: remove middleware-stack dev dep
1 parent defd342 commit b6a96c0

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

packages/util-create-request/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"tslib": "^1.8.0"
2121
},
2222
"devDependencies": {
23-
"@aws-sdk/middleware-stack": "^1.0.0-alpha.1",
2423
"@aws-sdk/protocol-http": "^1.0.0-alpha.6",
2524
"@types/jest": "^24.0.12",
2625
"@types/node": "^10.0.3",

packages/util-create-request/src/foo.fixture.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export const operationCommand: Command<
5353
config: any,
5454
options: any
5555
) => {
56-
return () => Promise.resolve({ output, response: {} });
56+
const concatStack = stack.concat(operationCommand.middlewareStack);
57+
return concatStack.resolve(
58+
() => Promise.resolve({ output, response: {} }),
59+
{} as any
60+
);
5761
}
5862
};
5963

packages/util-create-request/src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe("create-request", () => {
116116
);
117117
expect(request).toEqual({
118118
...httpRequest,
119-
body: "A1B2"
119+
body: "A1B2C3"
120120
});
121121
});
122122
});
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
HttpRequest,
3-
MetadataBearer,
4-
SerializeMiddleware
5-
} from "@aws-sdk/types";
1+
import { HttpRequest, MetadataBearer, BuildMiddleware } from "@aws-sdk/types";
62
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
73
import { Client, Command } from "@aws-sdk/smithy-client";
84

@@ -14,27 +10,26 @@ export async function createRequest<
1410
client: Client<any, InputTypesUnion, MetadataBearer, any>,
1511
command: Command<InputType, OutputType, any, InputTypesUnion, MetadataBearer>
1612
): Promise<HttpRequest> {
17-
const presignMiddleware: SerializeMiddleware<
13+
const interceptMiddleware: BuildMiddleware<
1814
InputType,
1915
OutputType
2016
> = next => async args => {
2117
return { output: { request: args.request } as any, response: undefined };
2218
};
2319
const clientStack = client.middlewareStack.clone();
24-
const commandStack = command.middlewareStack.clone();
25-
const concatenatedStack = clientStack.concat(commandStack) as MiddlewareStack<
26-
InputType,
27-
OutputType
28-
>;
20+
2921
//add middleware to the last of 'build' step
30-
concatenatedStack.add(presignMiddleware, {
31-
step: "serialize",
22+
clientStack.add(interceptMiddleware, {
23+
step: "build",
3224
priority: "low"
3325
});
3426

35-
const handler = concatenatedStack.resolve((() => {}) as any, {
36-
logger: {} as any
37-
});
27+
const handler = command.resolveMiddleware(
28+
clientStack as MiddlewareStack<any, any>,
29+
client.config,
30+
undefined
31+
);
32+
3833
//@ts-ignore
3934
return await handler(command).then(output => output.output.request);
4035
}

0 commit comments

Comments
 (0)