mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-10 20:57:18 +08:00
refactor(log): 兼容小写 user-agent 情况
This commit is contained in:
@@ -18,7 +18,6 @@ package top.charles7c.continew.starter.log.common.model;
|
|||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import top.charles7c.continew.starter.core.util.ExceptionUtils;
|
|
||||||
import top.charles7c.continew.starter.core.util.IpUtils;
|
import top.charles7c.continew.starter.core.util.IpUtils;
|
||||||
import top.charles7c.continew.starter.log.common.enums.Include;
|
import top.charles7c.continew.starter.log.common.enums.Include;
|
||||||
import top.charles7c.continew.starter.web.util.ServletUtils;
|
import top.charles7c.continew.starter.web.util.ServletUtils;
|
||||||
@@ -91,7 +90,15 @@ public class LogRequest {
|
|||||||
this.param = request.getParam();
|
this.param = request.getParam();
|
||||||
}
|
}
|
||||||
this.address = (includes.contains(Include.IP_ADDRESS)) ? IpUtils.getAddress(this.ip) : null;
|
this.address = (includes.contains(Include.IP_ADDRESS)) ? IpUtils.getAddress(this.ip) : null;
|
||||||
String userAgentString = ExceptionUtils.exToNull(() -> this.headers.get(HttpHeaders.USER_AGENT));
|
if (null == this.headers) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String userAgentString = this.headers.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(h -> HttpHeaders.USER_AGENT.equalsIgnoreCase(h.getKey()))
|
||||||
|
.map(Map.Entry::getValue)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
if (StrUtil.isNotBlank(userAgentString)) {
|
if (StrUtil.isNotBlank(userAgentString)) {
|
||||||
this.browser = (includes.contains(Include.BROWSER)) ? ServletUtils.getBrowser(userAgentString) : null;
|
this.browser = (includes.contains(Include.BROWSER)) ? ServletUtils.getBrowser(userAgentString) : null;
|
||||||
this.os = (includes.contains(Include.OS)) ? ServletUtils.getOs(userAgentString) : null;
|
this.os = (includes.contains(Include.OS)) ? ServletUtils.getOs(userAgentString) : null;
|
||||||
|
Reference in New Issue
Block a user