diff options
Diffstat (limited to 'together/node_modules/superagent/lib/node/response.js')
-rw-r--r-- | together/node_modules/superagent/lib/node/response.js | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/together/node_modules/superagent/lib/node/response.js b/together/node_modules/superagent/lib/node/response.js new file mode 100644 index 0000000..0208dfb --- /dev/null +++ b/together/node_modules/superagent/lib/node/response.js @@ -0,0 +1,139 @@ +"use strict"; + +/** + * Module dependencies. + */ +const util = require('util'); + +const Stream = require('stream'); + +const ResponseBase = require('../response-base'); + +const _require = require('../utils'), + mixin = _require.mixin; +/** + * 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(request) { + Stream.call(this); + this.res = request.res; + const res = this.res; + this.request = request; + this.req = request.req; + this.text = res.text; + this.files = res.files || {}; + this.buffered = request._resBuffered; + this.headers = res.headers; + this.header = this.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')); +} // Lazy access res.body. +// https://github.com/nodejs/node/pull/39520#issuecomment-889697136 + + +Object.defineProperty(Response.prototype, 'body', { + get() { + return this._body !== undefined ? this._body : this.res.body !== undefined ? this.res.body : {}; + }, + + set(value) { + this._body = value; + } + +}); +/** + * Inherit from `Stream`. + */ + +util.inherits(Response, Stream); +mixin(Response.prototype, ResponseBase.prototype); +/** + * Implements methods of a `ReadableStream` + */ + +Response.prototype.destroy = function (error) { + this.res.destroy(error); +}; +/** + * 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 message = "cannot ".concat(method, " ").concat(path, " (").concat(this.status, ")"); + const error = new Error(message); + error.status = this.status; + error.text = this.text; + error.method = method; + error.path = path; + return error; +}; + +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 + }; +}; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJ1dGlsIiwicmVxdWlyZSIsIlN0cmVhbSIsIlJlc3BvbnNlQmFzZSIsIm1peGluIiwibW9kdWxlIiwiZXhwb3J0cyIsIlJlc3BvbnNlIiwicmVxdWVzdCIsImNhbGwiLCJyZXMiLCJyZXEiLCJ0ZXh0IiwiZmlsZXMiLCJidWZmZXJlZCIsIl9yZXNCdWZmZXJlZCIsImhlYWRlcnMiLCJoZWFkZXIiLCJfc2V0U3RhdHVzUHJvcGVydGllcyIsInN0YXR1c0NvZGUiLCJfc2V0SGVhZGVyUHJvcGVydGllcyIsInNldEVuY29kaW5nIiwiYmluZCIsIm9uIiwiZW1pdCIsIk9iamVjdCIsImRlZmluZVByb3BlcnR5IiwicHJvdG90eXBlIiwiZ2V0IiwiX2JvZHkiLCJ1bmRlZmluZWQiLCJib2R5Iiwic2V0IiwidmFsdWUiLCJpbmhlcml0cyIsImRlc3Ryb3kiLCJlcnJvciIsInBhdXNlIiwicmVzdW1lIiwidG9FcnJvciIsIm1ldGhvZCIsInBhdGgiLCJtZXNzYWdlIiwic3RhdHVzIiwiRXJyb3IiLCJzZXRTdGF0dXNQcm9wZXJ0aWVzIiwiY29uc29sZSIsIndhcm4iLCJ0b0pTT04iXSwic291cmNlcyI6WyIuLi8uLi9zcmMvbm9kZS9yZXNwb25zZS5qc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