@@ -10,6 +10,7 @@ import (
1010 "time"
1111
1212 "github.com/fido-device-onboard/go-fdo"
13+ "github.com/fido-device-onboard/go-fdo-client/internal/version"
1314 "github.com/fido-device-onboard/go-fdo/http"
1415)
1516
@@ -29,7 +30,7 @@ func TlsTransport(baseURL string, conf *tls.Config, insecureTLS bool) fdo.Transp
2930
3031 return & http.Transport {
3132 BaseURL : baseURL ,
32- Client : & net_http.Client {Transport : & net_http.Transport {
33+ Client : & net_http.Client {Transport : & userAgentTransport { & net_http.Transport {
3334 Proxy : net_http .ProxyFromEnvironment ,
3435 DialContext : (& net.Dialer {
3536 Timeout : 30 * time .Second ,
@@ -41,6 +42,22 @@ func TlsTransport(baseURL string, conf *tls.Config, insecureTLS bool) fdo.Transp
4142 TLSClientConfig : conf ,
4243 TLSHandshakeTimeout : 10 * time .Second ,
4344 ExpectContinueTimeout : 1 * time .Second ,
44- }},
45+ }, "go-fdo-client/" + version . VERSION } },
4546 }
4647}
48+
49+ type userAgentTransport struct {
50+ next net_http.RoundTripper
51+ userAgent string
52+ }
53+
54+ func (t * userAgentTransport ) RoundTrip (req * net_http.Request ) (* net_http.Response , error ) {
55+ r := req .Clone (req .Context ())
56+ if r .Header == nil {
57+ r .Header = make (net_http.Header )
58+ }
59+ if r .Header .Get ("User-Agent" ) == "" {
60+ r .Header .Set ("User-Agent" , t .userAgent )
61+ }
62+ return t .next .RoundTrip (r )
63+ }
0 commit comments