From 85eeae9bedb24d1e889c991eb1cda55b33b4dc96 Mon Sep 17 00:00:00 2001 From: Nikolay Petrov Date: Sun, 22 Feb 2026 07:51:11 -0500 Subject: [PATCH] add http timeouts --- destinations.go | 4 +++- pkg/statusc/server.go | 5 ++++- sources.go | 15 ++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/destinations.go b/destinations.go index 6bccc47..6b73304 100644 --- a/destinations.go +++ b/destinations.go @@ -171,7 +171,9 @@ func NewHTTPProxyDestination(dst *Destination, dstURL *url.URL, cfg *tls.Config, func (d *HTTPDestination) Run(ctx context.Context) error { srv := &http.Server{ - Handler: d.handler, + Handler: d.handler, + ReadHeaderTimeout: 30 * time.Second, + IdleTimeout: 120 * time.Second, } go func() { diff --git a/pkg/statusc/server.go b/pkg/statusc/server.go index ada80c6..68e76ec 100644 --- a/pkg/statusc/server.go +++ b/pkg/statusc/server.go @@ -6,13 +6,16 @@ import ( "fmt" "net" "net/http" + "time" "github.com/connet-dev/connet/pkg/slogc" ) func Run[T any](ctx context.Context, addr *net.TCPAddr, f func(ctx context.Context) (T, error)) error { srv := &http.Server{ - Addr: addr.String(), + Addr: addr.String(), + ReadHeaderTimeout: 10 * time.Second, + IdleTimeout: 120 * time.Second, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { stat, err := f(r.Context()) if err == nil { diff --git a/sources.go b/sources.go index aa87359..24272be 100644 --- a/sources.go +++ b/sources.go @@ -10,6 +10,7 @@ import ( "net/http" "net/http/httputil" "net/url" + "time" "github.com/connet-dev/connet/model" "github.com/connet-dev/connet/pkg/netc" @@ -166,8 +167,10 @@ func (s *HTTPSource) Run(ctx context.Context) error { targetURL.Host = endpoint srv := &http.Server{ - Addr: s.srcURL.Host, - TLSConfig: s.cfg, + Addr: s.srcURL.Host, + TLSConfig: s.cfg, + ReadHeaderTimeout: 10 * time.Second, + IdleTimeout: 120 * time.Second, Handler: &httputil.ReverseProxy{ Rewrite: func(pr *httputil.ProxyRequest) { pr.SetURL(&targetURL) @@ -259,9 +262,11 @@ func (s *WSSource) Run(ctx context.Context) error { mux.HandleFunc(path, s.handle) srv := &http.Server{ - Addr: s.srcURL.Host, - TLSConfig: s.cfg, - Handler: mux, + Addr: s.srcURL.Host, + TLSConfig: s.cfg, + ReadHeaderTimeout: 10 * time.Second, + IdleTimeout: 120 * time.Second, + Handler: mux, } go func() {