Skip to content

Commit

Permalink
chore(middleware-expect-continue): do not set expect header if using …
Browse files Browse the repository at this point in the history
…FetchHttpHandler (#6046)
  • Loading branch information
kuhe committed May 8, 2024
1 parent 3179af2 commit 6bb0904
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/middleware-expect-continue/src/index.ts
@@ -1,4 +1,4 @@
import { HttpRequest } from "@smithy/protocol-http";
import { HttpHandler, HttpRequest } from "@smithy/protocol-http";
import {
BuildHandler,
BuildHandlerArguments,
Expand All @@ -7,21 +7,25 @@ import {
BuildMiddleware,
MetadataBearer,
Pluggable,
RequestHandler,
} from "@smithy/types";

interface PreviouslyResolved {
runtime: string;
requestHandler?: RequestHandler<any, any, any> | HttpHandler<any>;
}

export function addExpectContinueMiddleware(options: PreviouslyResolved): BuildMiddleware<any, any> {
return <Output extends MetadataBearer>(next: BuildHandler<any, Output>): BuildHandler<any, Output> =>
async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => {
const { request } = args;
if (HttpRequest.isInstance(request) && request.body && options.runtime === "node") {
request.headers = {
...request.headers,
Expect: "100-continue",
};
if (options.requestHandler?.constructor?.name !== "FetchHttpHandler") {
request.headers = {
...request.headers,
Expect: "100-continue",
};
}
}
return next({
...args,
Expand Down

0 comments on commit 6bb0904

Please sign in to comment.