File: httptransport.go

package info (click to toggle)
golang-github-smallstep-certificates 0.28.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,684 kB
  • sloc: sh: 367; makefile: 129
file content (37 lines) | stat: -rw-r--r-- 1,069 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Package httptransport implements initialization of [http.Transport] instances and related
// functionality.
package httptransport

import (
	"net"
	"net/http"
	"time"
)

// Wrapper wraps the set of functions mapping [http.Transport] references to [http.RoundTripper].
type Wrapper func(*http.Transport) http.RoundTripper

// NoopWrapper returns a [Wrapper] that simply casts its provided [http.Transport] to an
// [http.RoundTripper].
func NoopWrapper() Wrapper {
	return func(t *http.Transport) http.RoundTripper {
		return t
	}
}

// New returns a reference to an [http.Transport] that's initialized just like the
// [http.DefaultTransport] is by the standard library.
func New() *http.Transport {
	return &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).DialContext,
		ForceAttemptHTTP2:     true,
		MaxIdleConns:          100,
		IdleConnTimeout:       90 * time.Second,
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 1 * time.Second,
	}
}