File tree Expand file tree Collapse file tree 9 files changed +109
-0
lines changed Expand file tree Collapse file tree 9 files changed +109
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @smithy/protocol-http " : minor
3
+ ---
4
+
5
+ add RequestHandlerParams type for ctor passthrough
Original file line number Diff line number Diff line change
1
+ ---
2
+ " @smithy/fetch-http-handler " : minor
3
+ " @smithy/node-http-handler " : minor
4
+ " @smithy/protocol-http " : minor
5
+ ---
6
+
7
+ add static factory for http handlers
Original file line number Diff line number Diff line change @@ -47,6 +47,19 @@ export class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
47
47
private config ?: FetchHttpHandlerConfig ;
48
48
private configProvider : Promise < FetchHttpHandlerConfig > ;
49
49
50
+ /**
51
+ * @returns the input if it is an HttpHandler of any class,
52
+ * or instantiates a new instance of this handler.
53
+ */
54
+ public static create ( instanceOrOptions ?: HttpHandler < any > | FetchHttpHandlerConfig ) {
55
+ if ( typeof ( instanceOrOptions as any ) ?. handle === "function" ) {
56
+ // is already an instance of HttpHandler.
57
+ return instanceOrOptions as HttpHandler < any > ;
58
+ }
59
+ // input is ctor options or undefined.
60
+ return new FetchHttpHandler ( instanceOrOptions as FetchHttpHandlerConfig ) ;
61
+ }
62
+
50
63
constructor ( options ?: FetchHttpHandlerOptions | Provider < FetchHttpHandlerOptions | undefined > ) {
51
64
if ( typeof options === "function" ) {
52
65
this . configProvider = options ( ) . then ( ( opts ) => opts || { } ) ;
Original file line number Diff line number Diff line change @@ -57,6 +57,19 @@ export class NodeHttpHandler implements HttpHandler<NodeHttpHandlerOptions> {
57
57
// Node http handler is hard-coded to http/1.1: https://github.com/nodejs/node/blob/ff5664b83b89c55e4ab5d5f60068fb457f1f5872/lib/_http_server.js#L286
58
58
public readonly metadata = { handlerProtocol : "http/1.1" } ;
59
59
60
+ /**
61
+ * @returns the input if it is an HttpHandler of any class,
62
+ * or instantiates a new instance of this handler.
63
+ */
64
+ public static create ( instanceOrOptions ?: HttpHandler < any > | NodeHttpHandlerOptions ) {
65
+ if ( typeof ( instanceOrOptions as any ) ?. handle === "function" ) {
66
+ // is already an instance of HttpHandler.
67
+ return instanceOrOptions as HttpHandler < any > ;
68
+ }
69
+ // input is ctor options or undefined.
70
+ return new NodeHttpHandler ( instanceOrOptions as NodeHttpHandlerOptions ) ;
71
+ }
72
+
60
73
constructor ( options ?: NodeHttpHandlerOptions | Provider < NodeHttpHandlerOptions | void > ) {
61
74
this . configProvider = new Promise ( ( resolve , reject ) => {
62
75
if ( typeof options === "function" ) {
Original file line number Diff line number Diff line change @@ -49,6 +49,19 @@ export class NodeHttp2Handler implements HttpHandler<NodeHttp2HandlerOptions> {
49
49
50
50
private readonly connectionManager : NodeHttp2ConnectionManager = new NodeHttp2ConnectionManager ( { } ) ;
51
51
52
+ /**
53
+ * @returns the input if it is an HttpHandler of any class,
54
+ * or instantiates a new instance of this handler.
55
+ */
56
+ public static create ( instanceOrOptions ?: HttpHandler < any > | NodeHttp2HandlerOptions ) {
57
+ if ( typeof ( instanceOrOptions as any ) ?. handle === "function" ) {
58
+ // is already an instance of HttpHandler.
59
+ return instanceOrOptions as HttpHandler < any > ;
60
+ }
61
+ // input is ctor options or undefined.
62
+ return new NodeHttp2Handler ( instanceOrOptions as NodeHttp2HandlerOptions ) ;
63
+ }
64
+
52
65
constructor ( options ?: NodeHttp2HandlerOptions | Provider < NodeHttp2HandlerOptions | void > ) {
53
66
this . configProvider = new Promise ( ( resolve , reject ) => {
54
67
if ( typeof options === "function" ) {
Original file line number Diff line number Diff line change 16
16
"main" : " ./dist-cjs/index.js" ,
17
17
"module" : " ./dist-es/index.js" ,
18
18
"types" : " ./dist-types/index.d.ts" ,
19
+ "browser" : {
20
+ "./dist-es/httpHandlerInitialization" : " ./dist-es/httpHandlerInitialization.browser"
21
+ },
22
+ "react-native" : {
23
+ "./dist-es/httpHandlerInitialization" : " ./dist-es/httpHandlerInitialization.browser" ,
24
+ "./dist-cjs/httpHandlerInitialization" : " ./dist-cjs/httpHandlerInitialization.browser"
25
+ },
19
26
"author" : {
20
27
"name" : " AWS Smithy Team" ,
21
28
"email" : " " ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Alternate compilation for browser excluding http Agent types.
3
+ *
4
+ * @internal
5
+ */
6
+ export type DefaultRequestHandlerInitializationPassThroughParameters = FetchHttpHandlerOptions ;
7
+
8
+ /**
9
+ * Copy of the options in @smithy/fetch-http-handler FetchHttpHandler class.
10
+ * Not imported due to dependency ordering.
11
+ */
12
+ interface FetchHttpHandlerOptions {
13
+ requestTimeout ?: number ;
14
+ keepAlive ?: boolean ;
15
+ }
Original file line number Diff line number Diff line change
1
+ import type { Agent as hAgent } from "http" ;
2
+ import type { Agent as hsAgent } from "https" ;
3
+
4
+ /**
5
+ *
6
+ * This type represents an alternate client constructor option for the entry
7
+ * "requestHandler". Instead of providing an instance of a requestHandler, the user
8
+ * may provide the requestHandler's constructor options for either the
9
+ * NodeHttpHandler or FetchHttpHandler.
10
+ *
11
+ * For other RequestHandlers, constructor parameter passthrough is not available.
12
+ *
13
+ * @public
14
+ */
15
+ export type RequestHandlerParams = NodeHttpHandlerOptions | FetchHttpHandlerOptions ;
16
+
17
+ /**
18
+ * Copy of the options in @smithy/node-http-handler NodeHttpHandler class.
19
+ * Not imported due to dependency ordering.
20
+ */
21
+ export interface NodeHttpHandlerOptions {
22
+ connectionTimeout ?: number ;
23
+ requestTimeout ?: number ;
24
+ httpAgent ?: hAgent ;
25
+ httpsAgent ?: hsAgent ;
26
+ }
27
+
28
+ /**
29
+ * Copy of the options in @smithy/fetch-http-handler FetchHttpHandler class.
30
+ * Not imported due to dependency ordering.
31
+ */
32
+ export interface FetchHttpHandlerOptions {
33
+ requestTimeout ?: number ;
34
+ keepAlive ?: boolean ;
35
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ export * from "./extensions";
2
2
export * from "./Field" ;
3
3
export * from "./Fields" ;
4
4
export * from "./httpHandler" ;
5
+ export * from "./httpHandlerInitialization" ;
5
6
export * from "./httpRequest" ;
6
7
export * from "./httpResponse" ;
7
8
export * from "./isValidHostname" ;
You can’t perform that action at this time.
0 commit comments