| 40 | const proxyFlushInternal = 1 * time.Second |
| 41 | |
| 42 | func (h *HTTPServer) Setup() { |
| 43 | h.unixTransport = &http.Transport{ |
| 44 | DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) { |
| 45 | socketPath, _, err := net.SplitHostPort(addr) |
| 46 | if err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | |
| 50 | dialer := net.Dialer{ |
| 51 | Timeout: dialerTimeout, |
| 52 | KeepAlive: keepAlive, |
| 53 | } |
| 54 | return dialer.DialContext(ctx, "unix", socketPath) |
| 55 | }, |
| 56 | TLSHandshakeTimeout: tlsHandshakeTimeout, |
| 57 | ExpectContinueTimeout: expectContinueTimeout, |
| 58 | } |
| 59 | |
| 60 | h.unixProxy = &httputil.ReverseProxy{ |
| 61 | Director: func(_ *http.Request) {}, |
| 62 | Transport: h.unixTransport, |
| 63 | FlushInterval: proxyFlushInternal, |
| 64 | } |
| 65 | |
| 66 | h.tcpTransport = &http.Transport{ |
| 67 | DialContext: (&net.Dialer{ |
| 68 | Timeout: dialerTimeout, |
| 69 | KeepAlive: keepAlive, |
| 70 | }).DialContext, |
| 71 | TLSHandshakeTimeout: tlsHandshakeTimeout, |
| 72 | ExpectContinueTimeout: expectContinueTimeout, |
| 73 | } |
| 74 | |
| 75 | h.tcpProxy = &httputil.ReverseProxy{ |
| 76 | Director: func(_ *http.Request) {}, |
| 77 | Transport: h.tcpTransport, |
| 78 | FlushInterval: proxyFlushInternal, |
| 79 | } |
| 80 | |
| 81 | h.Pool.AppClosed = h.AppClosed |
| 82 | |
| 83 | h.mux = pat.New() |
| 84 | |
| 85 | h.mux.Get("/status", http.HandlerFunc(h.status)) |
| 86 | h.mux.Get("/events", http.HandlerFunc(h.events)) |
| 87 | } |
| 88 | |
| 89 | func (h *HTTPServer) AppClosed(app *App) { |
| 90 | // Whenever an app is closed, wipe out all idle conns. This |