Socket
Socket
Sign inDemoInstall

agent-base

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agent-base - npm Package Compare versions

Comparing version 7.0.2 to 7.1.0

59

./dist/index.js

@@ -32,11 +32,2 @@ "use strict";

__exportStar(require("./helpers"), exports);
function isSecureEndpoint() {
const { stack } = new Error();
if (typeof stack !== 'string')
return false;
return stack
.split('\n')
.some((l) => l.indexOf('(https.js:') !== -1 ||
l.indexOf('node:https:') !== -1);
}
const INTERNAL = Symbol('AgentBaseInternalState');

@@ -48,15 +39,19 @@ class Agent extends http.Agent {

}
createSocket(req, options, cb) {
// Need to determine whether this is an `http` or `https` request.
// First check the `secureEndpoint` property explicitly, since this
// means that a parent `Agent` is "passing through" to this instance.
let secureEndpoint = typeof options.secureEndpoint === 'boolean'
? options.secureEndpoint
: undefined;
// If no explicit `secure` endpoint, check if `protocol` property is
// set. This will usually be the case since using a full string URL
// or `URL` instance should be the most common case.
if (typeof secureEndpoint === 'undefined' &&
typeof options.protocol === 'string') {
secureEndpoint = options.protocol === 'https:';
/**
* Determine whether this is an `http` or `https` request.
*/
isSecureEndpoint(options) {
if (options) {
// First check the `secureEndpoint` property explicitly, since this
// means that a parent `Agent` is "passing through" to this instance.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (typeof options.secureEndpoint === 'boolean') {
return options.secureEndpoint;
}
// If no explicit `secure` endpoint, check if `protocol` property is
// set. This will usually be the case since using a full string URL
// or `URL` instance should be the most common usage.
if (typeof options.protocol === 'string') {
return options.protocol === 'https:';
}
}

@@ -66,6 +61,15 @@ // Finally, if no `protocol` property was set, then fall back to

// detect the "https" module.
if (typeof secureEndpoint === 'undefined') {
secureEndpoint = isSecureEndpoint();
}
const connectOpts = { ...options, secureEndpoint };
const { stack } = new Error();
if (typeof stack !== 'string')
return false;
return stack
.split('\n')
.some((l) => l.indexOf('(https.js:') !== -1 ||
l.indexOf('node:https:') !== -1);
}
createSocket(req, options, cb) {
const connectOpts = {
...options,
secureEndpoint: this.isSecureEndpoint(options),
};
Promise.resolve()

@@ -101,3 +105,4 @@ .then(() => this.connect(req, connectOpts))

get protocol() {
return (this[INTERNAL].protocol ?? (isSecureEndpoint() ? 'https:' : 'http:'));
return (this[INTERNAL].protocol ??
(this.isSecureEndpoint() ? 'https:' : 'http:'));
}

@@ -104,0 +109,0 @@ set protocol(v) {

@@ -8,3 +8,3 @@ /// <reference types="node" />

import * as http from 'http';
import { Duplex } from 'stream';
import type { Duplex } from 'stream';
export * from './helpers';

@@ -28,2 +28,6 @@ interface HttpConnectOpts extends net.TcpNetConnectOpts {

abstract connect(req: http.ClientRequest, options: AgentConnectOpts): Promise<Duplex | http.Agent> | Duplex | http.Agent;
/**
* Determine whether this is an `http` or `https` request.
*/
isSecureEndpoint(options?: AgentConnectOpts): boolean;
createSocket(req: http.ClientRequest, options: AgentConnectOpts, cb: (err: Error | null, s?: Duplex) => void): void;

@@ -30,0 +34,0 @@ createConnection(): Duplex;

@@ -32,11 +32,2 @@ "use strict";

__exportStar(require("./helpers"), exports);
function isSecureEndpoint() {
const { stack } = new Error();
if (typeof stack !== 'string')
return false;
return stack
.split('\n')
.some((l) => l.indexOf('(https.js:') !== -1 ||
l.indexOf('node:https:') !== -1);
}
const INTERNAL = Symbol('AgentBaseInternalState');

@@ -48,15 +39,19 @@ class Agent extends http.Agent {

}
createSocket(req, options, cb) {
// Need to determine whether this is an `http` or `https` request.
// First check the `secureEndpoint` property explicitly, since this
// means that a parent `Agent` is "passing through" to this instance.
let secureEndpoint = typeof options.secureEndpoint === 'boolean'
? options.secureEndpoint
: undefined;
// If no explicit `secure` endpoint, check if `protocol` property is
// set. This will usually be the case since using a full string URL
// or `URL` instance should be the most common case.
if (typeof secureEndpoint === 'undefined' &&
typeof options.protocol === 'string') {
secureEndpoint = options.protocol === 'https:';
/**
* Determine whether this is an `http` or `https` request.
*/
isSecureEndpoint(options) {
if (options) {
// First check the `secureEndpoint` property explicitly, since this
// means that a parent `Agent` is "passing through" to this instance.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (typeof options.secureEndpoint === 'boolean') {
return options.secureEndpoint;
}
// If no explicit `secure` endpoint, check if `protocol` property is
// set. This will usually be the case since using a full string URL
// or `URL` instance should be the most common usage.
if (typeof options.protocol === 'string') {
return options.protocol === 'https:';
}
}

@@ -66,6 +61,15 @@ // Finally, if no `protocol` property was set, then fall back to

// detect the "https" module.
if (typeof secureEndpoint === 'undefined') {
secureEndpoint = isSecureEndpoint();
}
const connectOpts = { ...options, secureEndpoint };
const { stack } = new Error();
if (typeof stack !== 'string')
return false;
return stack
.split('\n')
.some((l) => l.indexOf('(https.js:') !== -1 ||
l.indexOf('node:https:') !== -1);
}
createSocket(req, options, cb) {
const connectOpts = {
...options,
secureEndpoint: this.isSecureEndpoint(options),
};
Promise.resolve()

@@ -101,3 +105,4 @@ .then(() => this.connect(req, connectOpts))

get protocol() {
return (this[INTERNAL].protocol ?? (isSecureEndpoint() ? 'https:' : 'http:'));
return (this[INTERNAL].protocol ??
(this.isSecureEndpoint() ? 'https:' : 'http:'));
}

@@ -104,0 +109,0 @@ set protocol(v) {

{
"name": "agent-base",
"version": "7.0.2",
"version": "7.1.0",
"description": "Turn a function into an `http.Agent` instance",

@@ -33,3 +33,3 @@ "main": "./dist/index.js",

"@types/ws": "^6.0.4",
"async-listen": "^2.1.0",
"async-listen": "^3.0.0",
"jest": "^29.5.0",

@@ -36,0 +36,0 @@ "ts-jest": "^29.1.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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