@@ -32,8 +32,10 @@ type (
32
32
// Tailnet allows specifying a specific Tailnet by name, to which this Client will connect by default.
33
33
Tailnet string
34
34
35
- // http is the http client to use for requests to the API server. If specified, this supercedes the above configuration.
36
- http * http.Client
35
+ // HTTP is the [http.Client] to use for requests to the API server.
36
+ // If not specified, a new [http.Client] with a Timeout of 1 minute will be used.
37
+ // This will be ignored if using [Client.UseOAuth].
38
+ HTTP * http.Client
37
39
38
40
initOnce sync.Once
39
41
@@ -96,8 +98,8 @@ func (c *Client) init() {
96
98
if c .UserAgent == "" {
97
99
c .UserAgent = defaultUserAgent
98
100
}
99
- if c .http == nil {
100
- c .http = & http.Client {Timeout : defaultHttpClientTimeout }
101
+ if c .HTTP == nil {
102
+ c .HTTP = & http.Client {Timeout : defaultHttpClientTimeout }
101
103
}
102
104
c .contacts = & ContactsResource {c }
103
105
c .devicePosture = & DevicePostureResource {c }
@@ -113,6 +115,7 @@ func (c *Client) init() {
113
115
}
114
116
115
117
// UseOAuth configures the client to use the specified OAuth credentials.
118
+ // If [Client.HTTP] was previously specified, this replaces it.
116
119
func (c * Client ) UseOAuth (clientID , clientSecret string , scopes []string ) {
117
120
oauthConfig := clientcredentials.Config {
118
121
ClientID : clientID ,
@@ -122,8 +125,8 @@ func (c *Client) UseOAuth(clientID, clientSecret string, scopes []string) {
122
125
}
123
126
124
127
// use context.Background() here, since this is used to refresh the token in the future
125
- c .http = oauthConfig .Client (context .Background ())
126
- c .http .Timeout = defaultHttpClientTimeout
128
+ c .HTTP = oauthConfig .Client (context .Background ())
129
+ c .HTTP .Timeout = defaultHttpClientTimeout
127
130
}
128
131
129
132
func (c * Client ) Contacts () * ContactsResource {
@@ -275,7 +278,7 @@ func (c *Client) buildRequest(ctx context.Context, method string, uri *url.URL,
275
278
}
276
279
277
280
func (c * Client ) do (req * http.Request , out interface {}) error {
278
- res , err := c .http .Do (req )
281
+ res , err := c .HTTP .Do (req )
279
282
if err != nil {
280
283
return err
281
284
}
0 commit comments