1+ import { SerdeContext } from "@smithy/core/protocols" ;
12import { constructStack } from "@smithy/middleware-stack" ;
23import type {
4+ $ClientProtocol ,
5+ $ClientProtocolCtor ,
36 Client as IClient ,
7+ ClientProtocol ,
8+ ClientProtocolCtor ,
49 Command ,
510 FetchHttpHandlerOptions ,
611 Handler ,
@@ -14,17 +19,15 @@ import type {
1419 * @public
1520 */
1621export interface SmithyConfiguration < HandlerOptions > {
22+ /**
23+ * @public
24+ */
1725 requestHandler :
1826 | RequestHandler < any , any , HandlerOptions >
1927 | NodeHttpHandlerOptions
2028 | FetchHttpHandlerOptions
2129 | Record < string , unknown > ;
22- /**
23- * The API version set internally by the SDK, and is
24- * not planned to be used by customer code.
25- * @internal
26- */
27- readonly apiVersion : string ;
30+
2831 /**
2932 * @public
3033 *
@@ -41,15 +44,51 @@ export interface SmithyConfiguration<HandlerOptions> {
4144 * and not needing middleware modifications between requests.
4245 */
4346 cacheMiddleware ?: boolean ;
47+
48+ /**
49+ * A client request/response protocol or constructor of one.
50+ * A protocol in this context is not e.g. https.
51+ * It is the combined implementation of how to (de)serialize and create
52+ * the messages (e.g. http requests/responses) that are being exchanged.
53+ *
54+ * @public
55+ */
56+ protocol ?:
57+ | ClientProtocol < any , any >
58+ | $ClientProtocol < any , any >
59+ | ClientProtocolCtor < any , any >
60+ | $ClientProtocolCtor < any , any > ;
61+
62+ /**
63+ * These are automatically generated and will be passed to the
64+ * config.protocol if given as a constructor.
65+ * @internal
66+ */
67+ protocolSettings ?: {
68+ defaultNamespace ?: string ;
69+ [ setting : string ] : unknown ;
70+ } ;
71+
72+ /**
73+ * The API version set internally by the SDK, and is
74+ * not planned to be used by customer code.
75+ * @internal
76+ */
77+ readonly apiVersion : string ;
4478}
4579
4680/**
4781 * @internal
4882 */
4983export type SmithyResolvedConfiguration < HandlerOptions > = {
5084 requestHandler : RequestHandler < any , any , HandlerOptions > ;
51- readonly apiVersion : string ;
5285 cacheMiddleware ?: boolean ;
86+ protocol : ClientProtocol < any , any > | $ClientProtocol < any , any > ;
87+ protocolSettings ?: {
88+ defaultNamespace ?: string ;
89+ [ setting : string ] : unknown ;
90+ } ;
91+ readonly apiVersion : string ;
5392} ;
5493
5594/**
@@ -78,7 +117,15 @@ export class Client<
78117 */
79118 private handlers ?: WeakMap < Function , Handler < any , any > > | undefined ;
80119
81- constructor ( public readonly config : ResolvedClientConfiguration ) { }
120+ constructor ( public readonly config : ResolvedClientConfiguration ) {
121+ const { protocol, protocolSettings } = config ;
122+ if ( protocolSettings ) {
123+ if ( typeof protocol === "function" ) {
124+ // assumed to be a constructor
125+ config . protocol = new ( protocol as any ) ( protocolSettings ) ;
126+ }
127+ }
128+ }
82129
83130 send < InputType extends ClientInput , OutputType extends ClientOutput > (
84131 command : Command < ClientInput , InputType , ClientOutput , OutputType , SmithyResolvedConfiguration < HandlerOptions > > ,
0 commit comments