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)
30 строки
672 B
Go
30 строки
672 B
Go
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package testutils
|
|
|
|
import (
|
|
"github.com/mattermost/mattermost-server/services/httpservice"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
)
|
|
|
|
type MockedHTTPService struct {
|
|
Server *httptest.Server
|
|
}
|
|
|
|
func MakeMockedHTTPService(handler http.Handler) *MockedHTTPService {
|
|
return &MockedHTTPService{
|
|
Server: httptest.NewServer(handler),
|
|
}
|
|
}
|
|
|
|
func (h *MockedHTTPService) MakeClient(trustURLs bool) *httpservice.Client {
|
|
return &httpservice.Client{Client: h.Server.Client()}
|
|
}
|
|
|
|
func (h *MockedHTTPService) Close() {
|
|
h.Server.CloseClientConnections()
|
|
h.Server.Close()
|
|
}
|