@@ -90,36 +90,33 @@ type ClientOpts struct {
9090}
9191
9292func buildTransport (opts ClientOpts , flags * Flags ) http.RoundTripper {
93- transport := http .DefaultTransport .(* http.Transport ).Clone ()
93+ var transport http.RoundTripper
94+ {
95+ tp := http .DefaultTransport .(* http.Transport ).Clone ()
9496
95- if flags .insecureSkipVerify != nil && * flags .insecureSkipVerify {
96- transport .TLSClientConfig = & tls.Config {InsecureSkipVerify : true }
97- }
97+ if flags .insecureSkipVerify != nil && * flags .insecureSkipVerify {
98+ tp .TLSClientConfig = & tls.Config {InsecureSkipVerify : true }
99+ }
98100
99- if transport .TLSClientConfig == nil {
100- transport .TLSClientConfig = & tls.Config {}
101- }
101+ if tp .TLSClientConfig == nil {
102+ tp .TLSClientConfig = & tls.Config {}
103+ }
102104
103- if opts .ProxyPath != "" || opts .ProxyURL != nil {
104- // Use our custom dialer for proxied connections.
105- // A custom dialer is not always needed - the connection libraries will handle HTTP(S)_PROXY-defined proxies
106- // (Go supports http, https, socks5, and socks5h proxies via HTTP(S)_PROXY),
107- // but we're also supporting proxies defined via SRC_PROXY, which can include UDS proxies,
108- // and connecting to TLS-enabled proxies adds an additional wrinkle when using HTTP/2.
109- transport = withProxyTransport (transport , opts .ProxyURL , opts .ProxyPath )
110- }
105+ if opts .ProxyPath != "" || opts .ProxyURL != nil {
106+ tp = withProxyTransport (transport , opts .ProxyURL , opts .ProxyPath )
107+ }
111108
112- // For http:// and socks5:// proxies, the cloned
113- // transport's default Proxy handles them correctly without intervention.
109+ transport = tp
110+ }
114111
115- var rt http.RoundTripper = transport
112+ // not we do not fail here if requireAccessToken is true, because that would
113+ // mean returning an error on construction which we want to avoid for now
114+ // TODO(burmudar): allow returning of an error upon client construction
116115 if opts .AccessToken == "" && opts .OAuthToken != nil {
117- rt = & oauth.Transport {
118- Base : transport ,
119- Token : opts .OAuthToken ,
120- }
116+ transport = oauth .NewTransport (transport , opts .OAuthToken )
121117 }
122- return rt
118+
119+ return transport
123120}
124121
125122// NewClient creates a new API client.
0 commit comments