Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom http.Client to be passed to SR client #1099

Merged
merged 17 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion schemaregistry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 13 additions & 9 deletions schemaregistry/rest_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down