mirror of
https://github.com/mattermost/mattermost.git
synced 2026-10-24 23:34:52 +08:00
Set a proper HTTP user-agent header (#9482)
Previously, mattermost-server would always request with the default user-agent of Go's net/http package that is `Go-http-client/1.1` or something similar. This has several disadvantages, one is that the default user-agent made it pretty hard to distinguish mattermost requests from other service requests in a network log for example. Now a user-agent of the form `mattermost-<current-version>` is set in the client. - [x] Added or updated unit tests (required for all new features)
This commit is contained in:
committed by
Christopher Speller
parent
580b546862
commit
cf9b9802a8
@@ -118,3 +118,24 @@ func TestDialContextFilter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserAgentIsSet(t *testing.T) {
|
||||
testUserAgent := "test-user-agent"
|
||||
defaultUserAgent = testUserAgent
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
ua := req.UserAgent()
|
||||
if ua == "" {
|
||||
t.Error("expected user-agent to be non-empty")
|
||||
}
|
||||
if ua != testUserAgent {
|
||||
t.Errorf("expected user-agent to be %q but was %q", testUserAgent, ua)
|
||||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
client := NewHTTPClient(true, nil, nil)
|
||||
req, err := http.NewRequest("GET", ts.URL, nil)
|
||||
if err != nil {
|
||||
t.Fatal("NewRequest failed", err)
|
||||
}
|
||||
client.Do(req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user