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