index.js 866 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. // We define these manually to ensure they're always copied
  3. // even if they would move up the prototype chain
  4. // https://nodejs.org/api/http.html#http_class_http_incomingmessage
  5. const knownProperties = [
  6. 'aborted',
  7. 'complete',
  8. 'destroy',
  9. 'headers',
  10. 'httpVersion',
  11. 'httpVersionMinor',
  12. 'httpVersionMajor',
  13. 'method',
  14. 'rawHeaders',
  15. 'rawTrailers',
  16. 'setTimeout',
  17. 'socket',
  18. 'statusCode',
  19. 'statusMessage',
  20. 'trailers',
  21. 'url'
  22. ];
  23. module.exports = (fromStream, toStream) => {
  24. const fromProperties = new Set(Object.keys(fromStream).concat(knownProperties));
  25. for (const property of fromProperties) {
  26. // Don't overwrite existing properties.
  27. if (property in toStream) {
  28. continue;
  29. }
  30. toStream[property] = typeof fromStream[property] === 'function' ? fromStream[property].bind(fromStream) : fromStream[property];
  31. }
  32. return toStream;
  33. };