github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/services/httpservice/transport.go (about)

     1  // Copyright (c) 2017-present Xenia, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package httpservice
     5  
     6  import (
     7  	"net/http"
     8  )
     9  
    10  // XeniaTransport 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 Xenia instance.
    12  type XeniaTransport 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 *XeniaTransport) RoundTrip(req *http.Request) (*http.Response, error) {
    18  	req.Header.Set("User-Agent", defaultUserAgent)
    19  
    20  	return t.Transport.RoundTrip(req)
    21  }