summaryrefslogtreecommitdiffstats
path: root/services/httpservice/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'services/httpservice/client.go')
-rw-r--r--services/httpservice/client.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/services/httpservice/client.go b/services/httpservice/client.go
index 268f63b24..1e7b7b5f9 100644
--- a/services/httpservice/client.go
+++ b/services/httpservice/client.go
@@ -10,6 +10,8 @@ import (
"net"
"net/http"
"time"
+
+ "github.com/mattermost/mattermost-server/model"
)
const (
@@ -28,6 +30,8 @@ func IsReservedIP(ip net.IP) bool {
return false
}
+var defaultUserAgent string
+
func init() {
for _, cidr := range []string{
// See https://tools.ietf.org/html/rfc6890
@@ -48,6 +52,7 @@ func init() {
}
reservedIPRanges = append(reservedIPRanges, parsed)
}
+ defaultUserAgent = "mattermost-" + model.CurrentVersion
}
type DialContextFunction func(ctx context.Context, network, addr string) (net.Conn, error)
@@ -97,6 +102,15 @@ func dialContextFilter(dial DialContextFunction, allowHost func(host string) boo
}
}
+type Client struct {
+ *http.Client
+}
+
+func (c *Client) Do(req *http.Request) (*http.Response, error) {
+ req.Header.Set("User-Agent", defaultUserAgent)
+ return c.Client.Do(req)
+}
+
// NewHTTPClient returns a variation the default implementation of Client.
// It uses a Transport with the same settings as the default Transport
// but with the following modifications:
@@ -104,7 +118,7 @@ func dialContextFilter(dial DialContextFunction, allowHost func(host string) boo
// "connectTimeout")
// - timeout for the end-to-end request (defined as constant
// "requestTimeout")
-func NewHTTPClient(enableInsecureConnections bool, allowHost func(host string) bool, allowIP func(ip net.IP) bool) *http.Client {
+func NewHTTPClient(enableInsecureConnections bool, allowHost func(host string) bool, allowIP func(ip net.IP) bool) *Client {
dialContext := (&net.Dialer{
Timeout: connectTimeout,
KeepAlive: 30 * time.Second,
@@ -129,5 +143,5 @@ func NewHTTPClient(enableInsecureConnections bool, allowHost func(host string) b
Timeout: requestTimeout,
}
- return client
+ return &Client{Client: client}
}