Skip to content

Commit

Permalink
Revert "cleanup"
Browse files Browse the repository at this point in the history
This reverts commit 76e7ccc.
  • Loading branch information
buglloc committed Aug 6, 2023
1 parent a9c349a commit 2bfcbf2
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/xhttp/xhttp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package xhttp

import (
"crypto/tls"
"net"
"net/http"
"time"

"github.com/buglloc/certifi"
)

const (
dialTimeout = 1 * time.Second
requestTimeout = 5 * time.Second
keepAlive = 60 * time.Second
)

func NewHTTPClient() *http.Client {
return &http.Client{
Transport: NewTransport(),
Timeout: requestTimeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
}

func NewTransport() http.RoundTripper {
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.TLSClientConfig = NewTLSClientConfig()
transport.DialContext = (&net.Dialer{
Timeout: dialTimeout,
KeepAlive: keepAlive,
}).DialContext
return transport
}

func NewTLSClientConfig() *tls.Config {
return &tls.Config{
RootCAs: certifi.NewCertPool(),
}
}

0 comments on commit 2bfcbf2

Please sign in to comment.