@aws-sdk/node-http-handler
Advanced tools
Comparing version 3.295.0 to 3.296.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NodeHttpHandler = void 0; | ||
exports.NodeHttpHandler = exports.DEFAULT_REQUEST_TIMEOUT = void 0; | ||
const protocol_http_1 = require("@aws-sdk/protocol-http"); | ||
@@ -10,5 +10,4 @@ const querystring_builder_1 = require("@aws-sdk/querystring-builder"); | ||
const get_transformed_headers_1 = require("./get-transformed-headers"); | ||
const set_connection_timeout_1 = require("./set-connection-timeout"); | ||
const set_socket_timeout_1 = require("./set-socket-timeout"); | ||
const write_request_body_1 = require("./write-request-body"); | ||
exports.DEFAULT_REQUEST_TIMEOUT = 0; | ||
class NodeHttpHandler { | ||
@@ -31,3 +30,4 @@ constructor(options) { | ||
resolveDefaultConfig(options) { | ||
const { connectionTimeout, socketTimeout, httpAgent, httpsAgent } = options || {}; | ||
var _a, _b; | ||
const { requestTimeout, connectionTimeout, socketTimeout, httpAgent, httpsAgent } = options || {}; | ||
const keepAlive = true; | ||
@@ -38,2 +38,3 @@ const maxSockets = 50; | ||
socketTimeout, | ||
requestTimeout: (_b = (_a = requestTimeout !== null && requestTimeout !== void 0 ? requestTimeout : connectionTimeout) !== null && _a !== void 0 ? _a : socketTimeout) !== null && _b !== void 0 ? _b : exports.DEFAULT_REQUEST_TIMEOUT, | ||
httpAgent: httpAgent || new http_1.Agent({ keepAlive, maxSockets }), | ||
@@ -53,2 +54,3 @@ httpsAgent: httpsAgent || new https_1.Agent({ keepAlive, maxSockets }), | ||
return new Promise((resolve, reject) => { | ||
var _a, _b; | ||
if (!this.config) { | ||
@@ -90,4 +92,7 @@ throw new Error("Node HTTP request handler config is not resolved"); | ||
}); | ||
(0, set_connection_timeout_1.setConnectionTimeout)(req, reject, this.config.connectionTimeout); | ||
(0, set_socket_timeout_1.setSocketTimeout)(req, reject, this.config.socketTimeout); | ||
const timeout = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.requestTimeout) !== null && _b !== void 0 ? _b : exports.DEFAULT_REQUEST_TIMEOUT; | ||
req.setTimeout(timeout, () => { | ||
req.destroy(); | ||
reject(Object.assign(new Error(`Connection timed out after ${timeout} ms`), { name: "TimeoutError" })); | ||
}); | ||
if (abortSignal) { | ||
@@ -94,0 +99,0 @@ abortSignal.onabort = () => { |
@@ -8,2 +8,3 @@ "use strict"; | ||
const get_transformed_headers_1 = require("./get-transformed-headers"); | ||
const node_http2_connection_manager_1 = require("./node-http2-connection-manager"); | ||
const write_request_body_1 = require("./write-request-body"); | ||
@@ -13,2 +14,3 @@ class NodeHttp2Handler { | ||
this.metadata = { handlerProtocol: "h2" }; | ||
this.connectionManager = new node_http2_connection_manager_1.NodeHttp2ConnectionManager({}); | ||
this.configProvider = new Promise((resolve, reject) => { | ||
@@ -26,9 +28,5 @@ if (typeof options === "function") { | ||
}); | ||
this.sessionCache = new Map(); | ||
} | ||
destroy() { | ||
for (const sessions of this.sessionCache.values()) { | ||
sessions.forEach((session) => this.destroySession(session)); | ||
} | ||
this.sessionCache.clear(); | ||
this.connectionManager.destroy(); | ||
} | ||
@@ -38,5 +36,10 @@ async handle(request, { abortSignal } = {}) { | ||
this.config = await this.configProvider; | ||
this.connectionManager.setDisableConcurrentStreams(this.config.disableConcurrentStreams || false); | ||
if (this.config.maxConcurrentStreams) { | ||
this.connectionManager.setMaxConcurrentStreams(this.config.maxConcurrentStreams); | ||
} | ||
} | ||
const { requestTimeout, disableConcurrentStreams } = this.config; | ||
return new Promise((resolve, rejectOriginal) => { | ||
var _a; | ||
let fulfilled = false; | ||
@@ -52,3 +55,7 @@ if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) { | ||
const authority = `${protocol}//${hostname}${port ? `:${port}` : ""}`; | ||
const session = this.getSession(authority, disableConcurrentStreams || false); | ||
const requestContext = { destination: new URL(authority) }; | ||
const session = this.connectionManager.lease(requestContext, { | ||
requestTimeout: (_a = this.config) === null || _a === void 0 ? void 0 : _a.sessionTimeout, | ||
disableConcurrentStreams: disableConcurrentStreams || false, | ||
}); | ||
const reject = (err) => { | ||
@@ -78,3 +85,3 @@ if (disableConcurrentStreams) { | ||
session.close(); | ||
this.deleteSessionFromCache(authority, session); | ||
this.connectionManager.deleteSession(authority, session); | ||
} | ||
@@ -117,25 +124,2 @@ }); | ||
} | ||
getSession(authority, disableConcurrentStreams) { | ||
var _a; | ||
const sessionCache = this.sessionCache; | ||
const existingSessions = sessionCache.get(authority) || []; | ||
if (existingSessions.length > 0 && !disableConcurrentStreams) | ||
return existingSessions[0]; | ||
const newSession = (0, http2_1.connect)(authority); | ||
newSession.unref(); | ||
const destroySessionCb = () => { | ||
this.destroySession(newSession); | ||
this.deleteSessionFromCache(authority, newSession); | ||
}; | ||
newSession.on("goaway", destroySessionCb); | ||
newSession.on("error", destroySessionCb); | ||
newSession.on("frameError", destroySessionCb); | ||
newSession.on("close", () => this.deleteSessionFromCache(authority, newSession)); | ||
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.sessionTimeout) { | ||
newSession.setTimeout(this.config.sessionTimeout, destroySessionCb); | ||
} | ||
existingSessions.push(newSession); | ||
sessionCache.set(authority, existingSessions); | ||
return newSession; | ||
} | ||
destroySession(session) { | ||
@@ -146,10 +130,3 @@ if (!session.destroyed) { | ||
} | ||
deleteSessionFromCache(authority, session) { | ||
const existingSessions = this.sessionCache.get(authority) || []; | ||
if (!existingSessions.includes(session)) { | ||
return; | ||
} | ||
this.sessionCache.set(authority, existingSessions.filter((s) => s !== session)); | ||
} | ||
} | ||
exports.NodeHttp2Handler = NodeHttp2Handler; |
@@ -7,5 +7,4 @@ import { HttpResponse } from "@aws-sdk/protocol-http"; | ||
import { getTransformedHeaders } from "./get-transformed-headers"; | ||
import { setConnectionTimeout } from "./set-connection-timeout"; | ||
import { setSocketTimeout } from "./set-socket-timeout"; | ||
import { writeRequestBody } from "./write-request-body"; | ||
export const DEFAULT_REQUEST_TIMEOUT = 0; | ||
export class NodeHttpHandler { | ||
@@ -28,3 +27,3 @@ constructor(options) { | ||
resolveDefaultConfig(options) { | ||
const { connectionTimeout, socketTimeout, httpAgent, httpsAgent } = options || {}; | ||
const { requestTimeout, connectionTimeout, socketTimeout, httpAgent, httpsAgent } = options || {}; | ||
const keepAlive = true; | ||
@@ -35,2 +34,3 @@ const maxSockets = 50; | ||
socketTimeout, | ||
requestTimeout: requestTimeout ?? connectionTimeout ?? socketTimeout ?? DEFAULT_REQUEST_TIMEOUT, | ||
httpAgent: httpAgent || new hAgent({ keepAlive, maxSockets }), | ||
@@ -85,4 +85,7 @@ httpsAgent: httpsAgent || new hsAgent({ keepAlive, maxSockets }), | ||
}); | ||
setConnectionTimeout(req, reject, this.config.connectionTimeout); | ||
setSocketTimeout(req, reject, this.config.socketTimeout); | ||
const timeout = this.config?.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT; | ||
req.setTimeout(timeout, () => { | ||
req.destroy(); | ||
reject(Object.assign(new Error(`Connection timed out after ${timeout} ms`), { name: "TimeoutError" })); | ||
}); | ||
if (abortSignal) { | ||
@@ -89,0 +92,0 @@ abortSignal.onabort = () => { |
import { HttpResponse } from "@aws-sdk/protocol-http"; | ||
import { buildQueryString } from "@aws-sdk/querystring-builder"; | ||
import { connect, constants } from "http2"; | ||
import { constants } from "http2"; | ||
import { getTransformedHeaders } from "./get-transformed-headers"; | ||
import { NodeHttp2ConnectionManager } from "./node-http2-connection-manager"; | ||
import { writeRequestBody } from "./write-request-body"; | ||
@@ -9,2 +10,3 @@ export class NodeHttp2Handler { | ||
this.metadata = { handlerProtocol: "h2" }; | ||
this.connectionManager = new NodeHttp2ConnectionManager({}); | ||
this.configProvider = new Promise((resolve, reject) => { | ||
@@ -22,9 +24,5 @@ if (typeof options === "function") { | ||
}); | ||
this.sessionCache = new Map(); | ||
} | ||
destroy() { | ||
for (const sessions of this.sessionCache.values()) { | ||
sessions.forEach((session) => this.destroySession(session)); | ||
} | ||
this.sessionCache.clear(); | ||
this.connectionManager.destroy(); | ||
} | ||
@@ -34,2 +32,6 @@ async handle(request, { abortSignal } = {}) { | ||
this.config = await this.configProvider; | ||
this.connectionManager.setDisableConcurrentStreams(this.config.disableConcurrentStreams || false); | ||
if (this.config.maxConcurrentStreams) { | ||
this.connectionManager.setMaxConcurrentStreams(this.config.maxConcurrentStreams); | ||
} | ||
} | ||
@@ -48,3 +50,7 @@ const { requestTimeout, disableConcurrentStreams } = this.config; | ||
const authority = `${protocol}//${hostname}${port ? `:${port}` : ""}`; | ||
const session = this.getSession(authority, disableConcurrentStreams || false); | ||
const requestContext = { destination: new URL(authority) }; | ||
const session = this.connectionManager.lease(requestContext, { | ||
requestTimeout: this.config?.sessionTimeout, | ||
disableConcurrentStreams: disableConcurrentStreams || false, | ||
}); | ||
const reject = (err) => { | ||
@@ -74,3 +80,3 @@ if (disableConcurrentStreams) { | ||
session.close(); | ||
this.deleteSessionFromCache(authority, session); | ||
this.connectionManager.deleteSession(authority, session); | ||
} | ||
@@ -113,24 +119,2 @@ }); | ||
} | ||
getSession(authority, disableConcurrentStreams) { | ||
const sessionCache = this.sessionCache; | ||
const existingSessions = sessionCache.get(authority) || []; | ||
if (existingSessions.length > 0 && !disableConcurrentStreams) | ||
return existingSessions[0]; | ||
const newSession = connect(authority); | ||
newSession.unref(); | ||
const destroySessionCb = () => { | ||
this.destroySession(newSession); | ||
this.deleteSessionFromCache(authority, newSession); | ||
}; | ||
newSession.on("goaway", destroySessionCb); | ||
newSession.on("error", destroySessionCb); | ||
newSession.on("frameError", destroySessionCb); | ||
newSession.on("close", () => this.deleteSessionFromCache(authority, newSession)); | ||
if (this.config?.sessionTimeout) { | ||
newSession.setTimeout(this.config.sessionTimeout, destroySessionCb); | ||
} | ||
existingSessions.push(newSession); | ||
sessionCache.set(authority, existingSessions); | ||
return newSession; | ||
} | ||
destroySession(session) { | ||
@@ -141,9 +125,2 @@ if (!session.destroyed) { | ||
} | ||
deleteSessionFromCache(authority, session) { | ||
const existingSessions = this.sessionCache.get(authority) || []; | ||
if (!existingSessions.includes(session)) { | ||
return; | ||
} | ||
this.sessionCache.set(authority, existingSessions.filter((s) => s !== session)); | ||
} | ||
} |
@@ -12,2 +12,7 @@ /// <reference types="node" /> | ||
/** | ||
* @deprecated Use {@link requestTimeout} | ||
* | ||
* Note:{@link NodeHttpHandler} will resolve request timeout via nullish coalescing the following fields: | ||
* {@link requestTimeout} ?? {@link connectionTimeout} ?? {@link socketTimeout} ?? {@link DEFAULT_REQUEST_TIMEOUT} | ||
* | ||
* The maximum time in milliseconds that the connection phase of a request | ||
@@ -18,2 +23,12 @@ * may take before the connection attempt is abandoned. | ||
/** | ||
* The maximum time in milliseconds that the connection phase of a request | ||
* may take before the connection attempt is abandoned. | ||
*/ | ||
requestTimeout?: number; | ||
/** | ||
* @deprecated Use {@link requestTimeout} | ||
* | ||
* Note:{@link NodeHttpHandler} will resolve request timeout via nullish coalescing the following fields: | ||
* {@link requestTimeout} ?? {@link connectionTimeout} ?? {@link socketTimeout} ?? {@link DEFAULT_REQUEST_TIMEOUT} | ||
* | ||
* The maximum time in milliseconds that a socket may remain idle before it | ||
@@ -26,2 +41,3 @@ * is closed. | ||
} | ||
export declare const DEFAULT_REQUEST_TIMEOUT = 0; | ||
export declare class NodeHttpHandler implements HttpHandler { | ||
@@ -28,0 +44,0 @@ private config?; |
@@ -20,3 +20,3 @@ import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; | ||
* Disables processing concurrent streams on a ClientHttp2Session instance. When set | ||
* to true, the handler will create a new session instance for each request to a URL. | ||
* to true, a new session instance is created for each request to a URL. | ||
* **Default:** false. | ||
@@ -26,2 +26,9 @@ * https://nodejs.org/api/http2.html#http2_class_clienthttp2session | ||
disableConcurrentStreams?: boolean; | ||
/** | ||
* Maximum number of concurrent Http2Stream instances per ClientHttp2Session. Each session | ||
* may have up to 2^31-1 Http2Stream instances over its lifetime. | ||
* This value must be greater than or equal to 0. | ||
* https://nodejs.org/api/http2.html#class-http2stream | ||
*/ | ||
maxConcurrentStreams?: number; | ||
} | ||
@@ -34,3 +41,3 @@ export declare class NodeHttp2Handler implements HttpHandler { | ||
}; | ||
private sessionCache; | ||
private readonly connectionManager; | ||
constructor(options?: NodeHttp2HandlerOptions | Provider<NodeHttp2HandlerOptions | void>); | ||
@@ -42,10 +49,2 @@ destroy(): void; | ||
/** | ||
* Returns a session for the given URL. | ||
* | ||
* @param authority The URL to create a session for. | ||
* @param disableConcurrentStreams If true, a new session will be created for each request. | ||
* @returns A session for the given URL. | ||
*/ | ||
private getSession; | ||
/** | ||
* Destroys a session. | ||
@@ -55,8 +54,2 @@ * @param session The session to destroy. | ||
private destroySession; | ||
/** | ||
* Delete a session from the connection pool. | ||
* @param authority The authority of the session to delete. | ||
* @param session The session to delete. | ||
*/ | ||
private deleteSessionFromCache; | ||
} |
@@ -7,2 +7,3 @@ import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; | ||
connectionTimeout?: number; | ||
requestTimeout?: number; | ||
socketTimeout?: number; | ||
@@ -12,2 +13,3 @@ httpAgent?: hAgent; | ||
} | ||
export declare const DEFAULT_REQUEST_TIMEOUT = 0; | ||
export declare class NodeHttpHandler implements HttpHandler { | ||
@@ -14,0 +16,0 @@ private config?; |
@@ -7,2 +7,3 @@ import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; | ||
disableConcurrentStreams?: boolean; | ||
maxConcurrentStreams?: number; | ||
} | ||
@@ -15,3 +16,3 @@ export declare class NodeHttp2Handler implements HttpHandler { | ||
}; | ||
private sessionCache; | ||
private readonly connectionManager; | ||
constructor( | ||
@@ -27,5 +28,3 @@ options?: NodeHttp2HandlerOptions | Provider<NodeHttp2HandlerOptions | void> | ||
}>; | ||
private getSession; | ||
private destroySession; | ||
private deleteSessionFromCache; | ||
} |
{ | ||
"name": "@aws-sdk/node-http-handler", | ||
"version": "3.295.0", | ||
"version": "3.296.0", | ||
"description": "Provides a way to make requests", | ||
@@ -25,6 +25,6 @@ "scripts": { | ||
"dependencies": { | ||
"@aws-sdk/abort-controller": "3.295.0", | ||
"@aws-sdk/protocol-http": "3.295.0", | ||
"@aws-sdk/querystring-builder": "3.295.0", | ||
"@aws-sdk/types": "3.295.0", | ||
"@aws-sdk/abort-controller": "3.296.0", | ||
"@aws-sdk/protocol-http": "3.296.0", | ||
"@aws-sdk/querystring-builder": "3.296.0", | ||
"@aws-sdk/types": "3.296.0", | ||
"tslib": "^2.5.0" | ||
@@ -31,0 +31,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71278
63
1468
14
+ Added@aws-sdk/abort-controller@3.296.0(transitive)
+ Added@aws-sdk/protocol-http@3.296.0(transitive)
+ Added@aws-sdk/querystring-builder@3.296.0(transitive)
+ Added@aws-sdk/types@3.296.0(transitive)
- Removed@aws-sdk/abort-controller@3.295.0(transitive)
- Removed@aws-sdk/protocol-http@3.295.0(transitive)
- Removed@aws-sdk/querystring-builder@3.295.0(transitive)
- Removed@aws-sdk/types@3.295.0(transitive)
Updated@aws-sdk/types@3.296.0