Pushing changes
This commit is contained in:
82
node_modules/superagent/lib/node/agent.js
generated
vendored
Normal file
82
node_modules/superagent/lib/node/agent.js
generated
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var CookieJar = require('cookiejar').CookieJar;
|
||||
var CookieAccess = require('cookiejar').CookieAccessInfo;
|
||||
var parse = require('url').parse;
|
||||
var request = require('./index');
|
||||
var methods = require('methods');
|
||||
|
||||
/**
|
||||
* Expose `Agent`.
|
||||
*/
|
||||
|
||||
module.exports = Agent;
|
||||
|
||||
/**
|
||||
* Initialize a new `Agent`.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Agent(options) {
|
||||
if (!(this instanceof Agent)) return new Agent(options);
|
||||
if (options) this._ca = options.ca;
|
||||
this.jar = new CookieJar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the cookies in the given `res` to
|
||||
* the agent's cookie jar for persistence.
|
||||
*
|
||||
* @param {Response} res
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Agent.prototype.saveCookies = function(res){
|
||||
var cookies = res.headers['set-cookie'];
|
||||
if (cookies) this.jar.setCookies(cookies);
|
||||
};
|
||||
|
||||
/**
|
||||
* Attach cookies when available to the given `req`.
|
||||
*
|
||||
* @param {Request} req
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Agent.prototype.attachCookies = function(req){
|
||||
var url = parse(req.url);
|
||||
var access = CookieAccess(url.hostname, url.pathname, 'https:' == url.protocol);
|
||||
var cookies = this.jar.getCookies(access).toValueString();
|
||||
req.cookies = cookies;
|
||||
};
|
||||
|
||||
// generate HTTP verb methods
|
||||
if (methods.indexOf('del') == -1) {
|
||||
// create a copy so we don't cause conflicts with
|
||||
// other packages using the methods package and
|
||||
// npm 3.x
|
||||
methods = methods.slice(0);
|
||||
methods.push('del');
|
||||
}
|
||||
methods.forEach(function(method){
|
||||
var name = method;
|
||||
method = 'del' == method ? 'delete' : method;
|
||||
|
||||
method = method.toUpperCase();
|
||||
Agent.prototype[name] = function(url, fn){
|
||||
var req = request(method, url);
|
||||
req.ca(this._ca);
|
||||
|
||||
req.on('response', this.saveCookies.bind(this));
|
||||
req.on('redirect', this.saveCookies.bind(this));
|
||||
req.on('redirect', this.attachCookies.bind(this, req));
|
||||
this.attachCookies(req);
|
||||
|
||||
fn && req.end(fn);
|
||||
return req;
|
||||
};
|
||||
});
|
1093
node_modules/superagent/lib/node/index.js
generated
vendored
Normal file
1093
node_modules/superagent/lib/node/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10
node_modules/superagent/lib/node/parsers/image.js
generated
vendored
Normal file
10
node_modules/superagent/lib/node/parsers/image.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports = function(res, fn){
|
||||
var data = []; // Binary data needs binary storage
|
||||
|
||||
res.on('data', function(chunk){
|
||||
data.push(chunk);
|
||||
});
|
||||
res.on('end', function () {
|
||||
fn(null, Buffer.concat(data));
|
||||
});
|
||||
};
|
5
node_modules/superagent/lib/node/parsers/index.js
generated
vendored
Normal file
5
node_modules/superagent/lib/node/parsers/index.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
exports['application/x-www-form-urlencoded'] = require('./urlencoded');
|
||||
exports['application/json'] = require('./json');
|
||||
exports.text = require('./text');
|
||||
exports.image = require('./image');
|
19
node_modules/superagent/lib/node/parsers/json.js
generated
vendored
Normal file
19
node_modules/superagent/lib/node/parsers/json.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
module.exports = function parseJSON(res, fn){
|
||||
res.text = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', function(chunk){ res.text += chunk;});
|
||||
res.on('end', function(){
|
||||
try {
|
||||
var body = res.text && JSON.parse(res.text);
|
||||
} catch (e) {
|
||||
var err = e;
|
||||
// issue #675: return the raw response if the response parsing fails
|
||||
err.rawResponse = res.text || null;
|
||||
// issue #876: return the http status code if the response parsing fails
|
||||
err.statusCode = res.statusCode;
|
||||
} finally {
|
||||
fn(err, body);
|
||||
}
|
||||
});
|
||||
};
|
7
node_modules/superagent/lib/node/parsers/text.js
generated
vendored
Normal file
7
node_modules/superagent/lib/node/parsers/text.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
module.exports = function(res, fn){
|
||||
res.text = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', function(chunk){ res.text += chunk; });
|
||||
res.on('end', fn);
|
||||
};
|
19
node_modules/superagent/lib/node/parsers/urlencoded.js
generated
vendored
Normal file
19
node_modules/superagent/lib/node/parsers/urlencoded.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var qs = require('qs');
|
||||
|
||||
module.exports = function(res, fn){
|
||||
res.text = '';
|
||||
res.setEncoding('ascii');
|
||||
res.on('data', function(chunk){ res.text += chunk; });
|
||||
res.on('end', function(){
|
||||
try {
|
||||
fn(null, qs.parse(res.text));
|
||||
} catch (err) {
|
||||
fn(err);
|
||||
}
|
||||
});
|
||||
};
|
149
node_modules/superagent/lib/node/part.js
generated
vendored
Normal file
149
node_modules/superagent/lib/node/part.js
generated
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
var mime = require('mime');
|
||||
var FormData = require('form-data');
|
||||
var PassThrough = require('readable-stream/passthrough');
|
||||
|
||||
/**
|
||||
* Initialize a new `Part` for the given `req`.
|
||||
*
|
||||
* @param {Request} req
|
||||
* @api public
|
||||
* @deprecated pass a readable stream in to `Request#attach()` instead
|
||||
*/
|
||||
|
||||
var Part = function (req) {
|
||||
PassThrough.call(this);
|
||||
this._req = req;
|
||||
this._attached = false;
|
||||
this._name = null;
|
||||
this._type = null;
|
||||
this._header = null;
|
||||
this._filename = null;
|
||||
|
||||
this.once('pipe', this._attach.bind(this));
|
||||
};
|
||||
Part = util.deprecate(Part, 'The `Part()` constructor is deprecated. ' +
|
||||
'Pass a readable stream in to `Request#attach()` instead.');
|
||||
|
||||
/**
|
||||
* Inherit from `PassThrough`.
|
||||
*/
|
||||
|
||||
util.inherits(Part, PassThrough);
|
||||
|
||||
/**
|
||||
* Expose `Part`.
|
||||
*/
|
||||
|
||||
module.exports = Part;
|
||||
|
||||
/**
|
||||
* Set header `field` to `val`.
|
||||
*
|
||||
* @param {String} field
|
||||
* @param {String} val
|
||||
* @return {Part} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Part.prototype.set = function(field, val){
|
||||
//if (!this._header) this._header = {};
|
||||
//this._header[field] = val;
|
||||
//return this;
|
||||
throw new TypeError('setting custom form-data part headers is unsupported');
|
||||
};
|
||||
|
||||
/**
|
||||
* Set _Content-Type_ response header passed through `mime.lookup()`.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.type('html');
|
||||
* res.type('.html');
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {Part} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Part.prototype.type = function(type){
|
||||
var lookup = mime.lookup(type);
|
||||
this._type = lookup;
|
||||
//this.set('Content-Type', lookup);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the "name" portion for the _Content-Disposition_ header field.
|
||||
*
|
||||
* @param {String} name
|
||||
* @return {Part} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Part.prototype.name = function(name){
|
||||
this._name = name;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set _Content-Disposition_ header field to _attachment_ with `filename`
|
||||
* and field `name`.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {String} filename
|
||||
* @return {Part} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Part.prototype.attachment = function(name, filename){
|
||||
this.name(name);
|
||||
if (filename) {
|
||||
this.type(filename);
|
||||
this._filename = filename;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calls `FormData#append()` on the Request instance's FormData object.
|
||||
*
|
||||
* Gets called implicitly upon the first `write()` call, or the "pipe" event.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Part.prototype._attach = function(){
|
||||
if (this._attached) return;
|
||||
this._attached = true;
|
||||
|
||||
if (!this._name) throw new Error('must call `Part#name()` first!');
|
||||
|
||||
// add `this` Stream's readable side as a stream for this Part
|
||||
this._req._getFormData().append(this._name, this, {
|
||||
contentType: this._type,
|
||||
filename: this._filename
|
||||
});
|
||||
|
||||
// restore PassThrough's default `write()` function now that we're setup
|
||||
this.write = PassThrough.prototype.write;
|
||||
};
|
||||
|
||||
/**
|
||||
* Write `data` with `encoding`.
|
||||
*
|
||||
* @param {Buffer|String} data
|
||||
* @param {String} encoding
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Part.prototype.write = function(){
|
||||
this._attach();
|
||||
return this.write.apply(this, arguments);
|
||||
};
|
210
node_modules/superagent/lib/node/response.js
generated
vendored
Normal file
210
node_modules/superagent/lib/node/response.js
generated
vendored
Normal file
@ -0,0 +1,210 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
var utils = require('./utils');
|
||||
var Stream = require('stream');
|
||||
|
||||
/**
|
||||
* Expose `Response`.
|
||||
*/
|
||||
|
||||
module.exports = Response;
|
||||
|
||||
/**
|
||||
* Initialize a new `Response` with the given `xhr`.
|
||||
*
|
||||
* - set flags (.ok, .error, etc)
|
||||
* - parse header
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Object} options
|
||||
* @constructor
|
||||
* @extends {Stream}
|
||||
* @implements {ReadableStream}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function Response(req, options) {
|
||||
Stream.call(this);
|
||||
options = options || {};
|
||||
var res = this.res = req.res;
|
||||
this.request = req;
|
||||
this.req = req.req;
|
||||
this.links = {};
|
||||
this.text = res.text;
|
||||
this.body = res.body !== undefined ? res.body : {};
|
||||
this.files = res.files || {};
|
||||
this.buffered = 'string' == typeof this.text;
|
||||
this.header = this.headers = res.headers;
|
||||
this.setStatusProperties(res.statusCode);
|
||||
this.setHeaderProperties(this.header);
|
||||
this.setEncoding = res.setEncoding.bind(res);
|
||||
res.on('data', this.emit.bind(this, 'data'));
|
||||
res.on('end', this.emit.bind(this, 'end'));
|
||||
res.on('close', this.emit.bind(this, 'close'));
|
||||
res.on('error', this.emit.bind(this, 'error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Stream`.
|
||||
*/
|
||||
|
||||
util.inherits(Response, Stream);
|
||||
|
||||
/**
|
||||
* Get case-insensitive `field` value.
|
||||
*
|
||||
* @param {String} field
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Response.prototype.get = function(field){
|
||||
return this.header[field.toLowerCase()];
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements methods of a `ReadableStream`
|
||||
*/
|
||||
|
||||
Response.prototype.destroy = function(err){
|
||||
this.res.destroy(err);
|
||||
};
|
||||
|
||||
/**
|
||||
* Pause.
|
||||
*/
|
||||
|
||||
Response.prototype.pause = function(){
|
||||
this.res.pause();
|
||||
};
|
||||
|
||||
/**
|
||||
* Resume.
|
||||
*/
|
||||
|
||||
Response.prototype.resume = function(){
|
||||
this.res.resume();
|
||||
};
|
||||
|
||||
/**
|
||||
* Return an `Error` representative of this response.
|
||||
*
|
||||
* @return {Error}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Response.prototype.toError = function(){
|
||||
var req = this.req;
|
||||
var method = req.method;
|
||||
var path = req.path;
|
||||
|
||||
var msg = 'cannot ' + method + ' ' + path + ' (' + this.status + ')';
|
||||
var err = new Error(msg);
|
||||
err.status = this.status;
|
||||
err.text = this.text;
|
||||
err.method = method;
|
||||
err.path = path;
|
||||
|
||||
return err;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set header related properties:
|
||||
*
|
||||
* - `.type` the content type without params
|
||||
*
|
||||
* A response of "Content-Type: text/plain; charset=utf-8"
|
||||
* will provide you with a `.type` of "text/plain".
|
||||
*
|
||||
* @param {Object} header
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Response.prototype.setHeaderProperties = function(header){
|
||||
// TODO: moar!
|
||||
// TODO: make this a util
|
||||
|
||||
// content-type
|
||||
var ct = this.header['content-type'] || '';
|
||||
|
||||
// params
|
||||
var params = utils.params(ct);
|
||||
for (var key in params) this[key] = params[key];
|
||||
|
||||
this.type = utils.type(ct);
|
||||
|
||||
// links
|
||||
try {
|
||||
if (header.link) this.links = utils.parseLinks(header.link);
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set flags such as `.ok` based on `status`.
|
||||
*
|
||||
* For example a 2xx response will give you a `.ok` of __true__
|
||||
* whereas 5xx will be __false__ and `.error` will be __true__. The
|
||||
* `.clientError` and `.serverError` are also available to be more
|
||||
* specific, and `.statusType` is the class of error ranging from 1..5
|
||||
* sometimes useful for mapping respond colors etc.
|
||||
*
|
||||
* "sugar" properties are also defined for common cases. Currently providing:
|
||||
*
|
||||
* - .noContent
|
||||
* - .badRequest
|
||||
* - .unauthorized
|
||||
* - .notAcceptable
|
||||
* - .notFound
|
||||
*
|
||||
* @param {Number} status
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Response.prototype.setStatusProperties = function(status){
|
||||
var type = status / 100 | 0;
|
||||
|
||||
// status / class
|
||||
this.status = this.statusCode = status;
|
||||
this.statusType = type;
|
||||
|
||||
// basics
|
||||
this.info = 1 == type;
|
||||
this.ok = 2 == type;
|
||||
this.redirect = 3 == type;
|
||||
this.clientError = 4 == type;
|
||||
this.serverError = 5 == type;
|
||||
this.error = (4 == type || 5 == type)
|
||||
? this.toError()
|
||||
: false;
|
||||
|
||||
// sugar
|
||||
this.accepted = 202 == status;
|
||||
this.noContent = 204 == status;
|
||||
this.badRequest = 400 == status;
|
||||
this.unauthorized = 401 == status;
|
||||
this.notAcceptable = 406 == status;
|
||||
this.forbidden = 403 == status;
|
||||
this.notFound = 404 == status;
|
||||
};
|
||||
|
||||
/**
|
||||
* To json.
|
||||
*
|
||||
* @return {Object}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Response.prototype.toJSON = function(){
|
||||
return {
|
||||
req: this.request.toJSON(),
|
||||
header: this.header,
|
||||
status: this.status,
|
||||
text: this.text
|
||||
};
|
||||
};
|
142
node_modules/superagent/lib/node/utils.js
generated
vendored
Normal file
142
node_modules/superagent/lib/node/utils.js
generated
vendored
Normal file
@ -0,0 +1,142 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var StringDecoder = require('string_decoder').StringDecoder;
|
||||
var Stream = require('stream');
|
||||
var zlib;
|
||||
|
||||
/**
|
||||
* Require zlib module for Node 0.6+
|
||||
*/
|
||||
|
||||
try {
|
||||
zlib = require('zlib');
|
||||
} catch (e) { }
|
||||
|
||||
/**
|
||||
* Return the mime type for the given `str`.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.type = function(str){
|
||||
return str.split(/ *; */).shift();
|
||||
};
|
||||
|
||||
/**
|
||||
* Return header field parameters.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.params = function(str){
|
||||
return str.split(/ *; */).reduce(function(obj, str){
|
||||
var parts = str.split(/ *= */);
|
||||
var key = parts.shift();
|
||||
var val = parts.shift();
|
||||
|
||||
if (key && val) obj[key] = val;
|
||||
return obj;
|
||||
}, {});
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse Link header fields.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.parseLinks = function(str){
|
||||
return str.split(/ *, */).reduce(function(obj, str){
|
||||
var parts = str.split(/ *; */);
|
||||
var url = parts[0].slice(1, -1);
|
||||
var rel = parts[1].split(/ *= */)[1].slice(1, -1);
|
||||
obj[rel] = url;
|
||||
return obj;
|
||||
}, {});
|
||||
};
|
||||
|
||||
/**
|
||||
* Buffers response data events and re-emits when they're unzipped.
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.unzip = function(req, res){
|
||||
if (!zlib) return;
|
||||
|
||||
var unzip = zlib.createUnzip();
|
||||
var stream = new Stream;
|
||||
var decoder;
|
||||
|
||||
// make node responseOnEnd() happy
|
||||
stream.req = req;
|
||||
|
||||
unzip.on('error', function(err){
|
||||
stream.emit('error', err);
|
||||
});
|
||||
|
||||
// pipe to unzip
|
||||
res.pipe(unzip);
|
||||
|
||||
// override `setEncoding` to capture encoding
|
||||
res.setEncoding = function(type){
|
||||
decoder = new StringDecoder(type);
|
||||
};
|
||||
|
||||
// decode upon decompressing with captured encoding
|
||||
unzip.on('data', function(buf){
|
||||
if (decoder) {
|
||||
var str = decoder.write(buf);
|
||||
if (str.length) stream.emit('data', str);
|
||||
} else {
|
||||
stream.emit('data', buf);
|
||||
}
|
||||
});
|
||||
|
||||
unzip.on('end', function(){
|
||||
stream.emit('end');
|
||||
});
|
||||
|
||||
// override `on` to capture data listeners
|
||||
var _on = res.on;
|
||||
res.on = function(type, fn){
|
||||
if ('data' == type || 'end' == type) {
|
||||
stream.on(type, fn);
|
||||
} else if ('error' == type) {
|
||||
stream.on(type, fn);
|
||||
_on.call(res, type, fn);
|
||||
} else {
|
||||
_on.call(res, type, fn);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Strip content related fields from `header`.
|
||||
*
|
||||
* @param {Object} header
|
||||
* @return {Object} header
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.cleanHeader = function(header, shouldStripCookie){
|
||||
delete header['content-type'];
|
||||
delete header['content-length'];
|
||||
delete header['transfer-encoding'];
|
||||
delete header['host'];
|
||||
if (shouldStripCookie) {
|
||||
delete header['cookie'];
|
||||
}
|
||||
return header;
|
||||
};
|
Reference in New Issue
Block a user