forked fromnytimes/gziphandler
- Notifications
You must be signed in to change notification settings - Fork0
Golang middleware to gzip HTTP responses
License
NotificationsYou must be signed in to change notification settings
alexandrestein/gziphandler
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is a tiny Go package which wraps HTTP handlers to transparently gzip theresponse body, for clients which support it. Although it's usually simpler toleave that to a reverse proxy (like nginx or Varnish), this package is usefulwhen that's undesirable.
CallGzipHandler
with any handler (an object which implements thehttp.Handler
interface), and it'll return a new handler which gzips theresponse. For example:
package mainimport ("io""net/http""github.com/NYTimes/gziphandler")funcmain() {withoutGz:=http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {w.Header().Set("Content-Type","text/plain")io.WriteString(w,"Hello, World")})withGz:=gziphandler.GzipHandler(withoutGz)http.Handle("/",withGz)http.ListenAndServe("0.0.0.0:8000",nil)}
The docs can be found at [godoc.org]docs, as usual.
[Apache 2.0]license.
About
Golang middleware to gzip HTTP responses
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Languages
- Go100.0%