http.Server

The Go type that listens on a network address and serves HTTP requests through a handler, with fields for limits such as timeouts.

In more detail

Configure a server explicitly rather than using the package-level shortcut, so ReadHeaderTimeout, ReadTimeout and similar limits are visible. ListenAndServe starts it; Shutdown stops it gracefully. Missing timeouts let slow clients tie up connections.

Example

server := &http.Server{Addr: ":8080", Handler: mux, ReadHeaderTimeout: 5 * time.Second}

Related terms

Taught in

References