| 1026 | |
| 1027 | class UpgradeStream extends Duplex { |
| 1028 | constructor(socket, req) { |
| 1029 | super({ |
| 1030 | allowHalfOpen: socket.allowHalfOpen, |
| 1031 | }); |
| 1032 | |
| 1033 | this[kSocket] = socket; |
| 1034 | this[kIncomingMessage] = req; |
| 1035 | |
| 1036 | // Proxy error, end & closure events immediately. |
| 1037 | socket.on('error', (err) => this.destroy(err)); |
| 1038 | |
| 1039 | socket.on('close', () => this.destroy()); |
| 1040 | this.on('close', () => socket.destroy()); |
| 1041 | |
| 1042 | socket.on('end', () => { |
| 1043 | this.push(null); |
| 1044 | |
| 1045 | // Match the socket behaviour, where 'end' will fire despite no 'data' |
| 1046 | // listeners if a socket with no pending data ends: |
| 1047 | if (this.readableLength === 0) { |
| 1048 | this.resume(); |
| 1049 | } |
| 1050 | }); |
| 1051 | |
| 1052 | // Other events (most notably, reading) all only |
| 1053 | // activate after requestBodyCompleted is called. |
| 1054 | } |
| 1055 | |
| 1056 | requestBodyCompleted(upgradeHead) { |
| 1057 | this[kIncomingMessage] = null; |