New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nipple

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nipple - npm Package Compare versions

Comparing version

to
2.5.5

AUTHORS

115

lib/index.js

@@ -8,5 +8,7 @@

var Stream = require('stream');
var Zlib = require('zlib');
var Hoek = require('hoek');
var Boom = require('boom');
var Payload = require('./payload');
var Recorder = require('./recorder');
var Tap = require('./tap');

@@ -126,3 +128,3 @@

return exports.request(redirectMethod, location, redirectOptions, finish, _trace);
}
};

@@ -145,3 +147,3 @@ req.once('response', onResponse);

if (redirects) {
var collector = new internals.Tap();
var collector = new Tap();
collector.once('finish', function () {

@@ -168,26 +170,2 @@

// Tap
internals.Tap = function () {
Stream.Transform.call(this);
this.buffers = [];
};
Hoek.inherits(internals.Tap, Stream.Transform);
internals.Tap.prototype._transform = function (chunk, encoding, next) {
this.buffers.push(chunk);
next(null, chunk);
};
internals.Tap.prototype.collect = function () {
return exports.toReadableStream(this.buffers);
};
// read()

@@ -269,3 +247,3 @@

var reader = new internals.Recorder({ maxBytes: options.maxBytes });
var reader = new Recorder({ maxBytes: options.maxBytes });

@@ -291,37 +269,2 @@ var onReaderError = function (err) {

// Recorder
internals.Recorder = function (options) {
Stream.Writable.call(this);
this.settings = options; // No need to clone since called internally with new object
this.buffers = [];
this.length = 0;
};
Hoek.inherits(internals.Recorder, Stream.Writable);
internals.Recorder.prototype._write = function (chunk, encoding, next) {
if (this.settings.maxBytes &&
this.length + chunk.length > this.settings.maxBytes) {
return this.emit('error', Boom.badRequest('Payload content length greater than maximum allowed: ' + this.settings.maxBytes));
}
this.length += chunk.length;
this.buffers.push(chunk);
next();
};
internals.Recorder.prototype.collect = function () {
var buffer = (this.buffers.length === 0 ? new Buffer(0) : (this.buffers.length === 1 ? this.buffers[0] : Buffer.concat(this.buffers, this.length)));
return buffer;
};
// toReadableStream()

@@ -331,38 +274,6 @@

return new internals.Payload(payload, encoding);
return new Payload(payload, encoding);
};
internals.Payload = function (payload, encoding) {
Stream.Readable.call(this);
var data = [].concat(payload || '');
var size = 0;
for (var i = 0, il = data.length; i < il; ++i) {
var chunk = data[i];
size += chunk.length;
data[i] = Buffer.isBuffer(chunk) ? chunk : new Buffer(chunk);
}
this._data = Buffer.concat(data, size);
this._position = 0;
this._encoding = encoding || 'utf8';
};
Hoek.inherits(internals.Payload, Stream.Readable);
internals.Payload.prototype._read = function (size) {
var chunk = this._data.slice(this._position, this._position + size);
this.push(chunk, this._encoding);
this._position += chunk.length;
if (this._position >= this._data.length) {
this.push(null);
}
};
// parseCacheControl()

@@ -406,2 +317,8 @@

exports.get = function (uri, options, callback) { internals.shortcut('GET', uri, options, callback); };
exports.post = function (uri, options, callback) { internals.shortcut('POST', uri, options, callback); };
exports.put = function (uri, options, callback) { internals.shortcut('PUT', uri, options, callback); };
exports.delete = function (uri, options, callback) { internals.shortcut('DELETE', uri, options, callback); };
// Shortcuts

@@ -430,7 +347,1 @@

};
exports.get = function (uri, options, callback) { internals.shortcut('GET', uri, options, callback); };
exports.post = function (uri, options, callback) { internals.shortcut('POST', uri, options, callback); };
exports.put = function (uri, options, callback) { internals.shortcut('PUT', uri, options, callback); };
exports.delete = function (uri, options, callback) { internals.shortcut('DELETE', uri, options, callback); };
{
"name": "nipple",
"description": "HTTP Client Utilities",
"version": "2.5.4",
"version": "2.5.5",
"repository": "git://github.com/hapijs/nipple",

@@ -20,3 +20,3 @@ "main": "index",

"devDependencies": {
"lab": "3.x.x"
"lab": "4.x.x"
},

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

@@ -7,3 +7,3 @@ ![nipple Logo](https://raw.github.com/hapijs/nipple/master/images/nipple.png)

Lead Maintainer: [Eran Hammer](https://github.com/hueniverse)
Lead Maintainer: [Wyatt Preul](https://github.com/wpreul)

@@ -50,1 +50,109 @@ ## Usage

```
### `request(method, uri, [options], [callback])`
Initiate an HTTP request.
- `method` - A string specifying the HTTP request method, defaulting to 'GET'.
- `uri` - The URI of the requested resource.
- `options` - An optional configuration object with the following optional keys:
- `payload` - The request body as string, Buffer, or Readable Stream.
- `headers` - An object containing request headers.
- `rejectUnauthorized` - [TLS](http://nodejs.org/api/tls.html) flag indicating
whether the client should reject a response from a server with invalid certificates.
- `redirects` - The maximum number of redirects to follow.
- `agent` - Node Core [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent).
- `timeout` - The number of milliseconds to wait without receiving a response
before aborting the request. Defaults to unlimited.
- `callback` - The optional callback function using the signature `function (err, response)` where:
- `err` - Any error that may have occurred during the handling of the request.
- `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)
object, which is also a readable stream.
### `read(response, [options], callback)`
- `response` - An HTTP Incoming Message object.
- `options` - An optional configuration object with the following optional keys:
- `timeout` - The number of milliseconds to wait while reading data before
aborting handling of the response. Defaults to unlimited.
- `json` - A flag indicating whether the payload should be parsed as JSON
if the response indicates a JSON content-type.
- `maxBytes` - The maximum allowed response payload size. Defaults to unlimited.
- `callback` - The callback function using the signature `function (err, payload)` where:
- `err` - Any error that may have occurred while reading the response.
- `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).
### `get(uri, [options], callback)`
Convenience method for GET operations.
- `uri` - The URI of the requested resource.
- `options` - Optional config object containing settings for both `request` and
`read` operations.
- `callback` - The callback function using the signature `function (err, response, payload)` where:
- `err` - Any error that may have occurred during handling of the request.
- `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)
object, which is also a readable stream.
- `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).
### `post(uri, [options], callback)`
Convenience method for POST operations.
- `uri` - The URI of the requested resource.
- `options` - Optional config object containing settings for both `request` and
`read` operations.
- `callback` - The callback function using the signature `function (err, response, payload)` where:
- `err` - Any error that may have occurred during handling of the request.
- `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)
object, which is also a readable stream.
- `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).
### `put(uri, [options], callback)`
Convenience method for PUT operations.
- `uri` - The URI of the requested resource.
- `options` - Optional config object containing settings for both `request` and
`read` operations.
- `callback` - The callback function using the signature `function (err, response, payload)` where:
- `err` - Any error that may have occurred during handling of the request.
- `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)
object, which is also a readable stream.
- `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).
### `delete(uri, [options], callback)`
Convenience method for DELETE operations.
- `uri` - The URI of the requested resource.
- `options` - Optional config object containing settings for both `request` and
`read` operations.
- `callback` - The callback function using the signature `function (err, response, payload)` where:
- `err` - Any error that may have occurred during handling of the request.
- `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)
object, which is also a readable stream.
- `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).
### `toReadableStream(payload, [encoding])`
Creates a [readable stream](http://nodejs.org/api/stream.html#stream_class_stream_readable)
for the provided payload and encoding.
- `payload` - The Buffer or string to be wrapped in a readable stream.
- `encoding` - The encoding to use. Must be a valid Buffer encoding, such as 'utf8' or 'ascii'.
```javascript
var stream = Nipple.toReadableStream(new Buffer('Hello', 'ascii'), 'ascii');
var read = stream.read();
// read -> 'Hello'
```
### `parseCacheControl(field)`
Parses the provided *cache-control* request header value into an object containing
a property for each directive and it's value. Boolean directives, such as "private"
or "no-cache" will be set to the boolean `true`.
- `field` - The header cache control value to be parsed.
```javascript
var result = Nipple.parseCacheControl('private, max-age=0, no-cache');
// result.private -> true
// result['max-age'] -> 0
// result['no-cache'] -> true
```
// Load modules
var Http = require('http');
var Events = require('events');
var Path = require('path');

@@ -10,3 +9,2 @@ var Fs = require('fs');

var Lab = require('lab');
var Boom = require('boom');
var Nipple = require('../');

@@ -22,7 +20,8 @@

var lab = exports.lab = Lab.script();
var before = lab.before;
var after = lab.after;
var describe = lab.describe;
var it = lab.it;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;

@@ -29,0 +28,0 @@