Skip to content

Commit 17d5e96

Browse files
author
Chase Coalwell
authored
fix: apply header only in node (#582)
1 parent f2962b1 commit 17d5e96

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

packages/middleware-expect-continue/src/index.spec.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ describe("addExpectContinueMiddleware", () => {
88
jest.clearAllMocks();
99
});
1010

11-
it("sets the Expect header to 100-continue if there is a request body", async () => {
12-
const handler = addExpectContinueMiddleware()(mockNextHandler, {} as any);
11+
it("sets the Expect header to 100-continue if there is a request body in node runtime", async () => {
12+
const handler = addExpectContinueMiddleware({ runtime: "node" })(
13+
mockNextHandler,
14+
{} as any
15+
);
1316
await handler({
1417
input: {},
1518
request: new HttpRequest({
@@ -24,8 +27,11 @@ describe("addExpectContinueMiddleware", () => {
2427
expect(request.headers["Expect"]).toBe("100-continue");
2528
});
2629

27-
it("does not set the Expect header to 100-continue if there is no request body", async () => {
28-
const handler = addExpectContinueMiddleware()(mockNextHandler, {} as any);
30+
it("does not set the Expect header to 100-continue if there is no request body in node runtime", async () => {
31+
const handler = addExpectContinueMiddleware({ runtime: "node" })(
32+
mockNextHandler,
33+
{} as any
34+
);
2935
await handler({
3036
input: {},
3137
request: new HttpRequest({
@@ -38,4 +44,23 @@ describe("addExpectContinueMiddleware", () => {
3844
const { request } = mockNextHandler.mock.calls[0][0];
3945
expect(request.headers["Expect"]).toBeUndefined();
4046
});
47+
48+
it("does not set the Expect header to 100-continue for browser runtime", async () => {
49+
const handler = addExpectContinueMiddleware({ runtime: "browser" })(
50+
mockNextHandler,
51+
{} as any
52+
);
53+
await handler({
54+
input: {},
55+
request: new HttpRequest({
56+
body: "foo",
57+
headers: {}
58+
})
59+
});
60+
61+
const { calls } = (mockNextHandler as any).mock;
62+
expect(calls.length).toBe(1);
63+
const { request } = mockNextHandler.mock.calls[0][0];
64+
expect(request.headers["Expect"]).toBeUndefined();
65+
});
4166
});

packages/middleware-expect-continue/src/index.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@ import {
99
} from "@aws-sdk/types";
1010
import { HttpRequest } from "@aws-sdk/protocol-http";
1111

12-
export function addExpectContinueMiddleware(): BuildMiddleware<any, any> {
12+
interface PreviouslyResolved {
13+
runtime: string;
14+
}
15+
16+
export function addExpectContinueMiddleware(
17+
options: PreviouslyResolved
18+
): BuildMiddleware<any, any> {
1319
return <Output extends MetadataBearer>(
1420
next: BuildHandler<any, Output>
1521
): BuildHandler<any, Output> => async (
1622
args: BuildHandlerArguments<any>
1723
): Promise<BuildHandlerOutput<Output>> => {
1824
let { request } = args;
19-
if (HttpRequest.isInstance(request) && request.body) {
25+
if (
26+
HttpRequest.isInstance(request) &&
27+
request.body &&
28+
options.runtime === "node"
29+
) {
2030
request.headers = {
2131
...request.headers,
2232
Expect: "100-continue"
@@ -36,11 +46,11 @@ export const addExpectContinueMiddlewareOptions: BuildHandlerOptions = {
3646
};
3747

3848
export const getAddExpectContinuePlugin = (
39-
unused: any
49+
options: PreviouslyResolved
4050
): Pluggable<any, any> => ({
4151
applyToStack: clientStack => {
4252
clientStack.add(
43-
addExpectContinueMiddleware(),
53+
addExpectContinueMiddleware(options),
4454
addExpectContinueMiddlewareOptions
4555
);
4656
}

0 commit comments

Comments
 (0)