(cfgCp *config.ConnectionPool)
| 50 | } |
| 51 | |
| 52 | func newReverseProxy(cfgCp *config.ConnectionPool) *reverseProxy { |
| 53 | transport := &http.Transport{ |
| 54 | Proxy: http.ProxyFromEnvironment, |
| 55 | DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { |
| 56 | dialer := &net.Dialer{ |
| 57 | Timeout: 30 * time.Second, |
| 58 | KeepAlive: 30 * time.Second, |
| 59 | } |
| 60 | return dialer.DialContext(ctx, network, addr) |
| 61 | }, |
| 62 | ForceAttemptHTTP2: true, |
| 63 | MaxIdleConns: cfgCp.MaxIdleConns, |
| 64 | MaxIdleConnsPerHost: cfgCp.MaxIdleConnsPerHost, |
| 65 | IdleConnTimeout: 90 * time.Second, |
| 66 | TLSHandshakeTimeout: 10 * time.Second, |
| 67 | ExpectContinueTimeout: 1 * time.Second, |
| 68 | } |
| 69 | |
| 70 | return &reverseProxy{ |
| 71 | rp: &httputil.ReverseProxy{ |
| 72 | Director: func(*http.Request) {}, |
| 73 | Transport: transport, |
| 74 | |
| 75 | // Suppress error logging in ReverseProxy, since all the errors |
| 76 | // are handled and logged in the code below. |
| 77 | ErrorLog: log.NilLogger, |
| 78 | }, |
| 79 | reloadSignal: make(chan struct{}), |
| 80 | reloadWG: sync.WaitGroup{}, |
| 81 | maxIdleConns: cfgCp.MaxIdleConnsPerHost, |
| 82 | maxIdleConnsPerHost: cfgCp.MaxIdleConnsPerHost, |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func (rp *reverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { |
| 87 | startTime := time.Now() |
no outgoing calls