Skip to content

Commit

Permalink
Allow custom http.Client to be passed to SR client (#1099)
Browse files Browse the repository at this point in the history
* 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 <jenkins@confluent.io>
  • Loading branch information
rayokota and ConfluentJenkins authored Nov 8, 2023
1 parent 5f88a1c commit c050c1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
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

0 comments on commit c050c1f

Please sign in to comment.