summaryrefslogtreecommitdiffstats
path: root/services/httpservice/client_test.go
diff options
context:
space:
mode:
authorAndreas Linz <klingt.net@gmail.com>2018-10-03 19:28:44 +0200
committerChristopher Speller <crspeller@gmail.com>2018-10-03 10:28:44 -0700
commitcf9b9802a8732424b6cb7c233e3bfcf8cb3530ee (patch)
tree8be964e5c5c8e057dce58b09706ecd93994d790e /services/httpservice/client_test.go
parent580b546862860ca389305d0d4614471095ec67fe (diff)
downloadchat-cf9b9802a8732424b6cb7c233e3bfcf8cb3530ee.tar.gz
chat-cf9b9802a8732424b6cb7c233e3bfcf8cb3530ee.tar.bz2
chat-cf9b9802a8732424b6cb7c233e3bfcf8cb3530ee.zip
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)
Diffstat (limited to 'services/httpservice/client_test.go')
-rw-r--r--services/httpservice/client_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/services/httpservice/client_test.go b/services/httpservice/client_test.go
index ceb133140..174ddf2de 100644
--- a/services/httpservice/client_test.go
+++ b/services/httpservice/client_test.go
@@ -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)
+}