Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
.circleci/ | H | 23-Jul-2019 | - | |||
.github/ | H | 23-Jul-2019 | - | |||
LICENSE | H A D | 23-Jul-2019 | 1.3 KiB | |||
README.md | H A D | 23-Jul-2019 | 2.7 KiB | |||
canonical.go | H A D | 23-Jul-2019 | 1.9 KiB | |||
canonical_test.go | H A D | 23-Jul-2019 | 3.3 KiB | |||
compress.go | H A D | 23-Jul-2019 | 3.5 KiB | |||
compress_test.go | H A D | 23-Jul-2019 | 6.3 KiB | |||
cors.go | H A D | 23-Jul-2019 | 9.4 KiB | |||
cors_test.go | H A D | 23-Jul-2019 | 12.4 KiB | |||
doc.go | H A D | 23-Jul-2019 | 356 | |||
go.mod | H A D | 23-Jul-2019 | 35 | |||
handlers.go | H A D | 23-Jul-2019 | 4.8 KiB | |||
handlers_go18.go | H A D | 23-Jul-2019 | 616 | |||
handlers_go18_test.go | H A D | 23-Jul-2019 | 963 | |||
handlers_pre18.go | H A D | 23-Jul-2019 | 106 | |||
handlers_test.go | H A D | 23-Jul-2019 | 4.5 KiB | |||
logging.go | H A D | 23-Jul-2019 | 7 KiB | |||
logging_test.go | H A D | 23-Jul-2019 | 10.2 KiB | |||
proxy_headers.go | H A D | 23-Jul-2019 | 4.5 KiB | |||
proxy_headers_test.go | H A D | 23-Jul-2019 | 3.4 KiB | |||
recovery.go | H A D | 23-Jul-2019 | 2.1 KiB | |||
recovery_test.go | H A D | 23-Jul-2019 | 1.2 KiB |
README.md
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