gzip

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2015 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package gzip provides a simple middleware layer that performs gzip compression on the response.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidMIME added in v0.7.2

func ValidMIME(mime string) bool

Types

type Config added in v0.7.2

type Config struct {
	Filters []Filter // Filters to use
	Level   int      // Compression level
}

Config holds the configuration for Gzip middleware

type ExtFilter added in v0.7.2

type ExtFilter struct {
	// Exts is the file name extensions to accept
	Exts Set
}

ExtFilter is Filter for file name extensions.

func (ExtFilter) ShouldCompress added in v0.7.2

func (e ExtFilter) ShouldCompress(r *http.Request) bool

ShouldCompress checks if the request file extension matches any of the registered extensions. It returns true if the extension is found and false otherwise.

type Filter added in v0.7.2

type Filter interface {
	// ShouldCompress tells if gzip compression
	// should be done on the request.
	ShouldCompress(*http.Request) bool
}

Filter determines if a request should be gzipped.

type Gzip

type Gzip struct {
	Next    middleware.Handler
	Configs []Config
}

Gzip is a middleware type which gzips HTTP responses. It is imperative that any handler which writes to a gzipped response specifies the Content-Type, otherwise some clients will assume application/x-gzip and try to download a file.

func (Gzip) ServeHTTP

func (g Gzip) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServeHTTP serves a gzipped response if the client supports it.

type MIMEFilter added in v0.7.2

type MIMEFilter struct {
	// Types is the MIME types to accept.
	Types Set
}

MIMEFilter is Filter for request content types.

func DefaultMIMEFilter added in v0.7.2

func DefaultMIMEFilter() MIMEFilter

DefaultMIMEFilter creates a MIMEFilter with default types.

func (MIMEFilter) ShouldCompress added in v0.7.2

func (m MIMEFilter) ShouldCompress(r *http.Request) bool

ShouldCompress checks if the content type of the request matches any of the registered ones. It returns true if found and false otherwise.

type PathFilter added in v0.7.2

type PathFilter struct {
	// IgnoredPaths is the paths to ignore
	IgnoredPaths Set
}

PathFilter is Filter for request path.

func (PathFilter) ShouldCompress added in v0.7.2

func (p PathFilter) ShouldCompress(r *http.Request) bool

ShouldCompress checks if the request path matches any of the registered paths to ignore. It returns false if an ignored path is found and true otherwise.

type Set added in v0.7.2

type Set map[string]struct{}

Set stores distinct strings.

func (Set) Add added in v0.7.2

func (s Set) Add(value string)

Add adds an element to the set.

func (Set) Contains added in v0.7.2

func (s Set) Contains(value string) bool

Contains check if the set contains value.

func (Set) ContainsFunc added in v0.7.2

func (s Set) ContainsFunc(f func(string) bool) bool

ContainsFunc is similar to Contains. It iterates all the elements in the set and passes each to f. It returns true on the first call to f that returns true and false otherwise.

func (Set) Remove added in v0.7.2

func (s Set) Remove(value string)

Remove removes an element from the set.

Jump to

Keyboard shortcuts

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