response.js 949 B

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