fix: clientIp & clientPort

This commit is contained in:
avwo
2019-03-05 01:21:10 +08:00
parent e77b73d112
commit 0331e36612
5 changed files with 26 additions and 5 deletions
+7 -1
View File
@@ -622,9 +622,15 @@ module.exports = function(socket, hostname, next, isWebPort) {
if (!chunk) {//没有数据
return isWebPort ? socket.destroy() : next(chunk);
}
var clientPort = socket.remotePort;
if (HTTP_RE.test(headersStr)) {
socket.test = clientPort;
var statusLine = RegExp['$&'];
var len = Buffer.byteLength(statusLine);
server.emit('connection', socket);
socket.emit('data', chunk);
chunk = chunk.slice(len);
statusLine += '\r\n' + config.CLIENT_INFO_HEAD + ': ' + clientIp + ',' + clientPort;
socket.emit('data', Buffer.concat([Buffer.from(statusLine), chunk]));
} else if (chunk[0] != 22) {
next(chunk);
} else {