| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | '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 |
| 6 | const 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 | |
| 21 | module.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 | }; |