node-fetch/src/response.js

51 lines
946 B
JavaScript
Raw Normal View History

2016-04-05 10:43:12 -07:00
2015-01-27 05:11:26 -08:00
/**
* response.js
*
* Response class provides content decoding
*/
2016-03-19 03:45:02 -07:00
var http = require('http');
import Headers from './headers';
var Body = require('./body');
2015-01-27 05:11:26 -08:00
module.exports = Response;
/**
* Response class
*
* @param Stream body Readable stream
* @param Object opts Response options
* @return Void
*/
function Response(body, opts) {
opts = opts || {};
2015-01-27 05:11:26 -08:00
this.url = opts.url;
2016-07-12 16:28:36 -07:00
this.status = opts.status || 200;
this.statusText = opts.statusText || http.STATUS_CODES[this.status];
this.headers = new Headers(opts.headers);
this.ok = this.status >= 200 && this.status < 300;
2015-01-27 05:11:26 -08:00
Body.call(this, body, opts);
2015-01-27 05:11:26 -08:00
}
Response.prototype = Object.create(Body.prototype);
2016-03-19 03:06:33 -07:00
/**
* Clone this response
*
* @return Response
*/
Response.prototype.clone = function() {
return new Response(this._clone(this), {
url: this.url
, status: this.status
, statusText: this.statusText
, headers: this.headers
, ok: this.ok
});
};