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