|
- package control
-
- import (
- "net/http"
- "time"
-
- "github.com/jan/fm-rds-tx/internal/config"
- )
-
- const (
- defaultReadHeaderTimeout = 5 * time.Second
- defaultIdleTimeout = 60 * time.Second
- defaultMaxHeaderBytes = 1 << 20 // 1 MiB
- )
-
- // NewHTTPServer returns a configured HTTP server for the control plane.
- //
- // WriteTimeout is intentionally not set: /audio/stream accepts long-lived
- // POST bodies (continuous PCM push) that would be cut off by a global write
- // deadline. Individual endpoints are protected by MaxBytesReader limits.
- // ReadHeaderTimeout guards against slow-header attacks.
- func NewHTTPServer(cfg config.Config, handler http.Handler) *http.Server {
- return &http.Server{
- Addr: cfg.Control.ListenAddress,
- Handler: handler,
- ReadHeaderTimeout: defaultReadHeaderTimeout,
- IdleTimeout: defaultIdleTimeout,
- MaxHeaderBytes: defaultMaxHeaderBytes,
- }
- }
|