compression

package
v0.0.0-...-c2add7f Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package compression provides means to extract compressed data from net/http request and compress net/http response. Only gzip is supported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressResponse

func CompressResponse(next http.Handler) http.Handler

CompressResponse is net/http middleware executing gzip compression is gzip is supported by client and response belongs to supported type.

func DecompressRequest

func DecompressRequest(next http.Handler) http.Handler

DecompressRequest is net/http middleware extracting gzip-compressed requests.

func Pack

func Pack(data []byte) (*bytes.Buffer, error)

Pack compresses bytes using gzip algorithm.

Types

type Compressor

type Compressor struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

A Compressor implements data compression using grip encoder.

func NewCompressor

func NewCompressor(w http.ResponseWriter, logger *zerolog.Logger) *Compressor

NewCompressor creatse new Compressor instance.

func (*Compressor) Close

func (c *Compressor) Close()

Close dumps internal buffers and finishes compression. Must be called before end of response processing, otherwise part of data can be lost.

func (*Compressor) Write

func (c *Compressor) Write(resp []byte) (int, error)

Write compresses response content data in case of supported type. The content type should be specified in the Content-Type header in advance.

Jump to

Keyboard shortcuts

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