Skip to content

Commit de4a6fe

Browse files
committed
[fix] Only set x-forward-* headers if req.connection and req.connection.socket
1 parent 340be42 commit de4a6fe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/node-http-proxy/http-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
126126
// * `x-forwarded-proto`: Protocol of the original request
127127
// * `x-forwarded-port`: Port of the original request.
128128
//
129-
if (this.enable.xforward) {
129+
if (this.enable.xforward && req.connection && req.connection.socket) {
130130
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
131131
req.headers['x-forwarded-port'] = req.connection.remotePort || req.connection.socket.remotePort;
132-
req.headers['x-forwarded-proto'] = res.connection.pair ? 'https' : 'http';
132+
req.headers['x-forwarded-proto'] = req.connection.pair ? 'https' : 'http';
133133
}
134134

135135
//

0 commit comments

Comments
 (0)