compression

package
v0.0.0-...-891d2fd Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: BSD-3-Clause, BSD-3-Clause Imports: 6 Imported by: 0

README

compression

GoDoc

This package defines a request handler in charge of gzip compressing the response to an incoming http request.

It conforms to the signature of linkable handlers as defined by the xhttp package, by implementing the xhttp.HandlerLinker interface.

It is possible to disable gzip compression for some request methods in order to avoid some CSRF vulnerabilities.

How to use it?

It is typically used early in the request handling process as a catch-all-routes handler. Below, is a contrieved example (the imports are not showed)


mux := xhttp.NewServeMux()

compressor := compression.NewHandler().Skip("POST")

mux.USE(compressor)

Dependencies

These are the only two external dependencies required as they are necessary to take into account the execution context of a request-handling goroutine.

License

BSD 3-clause

Documentation

Overview

Package compression defines a response compressing Handler. It compresses the body of the http response sent back to a client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gzipper

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

Gzipper defines the structure of the response compressing Handler.

func NewHandler

func NewHandler() Gzipper

NewHandler returns a response compressing Handler.

Link registers a next request Handler to be called by ServeHTTP method. It returns the result of the linking.

func (Gzipper) ServeHTTP

func (g Gzipper) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP handles a http.Request by gzipping the http response body and setting the right http Headers.

func (Gzipper) Skip

func (g Gzipper) Skip(method string) Gzipper

Skip is used to disable gzip compression for a given http method.

Jump to

Keyboard shortcuts

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