diff --git a/schemaregistry/config.go b/schemaregistry/config.go index 0388b0e14..67ffc657b 100644 --- a/schemaregistry/config.go +++ b/schemaregistry/config.go @@ -16,7 +16,10 @@ package schemaregistry -import "fmt" +import ( + "fmt" + "net/http" +) // Config is used to pass multiple configuration options to the Schema Registry client. type Config struct { @@ -50,6 +53,9 @@ type Config struct { RequestTimeoutMs int // CacheCapacity positive integer or zero for unbounded capacity CacheCapacity int + + // HTTP client + HTTPClient *http.Client } // NewConfig returns a new configuration instance with sane defaults. diff --git a/schemaregistry/rest_service.go b/schemaregistry/rest_service.go index ef1bbb46a..4c5f5a19a 100644 --- a/schemaregistry/rest_service.go +++ b/schemaregistry/rest_service.go @@ -126,20 +126,24 @@ func newRestService(conf *Config) (*restService, error) { return nil, err } - transport, err := configureTransport(conf) - if err != nil { - return nil, err - } + if conf.HTTPClient == nil { + transport, err := configureTransport(conf) + if err != nil { + return nil, err + } + + timeout := conf.RequestTimeoutMs - timeout := conf.RequestTimeoutMs + conf.HTTPClient = &http.Client{ + Transport: transport, + Timeout: time.Duration(timeout) * time.Millisecond, + } + } return &restService{ url: u, headers: headers, - Client: &http.Client{ - Transport: transport, - Timeout: time.Duration(timeout) * time.Millisecond, - }, + Client: conf.HTTPClient, }, nil }