Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable ctor arg passthrough for requestHandler #1167

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/three-paws-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@smithy/protocol-http": minor
"@smithy/smithy-client": minor
---

allow constructor parameters pass-through when initializing requestHandler
35 changes: 32 additions & 3 deletions packages/protocol-http/src/httpHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { HttpHandlerOptions, RequestHandler } from "@smithy/types";
import type {
FetchHttpHandlerOptions,
HttpHandlerOptions,
NodeHttpHandlerOptions,
RequestHandler,
} from "@smithy/types";

import { HttpRequest } from "./httpRequest";
import { HttpResponse } from "./httpResponse";
import type { HttpRequest } from "./httpRequest";
import type { HttpResponse } from "./httpResponse";

/**
* @internal
Expand All @@ -23,3 +28,27 @@ export type HttpHandler<HttpHandlerConfig extends object = {}> = RequestHandler<
*/
httpHandlerConfigs(): HttpHandlerConfig;
};

/**
* @public
*
* A type representing the accepted user inputs for the `requestHandler` field
* of a client's constructor object.
*
* You may provide an instance of an HttpHandler, or alternatively
* provide the constructor arguments as an object which will be passed
* to the constructor of the default request handler.
*
* The default class constructor to which your arguments will be passed
* varies. The Node.js default is the NodeHttpHandler and the browser/react-native
* default is the FetchHttpHandler. In rarer cases specific clients may be
* configured to use other default implementations such as Websocket or HTTP2.
*
* The fallback type Record<string, unknown> is part of the union to allow
* passing constructor params to an unknown requestHandler type.
*/
export type HttpHandlerUserInput =
| HttpHandler
| NodeHttpHandlerOptions
| FetchHttpHandlerOptions
| Record<string, unknown>;
21 changes: 18 additions & 3 deletions packages/smithy-client/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { constructStack } from "@smithy/middleware-stack";
import { Client as IClient, Command, MetadataBearer, MiddlewareStack, RequestHandler } from "@smithy/types";
import {
Client as IClient,
Command,
FetchHttpHandlerOptions,
MetadataBearer,
MiddlewareStack,
NodeHttpHandlerOptions,
RequestHandler,
} from "@smithy/types";

/**
* @public
*/
export interface SmithyConfiguration<HandlerOptions> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an input config corresponding to the resolved config below. So, it can be loosened.

requestHandler: RequestHandler<any, any, HandlerOptions>;
requestHandler:
| RequestHandler<any, any, HandlerOptions>
| NodeHttpHandlerOptions
| FetchHttpHandlerOptions
| Record<string, unknown>;
/**
* The API version set internally by the SDK, and is
* not planned to be used by customer code.
Expand All @@ -17,7 +29,10 @@ export interface SmithyConfiguration<HandlerOptions> {
/**
* @internal
*/
export type SmithyResolvedConfiguration<HandlerOptions> = SmithyConfiguration<HandlerOptions>;
export type SmithyResolvedConfiguration<HandlerOptions> = {
requestHandler: RequestHandler<any, any, HandlerOptions>;
readonly apiVersion: string;
};

/**
* @public
Expand Down
Loading