()
| 15 | ) |
| 16 | |
| 17 | func Init() { |
| 18 | dialer := &net.Dialer{ |
| 19 | Timeout: 5 * time.Second, |
| 20 | } |
| 21 | dialUnix := func(ctx context.Context, network, addr string) (net.Conn, error) { |
| 22 | return dialer.DialContext(ctx, "unix", SockPath) |
| 23 | } |
| 24 | transport := &http.Transport{ |
| 25 | DialContext: dialUnix, |
| 26 | ForceAttemptHTTP2: false, |
| 27 | MaxIdleConns: 50, |
| 28 | MaxIdleConnsPerHost: 50, |
| 29 | IdleConnTimeout: 30 * time.Second, |
| 30 | } |
| 31 | LocalAgentProxy = &httputil.ReverseProxy{ |
| 32 | Director: func(req *http.Request) { |
| 33 | if req.Header.Get("X-Forwarded-Proto") == "" { |
| 34 | if req.TLS != nil { |
| 35 | req.Header.Set("X-Forwarded-Proto", "https") |
| 36 | } else { |
| 37 | req.Header.Set("X-Forwarded-Proto", "http") |
| 38 | } |
| 39 | } |
| 40 | if req.Header.Get("X-Forwarded-Host") == "" && req.Host != "" { |
| 41 | req.Header.Set("X-Forwarded-Host", req.Host) |
| 42 | } |
| 43 | req.URL.Scheme = "http" |
| 44 | req.URL.Host = "unix" |
| 45 | }, |
| 46 | Transport: transport, |
| 47 | ErrorHandler: func(rw http.ResponseWriter, req *http.Request, err error) { |
| 48 | rw.WriteHeader(http.StatusBadGateway) |
| 49 | _, _ = rw.Write([]byte("Bad Gateway: " + err.Error())) |
| 50 | }, |
| 51 | } |
| 52 | } |
nothing calls this directly
no test coverage detected