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
  • Loading branch information
kuhe committed May 6, 2024
1 parent 20098c1 commit d071a40
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/middleware-expect-continue/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 d071a40

Please sign in to comment.