From 726a5d1b2df8a0c89dfbcd75587a28b547caed2f Mon Sep 17 00:00:00 2001 From: Milos Mileusnic Date: Fri, 28 Aug 2020 15:54:34 +0200 Subject: [PATCH] Add support for Applebot --- ua.go | 8 ++++++++ ua_test.go | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ua.go b/ua.go index d374aeb..b4deb4d 100644 --- a/ua.go +++ b/ua.go @@ -51,6 +51,7 @@ const ( Googlebot = "Googlebot" Twitterbot = "Twitterbot" FacebookExternalHit = "facebookexternalhit" + Applebot = "Applebot" ) // Parse user agent string returning UserAgent struct @@ -128,6 +129,13 @@ func Parse(userAgent string) UserAgent { ua.Bot = true ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari") + case tokens.exists("Applebot"): + ua.Name = Applebot + ua.Version = tokens[Applebot] + ua.Bot = true + ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari") + ua.OS = "" + case tokens["Opera Mini"] != "": ua.Name = OperaMini ua.Version = tokens[OperaMini] diff --git a/ua_test.go b/ua_test.go index c71ddd3..7b940c6 100644 --- a/ua_test.go +++ b/ua_test.go @@ -61,7 +61,8 @@ func TestParse(t *testing.T) { // Bots {"Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", ua.Googlebot, "2.1", "mobile", "Android"}, {"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", ua.Googlebot, "2.1", "bot", ""}, - {"Twitterbot/1.0", ua.Twitterbot, "1.0", "bot", ""}, + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15 (Applebot/0.1; +http://www.apple.com/go/applebot)", "Applebot", "0.1", "bot", ""}, + {"Twitterbot/1.0", ua.Twitterbot, "1.0", ua.Applebot, ""}, {"facebookexternalhit/1.1", ua.FacebookExternalHit, "1.1", "bot", ""}, // other