UNPKG

949 BJavaScriptView Raw
1
2/**
3 * response.js
4 *
5 * Response class provides content decoding
6 */
7
8var http = require('http');
9var Headers = require('./headers');
10var Body = require('./body');
11
12module.exports = Response;
13
14/**
15 * Response class
16 *
17 * @param Stream body Readable stream
18 * @param Object opts Response options
19 * @return Void
20 */
21function Response(body, opts) {
22
23 opts = opts || {};
24
25 this.url = opts.url;
26 this.status = opts.status || 200;
27 this.statusText = opts.statusText || http.STATUS_CODES[this.status];
28 this.headers = new Headers(opts.headers);
29 this.ok = this.status >= 200 && this.status < 300;
30
31 Body.call(this, body, opts);
32
33}
34
35Response.prototype = Object.create(Body.prototype);
36
37/**
38 * Clone this response
39 *
40 * @return Response
41 */
42Response.prototype.clone = function() {
43 return new Response(this._clone(this), {
44 url: this.url
45 , status: this.status
46 , statusText: this.statusText
47 , headers: this.headers
48 , ok: this.ok
49 });
50};