summaryrefslogtreecommitdiff
path: root/node_modules/superagent/lib/node/response.js
diff options
context:
space:
mode:
authorAlee14 <alee14498@gmail.com>2017-03-26 15:18:10 -0400
committerAlee14 <alee14498@gmail.com>2017-03-26 15:18:10 -0400
commit29433e2f7dbd0e4a73d3c78ffe1005b922fb5982 (patch)
treeaa0ad3fe59468cbe452ee597e914839b68c01436 /node_modules/superagent/lib/node/response.js
parent878fefb4c4e1f12b804ae5c0def433fa873f4c8b (diff)
downloadAleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.tar.gz
AleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.tar.bz2
AleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.zip
Don't mind me i'm adding the discord.js files
Diffstat (limited to 'node_modules/superagent/lib/node/response.js')
-rw-r--r--node_modules/superagent/lib/node/response.js123
1 files changed, 123 insertions, 0 deletions
diff --git a/node_modules/superagent/lib/node/response.js b/node_modules/superagent/lib/node/response.js
new file mode 100644
index 0000000..9a9ea15
--- /dev/null
+++ b/node_modules/superagent/lib/node/response.js
@@ -0,0 +1,123 @@
+
+/**
+ * Module dependencies.
+ */
+
+var util = require('util');
+var Stream = require('stream');
+var 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);
+ var 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(){
+ 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;
+};
+
+
+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
+ };
+};