Skip to content

Commit

Permalink
Nicely formatted User Agent list
Browse files Browse the repository at this point in the history
  • Loading branch information
uaalto committed Aug 17, 2015
1 parent 1271b3b commit fa5d299
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/github.com/getlantern/flashlight/logging/useragents.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package logging

import (
"bytes"
"fmt"
"regexp"
"sync"
)

Expand All @@ -10,6 +12,7 @@ type agentsMap map[string]int
var (
userAgents = make(agentsMap)
agentsMutex = &sync.Mutex{}
reg = regexp.MustCompile("^Go.*package http$")
)

// registerUserAgent tries to find the User-Agent in the HTTP request
Expand All @@ -34,5 +37,14 @@ func RegisterUserAgent(agent string) {
func GetSessionUserAgents() string {
agentsMutex.Lock()
defer agentsMutex.Unlock()
return (fmt.Sprintf("%v", userAgents))

var buffer bytes.Buffer

for key, val := range userAgents {
if !reg.MatchString(key) {
buffer.WriteString(key)
buffer.WriteString(fmt.Sprintf(": %d requests; ", val))
}
}
return string(buffer.String())
}

0 comments on commit fa5d299

Please sign in to comment.