Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
bot: check for in user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
crackcomm committed Jan 17, 2016
1 parent ea7cf3c commit 0319fcf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (p *UserAgent) fixOther(sections []section) {
}
}

var botRegex = regexp.MustCompile("(?i)(bot|crawler|sp(i|y)der|search|worm|fetch|nutch)")

// Check if we're dealing with a bot or with some weird browser. If that is the
// case, the receiver will be modified accordingly.
func (p *UserAgent) checkBot(sections []section) {
Expand All @@ -83,9 +85,8 @@ func (p *UserAgent) checkBot(sections []section) {
if len(sections) == 1 && sections[0].name != "Mozilla" {
p.mozilla = ""

// Check whether the name has some suspicious "bot" in his name.
reg, _ := regexp.Compile("(?i)bot")
if reg.Match([]byte(sections[0].name)) {
// Check whether the name has some suspicious "bot" or "crawler" in his name.
if botRegex.Match([]byte(sections[0].name)) {
p.setSimple(sections[0].name, "", true)
return
}
Expand Down

0 comments on commit 0319fcf

Please sign in to comment.