gziphandler

Go middleware to gzip HTTP responses

Github stars Tracking Chart

Gzip Handler

This is a tiny Go package which wraps HTTP handlers to transparently gzip the
response body, for clients which support it. Although it's usually simpler to
leave that to a reverse proxy (like nginx or Varnish), this package is useful
when that's undesirable.

Install

go get -u github.com/NYTimes/gziphandler

Usage

Call GzipHandler with any handler (an object which implements the
http.Handler interface), and it'll return a new handler which gzips the
response. For example:

package main

import (
	"io"
	"net/http"
	"github.com/NYTimes/gziphandler"
)

func main() {
	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)
}

Documentation

The docs can be found at godoc.org, as usual.

License

Apache 2.0.

Main metrics

Overview
Name With Ownernytimes/gziphandler
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:Apache License 2.0
所有者活动
Created At2015-01-22 22:43:10
Pushed At2024-08-15 09:51:10
Last Commit At2019-11-13 16:51:20
Release Count4
Last Release Namev1.1.1 (Posted on )
First Release Namev1.0.0 (Posted on )
用户参与
Stargazers Count880
Watchers Count43
Fork Count125
Commits Count78
Has Issues Enabled
Issues Count40
Issue Open Count15
Pull Requests Count44
Pull Requests Open Count9
Pull Requests Close Count23
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private