From f765e5365bea7c0b6b4c349e3d858d84fe113a75 Mon Sep 17 00:00:00 2001 From: WuPeng Date: Tue, 6 Sep 2022 21:13:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=9C=A8=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6forwarded=5Fip=5Fheader?= =?UTF-8?q?=E7=9A=84=E5=80=BC=E5=90=8E=EF=BC=8C=E6=97=A0=E6=B3=95=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8D=E9=80=9A=E8=BF=87=E4=BB=A3=E7=90=86=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E7=9A=84=E5=AE=A2=E6=88=B7=E7=AB=AFIP=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpSession.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 413bf9dd..af2eeaab 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -674,7 +674,10 @@ bool HttpSession::emitHttpEvent(bool doInvoke){ std::string HttpSession::get_peer_ip() { GET_CONFIG(string, forwarded_ip_header, Http::kForwardedIpHeader); - return forwarded_ip_header.empty() ? TcpSession::get_peer_ip() : _parser.getHeader()[forwarded_ip_header]; + if(!forwarded_ip_header.empty() && !_parser.getHeader()[forwarded_ip_header].empty()){ + return _parser.getHeader()[forwarded_ip_header]; + } + return TcpSession::get_peer_ip(); } void HttpSession::Handle_Req_POST(ssize_t &content_len) {