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 3.0.0 to 4.0.0

13

History.md
4.0.0 / 2017-06-06
==================
* drop support for Node.js < 4
* drop old versions of Node.js from Travis-CI
* specify Node.js >= 4.0.0 in `engines.node`
* remove more old code
* remove "extend" dependency
* remove "semver" dependency
* make the Promise logic a bit cleaner
* add async function pseudo-example to README
* use direct return in README example
3.0.0 / 2017-06-02

@@ -3,0 +16,0 @@ ==================

76

index.js

@@ -0,1 +1,3 @@

'use strict';
/**

@@ -6,6 +8,5 @@ * Module dependencies.

require('./patch-core');
var extend = require('extend');
var inherits = require('util').inherits;
var promisify = require('es6-promisify');
var EventEmitter = require('events').EventEmitter;
const inherits = require('util').inherits;
const promisify = require('es6-promisify');
const EventEmitter = require('events').EventEmitter;

@@ -33,3 +34,3 @@ /**

var opts = _opts;
let opts = _opts;
if ('function' === typeof callback) {

@@ -69,17 +70,5 @@ this.callback = callback;

req,
host,
port,
localAddress
_opts
) {
var opts;
if ('object' == typeof host) {
// >= v0.11.x API
opts = extend({}, req._options, host);
} else {
// <= v0.10.x API
opts = extend({}, req._options, { host: host, port: port });
if (null != localAddress) {
opts.localAddress = localAddress;
}
}
const opts = Object.assign({}, _opts);

@@ -93,3 +82,3 @@ if (opts.host && opts.path) {

// set default `port` if none was explicitly specified
// set default `port` for HTTP if none was explicitly specified
if (null == opts.port) {

@@ -110,9 +99,6 @@ opts.port = opts.secureEndpoint ? 443 : 80;

// clean up a bit of memory since we're no longer using this
req._options = null;
// create the `stream.Duplex` instance
var timeout;
var timedOut = false;
var timeoutMs = this.timeout;
let timeout;
let timedOut = false;
const timeoutMs = this.timeout;

@@ -129,3 +115,3 @@ function onerror(err) {

timedOut = true;
var err = new Error(
const err = new Error(
'A "socket" was not created for HTTP request before ' + timeoutMs + 'ms'

@@ -137,2 +123,18 @@ );

function callbackError(err) {
if (timedOut) return;
if (timeout != null) {
clearTimeout(timeout);
}
onerror(err);
}
function onsocket(socket) {
if (timedOut) return;
if (timeout != null) {
clearTimeout(timeout);
}
req.onSocket(socket);
}
if (timeoutMs > 0) {

@@ -144,21 +146,7 @@ timeout = setTimeout(ontimeout, timeoutMs);

Promise.resolve(this.callback(req, opts))
.then(function(socket) {
if (timedOut) return;
if (timeout != null) {
clearTimeout(timeout);
}
req.onSocket(socket);
})
.catch(function(err) {
if (timedOut) return;
if (timeout != null) {
clearTimeout(timeout);
}
onerror(err);
});
.then(onsocket, callbackError);
} catch (err) {
process.nextTick(function() {
onerror(err);
});
Promise.reject(err)
.catch(callbackError);
}
};
{
"name": "agent-base",
"version": "3.0.0",
"version": "4.0.0",
"description": "Turn a function into an `http.Agent` instance",

@@ -30,9 +30,7 @@ "main": "./index.js",

"dependencies": {
"es6-promisify": "^5.0.0",
"extend": "~3.0.0",
"semver": "~5.0.1"
"es6-promisify": "^5.0.0"
},
"engines": {
"node": ">= 0.12.0"
"node": ">= 4.0.0"
}
}

@@ -1,51 +0,21 @@

var url = require('url');
var http = require('http');
var https = require('https');
var semver = require('semver');
var inherits = require('util').inherits;
'use strict';
const url = require('url');
const http = require('http');
const https = require('https');
// we only need to patch the `http.request()` and
// `http.ClientRequest` on older versions of Node.js
if (semver.lt(process.version, '0.11.8')) {
// subclass the native ClientRequest to include the
// passed in `options` object.
http.ClientRequest = (function (_ClientRequest) {
function ClientRequest (options, cb) {
this._options = options;
_ClientRequest.call(this, options, cb);
}
inherits(ClientRequest, _ClientRequest);
return ClientRequest;
})(http.ClientRequest);
// need to re-define the `request()` method, since on node v0.8/v0.10
// the closure-local ClientRequest is used, rather than the monkey
// patched version we have created here.
http.request = (function (request) {
return function (options, cb) {
if (typeof options === 'string') {
options = url.parse(options);
}
if (options.protocol && options.protocol !== 'http:') {
throw new Error('Protocol:' + options.protocol + ' not supported.');
}
return new http.ClientRequest(options, cb);
};
})(http.request);
}
// this currently needs to be applied to all Node.js versions
// (v0.8.x, v0.10.x, v0.12.x), in order to determine if the `req`
// is an HTTP or HTTPS request. There is currently no PR attempting
// to move this property upstream.
https.request = (function (request) {
return function (options, cb) {
/**
* This currently needs to be applied to all Node.js versions
* in order to determine if the `req` is an HTTP or HTTPS request.
*
* There is currently no PR attempting to move this property upstream.
*/
https.request = (function(request) {
return function(options, cb) {
if (typeof options === 'string') {
options = url.parse(options);
}
if (null == options.port) options.port = 443;
if (null == options.port) {
options.port = 443;
}
options.secureEndpoint = true;

@@ -52,0 +22,0 @@ return request.call(https, options, cb);

@@ -37,3 +37,3 @@ agent-base

``` js
```js
var net = require('net');

@@ -49,3 +49,3 @@ var tls = require('tls');

// This is the important part!
parsed.agent = agent(function (req, opts, fn) {
parsed.agent = agent(function (req, opts) {
var socket;

@@ -58,3 +58,3 @@ // `secureEndpoint` is true when using the https module

}
fn(null, socket);
return socket;
});

@@ -69,2 +69,12 @@

You can also return a Promise or use an `async` function:
```js
agent(async function (req, opts) {
await sleep(1000);
// etc…
});
```
API

@@ -71,0 +81,0 @@ ---

@@ -15,3 +15,2 @@ /**

var inherits = require('util').inherits;
var semver = require('semver');
var Agent = require('../');

@@ -18,0 +17,0 @@

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