You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 823B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const Readable = require('stream').Readable;
  3. const lowercaseKeys = require('lowercase-keys');
  4. class Response extends Readable {
  5. constructor(statusCode, headers, body, url) {
  6. if (typeof statusCode !== 'number') {
  7. throw new TypeError('Argument `statusCode` should be a number');
  8. }
  9. if (typeof headers !== 'object') {
  10. throw new TypeError('Argument `headers` should be an object');
  11. }
  12. if (!(body instanceof Buffer)) {
  13. throw new TypeError('Argument `body` should be a buffer');
  14. }
  15. if (typeof url !== 'string') {
  16. throw new TypeError('Argument `url` should be a string');
  17. }
  18. super();
  19. this.statusCode = statusCode;
  20. this.headers = lowercaseKeys(headers);
  21. this.body = body;
  22. this.url = url;
  23. }
  24. _read() {
  25. this.push(this.body);
  26. this.push(null);
  27. }
  28. }
  29. module.exports = Response;