mirror of
https://github.com/maxswa/osrs-json-hiscores.git
synced 2025-10-15 10:19:04 +00:00
1.0.1
This commit is contained in:
92
node_modules/superagent/lib/node/agent.js
generated
vendored
Normal file
92
node_modules/superagent/lib/node/agent.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const CookieJar = require('cookiejar').CookieJar;
|
||||
const CookieAccess = require('cookiejar').CookieAccessInfo;
|
||||
const parse = require('url').parse;
|
||||
const request = require('../..');
|
||||
const AgentBase = require('../agent-base');
|
||||
let 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);
|
||||
}
|
||||
AgentBase.call(this);
|
||||
this.jar = new CookieJar();
|
||||
|
||||
if (options) {
|
||||
if (options.ca) {this.ca(options.ca);}
|
||||
if (options.key) {this.key(options.key);}
|
||||
if (options.pfx) {this.pfx(options.pfx);}
|
||||
if (options.cert) {this.cert(options.cert);}
|
||||
}
|
||||
}
|
||||
|
||||
Agent.prototype = Object.create(AgentBase.prototype);
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
const 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) {
|
||||
const url = parse(req.url);
|
||||
const access = CookieAccess(
|
||||
url.hostname,
|
||||
url.pathname,
|
||||
'https:' == url.protocol
|
||||
);
|
||||
const cookies = this.jar.getCookies(access).toValueString();
|
||||
req.cookies = cookies;
|
||||
};
|
||||
|
||||
methods.forEach(name => {
|
||||
const method = name.toUpperCase();
|
||||
Agent.prototype[name] = function(url, fn) {
|
||||
const req = new request.Request(method, url);
|
||||
|
||||
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);
|
||||
this._setDefaults(req);
|
||||
|
||||
if (fn) {
|
||||
req.end(fn);
|
||||
}
|
||||
return req;
|
||||
};
|
||||
});
|
||||
|
||||
Agent.prototype.del = Agent.prototype['delete'];
|
||||
1120
node_modules/superagent/lib/node/index.js
generated
vendored
Normal file
1120
node_modules/superagent/lib/node/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
12
node_modules/superagent/lib/node/parsers/image.js
generated
vendored
Normal file
12
node_modules/superagent/lib/node/parsers/image.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (res, fn) => {
|
||||
const data = []; // Binary data needs binary storage
|
||||
|
||||
res.on('data', chunk => {
|
||||
data.push(chunk);
|
||||
});
|
||||
res.on('end', () => {
|
||||
fn(null, Buffer.concat(data));
|
||||
});
|
||||
};
|
||||
10
node_modules/superagent/lib/node/parsers/index.js
generated
vendored
Normal file
10
node_modules/superagent/lib/node/parsers/index.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
exports['application/x-www-form-urlencoded'] = require('./urlencoded');
|
||||
exports['application/json'] = require('./json');
|
||||
exports.text = require('./text');
|
||||
|
||||
const binary = require('./image');
|
||||
exports['application/octet-stream'] = binary;
|
||||
exports['application/pdf'] = binary;
|
||||
exports.image = binary;
|
||||
22
node_modules/superagent/lib/node/parsers/json.js
generated
vendored
Normal file
22
node_modules/superagent/lib/node/parsers/json.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function parseJSON(res, fn){
|
||||
res.text = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', chunk => {
|
||||
res.text += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
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);
|
||||
}
|
||||
});
|
||||
};
|
||||
10
node_modules/superagent/lib/node/parsers/text.js
generated
vendored
Normal file
10
node_modules/superagent/lib/node/parsers/text.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(res, fn){
|
||||
res.text = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', chunk => {
|
||||
res.text += chunk;
|
||||
});
|
||||
res.on('end', fn);
|
||||
};
|
||||
22
node_modules/superagent/lib/node/parsers/urlencoded.js
generated
vendored
Normal file
22
node_modules/superagent/lib/node/parsers/urlencoded.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const qs = require('qs');
|
||||
|
||||
module.exports = function(res, fn){
|
||||
res.text = '';
|
||||
res.setEncoding('ascii');
|
||||
res.on('data', chunk => {
|
||||
res.text += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
try {
|
||||
fn(null, qs.parse(res.text));
|
||||
} catch (err) {
|
||||
fn(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
123
node_modules/superagent/lib/node/response.js
generated
vendored
Normal file
123
node_modules/superagent/lib/node/response.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const util = require('util');
|
||||
const Stream = require('stream');
|
||||
const ResponseBase = require('../response-base');
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
Stream.call(this);
|
||||
const res = (this.res = req.res);
|
||||
this.request = req;
|
||||
this.req = req.req;
|
||||
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);
|
||||
ResponseBase(Response.prototype);
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
const req = this.req;
|
||||
const method = req.method;
|
||||
const path = req.path;
|
||||
|
||||
const msg = `cannot ${method} ${path} (${this.status})`;
|
||||
const err = new Error(msg);
|
||||
err.status = this.status;
|
||||
err.text = this.text;
|
||||
err.method = method;
|
||||
err.path = path;
|
||||
|
||||
return err;
|
||||
};
|
||||
|
||||
|
||||
Response.prototype.setStatusProperties = function(status){
|
||||
console.warn("In superagent 2.x setStatusProperties is a private method");
|
||||
return this._setStatusProperties(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,
|
||||
};
|
||||
};
|
||||
71
node_modules/superagent/lib/node/unzip.js
generated
vendored
Normal file
71
node_modules/superagent/lib/node/unzip.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const StringDecoder = require('string_decoder').StringDecoder;
|
||||
const Stream = require('stream');
|
||||
const zlib = require('zlib');
|
||||
|
||||
/**
|
||||
* Buffers response data events and re-emits when they're unzipped.
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.unzip = (req, res) => {
|
||||
const unzip = zlib.createUnzip();
|
||||
const stream = new Stream();
|
||||
let decoder;
|
||||
|
||||
// make node responseOnEnd() happy
|
||||
stream.req = req;
|
||||
|
||||
unzip.on('error', err => {
|
||||
if (err && err.code === 'Z_BUF_ERROR') {
|
||||
// unexpected end of file is ignored by browsers and curl
|
||||
stream.emit('end');
|
||||
return;
|
||||
}
|
||||
stream.emit('error', err);
|
||||
});
|
||||
|
||||
// pipe to unzip
|
||||
res.pipe(unzip);
|
||||
|
||||
// override `setEncoding` to capture encoding
|
||||
res.setEncoding = type => {
|
||||
decoder = new StringDecoder(type);
|
||||
};
|
||||
|
||||
// decode upon decompressing with captured encoding
|
||||
unzip.on('data', buf => {
|
||||
if (decoder) {
|
||||
const str = decoder.write(buf);
|
||||
if (str.length) stream.emit('data', str);
|
||||
} else {
|
||||
stream.emit('data', buf);
|
||||
}
|
||||
});
|
||||
|
||||
unzip.on('end', () => {
|
||||
stream.emit('end');
|
||||
});
|
||||
|
||||
// override `on` to capture data listeners
|
||||
const _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);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user