From eee94bf0ae306db980ebc82b62c18502b69eeb6f Mon Sep 17 00:00:00 2001 From: youkunhuang Date: Thu, 15 Nov 2018 15:01:30 +0800 Subject: [PATCH] chore(util): use realIp first --- bin/tsw/util/http.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/tsw/util/http.js b/bin/tsw/util/http.js index ce8f918e..c554403a 100644 --- a/bin/tsw/util/http.js +++ b/bin/tsw/util/http.js @@ -416,7 +416,13 @@ this.getUserIp = function(request) { const qvia = request.headers['qvia'] || ''; const realIp = request.headers['x-real-ip'] || ''; - if (xff) { + if (realIp) { + + // x-real-ip + if (userIp && this.isInnerIP(userIp)) { + userIp = realIp; + } + } else if (xff) { // xff判断,注意只认内网ip带的xff,外网带的不算 if (userIp && this.isInnerIP(userIp)) { @@ -425,12 +431,6 @@ this.getUserIp = function(request) { userIp = xff.trim() || userIp; } - } else if (realIp) { - - // x-real-ip - if (userIp && this.isInnerIP(userIp)) { - userIp = realIp; - } } else if (qvia) { // 注意只认内网ip带的qvia,外网带的不算