33 lines
723 B
Go
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)
|
|
}
|