Skip to content

Commit 1427bbb

Browse files
authored
feat: Add HTTPClient option (#86)
1 parent 81a431c commit 1427bbb

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

client.go

+4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ type ClientOptions struct {
7474
Environment string
7575
// Maximum number of breadcrumbs.
7676
MaxBreadcrumbs int
77+
// An optional pointer to `http.Client` that will be used with a default HTTPTransport.
78+
// Using your own client will make HTTPTransport, HTTPProxy, HTTPSProxy and CaCerts options ignored.
79+
HTTPClient *http.Client
7780
// An optional pointer to `http.Transport` that will be used with a default HTTPTransport.
81+
// Using your own transport will make HTTPProxy, HTTPSProxy and CaCerts options ignored.
7882
HTTPTransport *http.Transport
7983
// An optional HTTP proxy to use.
8084
// This will default to the `http_proxy` environment variable.

transport.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ func (t *HTTPTransport) Configure(options ClientOptions) {
143143
}
144144
}
145145

146-
t.client = &http.Client{
147-
Transport: t.transport,
148-
Timeout: t.Timeout,
146+
if options.HTTPClient != nil {
147+
t.client = options.HTTPClient
148+
} else {
149+
t.client = &http.Client{
150+
Transport: t.transport,
151+
Timeout: t.Timeout,
152+
}
149153
}
150154

151155
t.start.Do(func() {
@@ -276,9 +280,13 @@ func (t *HTTPSyncTransport) Configure(options ClientOptions) {
276280
}
277281
}
278282

279-
t.client = &http.Client{
280-
Transport: t.transport,
281-
Timeout: t.Timeout,
283+
if options.HTTPClient != nil {
284+
t.client = options.HTTPClient
285+
} else {
286+
t.client = &http.Client{
287+
Transport: t.transport,
288+
Timeout: t.Timeout,
289+
}
282290
}
283291
}
284292

0 commit comments

Comments
 (0)