fix: 在获取客服端真实 ip 的方法中添加获取根据 X-Forwarded-For header 来进行获取的实现
This commit is contained in:
parent
9ac02e638b
commit
0a229a7fcf
@ -49,8 +49,15 @@ public class RequestUtil {
|
||||
return StringUtils.isBlank(nginxHeader) ? request.getRemoteAddr() : nginxHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 header 中的客服端应用名称
|
||||
* <p>
|
||||
*
|
||||
* @param request {@link HttpServletRequest}
|
||||
* @return 可能为 null
|
||||
*/
|
||||
public static String getAppName(HttpServletRequest request) {
|
||||
return request.getHeader("Client-AppName");
|
||||
return request.getHeader(CLIENT_APPNAME_HEADER);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,4 +35,12 @@ public class RequestUtilTest {
|
||||
Mockito.when(request.getHeader(eq(X_REAL_IP))).thenReturn("");
|
||||
Assert.assertEquals(RequestUtil.getRemoteIp(request), "127.0.0.1");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getAppName() {
|
||||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
||||
Mockito.when(request.getHeader(eq(RequestUtil.CLIENT_APPNAME_HEADER))).thenReturn("test");
|
||||
Assert.assertEquals(RequestUtil.getAppName(request), "test");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user