Skip to content

Commit

Permalink
removed user agent listening
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed May 17, 2016
1 parent 31476ae commit 6ba8a00
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
14 changes: 2 additions & 12 deletions src/github.com/getlantern/flashlight/logging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"
"time"

"github.com/getlantern/eventual"
"github.com/getlantern/go-loggly"
"github.com/getlantern/golog"
"github.com/stretchr/testify/assert"
Expand All @@ -18,28 +17,19 @@ import (
// Test to make sure user agent registration, listening, etc is all working.
func TestUserAgent(t *testing.T) {
agent := "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36"
userAgent := eventual.NewValue()

listener := func(a string) {
userAgent.Set(a)
}

// Do an initial register just to test the duplicate agent paths.
RegisterUserAgent(agent)

AddUserAgentListener(listener)

go func() {
time.Sleep(200 * time.Millisecond)
RegisterUserAgent(agent)
}()

received, _ := userAgent.Get(4 * time.Second)
assert.Equal(t, agent, received.(string), "Unexpected agent!")
time.Sleep(200 * time.Millisecond)

agents := getSessionUserAgents()

assert.True(t, strings.Contains(agents, "AppleWebKit"), "Expected agent not there!")
assert.True(t, strings.Contains(agents, "AppleWebKit"), "Expected agent not in "+agents)
}

type BadWriter struct{}
Expand Down
13 changes: 0 additions & 13 deletions src/github.com/getlantern/flashlight/logging/useragents.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@ var (
userAgents = make(map[string]int)
agentsMutex = &sync.Mutex{}
reg = regexp.MustCompile("^Go.*package http$")
listeners = make([]func(string), 0)
)

// AddUserAgentListener registers a listener for user agents.
func AddUserAgentListener(listener func(string)) {
agentsMutex.Lock()
defer agentsMutex.Unlock()
listeners = append(listeners, listener)
}

// RegisterUserAgent tries to find the User-Agent in the HTTP request
// and keep track of the applications using Lantern during this session
func RegisterUserAgent(agent string) {
Expand All @@ -34,11 +26,6 @@ func RegisterUserAgent(agent string) {
userAgents[agent] = n + 1
} else {
userAgents[agent] = 1

// Only notify listeners when we have a new agent.
for _, f := range listeners {
f(agent)
}
}
}
}()
Expand Down

0 comments on commit 6ba8a00

Please sign in to comment.