1
0
mirror of https://gitee.com/dromara/hutool.git synced 2025-04-05 17:37:59 +08:00

UserAgent增加百度浏览器识别

This commit is contained in:
Looly 2023-09-25 17:31:10 +08:00
parent f21dfc927d
commit a341bf04bd
3 changed files with 75 additions and 56 deletions
CHANGELOG.md
hutool-http/src
main/java/cn/hutool/http/useragent
test/java/cn/hutool/http/useragent

View File

@ -2,11 +2,12 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.23(2023-09-21)
# 5.8.23(2023-09-25)
### 🐣新特性
* 【json 】 改进TemporalAccessorSerializer支持dayOfMonth和month枚举名issue#I82AM8@Gitee
* 【core 】 新增ProxySocketFactory
* 【http 】 UserAgent增加百度浏览器识别issue#I847JY@Gitee
### 🐞Bug修复
* 【cron 】 修复Cron表达式range解析错误问题issue#I82CSH@Gitee

View File

@ -28,54 +28,56 @@ public class Browser extends UserAgentInfo {
* 支持的浏览器类型
*/
public static final List<Browser> browers = CollUtil.newArrayList(
// 部分特殊浏览器是基于安卓Iphone等的需要优先判断
// 企业微信 企业微信使用微信浏览器内核,会包含 MicroMessenger 所以要放在前面
new Browser("wxwork", "wxwork", "wxwork\\/([\\d\\w\\.\\-]+)"),
// 微信
new Browser("MicroMessenger", "MicroMessenger", Other_Version),
// 微信小程序
new Browser("miniProgram", "miniProgram", Other_Version),
// QQ浏览器
new Browser("QQBrowser", "MQQBrowser", "MQQBrowser\\/([\\d\\w\\.\\-]+)"),
// 钉钉PC端浏览器
new Browser("DingTalk-win", "dingtalk-win", "DingTalk\\(([\\d\\w\\.\\-]+)\\)"),
// 钉钉内置浏览器
new Browser("DingTalk", "DingTalk", "AliApp\\(DingTalk\\/([\\d\\w\\.\\-]+)\\)"),
// 支付宝内置浏览器
new Browser("Alipay", "AlipayClient", "AliApp\\(AP\\/([\\d\\w\\.\\-]+)\\)"),
// 淘宝内置浏览器
new Browser("Taobao", "taobao", "AliApp\\(TB\\/([\\d\\w\\.\\-]+)\\)"),
// UC浏览器
new Browser("UCBrowser", "UC?Browser", "UC?Browser\\/([\\d\\w\\.\\-]+)"),
// XiaoMi 浏览器
new Browser("MiuiBrowser", "MiuiBrowser|mibrowser", "MiuiBrowser\\/([\\d\\w\\.\\-]+)"),
// 夸克浏览器
new Browser("Quark", "Quark", Other_Version),
// 联想浏览器
new Browser("Lenovo", "SLBrowser", "SLBrowser/([\\d\\w\\.\\-]+)"),
new Browser("MSEdge", "Edge|Edg", "(?:edge|Edg|EdgA)\\/([\\d\\w\\.\\-]+)"),
new Browser("Chrome", "chrome|(iphone.*crios.*safari)", "(?:Chrome|CriOS)\\/([\\d\\w\\.\\-]+)"),
new Browser("Firefox", "firefox", Other_Version),
new Browser("IEMobile", "iemobile", Other_Version),
new Browser("Android Browser", "android", "version\\/([\\d\\w\\.\\-]+)"),
new Browser("Safari", "safari", "version\\/([\\d\\w\\.\\-]+)"),
new Browser("Opera", "opera", Other_Version),
new Browser("Konqueror", "konqueror", Other_Version),
new Browser("PS3", "playstation 3", "([\\d\\w\\.\\-]+)\\)\\s*$"),
new Browser("PSP", "playstation portable", "([\\d\\w\\.\\-]+)\\)?\\s*$"),
new Browser("Lotus", "lotus.notes", "Lotus-Notes\\/([\\w.]+)"),
new Browser("Thunderbird", "thunderbird", Other_Version),
new Browser("Netscape", "netscape", Other_Version),
new Browser("Seamonkey", "seamonkey", Other_Version),
new Browser("Outlook", "microsoft.outlook", Other_Version),
new Browser("Evolution", "evolution", Other_Version),
new Browser("MSIE", "msie", "msie ([\\d\\w\\.\\-]+)"),
new Browser("MSIE11", "rv:11", "rv:([\\d\\w\\.\\-]+)"),
new Browser("Gabble", "Gabble", Other_Version),
new Browser("Yammer Desktop", "AdobeAir", "([\\d\\w\\.\\-]+)\\/Yammer"),
new Browser("Yammer Mobile", "Yammer[\\s]+([\\d\\w\\.\\-]+)", "Yammer[\\s]+([\\d\\w\\.\\-]+)"),
new Browser("Apache HTTP Client", "Apache\\\\-HttpClient", "Apache\\-HttpClient\\/([\\d\\w\\.\\-]+)"),
new Browser("BlackBerry", "BlackBerry", "BlackBerry[\\d]+\\/([\\d\\w\\.\\-]+)")
// 部分特殊浏览器是基于安卓Iphone等的需要优先判断
// 企业微信 企业微信使用微信浏览器内核,会包含 MicroMessenger 所以要放在前面
new Browser("wxwork", "wxwork", "wxwork\\/([\\d\\w\\.\\-]+)"),
// 微信
new Browser("MicroMessenger", "MicroMessenger", Other_Version),
// 微信小程序
new Browser("miniProgram", "miniProgram", Other_Version),
// QQ浏览器
new Browser("QQBrowser", "MQQBrowser", "MQQBrowser\\/([\\d\\w\\.\\-]+)"),
// 钉钉PC端浏览器
new Browser("DingTalk-win", "dingtalk-win", "DingTalk\\(([\\d\\w\\.\\-]+)\\)"),
// 钉钉内置浏览器
new Browser("DingTalk", "DingTalk", "AliApp\\(DingTalk\\/([\\d\\w\\.\\-]+)\\)"),
// 支付宝内置浏览器
new Browser("Alipay", "AlipayClient", "AliApp\\(AP\\/([\\d\\w\\.\\-]+)\\)"),
// 淘宝内置浏览器
new Browser("Taobao", "taobao", "AliApp\\(TB\\/([\\d\\w\\.\\-]+)\\)"),
// UC浏览器
new Browser("UCBrowser", "UC?Browser", "UC?Browser\\/([\\d\\w\\.\\-]+)"),
// XiaoMi 浏览器
new Browser("MiuiBrowser", "MiuiBrowser|mibrowser", "MiuiBrowser\\/([\\d\\w\\.\\-]+)"),
// 夸克浏览器
new Browser("Quark", "Quark", Other_Version),
// 联想浏览器
new Browser("Lenovo", "SLBrowser", "SLBrowser/([\\d\\w\\.\\-]+)"),
new Browser("MSEdge", "Edge|Edg", "(?:edge|Edg|EdgA)\\/([\\d\\w\\.\\-]+)"),
new Browser("Chrome", "chrome|(iphone.*crios.*safari)", "(?:Chrome|CriOS)\\/([\\d\\w\\.\\-]+)"),
new Browser("Firefox", "firefox", Other_Version),
new Browser("IEMobile", "iemobile", Other_Version),
new Browser("Android Browser", "android", "version\\/([\\d\\w\\.\\-]+)"),
new Browser("Safari", "safari", "version\\/([\\d\\w\\.\\-]+)"),
new Browser("Opera", "opera", Other_Version),
new Browser("Konqueror", "konqueror", Other_Version),
new Browser("PS3", "playstation 3", "([\\d\\w\\.\\-]+)\\)\\s*$"),
new Browser("PSP", "playstation portable", "([\\d\\w\\.\\-]+)\\)?\\s*$"),
new Browser("Lotus", "lotus.notes", "Lotus-Notes\\/([\\w.]+)"),
new Browser("Thunderbird", "thunderbird", Other_Version),
new Browser("Netscape", "netscape", Other_Version),
new Browser("Seamonkey", "seamonkey", Other_Version),
new Browser("Outlook", "microsoft.outlook", Other_Version),
new Browser("Evolution", "evolution", Other_Version),
new Browser("MSIE", "msie", "msie ([\\d\\w\\.\\-]+)"),
new Browser("MSIE11", "rv:11", "rv:([\\d\\w\\.\\-]+)"),
new Browser("Gabble", "Gabble", Other_Version),
new Browser("Yammer Desktop", "AdobeAir", "([\\d\\w\\.\\-]+)\\/Yammer"),
new Browser("Yammer Mobile", "Yammer[\\s]+([\\d\\w\\.\\-]+)", "Yammer[\\s]+([\\d\\w\\.\\-]+)"),
new Browser("Apache HTTP Client", "Apache\\\\-HttpClient", "Apache\\-HttpClient\\/([\\d\\w\\.\\-]+)"),
new Browser("BlackBerry", "BlackBerry", "BlackBerry[\\d]+\\/([\\d\\w\\.\\-]+)"),
// issue#I847JY 百度浏览器
new Browser("Baidu", "Baidu", "baiduboxapp\\/([\\d\\w\\.\\-]+)")
);
/**
@ -116,7 +118,7 @@ public class Browser extends UserAgentInfo {
* @return 版本
*/
public String getVersion(String userAgentString) {
if(isUnknown()){
if (isUnknown()) {
return null;
}
return ReUtil.getGroup1(this.versionPattern, userAgentString);
@ -130,11 +132,11 @@ public class Browser extends UserAgentInfo {
public boolean isMobile() {
final String name = this.getName();
return "PSP".equals(name) ||
"Yammer Mobile".equals(name) ||
"Android Browser".equals(name) ||
"IEMobile".equals(name) ||
"MicroMessenger".equals(name) ||
"miniProgram".equals(name) ||
"DingTalk".equals(name);
"Yammer Mobile".equals(name) ||
"Android Browser".equals(name) ||
"IEMobile".equals(name) ||
"MicroMessenger".equals(name) ||
"miniProgram".equals(name) ||
"DingTalk".equals(name);
}
}

View File

@ -456,4 +456,20 @@ public class UserAgentUtilTest {
Assert.assertEquals("iPhone", ua2.getPlatform().toString());
Assert.assertTrue(ua2.isMobile());
}
@Test
public void issueI847JYTest() {
final String s = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) " +
"Mobile/15E148 SP-engine/2.80.0 main%2F1.0 baiduboxapp/13.42.0.11 (Baidu; P2 17.0) NABar/1.0 themeUA=Them";
final UserAgent ua2 = UserAgentUtil.parse(s);
Assert.assertEquals("Baidu", ua2.getBrowser().toString());
Assert.assertEquals("13.42.0.11", ua2.getVersion());
Assert.assertEquals("Webkit", ua2.getEngine().toString());
Assert.assertEquals("605.1.15", ua2.getEngineVersion());
Assert.assertEquals("iPhone", ua2.getOs().toString());
Assert.assertEquals("17_0", ua2.getOsVersion());
Assert.assertEquals("iPhone", ua2.getPlatform().toString());
Assert.assertTrue(ua2.isMobile());
}
}