Skip to content
Open
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
10 changes: 9 additions & 1 deletion pipeline/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"net/http"
"os"
"sync"
"time"
)

Expand Down Expand Up @@ -199,7 +200,8 @@ func (po *PolicyOptions) Log(level LogLevel, msg string) {
}
}

var pipelineHTTPClient = newDefaultHTTPClient()
var onceHTTPInit sync.Once
var pipelineHTTPClient *http.Client

func newDefaultHTTPClient() *http.Client {
// We want the Transport to have a large connection pool
Expand Down Expand Up @@ -228,6 +230,12 @@ func newDefaultHTTPClient() *http.Client {

// newDefaultHTTPClientFactory creates a DefaultHTTPClientPolicyFactory object that sends HTTP requests to a Go's default http.Client.
func newDefaultHTTPClientFactory() Factory {
onceHTTPInit.Do(func () {
if pipelineHTTPClient == nil {
pipelineHTTPClient = newDefaultHTTPClient()
}
})

return FactoryFunc(func(next Policy, po *PolicyOptions) PolicyFunc {
return func(ctx context.Context, request Request) (Response, error) {
r, err := pipelineHTTPClient.Do(request.WithContext(ctx))
Expand Down