修改通过X-Forwarded-For请求头获取IP的行为,使其支持由逗号分隔的多个IP的形式

This commit is contained in:
2025-08-13 16:08:30 +08:00
parent 7c5269ecf9
commit e72b31ed7a
@@ -32,6 +32,7 @@ class IP {
HttpStatus.OK); }
else {
if (HttpHeader.get("X-Forwarded-For".toLowerCase()) instanceof String IP) {
IP = IP.split(",")[0].trim();
log.info("请求携带了X-Forwarded-For头部,IP为:{}", IP);
return new ResponseEntity<>(IP,
MultiValueMap.fromSingleValue(Map.of("Content-Type", "text/plain;charset=UTF-8")),