Skip to content

Commit c050c1f

Browse files
Allow custom http.Client to be passed to SR client (#1099)
* chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * chore: update repo semaphore config * Allow custom http.Client to be passed in to SR client --------- Co-authored-by: Confluent Jenkins Bot <[email protected]>
1 parent 5f88a1c commit c050c1f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

schemaregistry/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
package schemaregistry
1818

19-
import "fmt"
19+
import (
20+
"fmt"
21+
"net/http"
22+
)
2023

2124
// Config is used to pass multiple configuration options to the Schema Registry client.
2225
type Config struct {
@@ -50,6 +53,9 @@ type Config struct {
5053
RequestTimeoutMs int
5154
// CacheCapacity positive integer or zero for unbounded capacity
5255
CacheCapacity int
56+
57+
// HTTP client
58+
HTTPClient *http.Client
5359
}
5460

5561
// NewConfig returns a new configuration instance with sane defaults.

schemaregistry/rest_service.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,24 @@ func newRestService(conf *Config) (*restService, error) {
126126
return nil, err
127127
}
128128

129-
transport, err := configureTransport(conf)
130-
if err != nil {
131-
return nil, err
132-
}
129+
if conf.HTTPClient == nil {
130+
transport, err := configureTransport(conf)
131+
if err != nil {
132+
return nil, err
133+
}
134+
135+
timeout := conf.RequestTimeoutMs
133136

134-
timeout := conf.RequestTimeoutMs
137+
conf.HTTPClient = &http.Client{
138+
Transport: transport,
139+
Timeout: time.Duration(timeout) * time.Millisecond,
140+
}
141+
}
135142

136143
return &restService{
137144
url: u,
138145
headers: headers,
139-
Client: &http.Client{
140-
Transport: transport,
141-
Timeout: time.Duration(timeout) * time.Millisecond,
142-
},
146+
Client: conf.HTTPClient,
143147
}, nil
144148
}
145149

0 commit comments

Comments
 (0)