Skip to content

Commit abddf1e

Browse files
committed
feat: enable ctor arg passthrough for requestHandler
1 parent d70a00a commit abddf1e

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

.changeset/three-paws-add.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@smithy/protocol-http": minor
3+
"@smithy/smithy-client": minor
4+
---
5+
6+
allow constructor parameters pass-through when initializing requestHandler

packages/protocol-http/src/httpHandler.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import { HttpHandlerOptions, RequestHandler } from "@smithy/types";
1+
import type {
2+
FetchHttpHandlerOptions,
3+
HttpHandlerOptions,
4+
NodeHttpHandlerOptions,
5+
RequestHandler,
6+
} from "@smithy/types";
27

3-
import { HttpRequest } from "./httpRequest";
4-
import { HttpResponse } from "./httpResponse";
8+
import type { HttpRequest } from "./httpRequest";
9+
import type { HttpResponse } from "./httpResponse";
510

611
/**
712
* @internal
@@ -23,3 +28,21 @@ export type HttpHandler<HttpHandlerConfig extends object = {}> = RequestHandler<
2328
*/
2429
httpHandlerConfigs(): HttpHandlerConfig;
2530
};
31+
32+
/**
33+
* @public
34+
*
35+
* A type representing the accepted user inputs for the `requestHandler` field
36+
* of a client's constructor object.
37+
*
38+
* You may provide an instance of an HttpHandler, or alternatively
39+
* provide the constructor arguments as an object which will be passed
40+
* to the constructor of the default request handler.
41+
*
42+
* The default class constructor to which your arguments will be passed
43+
* varies. The Node.js default is the NodeHttpHandler and the browser/react-native
44+
* default is the FetchHttpHandler. In rarer cases specific clients may be
45+
* configured to use other default implementations such as Websocket or HTTP2.
46+
*
47+
*/
48+
export type HttpHandlerUserInput = HttpHandler | NodeHttpHandlerOptions | FetchHttpHandlerOptions;

packages/smithy-client/src/client.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { constructStack } from "@smithy/middleware-stack";
2-
import { Client as IClient, Command, MetadataBearer, MiddlewareStack, RequestHandler } from "@smithy/types";
2+
import {
3+
Client as IClient,
4+
Command,
5+
FetchHttpHandlerOptions,
6+
MetadataBearer,
7+
MiddlewareStack,
8+
NodeHttpHandlerOptions,
9+
RequestHandler,
10+
} from "@smithy/types";
311

412
/**
513
* @public
614
*/
715
export interface SmithyConfiguration<HandlerOptions> {
8-
requestHandler: RequestHandler<any, any, HandlerOptions>;
16+
requestHandler: RequestHandler<any, any, HandlerOptions> | NodeHttpHandlerOptions | FetchHttpHandlerOptions | any;
917
/**
1018
* The API version set internally by the SDK, and is
1119
* not planned to be used by customer code.
@@ -17,7 +25,10 @@ export interface SmithyConfiguration<HandlerOptions> {
1725
/**
1826
* @internal
1927
*/
20-
export type SmithyResolvedConfiguration<HandlerOptions> = SmithyConfiguration<HandlerOptions>;
28+
export type SmithyResolvedConfiguration<HandlerOptions> = {
29+
requestHandler: RequestHandler<any, any, HandlerOptions>;
30+
readonly apiVersion: string;
31+
};
2132

2233
/**
2334
* @public

0 commit comments

Comments
 (0)