mirror of
https://github.com/TheWhiteDog9487/WebAPI.git
synced 2026-08-11 23:01:30 +08:00
修改通过X-Forwarded-For请求头获取IP的行为,使其支持由逗号分隔的多个IP的形式
This commit is contained in:
@@ -32,6 +32,7 @@ class IP {
|
|||||||
HttpStatus.OK); }
|
HttpStatus.OK); }
|
||||||
else {
|
else {
|
||||||
if (HttpHeader.get("X-Forwarded-For".toLowerCase()) instanceof String IP) {
|
if (HttpHeader.get("X-Forwarded-For".toLowerCase()) instanceof String IP) {
|
||||||
|
IP = IP.split(",")[0].trim();
|
||||||
log.info("请求携带了X-Forwarded-For头部,IP为:{}", IP);
|
log.info("请求携带了X-Forwarded-For头部,IP为:{}", IP);
|
||||||
return new ResponseEntity<>(IP,
|
return new ResponseEntity<>(IP,
|
||||||
MultiValueMap.fromSingleValue(Map.of("Content-Type", "text/plain;charset=UTF-8")),
|
MultiValueMap.fromSingleValue(Map.of("Content-Type", "text/plain;charset=UTF-8")),
|
||||||
|
|||||||
Reference in New Issue
Block a user