| 33 | } |
| 34 | |
| 35 | func (o *httpService) RoundTrip(req *http.Request) (*http.Response, error) { |
| 36 | // Rewrite the request URL so that it goes to the origin service. |
| 37 | req.URL.Host = o.url.Host |
| 38 | switch o.url.Scheme { |
| 39 | case "ws": |
| 40 | req.URL.Scheme = "http" |
| 41 | case "wss": |
| 42 | req.URL.Scheme = "https" |
| 43 | default: |
| 44 | req.URL.Scheme = o.url.Scheme |
| 45 | } |
| 46 | |
| 47 | if o.hostHeader != "" { |
| 48 | // For incoming requests, the Host header is promoted to the Request.Host field and removed from the Header map. |
| 49 | // Pass the original Host header as X-Forwarded-Host. |
| 50 | req.Header.Set("X-Forwarded-Host", req.Host) |
| 51 | req.Host = o.hostHeader |
| 52 | } |
| 53 | |
| 54 | if o.matchSNIToHost { |
| 55 | o.SetOriginServerName(req) |
| 56 | } |
| 57 | |
| 58 | return o.transport.RoundTrip(req) |
| 59 | } |
| 60 | |
| 61 | func (o *httpService) SetOriginServerName(req *http.Request) { |
| 62 | o.transport.DialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) { |