Socket
Socket
Sign inDemoInstall

@aws-sdk/node-http-handler

Package Overview
Dependencies
Maintainers
5
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-sdk/node-http-handler - npm Package Compare versions

Comparing version 3.78.0 to 3.82.0

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [3.82.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.81.0...v3.82.0) (2022-05-02)
**Note:** Version bump only for package @aws-sdk/node-http-handler
# [3.78.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.77.0...v3.78.0) (2022-04-26)

@@ -8,0 +16,0 @@

38

dist-cjs/node-http2-handler.js

@@ -10,7 +10,16 @@ "use strict";

class NodeHttp2Handler {
constructor({ requestTimeout, sessionTimeout, disableConcurrentStreams } = {}) {
constructor(options) {
this.metadata = { handlerProtocol: "h2" };
this.requestTimeout = requestTimeout;
this.sessionTimeout = sessionTimeout;
this.disableConcurrentStreams = disableConcurrentStreams;
this.configProvider = new Promise((resolve, reject) => {
if (typeof options === "function") {
options()
.then((opts) => {
resolve(opts || {});
})
.catch(reject);
}
else {
resolve(options || {});
}
});
this.sessionCache = new Map();

@@ -24,3 +33,7 @@ }

}
handle(request, { abortSignal } = {}) {
async handle(request, { abortSignal } = {}) {
if (!this.config) {
this.config = await this.configProvider;
}
const { requestTimeout, disableConcurrentStreams } = this.config;
return new Promise((resolve, rejectOriginal) => {

@@ -37,5 +50,5 @@ let fulfilled = false;

const authority = `${protocol}//${hostname}${port ? `:${port}` : ""}`;
const session = this.getSession(authority, this.disableConcurrentStreams || false);
const session = this.getSession(authority, disableConcurrentStreams || false);
const reject = (err) => {
if (this.disableConcurrentStreams) {
if (disableConcurrentStreams) {
this.destroySession(session);

@@ -61,3 +74,3 @@ }

resolve({ response: httpResponse });
if (this.disableConcurrentStreams) {
if (disableConcurrentStreams) {
session.close();

@@ -67,3 +80,2 @@ this.deleteSessionFromCache(authority, session);

});
const requestTimeout = this.requestTimeout;
if (requestTimeout) {

@@ -94,3 +106,3 @@ req.setTimeout(requestTimeout, () => {

session.unref();
if (this.disableConcurrentStreams) {
if (disableConcurrentStreams) {
session.destroy();

@@ -106,2 +118,3 @@ }

getSession(authority, disableConcurrentStreams) {
var _a;
const sessionCache = this.sessionCache;

@@ -120,5 +133,4 @@ const existingSessions = sessionCache.get(authority) || [];

newSession.on("frameError", destroySessionCb);
const sessionTimeout = this.sessionTimeout;
if (sessionTimeout) {
newSession.setTimeout(sessionTimeout, destroySessionCb);
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.sessionTimeout) {
newSession.setTimeout(this.config.sessionTimeout, destroySessionCb);
}

@@ -125,0 +137,0 @@ existingSessions.push(newSession);

@@ -1,2 +0,2 @@

import { __assign, __values } from "tslib";
import { __assign, __awaiter, __generator, __values } from "tslib";
import { HttpResponse } from "@aws-sdk/protocol-http";

@@ -8,8 +8,16 @@ import { buildQueryString } from "@aws-sdk/querystring-builder";

var NodeHttp2Handler = (function () {
function NodeHttp2Handler(_a) {
var _b = _a === void 0 ? {} : _a, requestTimeout = _b.requestTimeout, sessionTimeout = _b.sessionTimeout, disableConcurrentStreams = _b.disableConcurrentStreams;
function NodeHttp2Handler(options) {
this.metadata = { handlerProtocol: "h2" };
this.requestTimeout = requestTimeout;
this.sessionTimeout = sessionTimeout;
this.disableConcurrentStreams = disableConcurrentStreams;
this.configProvider = new Promise(function (resolve, reject) {
if (typeof options === "function") {
options()
.then(function (opts) {
resolve(opts || {});
})
.catch(reject);
}
else {
resolve(options || {});
}
});
this.sessionCache = new Map();

@@ -36,74 +44,89 @@ }

NodeHttp2Handler.prototype.handle = function (request, _a) {
var _this = this;
var _b = _a === void 0 ? {} : _a, abortSignal = _b.abortSignal;
return new Promise(function (resolve, rejectOriginal) {
var _a;
var fulfilled = false;
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
fulfilled = true;
var abortError = new Error("Request aborted");
abortError.name = "AbortError";
rejectOriginal(abortError);
return;
}
var hostname = request.hostname, method = request.method, port = request.port, protocol = request.protocol, path = request.path, query = request.query;
var authority = "".concat(protocol, "//").concat(hostname).concat(port ? ":".concat(port) : "");
var session = _this.getSession(authority, _this.disableConcurrentStreams || false);
var reject = function (err) {
if (_this.disableConcurrentStreams) {
_this.destroySession(session);
return __awaiter(this, void 0, void 0, function () {
var _c, _d, requestTimeout, disableConcurrentStreams;
var _this = this;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
if (!!this.config) return [3, 2];
_c = this;
return [4, this.configProvider];
case 1:
_c.config = _e.sent();
_e.label = 2;
case 2:
_d = this.config, requestTimeout = _d.requestTimeout, disableConcurrentStreams = _d.disableConcurrentStreams;
return [2, new Promise(function (resolve, rejectOriginal) {
var _a;
var fulfilled = false;
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
fulfilled = true;
var abortError = new Error("Request aborted");
abortError.name = "AbortError";
rejectOriginal(abortError);
return;
}
var hostname = request.hostname, method = request.method, port = request.port, protocol = request.protocol, path = request.path, query = request.query;
var authority = "".concat(protocol, "//").concat(hostname).concat(port ? ":".concat(port) : "");
var session = _this.getSession(authority, disableConcurrentStreams || false);
var reject = function (err) {
if (disableConcurrentStreams) {
_this.destroySession(session);
}
fulfilled = true;
rejectOriginal(err);
};
var queryString = buildQueryString(query || {});
var req = session.request(__assign(__assign({}, request.headers), (_a = {}, _a[constants.HTTP2_HEADER_PATH] = queryString ? "".concat(path, "?").concat(queryString) : path, _a[constants.HTTP2_HEADER_METHOD] = method, _a)));
session.ref();
req.on("response", function (headers) {
var httpResponse = new HttpResponse({
statusCode: headers[":status"] || -1,
headers: getTransformedHeaders(headers),
body: req,
});
fulfilled = true;
resolve({ response: httpResponse });
if (disableConcurrentStreams) {
session.close();
_this.deleteSessionFromCache(authority, session);
}
});
if (requestTimeout) {
req.setTimeout(requestTimeout, function () {
req.close();
var timeoutError = new Error("Stream timed out because of no activity for ".concat(requestTimeout, " ms"));
timeoutError.name = "TimeoutError";
reject(timeoutError);
});
}
if (abortSignal) {
abortSignal.onabort = function () {
req.close();
var abortError = new Error("Request aborted");
abortError.name = "AbortError";
reject(abortError);
};
}
req.on("frameError", function (type, code, id) {
reject(new Error("Frame type id ".concat(type, " in stream id ").concat(id, " has failed with code ").concat(code, ".")));
});
req.on("error", reject);
req.on("aborted", function () {
reject(new Error("HTTP/2 stream is abnormally aborted in mid-communication with result code ".concat(req.rstCode, ".")));
});
req.on("close", function () {
session.unref();
if (disableConcurrentStreams) {
session.destroy();
}
if (!fulfilled) {
reject(new Error("Unexpected error: http2 request did not get a response"));
}
});
writeRequestBody(req, request);
})];
}
fulfilled = true;
rejectOriginal(err);
};
var queryString = buildQueryString(query || {});
var req = session.request(__assign(__assign({}, request.headers), (_a = {}, _a[constants.HTTP2_HEADER_PATH] = queryString ? "".concat(path, "?").concat(queryString) : path, _a[constants.HTTP2_HEADER_METHOD] = method, _a)));
session.ref();
req.on("response", function (headers) {
var httpResponse = new HttpResponse({
statusCode: headers[":status"] || -1,
headers: getTransformedHeaders(headers),
body: req,
});
fulfilled = true;
resolve({ response: httpResponse });
if (_this.disableConcurrentStreams) {
session.close();
_this.deleteSessionFromCache(authority, session);
}
});
var requestTimeout = _this.requestTimeout;
if (requestTimeout) {
req.setTimeout(requestTimeout, function () {
req.close();
var timeoutError = new Error("Stream timed out because of no activity for ".concat(requestTimeout, " ms"));
timeoutError.name = "TimeoutError";
reject(timeoutError);
});
}
if (abortSignal) {
abortSignal.onabort = function () {
req.close();
var abortError = new Error("Request aborted");
abortError.name = "AbortError";
reject(abortError);
};
}
req.on("frameError", function (type, code, id) {
reject(new Error("Frame type id ".concat(type, " in stream id ").concat(id, " has failed with code ").concat(code, ".")));
});
req.on("error", reject);
req.on("aborted", function () {
reject(new Error("HTTP/2 stream is abnormally aborted in mid-communication with result code ".concat(req.rstCode, ".")));
});
req.on("close", function () {
session.unref();
if (_this.disableConcurrentStreams) {
session.destroy();
}
if (!fulfilled) {
reject(new Error("Unexpected error: http2 request did not get a response"));
}
});
writeRequestBody(req, request);
});

@@ -113,2 +136,3 @@ };

var _this = this;
var _a;
var sessionCache = this.sessionCache;

@@ -127,5 +151,4 @@ var existingSessions = sessionCache.get(authority) || [];

newSession.on("frameError", destroySessionCb);
var sessionTimeout = this.sessionTimeout;
if (sessionTimeout) {
newSession.setTimeout(sessionTimeout, destroySessionCb);
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.sessionTimeout) {
newSession.setTimeout(this.config.sessionTimeout, destroySessionCb);
}

@@ -132,0 +155,0 @@ existingSessions.push(newSession);

import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
import { HttpHandlerOptions } from "@aws-sdk/types";
import { HttpHandlerOptions, Provider } from "@aws-sdk/types";
/**

@@ -27,5 +27,4 @@ * Represents the http2 options that can be passed to a node http2 client.

export declare class NodeHttp2Handler implements HttpHandler {
private readonly requestTimeout?;
private readonly sessionTimeout?;
private readonly disableConcurrentStreams?;
private config?;
private readonly configProvider;
readonly metadata: {

@@ -35,3 +34,3 @@ handlerProtocol: string;

private sessionCache;
constructor({ requestTimeout, sessionTimeout, disableConcurrentStreams }?: NodeHttp2HandlerOptions);
constructor(options?: NodeHttp2HandlerOptions | Provider<NodeHttp2HandlerOptions | void>);
destroy(): void;

@@ -38,0 +37,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";

@@ -13,5 +13,4 @@ export interface NodeHttp2HandlerOptions {

export declare class NodeHttp2Handler implements HttpHandler {
private readonly requestTimeout?;
private readonly sessionTimeout?;
private readonly disableConcurrentStreams?;
private config?;
private readonly configProvider;
readonly metadata: {

@@ -21,3 +20,3 @@ handlerProtocol: string;

private sessionCache;
constructor({ requestTimeout, sessionTimeout, disableConcurrentStreams }?: NodeHttp2HandlerOptions);
constructor(options?: NodeHttp2HandlerOptions | Provider<NodeHttp2HandlerOptions | void>);
destroy(): void;

@@ -24,0 +23,0 @@ handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{

{
"name": "@aws-sdk/node-http-handler",
"version": "3.78.0",
"version": "3.82.0",
"description": "Provides a way to make requests",

@@ -5,0 +5,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc