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

shred

Package Overview
Dependencies
Maintainers
3
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shred - npm Package Compare versions

Comparing version 0.8.3 to 0.8.8

12

lib/shred.js

@@ -7,6 +7,5 @@ // Shred is an HTTP client library intended to simplify the use of Node's

var _ = require("underscore")
// Ax is a nice logging library we wrote. You can use any logger, providing it
// has `info`, `warn`, `debug`, and `error` methods that take a string.
, Ax = require("ax")
var Ax = require("ax")
, CookieJarLib = require( "cookiejar" )

@@ -31,2 +30,3 @@ , CookieJar = CookieJarLib.CookieJar

Shred.Response = require("./shred/response");
Shred.registerProcessor = require("./shred/content").registerProcessor;

@@ -42,3 +42,9 @@ // The `request` method kicks off a new request, instantiating a new `Request`

options.agent = options.agent || this.agent;
return new Shred.Request(_.defaults(options,this.defaults));
// fill in default options
for (var key in this.defaults) {
if (this.defaults.hasOwnProperty(key) && !options[key]) {
options[key] = this.defaults[key]
}
}
return new Shred.Request(options);
}

@@ -45,0 +51,0 @@ };

@@ -1,2 +0,1 @@

var _ = require("underscore");

@@ -113,8 +112,8 @@ // The purpose of the `Content` object is to abstract away the data conversions

// content type. ex: application/vnd.foobar.baz+json will match json.
processor = _(this.type.split(";")[0]
.split(/\+|\//)).detect(function(type) {
return Content.processors[type];
});
return Content.processors[processor]||
{parser:identity,stringify:toString};
var main = this.type.split(";")[0];
var parts = main.split(/\+|\//);
for (var i=0, l=parts.length; i < l; i++) {
processor = Content.processors[parts[i]]
}
return processor || {parser:identity,stringify:toString};
}

@@ -177,2 +176,8 @@ },

var qs = require('querystring');
// Register the post processor, which is used for JSON-based media types.
Content.registerProcessor(
["application/x-www-form-urlencoded"],
{ parser : qs.parse, stringify : qs.stringify });
// Error functions are defined separately here in an attempt to make the code

@@ -179,0 +184,0 @@ // easier to read.

@@ -16,4 +16,2 @@ // The header mixins allow you to add HTTP header support to any object. This

// that haven't properly implemented the spec.
var _ = require("underscore")
;

@@ -53,8 +51,7 @@ // Convert headers to corset-case. **Example:** `CONTENT-TYPE` will be converted

var keys = (names && names.length>0) ? names : Object.keys($H(object));
var hash = keys.reduce(function(hash,key) {
hash[key] = getHeader(object,key);
return hash;
},{});
// Freeze the resulting hash so you don't mistakenly think you're modifying
// the real headers.
var hash = {};
for (var i=0,l=keys.length;i<l;i++) {
var key = keys[i];
hash[key] = getHeader(object, key);
}
Object.freeze(hash);

@@ -83,3 +80,3 @@ return hash;

constructor.prototype.getHeader = function(name) { return getHeader(this,name); };
constructor.prototype.getHeaders = function() { return getHeaders(this,_(arguments)); };
constructor.prototype.getHeaders = function() { return getHeaders(this,arguments); };
},

@@ -99,6 +96,6 @@ // Add setters but as "private" methods.

constructor.prototype.getHeader = function(name) { return getHeader(this,name); };
constructor.prototype.getHeaders = function() { return getHeaders(this,_(arguments)); };
constructor.prototype.getHeaders = function() { return getHeaders(this,arguments); };
constructor.prototype.setHeader = function(key,value) { return setHeader(this,key,value); };
constructor.prototype.setHeaders = function(hash) { return setHeaders(this,hash); };
},
};
};

@@ -9,3 +9,2 @@ // The request object encapsulates a request, creating a Node.js HTTP request and

, sprintf = require("sprintf").sprintf
, _ = require("underscore")
, Response = require("./response")

@@ -16,3 +15,56 @@ , HeaderMixins = require("./mixins/headers")

