Skip to content

Commit

Permalink
Update pkg/osv to allow overriding the http client / transport.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Mendoza <[email protected]>
  • Loading branch information
jeffmendoza committed Apr 25, 2023
1 parent 2c101c1 commit ce0e9f3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/osv/osv.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
maxConcurrentRequests = 25
)

var HttpClient = http.DefaultClient

// Package represents a package identifier for OSV.
type Package struct {
PURL string `json:"purl,omitempty"`
Expand Down Expand Up @@ -140,7 +142,7 @@ func MakeRequest(request BatchedQuery) (*BatchedResponse, error) {
resp, err := makeRetryRequest(func() (*http.Response, error) {
// We do not need a specific context
//nolint:noctx
return http.Post(QueryEndpoint, "application/json", requestBuf)
return HttpClient.Post(QueryEndpoint, "application/json", requestBuf)
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -168,7 +170,7 @@ func MakeRequest(request BatchedQuery) (*BatchedResponse, error) {
func Get(id string) (*models.Vulnerability, error) {
resp, err := makeRetryRequest(func() (*http.Response, error) {
//nolint:noctx
return http.Get(GetEndpoint + "/" + id)
return HttpClient.Get(GetEndpoint + "/" + id)
})
if err != nil {
return nil, err
Expand Down

0 comments on commit ce0e9f3

Please sign in to comment.