1gorilla/handlers
2================
3[![GoDoc](https://godoc.org/github.com/gorilla/handlers?status.svg)](https://godoc.org/github.com/gorilla/handlers)
4[![CircleCI](https://circleci.com/gh/gorilla/handlers.svg?style=svg)](https://circleci.com/gh/gorilla/handlers)
5[![Sourcegraph](https://sourcegraph.com/github.com/gorilla/handlers/-/badge.svg)](https://sourcegraph.com/github.com/gorilla/handlers?badge)
6
7
8Package handlers is a collection of handlers (aka "HTTP middleware") for use
9with Go's `net/http` package (or any framework supporting `http.Handler`), including:
10
11* [**LoggingHandler**](https://godoc.org/github.com/gorilla/handlers#LoggingHandler) for logging HTTP requests in the Apache [Common Log
12  Format](http://httpd.apache.org/docs/2.2/logs.html#common).
13* [**CombinedLoggingHandler**](https://godoc.org/github.com/gorilla/handlers#CombinedLoggingHandler) for logging HTTP requests in the Apache [Combined Log
14  Format](http://httpd.apache.org/docs/2.2/logs.html#combined) commonly used by
15  both Apache and nginx.
16* [**CompressHandler**](https://godoc.org/github.com/gorilla/handlers#CompressHandler) for gzipping responses.
17* [**ContentTypeHandler**](https://godoc.org/github.com/gorilla/handlers#ContentTypeHandler) for validating requests against a list of accepted
18  content types.
19* [**MethodHandler**](https://godoc.org/github.com/gorilla/handlers#MethodHandler) for matching HTTP methods against handlers in a
20  `map[string]http.Handler`
21* [**ProxyHeaders**](https://godoc.org/github.com/gorilla/handlers#ProxyHeaders) for populating `r.RemoteAddr` and `r.URL.Scheme` based on the
22  `X-Forwarded-For`, `X-Real-IP`, `X-Forwarded-Proto` and RFC7239 `Forwarded`
23  headers when running a Go server behind a HTTP reverse proxy.
24* [**CanonicalHost**](https://godoc.org/github.com/gorilla/handlers#CanonicalHost) for re-directing to the preferred host when handling multiple
25  domains (i.e. multiple CNAME aliases).
26* [**RecoveryHandler**](https://godoc.org/github.com/gorilla/handlers#RecoveryHandler) for recovering from unexpected panics.
27
28Other handlers are documented [on the Gorilla
29website](https://www.gorillatoolkit.org/pkg/handlers).
30
31## Example
32
33A simple example using `handlers.LoggingHandler` and `handlers.CompressHandler`:
34
35```go
36import (
37    "net/http"
38    "github.com/gorilla/handlers"
39)
40
41func main() {
42    r := http.NewServeMux()
43
44    // Only log requests to our admin dashboard to stdout
45    r.Handle("/admin", handlers.LoggingHandler(os.Stdout, http.HandlerFunc(ShowAdminDashboard)))
46    r.HandleFunc("/", ShowIndex)
47
48    // Wrap our server with our gzip handler to gzip compress all responses.
49    http.ListenAndServe(":8000", handlers.CompressHandler(r))
50}
51```
52
53## License
54
55BSD licensed. See the included LICENSE file for details.
56
57