encoding

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package encoding 处理 Accept-encoding 报头内容

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encodings

type Encodings struct {
	// contains filtered or unexported fields
}

func NewEncodings

func NewEncodings(errlog logs.Logger) *Encodings

func (*Encodings) Add

func (c *Encodings) Add(id, name string, f NewEncodingFunc)

Add 添加压缩算法

id 表示当前算法的唯一名称,在 Allow 中可以用来查找使用; name 表示通过 Accept-Encoding 匹配的名称; f 表示生成压缩对象的方法;

func (*Encodings) Allow

func (c *Encodings) Allow(contentType string, id ...string)

Allow 允许 contentType 采用的压缩方式

id 是指由 Add 中指定的值; contentType 表示经由 Accept-Encoding 提交的值,该值不能是 identity 和 *;

如果未添加任何算法,则每个请求都相当于是 identity 规则。

func (*Encodings) Search

func (c *Encodings) Search(contentType, h string) (w *Pool, notAcceptable bool)

Search 从报头中查找最合适的算法

如果返回的 w 为空值表示不需要压缩。

type NewEncodingFunc

type NewEncodingFunc func() WriteCloseRester

func BrotliWriter

func BrotliWriter(o brotli.WriterOptions) NewEncodingFunc

BrotliWriter br

func CompressWriter

func CompressWriter(order lzw.Order, width int) NewEncodingFunc

CompressWriter compress

func DeflateWriter

func DeflateWriter(level int) NewEncodingFunc

DeflateWriter deflate

func GZipWriter

func GZipWriter(level int) NewEncodingFunc

GZipWriter gzip

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool 压缩对象池

每个 Pool 对象与特定的压缩对象关联,可以复用这些压缩对象。

func (*Pool) Get

func (p *Pool) Get(w io.Writer) io.WriteCloser

func (*Pool) Name

func (p *Pool) Name() string

type WriteCloseRester

type WriteCloseRester interface {
	io.WriteCloser
	Reset(io.Writer)
}

WriteCloseRester 每种压缩实例需要实现的最小接口

Jump to

Keyboard shortcuts

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