var STATUS_CODES = HTTP.STATUS_CODES;
var STATUS_CODES = HTTP.STATUS_CODES || {
100 : 'Continue',
101 : 'Switching Protocols',
102 : 'Processing', // RFC 2518, obsoleted by RFC 4918
200 : 'OK',
201 : 'Created',
202 : 'Accepted',
203 : 'Non-Authoritative Information',
204 : 'No Content',
205 : 'Reset Content',
206 : 'Partial Content',
207 : 'Multi-Status', // RFC 4918
300 : 'Multiple Choices',
301 : 'Moved Permanently',
302 : 'Moved Temporarily',
303 : 'See Other',
304 : 'Not Modified',
305 : 'Use Proxy',
307 : 'Temporary Redirect',
400 : 'Bad Request',
401 : 'Unauthorized',
402 : 'Payment Required',
403 : 'Forbidden',
404 : 'Not Found',
405 : 'Method Not Allowed',
406 : 'Not Acceptable',
407 : 'Proxy Authentication Required',
408 : 'Request Time-out',
409 : 'Conflict',
410 : 'Gone',
411 : 'Length Required',
412 : 'Precondition Failed',
413 : 'Request Entity Too Large',
414 : 'Request-URI Too Large',
415 : 'Unsupported Media Type',
416 : 'Requested Range Not Satisfiable',
417 : 'Expectation Failed',
418 : 'I\'m a teapot', // RFC 2324
422 : 'Unprocessable Entity', // RFC 4918
423 : 'Locked', // RFC 4918
424 : 'Failed Dependency', // RFC 4918
425 : 'Unordered Collection', // RFC 4918
426 : 'Upgrade Required', // RFC 2817
500 : 'Internal Server Error',
501 : 'Not Implemented',
502 : 'Bad Gateway',
503 : 'Service Unavailable',
504 : 'Gateway Time-out',
505 : 'HTTP Version not supported',
506 : 'Variant Also Negotiates', // RFC 2295
507 : 'Insufficient Storage', // RFC 4918
509 : 'Bandwidth Limit Exceeded',
510 : 'Not Extended' // RFC 2774
};

@@ -201,13 +253,21 @@ // The Shred object itself constructs the `Request` object. You should rarely

