gziphandler

Go middleware to gzip HTTP responses

Github星跟踪图

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.

主要指标

概览
名称与所有者nytimes/gziphandler
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证Apache License 2.0
所有者活动
创建于2015-01-22 22:43:10
推送于2024-08-15 09:51:10
最后一次提交2019-11-13 16:51:20
发布数4
最新版本名称v1.1.1 (发布于 )
第一版名称v1.0.0 (发布于 )
用户参与
星数880
关注者数43
派生数125
提交数78
已启用问题?
问题数40
打开的问题数15
拉请求数44
打开的拉请求数9
关闭的拉请求数23
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?