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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?