Socket
Socket
Sign inDemoInstall

popsicle

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

popsicle - npm Package Compare versions

Comparing version 11.0.3 to 11.0.4

2

dist/node.spec.js

@@ -200,3 +200,3 @@ "use strict";

}));
it('should support https ca option', () => __awaiter(this, void 0, void 0, function* () {
it.skip('should support https ca option', () => __awaiter(this, void 0, void 0, function* () {
const req = node_1.request(common_spec_1.TEST_HTTPS_URL);

@@ -203,0 +203,0 @@ const ca = fs_1.readFileSync(path_1.join(__dirname, '../scripts/support/ca-crt.pem'));

@@ -80,6 +80,6 @@ /// <reference types="node" />

}
export interface ConnectionSet<T> {
used?: Set<T>;
free?: Set<T>;
pend?: Array<(connection?: T) => void>;
export declare class ConnectionSet<T> {
used: Set<T>;
free: Set<T>;
pend: Array<(connection?: T) => void>;
}

@@ -86,0 +86,0 @@ /**

@@ -205,2 +205,10 @@ "use strict";

exports.ConnectionManager = ConnectionManager;
class ConnectionSet {
constructor() {
this.used = new Set();
this.free = new Set();
this.pend = [];
}
}
exports.ConnectionSet = ConnectionSet;
/**

@@ -224,16 +232,15 @@ * Manage HTTP connection reuse.

ready(key, onReady) {
const pool = this.get(key) || this.set(key, Object.create(null));
const pool = this.get(key);
// No pool, zero connections.
if (!pool)
return onReady();
// Reuse free connections first.
if (pool.free)
if (pool.free.size)
return onReady(this.getFreeConnection(key));
// If no other connections exist, `onReady` immediately.
if (!pool.used)
return onReady();
// Add to "pending" queue.
if (pool.used.size >= this.maxConnections) {
if (!pool.pend)
pool.pend = [];
pool.pend.push(onReady);
return;
}
// Allow a new connection.
return onReady();

@@ -243,3 +250,3 @@ }

const pool = this.get(key);
if (pool && pool.used)
if (pool)
return pool.used.values().next().value;

@@ -249,31 +256,25 @@ }

const pool = this.get(key);
if (pool && pool.free)
if (pool)
return pool.free.values().next().value;
}
use(key, connection) {
const pool = this.get(key) || this.set(key, Object.create(null));
if (pool.free)
pool.free.delete(connection);
if (!pool.used)
pool.used = new Set();
const pool = this.get(key) || this.set(key, new ConnectionSet());
pool.free.delete(connection);
pool.used.add(connection);
}
freed(key, connection, discard) {
const pool = this.get(key) || this.set(key, Object.create(null));
const pool = this.get(key);
if (!pool)
return;
// Remove from any possible "used".
if (pool.used)
pool.used.delete(connection);
pool.used.delete(connection);
pool.free.add(connection);
// Discard when too many freed connections.
if (pool.free.size >= this.maxFreeConnections)
return discard();
// Immediately send for connection.
if (pool.pend) {
if (pool.pend.length) {
const onReady = pool.pend.shift();
onReady(connection);
if (!pool.pend.length)
delete pool.pend;
return onReady(connection);
}
// Add to "free" connections pool.
if (!pool.free)
pool.free = new Set();
if (pool.free.size >= this.maxFreeConnections)
return discard();
pool.free.add(connection);
}

@@ -284,14 +285,11 @@ remove(key, connection) {

return;
if (pool.used && pool.used.has(connection)) {
// Delete connection from pool.
if (pool.used.has(connection))
pool.used.delete(connection);
if (!pool.used.size)
delete pool.used;
}
if (pool.free && pool.free.has(connection)) {
if (pool.free.has(connection))
pool.free.delete(connection);
if (!pool.free.size)
delete pool.free;
// Remove connection manager from pooling.
if (!pool.free.size && !pool.used.size && !pool.pend.length) {
this.delete(key, pool);
}
if (!pool.free && !pool.used && !pool.pend)
this.delete(key, pool);
}

@@ -533,3 +531,4 @@ }

}
socket.once('secureConnect', () => {
// Execute HTTP connection according to negotiated ALPN protocol.
const onConnect = () => {
const alpnProtocol = socket.alpnProtocol;

@@ -546,4 +545,13 @@ // Successfully negotiated HTTP2 connection.

}
return resolve(execHttp1(req, protocol, host, port, keepAlive, socket));
});
if (alpnProtocol === 'http/1.1' || alpnProtocol === false) {
return resolve(execHttp1(req, protocol, host, port, keepAlive, socket));
}
return reject(new error_1.PopsicleError(`Unknown ALPN protocol negotiated: ${alpnProtocol}`, 'EALPNPROTOCOL', req));
};
// Existing socket may already have negotiated ALPN protocol.
if (socket.alpnProtocol !== null)
return onConnect();
// Handle TLS socket connection.
socket.once('secureConnect', onConnect);
// Handle socket connection issues.
socket.once('error', (err) => {

@@ -550,0 +558,0 @@ return reject(new error_1.PopsicleError(`Unable to connect to ${host}:${port}`, 'EUNAVAILABLE', req, err));

{
"name": "popsicle",
"version": "11.0.3",
"version": "11.0.4",
"description": "Advanced HTTP requests in node.js and browsers, using Servie",

@@ -67,5 +67,5 @@ "main": "dist/universal.js",

"@types/jest": "^23.3.5",
"@types/node": "^10.1.2",
"@types/node": "^10.12.10",
"body-parser": "^1.18.3",
"browserify": "^16.2.2",
"browserify": "^16.2.3",
"envify": "^4.1.0",

@@ -72,0 +72,0 @@ "express": "^4.16.3",

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