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
- http.ServeMux — The request router in Go's net/http package, which matches each request's path, and optionally its method, to the handler registered for it.
- Server.Shutdown — The http.Server method that stops accepting new connections and waits for active requests to finish, up to the deadline of the context you pass.
- listener — An open network socket that waits for and accepts incoming connections on an address and port.
- timeout — A limit on how long a caller waits for an answer before giving up.
- http.Handler — In Go, a function or type that receives an HTTP request and writes the response, with the signature func(w http.ResponseWriter, r *http.Request).
Taught in
- Serving HTTP with net/http Server — Concurrent Systems Programming with Go
- Graceful Shutdown on SIGTERM — Concurrent Systems Programming with Go