Skip to content

Commit

Permalink
Add support for Applebot
Browse files Browse the repository at this point in the history
  • Loading branch information
mileusna committed Aug 28, 2020
1 parent 2aaeb7a commit 726a5d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ua.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
Googlebot = "Googlebot"
Twitterbot = "Twitterbot"
FacebookExternalHit = "facebookexternalhit"
Applebot = "Applebot"
)

// Parse user agent string returning UserAgent struct
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion ua_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 726a5d1

Please sign in to comment.