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
38
39
40
41
42
43
44
45
46
|
package serverless
import (
"context"
"net"
"net/http"
"time"
)
// Transport is a struct that handle the proxy connection round trip to Knative
// cluster
type Transport struct {
cluster Cluster
transport *http.Transport
}
// NewTransport fabricates as new transport type
func NewTransport(cluster Cluster) *Transport {
dialer := net.Dialer{
Timeout: 4 * time.Minute,
KeepAlive: 6 * time.Minute,
}
dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
address = cluster.Host()
return dialer.DialContext(ctx, network, address)
}
return &Transport{
cluster: cluster,
transport: &http.Transport{
DialContext: dialContext,
TLSHandshakeTimeout: 5 * time.Second,
TLSClientConfig: cluster.TLSConfig(),
},
}
}
// RoundTrip performs a connection to a Knative cluster and returns a response
func (t *Transport) RoundTrip(request *http.Request) (*http.Response, error) {
response, err := t.transport.RoundTrip(request)
// TODO add prometheus metrics for round trip timing
return response, err
}
|