1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var http = require('http');
|
9 | var Headers = require('./headers');
|
10 | var Body = require('./body');
|
11 |
|
12 | module.exports = Response;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function 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 |
|
35 | Response.prototype = Object.create(Body.prototype);
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | Response.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 | };
|