Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
.circleci/ | H | 23-Jul-2019 | - | 70 | 60 | |
.github/ | H | 23-Jul-2019 | - | 22 | 17 | |
LICENSE | H A D | 23-Jul-2019 | 1.3 KiB | 23 | 18 | |
README.md | H A D | 23-Jul-2019 | 2.7 KiB | 57 | 43 | |
canonical.go | H A D | 23-Jul-2019 | 1.9 KiB | 75 | 43 | |
canonical_test.go | H A D | 23-Jul-2019 | 3.3 KiB | 128 | 94 | |
compress.go | H A D | 23-Jul-2019 | 3.5 KiB | 151 | 109 | |
compress_test.go | H A D | 23-Jul-2019 | 6.3 KiB | 220 | 191 | |
cors.go | H A D | 23-Jul-2019 | 9.4 KiB | 356 | 245 | |
cors_test.go | H A D | 23-Jul-2019 | 12.4 KiB | 411 | 300 | |
doc.go | H A D | 23-Jul-2019 | 356 | 10 | 1 | |
go.mod | H A D | 23-Jul-2019 | 35 | 2 | 1 | |
handlers.go | H A D | 23-Jul-2019 | 4.8 KiB | 175 | 116 | |
handlers_go18.go | H A D | 23-Jul-2019 | 616 | 30 | 23 | |
handlers_go18_test.go | H A D | 23-Jul-2019 | 963 | 35 | 27 | |
handlers_pre18.go | H A D | 23-Jul-2019 | 106 | 8 | 4 | |
handlers_test.go | H A D | 23-Jul-2019 | 4.5 KiB | 149 | 124 | |
logging.go | H A D | 23-Jul-2019 | 7 KiB | 256 | 184 | |
logging_test.go | H A D | 23-Jul-2019 | 10.2 KiB | 385 | 316 | |
proxy_headers.go | H A D | 23-Jul-2019 | 4.5 KiB | 121 | 70 | |
proxy_headers_test.go | H A D | 23-Jul-2019 | 3.4 KiB | 112 | 98 | |
recovery.go | H A D | 23-Jul-2019 | 2.1 KiB | 92 | 58 | |
recovery_test.go | H A D | 23-Jul-2019 | 1.2 KiB | 45 | 35 |
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