• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.circleci/H23-Jul-2019-

.github/H23-Jul-2019-

LICENSEH A D23-Jul-20191.3 KiB

README.mdH A D23-Jul-20192.7 KiB

canonical.goH A D23-Jul-20191.9 KiB

canonical_test.goH A D23-Jul-20193.3 KiB

compress.goH A D23-Jul-20193.5 KiB

compress_test.goH A D23-Jul-20196.3 KiB

cors.goH A D23-Jul-20199.4 KiB

cors_test.goH A D23-Jul-201912.4 KiB

doc.goH A D23-Jul-2019356

go.modH A D23-Jul-201935

handlers.goH A D23-Jul-20194.8 KiB

handlers_go18.goH A D23-Jul-2019616

handlers_go18_test.goH A D23-Jul-2019963

handlers_pre18.goH A D23-Jul-2019106

handlers_test.goH A D23-Jul-20194.5 KiB

logging.goH A D23-Jul-20197 KiB

logging_test.goH A D23-Jul-201910.2 KiB

proxy_headers.goH A D23-Jul-20194.5 KiB

proxy_headers_test.goH A D23-Jul-20193.4 KiB

recovery.goH A D23-Jul-20192.1 KiB

recovery_test.goH A D23-Jul-20191.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