4
0

httptransport.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Package httptransport implements initialization of [http.Transport] instances and related
  2. // functionality.
  3. package httptransport
  4. import (
  5. "net"
  6. "net/http"
  7. "time"
  8. )
  9. // Wrapper wraps the set of functions mapping [http.Transport] references to [http.RoundTripper].
  10. type Wrapper func(*http.Transport) http.RoundTripper
  11. // NoopWrapper returns a [Wrapper] that simply casts its provided [http.Transport] to an
  12. // [http.RoundTripper].
  13. func NoopWrapper() Wrapper {
  14. return func(t *http.Transport) http.RoundTripper {
  15. return t
  16. }
  17. }
  18. // New returns a reference to an [http.Transport] that's initialized just like the
  19. // [http.DefaultTransport] is by the standard library.
  20. func New() *http.Transport {
  21. return &http.Transport{
  22. Proxy: http.ProxyFromEnvironment,
  23. DialContext: (&net.Dialer{
  24. Timeout: 30 * time.Second,
  25. KeepAlive: 30 * time.Second,
  26. }).DialContext,
  27. ForceAttemptHTTP2: true,
  28. MaxIdleConns: 100,
  29. IdleConnTimeout: 90 * time.Second,
  30. TLSHandshakeTimeout: 10 * time.Second,
  31. ExpectContinueTimeout: 1 * time.Second,
  32. }
  33. }