MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / Init

Function Init

core/init/proxy/proxy.go:17–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func 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}

Callers

nothing calls this directly

Calls 5

WriteHeaderMethod · 0.80
GetMethod · 0.65
SetMethod · 0.45
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected