compress

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package compress 提供一个支持内容压缩的中间件。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(next http.Handler, opt *Options) http.Handler

New 构建一个支持压缩的中间件。

将 opt 传递给 New 之后,再修改 opt 中的值,将不再启作用。

func NewDeflate

func NewDeflate(w io.Writer) (io.WriteCloser, error)

NewDeflate 表示支持 deflate 压缩

func NewGzip

func NewGzip(w io.Writer) (io.WriteCloser, error)

NewGzip 表示支持 gzip 格式的压缩

Types

type Options

type Options struct {
	Funcs    map[string]WriterFunc
	Size     int // 大于此值才会启用压缩
	ErrorLog *log.Logger

	// 仅对该表中的类型进行压缩
	//
	// 可以用通配符 * 作为结尾:
	// text* 表示以 text 开头的 mimetype;
	// 其它类型的值,表示完全匹配。
	Types []string
	// contains filtered or unexported fields
}

Options New 的参数

type WriterFunc

type WriterFunc func(w io.Writer) (io.WriteCloser, error)

WriterFunc 定义了将一个 io.Writer 声明为具有压缩功能的 io.WriteCloser

Notes

Bugs

  • gzw.Close() 在执行时,可能会调用 w.Write() 进行输出, 而 w.Write() 又有可能隐性调用 w.WriteHeader() 输出报头。

    所以如果在 c.h 中进行 panic,并让外层接收后作报头输出,可能会出错, 比如 issue9/web/internal/errors.Exit() 函数。

Directories

Path Synopsis
Package accept 用于处理 accpet 系列的报头。
Package accept 用于处理 accpet 系列的报头。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL