package main
import (
"net/http"
"time"
)
const (
// serveReadHeaderTimeout bounds how long a client may take to send
// its request headers. A real client sends them at once; one that
// trickles them is holding a connection and a goroutine for nothing.
serveReadHeaderTimeout = 10 * time.Second
// serveIdleTimeout bounds how long a kept-alive connection may sit
// between requests. It is longer than the idle timeouts of the
// proxies commonly put in front of a server (nginx 60s, Go's own
// transport 90s, Caddy 2m), so the proxy always closes an idle
// connection first and never reuses one this server has just shut.
serveIdleTimeout = 3 * time.Minute
)
// newServer is the HTTP server the forge listens with. It carries no
// ReadTimeout or WriteTimeout: both bound the whole request, which
// would end every live stream and every long upload at the same fixed
// age. Streams set a write deadline per frame instead, which cuts off a
// reader that stopped reading without touching one that is keeping up.
func newServer(h http.Handler) *http.Server {
return &http.Server{
Handler: h,
ReadHeaderTimeout: serveReadHeaderTimeout,
IdleTimeout: serveIdleTimeout,
}
}