github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/services/httpservice/transport.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package httpservice
     5  
     6  import (
     7  	"net/http"
     8  )
     9  
    10  // MattermostTransport is an implementation of http.RoundTripper that ensures each request contains a custom user agent
    11  // string to indicate that the request is coming from a Mattermost instance.
    12  type MattermostTransport struct {
    13  	// Transport is the underlying http.RoundTripper that is actually used to make the request
    14  	Transport http.RoundTripper
    15  }
    16  
    17  func (t *MattermostTransport) RoundTrip(req *http.Request) (*http.Response, error) {
    18  	req.Header.Set("User-Agent", defaultUserAgent)
    19  
    20  	return t.Transport.RoundTrip(req)
    21  }