@aws-sdk/node-http-handler
Advanced tools
Comparing version 3.46.0 to 3.47.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [3.47.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.46.0...v3.47.0) (2022-01-15) | ||
### Features | ||
* **clients:** update clients to use default values inferred from defaults mode ([#3192](https://github.com/aws/aws-sdk-js-v3/issues/3192)) ([9152e21](https://github.com/aws/aws-sdk-js-v3/commit/9152e210c6ec29f34bb070eaf2874039022e6ab7)) | ||
# [3.46.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.45.0...v3.46.0) (2022-01-07) | ||
@@ -8,0 +19,0 @@ |
@@ -14,17 +14,37 @@ "use strict"; | ||
class NodeHttpHandler { | ||
constructor({ connectionTimeout, socketTimeout, httpAgent, httpsAgent } = {}) { | ||
constructor(options) { | ||
this.metadata = { handlerProtocol: "http/1.1" }; | ||
this.connectionTimeout = connectionTimeout; | ||
this.socketTimeout = socketTimeout; | ||
if (typeof options === "function") { | ||
this.configProvider = async () => { | ||
return this.resolveDefaultConfig(await options()); | ||
}; | ||
} | ||
else { | ||
this.config = this.resolveDefaultConfig(options); | ||
} | ||
} | ||
resolveDefaultConfig(options) { | ||
const { connectionTimeout, socketTimeout, httpAgent, httpsAgent } = options || {}; | ||
const keepAlive = true; | ||
const maxSockets = 50; | ||
this.httpAgent = httpAgent || new http_1.Agent({ keepAlive, maxSockets }); | ||
this.httpsAgent = httpsAgent || new https_1.Agent({ keepAlive, maxSockets }); | ||
return { | ||
connectionTimeout, | ||
socketTimeout, | ||
httpAgent: httpAgent || new http_1.Agent({ keepAlive, maxSockets }), | ||
httpsAgent: httpsAgent || new https_1.Agent({ keepAlive, maxSockets }), | ||
}; | ||
} | ||
destroy() { | ||
this.httpAgent.destroy(); | ||
this.httpsAgent.destroy(); | ||
var _a, _b, _c, _d; | ||
(_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.httpAgent) === null || _b === void 0 ? void 0 : _b.destroy(); | ||
(_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.httpsAgent) === null || _d === void 0 ? void 0 : _d.destroy(); | ||
} | ||
handle(request, { abortSignal } = {}) { | ||
async handle(request, { abortSignal } = {}) { | ||
if (!this.config && this.configProvider) { | ||
this.config = await this.configProvider(); | ||
} | ||
return new Promise((resolve, reject) => { | ||
if (!this.config) { | ||
throw new Error("Node HTTP request handler config is not resolved"); | ||
} | ||
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) { | ||
@@ -44,3 +64,3 @@ const abortError = new Error("Request aborted"); | ||
port: request.port, | ||
agent: isSSL ? this.httpsAgent : this.httpAgent, | ||
agent: isSSL ? this.config.httpsAgent : this.config.httpAgent, | ||
}; | ||
@@ -64,4 +84,4 @@ const requestFunc = isSSL ? https_1.request : http_1.request; | ||
}); | ||
set_connection_timeout_1.setConnectionTimeout(req, reject, this.connectionTimeout); | ||
set_socket_timeout_1.setSocketTimeout(req, reject, this.socketTimeout); | ||
set_connection_timeout_1.setConnectionTimeout(req, reject, this.config.connectionTimeout); | ||
set_socket_timeout_1.setSocketTimeout(req, reject, this.config.socketTimeout); | ||
if (abortSignal) { | ||
@@ -68,0 +88,0 @@ abortSignal.onabort = () => { |
@@ -0,1 +1,2 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { HttpResponse } from "@aws-sdk/protocol-http"; | ||
@@ -11,64 +12,103 @@ import { buildQueryString } from "@aws-sdk/querystring-builder"; | ||
var NodeHttpHandler = (function () { | ||
function NodeHttpHandler(_a) { | ||
var _b = _a === void 0 ? {} : _a, connectionTimeout = _b.connectionTimeout, socketTimeout = _b.socketTimeout, httpAgent = _b.httpAgent, httpsAgent = _b.httpsAgent; | ||
function NodeHttpHandler(options) { | ||
var _this = this; | ||
this.metadata = { handlerProtocol: "http/1.1" }; | ||
this.connectionTimeout = connectionTimeout; | ||
this.socketTimeout = socketTimeout; | ||
if (typeof options === "function") { | ||
this.configProvider = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_a = this.resolveDefaultConfig; | ||
return [4, options()]; | ||
case 1: return [2, _a.apply(this, [_b.sent()])]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
else { | ||
this.config = this.resolveDefaultConfig(options); | ||
} | ||
} | ||
NodeHttpHandler.prototype.resolveDefaultConfig = function (options) { | ||
var _a = options || {}, connectionTimeout = _a.connectionTimeout, socketTimeout = _a.socketTimeout, httpAgent = _a.httpAgent, httpsAgent = _a.httpsAgent; | ||
var keepAlive = true; | ||
var maxSockets = 50; | ||
this.httpAgent = httpAgent || new hAgent({ keepAlive: keepAlive, maxSockets: maxSockets }); | ||
this.httpsAgent = httpsAgent || new hsAgent({ keepAlive: keepAlive, maxSockets: maxSockets }); | ||
} | ||
return { | ||
connectionTimeout: connectionTimeout, | ||
socketTimeout: socketTimeout, | ||
httpAgent: httpAgent || new hAgent({ keepAlive: keepAlive, maxSockets: maxSockets }), | ||
httpsAgent: httpsAgent || new hsAgent({ keepAlive: keepAlive, maxSockets: maxSockets }), | ||
}; | ||
}; | ||
NodeHttpHandler.prototype.destroy = function () { | ||
this.httpAgent.destroy(); | ||
this.httpsAgent.destroy(); | ||
var _a, _b, _c, _d; | ||
(_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.httpAgent) === null || _b === void 0 ? void 0 : _b.destroy(); | ||
(_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.httpsAgent) === null || _d === void 0 ? void 0 : _d.destroy(); | ||
}; | ||
NodeHttpHandler.prototype.handle = function (request, _a) { | ||
var _this = this; | ||
var _b = _a === void 0 ? {} : _a, abortSignal = _b.abortSignal; | ||
return new Promise(function (resolve, reject) { | ||
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) { | ||
var abortError = new Error("Request aborted"); | ||
abortError.name = "AbortError"; | ||
reject(abortError); | ||
return; | ||
} | ||
var isSSL = request.protocol === "https:"; | ||
var queryString = buildQueryString(request.query || {}); | ||
var nodeHttpsOptions = { | ||
headers: request.headers, | ||
host: request.hostname, | ||
method: request.method, | ||
path: queryString ? request.path + "?" + queryString : request.path, | ||
port: request.port, | ||
agent: isSSL ? _this.httpsAgent : _this.httpAgent, | ||
}; | ||
var requestFunc = isSSL ? hsRequest : hRequest; | ||
var req = requestFunc(nodeHttpsOptions, function (res) { | ||
var httpResponse = new HttpResponse({ | ||
statusCode: res.statusCode || -1, | ||
headers: getTransformedHeaders(res.headers), | ||
body: res, | ||
}); | ||
resolve({ response: httpResponse }); | ||
}); | ||
req.on("error", function (err) { | ||
if (NODEJS_TIMEOUT_ERROR_CODES.includes(err.code)) { | ||
reject(Object.assign(err, { name: "TimeoutError" })); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _c; | ||
var _this = this; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
if (!(!this.config && this.configProvider)) return [3, 2]; | ||
_c = this; | ||
return [4, this.configProvider()]; | ||
case 1: | ||
_c.config = _d.sent(); | ||
_d.label = 2; | ||
case 2: return [2, new Promise(function (resolve, reject) { | ||
if (!_this.config) { | ||
throw new Error("Node HTTP request handler config is not resolved"); | ||
} | ||
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) { | ||
var abortError = new Error("Request aborted"); | ||
abortError.name = "AbortError"; | ||
reject(abortError); | ||
return; | ||
} | ||
var isSSL = request.protocol === "https:"; | ||
var queryString = buildQueryString(request.query || {}); | ||
var nodeHttpsOptions = { | ||
headers: request.headers, | ||
host: request.hostname, | ||
method: request.method, | ||
path: queryString ? request.path + "?" + queryString : request.path, | ||
port: request.port, | ||
agent: isSSL ? _this.config.httpsAgent : _this.config.httpAgent, | ||
}; | ||
var requestFunc = isSSL ? hsRequest : hRequest; | ||
var req = requestFunc(nodeHttpsOptions, function (res) { | ||
var httpResponse = new HttpResponse({ | ||
statusCode: res.statusCode || -1, | ||
headers: getTransformedHeaders(res.headers), | ||
body: res, | ||
}); | ||
resolve({ response: httpResponse }); | ||
}); | ||
req.on("error", function (err) { | ||
if (NODEJS_TIMEOUT_ERROR_CODES.includes(err.code)) { | ||
reject(Object.assign(err, { name: "TimeoutError" })); | ||
} | ||
else { | ||
reject(err); | ||
} | ||
}); | ||
setConnectionTimeout(req, reject, _this.config.connectionTimeout); | ||
setSocketTimeout(req, reject, _this.config.socketTimeout); | ||
if (abortSignal) { | ||
abortSignal.onabort = function () { | ||
req.abort(); | ||
var abortError = new Error("Request aborted"); | ||
abortError.name = "AbortError"; | ||
reject(abortError); | ||
}; | ||
} | ||
writeRequestBody(req, request); | ||
})]; | ||
} | ||
else { | ||
reject(err); | ||
} | ||
}); | ||
setConnectionTimeout(req, reject, _this.connectionTimeout); | ||
setSocketTimeout(req, reject, _this.socketTimeout); | ||
if (abortSignal) { | ||
abortSignal.onabort = function () { | ||
req.abort(); | ||
var abortError = new Error("Request aborted"); | ||
abortError.name = "AbortError"; | ||
reject(abortError); | ||
}; | ||
} | ||
writeRequestBody(req, request); | ||
}); | ||
@@ -75,0 +115,0 @@ }; |
/// <reference types="node" /> | ||
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; | ||
import { HttpHandlerOptions } from "@aws-sdk/types"; | ||
import { HttpHandlerOptions, Provider } from "@aws-sdk/types"; | ||
import { Agent as hAgent } from "http"; | ||
@@ -24,10 +24,9 @@ import { Agent as hsAgent } from "https"; | ||
export declare class NodeHttpHandler implements HttpHandler { | ||
private readonly httpAgent; | ||
private readonly httpsAgent; | ||
private readonly connectionTimeout?; | ||
private readonly socketTimeout?; | ||
private config?; | ||
private readonly configProvider?; | ||
readonly metadata: { | ||
handlerProtocol: string; | ||
}; | ||
constructor({ connectionTimeout, socketTimeout, httpAgent, httpsAgent }?: NodeHttpHandlerOptions); | ||
constructor(options?: NodeHttpHandlerOptions | Provider<NodeHttpHandlerOptions | void>); | ||
private resolveDefaultConfig; | ||
destroy(): void; | ||
@@ -34,0 +33,0 @@ handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{ |
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; | ||
import { HttpHandlerOptions } from "@aws-sdk/types"; | ||
import { HttpHandlerOptions, Provider } from "@aws-sdk/types"; | ||
import { Agent as hAgent } from "http"; | ||
@@ -16,10 +16,9 @@ import { Agent as hsAgent } from "https"; | ||
export declare class NodeHttpHandler implements HttpHandler { | ||
private readonly httpAgent; | ||
private readonly httpsAgent; | ||
private readonly connectionTimeout?; | ||
private readonly socketTimeout?; | ||
private config?; | ||
private readonly configProvider?; | ||
readonly metadata: { | ||
handlerProtocol: string; | ||
}; | ||
constructor({ connectionTimeout, socketTimeout, httpAgent, httpsAgent }?: NodeHttpHandlerOptions); | ||
constructor(options?: NodeHttpHandlerOptions | Provider<NodeHttpHandlerOptions | void>); | ||
private resolveDefaultConfig; | ||
destroy(): void; | ||
@@ -26,0 +25,0 @@ handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{ |
{ | ||
"name": "@aws-sdk/node-http-handler", | ||
"version": "3.46.0", | ||
"version": "3.47.0", | ||
"description": "Provides a way to make requests", | ||
@@ -11,2 +11,3 @@ "scripts": { | ||
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4", | ||
"clean": "rimraf ./dist-*", | ||
"test": "jest --coverage" | ||
@@ -24,6 +25,6 @@ }, | ||
"dependencies": { | ||
"@aws-sdk/abort-controller": "3.46.0", | ||
"@aws-sdk/protocol-http": "3.46.0", | ||
"@aws-sdk/querystring-builder": "3.46.0", | ||
"@aws-sdk/types": "3.46.0", | ||
"@aws-sdk/abort-controller": "3.47.0", | ||
"@aws-sdk/protocol-http": "3.47.0", | ||
"@aws-sdk/querystring-builder": "3.47.0", | ||
"@aws-sdk/types": "3.47.0", | ||
"tslib": "^2.3.0" | ||
@@ -30,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
111973
1185
+ Added@aws-sdk/abort-controller@3.47.0(transitive)
+ Added@aws-sdk/protocol-http@3.47.0(transitive)
+ Added@aws-sdk/querystring-builder@3.47.0(transitive)
+ Added@aws-sdk/types@3.47.0(transitive)
+ Added@aws-sdk/util-uri-escape@3.47.0(transitive)
- Removed@aws-sdk/abort-controller@3.46.0(transitive)
- Removed@aws-sdk/protocol-http@3.46.0(transitive)
- Removed@aws-sdk/querystring-builder@3.46.0(transitive)
- Removed@aws-sdk/types@3.46.0(transitive)
- Removed@aws-sdk/util-uri-escape@3.46.0(transitive)
Updated@aws-sdk/types@3.47.0