diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java b/eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java index d51d4aefa..dfaf40e6e 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java @@ -18,8 +18,8 @@ import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; -import eu.bitwalker.useragentutils.Browser; -import eu.bitwalker.useragentutils.UserAgent; +import nl.basjes.parse.useragent.UserAgent; +import nl.basjes.parse.useragent.UserAgentAnalyzer; import org.lionsoul.ip2region.DataBlock; import org.lionsoul.ip2region.DbConfig; import org.lionsoul.ip2region.DbSearcher; @@ -50,6 +50,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { private static final char SEPARATOR = '_'; private static final String UNKNOWN = "unknown"; + private static final UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer + .newBuilder() + .hideMatcherLoadStats() + .withCache(10000) + .withField(UserAgent.AGENT_NAME_VERSION) + .build(); + + static { SpringContextHolder.addCallBacks(() -> { StringUtils.ipLocal = SpringContextHolder.getProperties("ip.local-parsing", false, Boolean.class); @@ -225,9 +233,8 @@ public static String getLocalCityInfo(String ip) { } public static String getBrowser(HttpServletRequest request) { - UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); - Browser browser = userAgent.getBrowser(); - return browser.getName(); + UserAgent.ImmutableUserAgent userAgent = userAgentAnalyzer.parse(request.getHeader("User-Agent")); + return userAgent.get(UserAgent.AGENT_NAME_VERSION).getValue(); } /** diff --git a/pom.xml b/pom.xml index 0b8a40627..4a20b4ddb 100644 --- a/pom.xml +++ b/pom.xml @@ -203,9 +203,9 @@ - eu.bitwalker - UserAgentUtils - 1.21 + nl.basjes.parse.useragent + yauaa + 5.23