Files
helix-proxy/cmd/helix-proxy/https.go
T
s1d3sw1ped 1cc94f2c99
Format / gofmt (push) Failing after 27s
CI / Build (push) Successful in 51s
CI / Go Tests (push) Failing after 21s
initial commit
2026-06-06 07:54:44 -05:00

33 lines
723 B
Go

package main
import (
"context"
"crypto/tls"
"net/http"
"time"
"helix-proxy/internal/proxy"
)
// serveHTTPS listens with TLS and serves the proxy engine handler (SNI via eng.TLSConfig).
// Shuts down when ctx is cancelled.
func serveHTTPS(ctx context.Context, eng *proxy.Engine, addr string) error {
ln, err := tls.Listen("tcp", addr, eng.TLSConfig())
if err != nil {
return err
}
srv := &http.Server{
Handler: eng.Handler(),
ReadTimeout: 30 * time.Second,
WriteTimeout: 60 * time.Second,
}
go func() {
<-ctx.Done()
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_ = srv.Shutdown(shutdownCtx)
_ = ln.Close()
}()
return srv.Serve(ln)
}