_.extend(Request.prototype,{
inspect: function() {
var request = this;
var headers = _(request.headers).reduce(function(array,value,key){
array.push("\t" + key + ": " + value); return array;
},[]).join("\n");
var summary = ["<Shred Request> ", request.method.toUpperCase(),
request.url].join(" ")
return [ summary, "- Headers:", headers].join("\n");
Request.prototype.inspect = function () {
var request = this;
var headers = this.format_headers();
var summary = ["<Shred Request> ", request.method.toUpperCase(),
request.url].join(" ")
return [ summary, "- Headers:", headers].join("\n");
};
Request.prototype.format_headers = function () {
var array = []
var headers = this._headers
for (var key in headers) {
if (headers.hasOwnProperty(key)) {
var value = headers[key]
array.push("\t" + key + ": " + value);
}
}
});
return array.join("\n");
};

@@ -217,18 +277,18 @@ // Allow chainable 'on's: shred.get({ ... }).on( ... ). You can pass in a

// { event: function, event: function }
_.extend(Request.prototype,{
on: function(eventOrHash, listener) {
var emitter = this.emitter;
// Pass in a single argument as a function then make it the default response handler
if (arguments.length === 1 && typeof(eventOrHash) === 'function') {
emitter.on('response', eventOrHash);
} else if (arguments.length === 1 && typeof(eventOrHash) === 'object') {
_(eventOrHash).each(function(value,key) {
emitter.on(key,value);
});
} else {
emitter.on(eventOrHash, listener);
Request.prototype.on = function (eventOrHash, listener) {
var emitter = this.emitter;
// Pass in a single argument as a function then make it the default response handler
if (arguments.length === 1 && typeof(eventOrHash) === 'function') {
emitter.on('response', eventOrHash);
} else if (arguments.length === 1 && typeof(eventOrHash) === 'object') {
for (var key in eventOrHash) {
if (eventOrHash.hasOwnProperty(key)) {
emitter.on(key, eventOrHash[key]);
}
}
return this;
} else {
emitter.on(eventOrHash, listener);
}
});
return this;
};

@@ -253,5 +313,7 @@ // Add in the header methods. Again, these ensure we don't get the same header

if (options.on) {
_(options.on).each(function(value,key) {
request.emitter.on(key,value);
});
for (var key in options.on) {
if (options.on.hasOwnProperty(key)) {
request.emitter.on(key, options.on[key]);
}
}
}

@@ -280,2 +342,4 @@

request.method = options.method;
// FIXME: options.agent is supposed to be a Node http.Agent, not the
// User-Agent string.
request.setHeader("user-agent",options.agent||"Shred");

@@ -341,2 +405,5 @@ request.setHeaders(options.headers);

request._raw = http.request(reqParams, function(response) {
// The "cleanup" event signifies that any timeout or error handlers
// that have been set for this request should now be disposed of.
request.emitter.emit("cleanup");
request.log.debug("Received response ..");

@@ -368,3 +435,3 @@

emitter.emit("response", response);
console.warn("Request has no event listener for status code " + response.status);
//console.warn("Request has no event listener for status code " + response.status);
}

@@ -400,2 +467,3 @@ }

request.emitter.emit("request_error", error);
request.emitter.emit("cleanup", error);
});

@@ -409,7 +477,11 @@

request._raw.on('socket', function () {
request._raw.socket.on('timeout', function () {
// This should trigger the "error" event on the raw request, which will
// trigger the "response_error" on the shred request.
request._raw.abort();
var timeout_handler = function () { request._raw.abort(); };
request.emitter.once("cleanup", function () {
request._raw.socket.removeListener("timeout", timeout_handler);
});
// This should trigger the "error" event on the raw request, which will
// trigger the "response_error" on the shred request.
request._raw.socket.on('timeout', timeout_handler);
});

@@ -454,3 +526,3 @@

if (req.content) {
bodyString += "-d '" + req.content.body + " ";
bodyString += "-d '" + req.content.body + "' ";
}

@@ -457,0 +529,0 @@

// The `Response object` encapsulates a Node.js HTTP response.
var _ = require("underscore")
, Content = require("./content")
var Content = require("./content")
, HeaderMixins = require("./mixins/headers")

@@ -134,7 +133,16 @@ , CookieJarLib = require( "cookiejar" )

var response = this;
var headers = _(response.headers).reduce(function(array,value,key){
array.push("\t" + key + ": " + value); return array;
},[]).join("\n");
var headers = this.format_headers();
var summary = ["<Shred Response> ", response.status].join(" ")
return [ summary, "- Headers:", headers].join("\n");
},
format_headers: function () {
var array = []
var headers = this.headers
for (var key in headers) {
if (headers.hasOwnProperty(key)) {
var value = headers[key]
array.push("\t" + key + ": " + value);
}
}
return array.join("\n");
}

@@ -165,2 +173,8 @@ };

headers: {
get: function() {
return this._headers;
},
enumerable: true
},
// - **isRedirect**. Is the response a redirect? These are responses with 3xx

@@ -167,0 +181,0 @@ // status and a `Location` header.

@@ -1,67 +0,76 @@

{ "name": "shred"
, "version": "0.8.3"
, "description": "A simple HTTP client for nodejs and browsers. Supports gzip, cookies, redirects, and https."
, "keywords": [ "http", "client" ]
, "licenses": [
{ "type": "MIT"
, "url": "https://github.com/spire-io/shred/blob/master/LICENSE"
}
]
, "homepage": "https://github.com/spire-io/shred"
, "bugs": { "url": "https://github.com/spire-io/shred/issues" }
, "author": { "name": "Dan Yoder"
, "email": "dan@spire.io"
}
, "maintainers": [
{ "name": "Dan Yoder"
, "email": "dan@spire.io"
}
, { "name": "Jason Campbell"
, "email": "jason@spire.io"
}
, { "name": "Matthew King"
, "email": "mking@spire.io"
}
, { "name": "Nicolas LaCasse"
, "email": "nicolas@spire.io"
}
]
, "contributors": [
{ "name": "Dan Yoder"
, "email": "dyoder@spire.io"
}
, { "name": "Jason Campbell"
, "email": "jason@spire.io"
}
, { "name": "Matthew King"
, "email": "mking@spire.io"
}
, { "name": "Andy Burke"
, "email": "aburke@bitflood.org"
}
]
, "main" : "./lib/shred.js"
, "repository": { "type": "git"
, "url": "git://github.com/spire-io/shred.git"
}
, "directories" : { "docs" : "./docs"
, "lib" : "./lib"
, "test" : "./test"
, "examples" : "./examples"
}
, "dependencies": { "underscore": "1.3.0"
, "sprintf": "0.1.1"
, "ax": ">= 0.1.5"
, "cookiejar": "1.3.x"
, "iconv-lite":">= 0.1.2"
}
, "devDependencies": { "vows": "0.6.1"
, "express": "2.5.10"
, "rephraser": ">= 0.1.6"
, "browserify": "1.8.3"
, "http-browserify": "https://github.com/spire-io/http-browserify/tarball/master"
, "uglify-js": ">= 1.2.5"
, "docco": ">= 0.3.0"
}
, "engine": "node >= 0.8.x"
{
"name":"shred",
"version":"0.8.8",
"description":"A simple HTTP client for nodejs and browsers. Supports gzip, cookies, redirects, and https.",
"keywords":[
"http",
"client"
],
"licenses":[
{
"type":"MIT",
"url":"https://github.com/automatthew/shred/blob/master/LICENSE"
}
],
"homepage":"https://github.com/automatthew/shred",
"bugs":{
"url":"https://github.com/automatthew/shred/issues"
},
"author":{
"name":"Dan Yoder",
"email":"dan@spire.io"
},
"maintainers":[
{
"name":"Dan Yoder", "email":"dan@spire.io"
},
{
"name":"Jason Campbell", "email":"jason@spire.io"
},
{
"name":"Matthew King", "email":"mking@spire.io"
},
{
"name":"Nicolas LaCasse", "email":"nicolas@spire.io"
}
],
"contributors":[
{
"name":"Dan Yoder", "email":"dyoder@spire.io"
},
{
"name":"Jason Campbell", "email":"jason@spire.io"
},
{
"name":"Matthew King", "email":"mking@spire.io"
},
{
"name":"Andy Burke", "email":"aburke@bitflood.org"
}
],
"main":"./lib/shred.js",
"repository":{
"type":"git",
"url":"git://github.com/automatthew/shred.git"
},
"files": [
"lib"
],
"dependencies":{
"sprintf":"0.1.1",
"ax":"0.1.8",
"cookiejar":"1.3.x",
"iconv-lite":">= 0.1.2"
},
"devDependencies":{
"testify":"0.1.0",
"express":"2.5.10",
"rephraser":">= 0.1.6",
"browserify":"1.8.3",
"http-browserify":"https://github.com/spire-io/http-browserify/tarball/master",
"uglify-js":">= 1.2.5",
"docco":">= 0.3.0"
},
"engine":"node >= 0.8.x"
}

@@ -136,3 +136,3 @@ # Introduction

See [the wiki](https://github.com/spire-io/shred/wiki) for more examples.
See [the wiki](https://github.com/automatthew/shred/wiki) for more examples.

@@ -195,3 +195,3 @@ Also, we wrote [a blog post][blog] on why we wrote Shred instead of going with existing libraries.

We'd love [your contributions](repo) - don't hesitate to send us pull requests. We'll also happily add you as a committer after we've accepted it.
We'd love your contributions - don't hesitate to send us pull requests. We'll also happily add you as a committer after we've accepted it.

@@ -213,15 +213,13 @@ # Tests

Shred is based on code originally written by [Matthew King][king].
That code was adapted and converted into a separate Node.js library by [Dan Yoder][yoder], [Jason Campbell][campbell], [Nick LaCasse][lacasse], and [Vicent Piquer Suria][suria].
Shred is based on code originally written by Matthew King.
That code was adapted and converted into a separate Node.js library by Dan Yoder, Jason Campbell, Nick LaCasse, and Vicent Piquer Suria.
[code]: https://github.com/spire-io/shred
[tickets]: https://github.com/spire-io/shred/issues
[license]: https://github.com/spire-io/shred/blob/master/LICENSE
[yoder]: mailto:dan@spire.io
[king]: mailto:mking@spire.io
[campbell]: mailto:jason@spire.io
[lacasse]: mailto:nlacasse@spire.io
[suria]: mailto:vsuria@spire.io
[docs]: http://www.spire.io/docs/shred/
[blog]: http://www.spire.io/posts/introducing-shred.html
Current maintainers: [Dan Yoder][yoder], [Matthew King][king]
[code]: https://github.com/automatthew/shred
[tickets]: https://github.com/automatthew/shred/issues
[license]: https://github.com/automatthew/shred/blob/master/LICENSE
[yoder]: mailto:daniel.yoder@gmail.com
[king]: mailto:automatthew@gmail.com
[curl]: http://curl.haxx.se/
[blog]: http://webcache.googleusercontent.com/search?q=cache:6RFaj1yLIZEJ:www.spire.io/posts/introducing-shred.html+http://www.spire.io/posts/introducing-shred.html&cd=1&hl=en&ct=clnk&gl=us
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