Socket
Socket
Sign inDemoInstall

wreck

Package Overview
Dependencies
2
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 4.0.0

16

lib/index.js

@@ -20,2 +20,8 @@

exports.agents = {
https: new Https.Agent({ maxSockets: Infinity }),
http: new Http.Agent({ maxSockets: Infinity })
};
exports.request = function (method, url, options, callback, _trace) {

@@ -25,3 +31,5 @@

Hoek.assert(options.payload === null || options.payload === undefined || typeof options.payload === 'string' || options.payload instanceof Stream || Buffer.isBuffer(options.payload), 'options.payload must be a string, a Buffer, or a Stream');
Hoek.assert(options.payload === null || options.payload === undefined || typeof options.payload === 'string' ||
options.payload instanceof Stream || Buffer.isBuffer(options.payload),
'options.payload must be a string, a Buffer, or a Stream');

@@ -53,5 +61,9 @@ // Setup request

var client = (uri.protocol === 'https:' ? Https : Http);
if (options.agent) {
if (options.agent || options.agent === false) {
uri.agent = options.agent;
}
else {
uri.agent = uri.protocol === 'https:' ? exports.agents.https : exports.agents.http;
}

@@ -58,0 +70,0 @@ var req = client.request(uri);

2

package.json
{
"name": "wreck",
"description": "HTTP Client Utilities",
"version": "3.0.0",
"version": "4.0.0",
"repository": "git://github.com/hapijs/wreck",

@@ -6,0 +6,0 @@ "main": "index",

@@ -41,2 +41,4 @@ ![wreck Logo](https://raw.github.com/hapijs/wreck/master/images/wreck.png)

/* handle err if it exists, in which case res will be undefined */
// buffer the response stream

@@ -66,2 +68,3 @@ Wreck.read(res, null, function (err, body) {

- `agent` - Node Core [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent).
Defaults to either `wreck.agents.http` or `wreck.agents.https`. Setting to `false` disables agent pooling.
- `timeout` - The number of milliseconds to wait without receiving a response

@@ -161,1 +164,13 @@ before aborting the request. Defaults to unlimited.

```
### `agents`
Object that contains the default `http` and `https` agents to use when making requests. Both agents have `maxSockets`
configured to `Infinity`. Both agents are instances of the node.js [Agent](http://nodejs.org/api/http.html#http_class_http_agent)
and expose the standard properties. For example, the following code demonstrates changing `maxSockets` on the `http` agent.
```js
var Wreck = require('wreck');
Wreck.agents.http.maxSockets = 20;
```

@@ -550,2 +550,51 @@ // Load modules

it('pooling can be disable by setting agent to false', function (done) {
var complete;
var server = Http.createServer(function (req, res) {
res.writeHead(200);
res.write('foo');
complete = complete || function () {
res.end();
};
});
server.listen(0, function () {
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0);
Wreck.request('get', 'http://localhost:' + server.address().port, { agent: false, timeout: 15 }, function (err, res) {
expect(err).to.not.exist;
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0);
expect(Object.keys(Wreck.agents.http.requests).length).to.equal(0);
Wreck.request('get', 'http://localhost:' + server.address().port + '/thatone', { agent: false, timeout: 15 }, function (err, innerRes) {
expect(err).to.not.exist;
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0);
expect(Object.keys(Wreck.agents.http.requests).length).to.equal(0);
complete();
Wreck.read(res, null, function () {
setTimeout(function () {
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0);
expect(Object.keys(Wreck.agents.http.requests).length).to.equal(0);
done();
}, 100);
});
});
});
});
});
it('requests payload in buffer', function (done) {

@@ -699,2 +748,63 @@

});
it('defaults maxSockets to Infinity', function (done) {
var server = Http.createServer(function (req, res) {
res.writeHead(200);
res.write(payload);
res.end();
});
server.listen(0, function () {
Wreck.request('get', 'http://localhost:' + server.address().port, { timeout: 100 }, function (err, res) {
expect(err).to.not.exist;
expect(res.statusCode).to.equal(200);
expect(Wreck.agents.http.maxSockets).to.equal(Infinity);
done();
});
});
});
it('maxSockets on default agents can be changed', function (done) {
var complete;
var server = Http.createServer(function (req, res) {
res.writeHead(200);
res.write('foo');
complete = complete || function () {
res.end();
};
});
server.listen(0, function () {
Wreck.agents.http.maxSockets = 1;
Wreck.request('get', 'http://localhost:' + server.address().port, { timeout: 15 }, function (err, res) {
expect(err).to.not.exist;
Wreck.request('get', 'http://localhost:' + server.address().port + '/thatone', { timeout: 15 }, function (err, innerRes) {
expect(err).to.exist;
expect(err.output.statusCode).to.equal(504);
complete();
Wreck.read(res, null, function () {
Wreck.agents.http.maxSockets = Infinity;
done();
});
});
});
});
});
});

@@ -701,0 +811,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc