-
Notifications
You must be signed in to change notification settings - Fork 51
/
transport.go
45 lines (36 loc) · 989 Bytes
/
transport.go
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
package httpproxy
import (
"net/http"
)
// TriremeRoundTripper is the Trireme RoundTripper that will handle
// responses.
type TriremeRoundTripper struct {
http.RoundTripper
}
// NewTriremeRoundTripper creates a new RoundTripper that handles the
// responses.
func NewTriremeRoundTripper(r http.RoundTripper) *TriremeRoundTripper {
return &TriremeRoundTripper{
RoundTripper: r,
}
}
// RoundTrip implements the RoundTripper interface. It will add a cookie
// in the response in case of OIDC requests with refresh tokens.
func (t *TriremeRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
res, err := t.RoundTripper.RoundTrip(req)
if err != nil || res == nil {
return res, err
}
data := req.Context().Value(statsContextKey)
if data == nil {
return res, nil
}
state, ok := data.(*connectionState)
if ok && state.cookie == nil {
return res, nil
}
if v := state.cookie.String(); v != "" {
res.Header.Add("Set-Cookie", v)
}
return res, nil
}