httpgzip

package module
v0.0.0-...-011e294 Latest Latest
Warning

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

Go to latest
Published: May 18, 2014 License: MIT Imports: 6 Imported by: 0

README

package httpgzip

A handler that compresses http.ResponseWriter if its related *http.Request mentions gzip in it's Accept-Encoding headers.

If possible, the handler flushes data as it streams it, making it suitable for long streams of data that should be sent regularly.

Godoc?

Godoc!

Usage

h := MyHandler()
gzh := httpgzip.NewHandler(h)
log.Fatal(http.ListenAndServe(":8080", gzh))

That's it.

Documentation

Overview

Package httpgzip implements a http.Handler that compresses all HTTP operations with GZIP if the client supports it. It supports long-lived operations such as streams of data over HTTP, or short, regular HTTP operations.

gzh := httpgzip.NewHandler(myHandler)
log.Fatal(http.ListenAndServe(":8080", gzh))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultOnError

func DefaultOnError(err error, w http.ResponseWriter, r *http.Request)

DefaultOnError logs errors to the standard log.Printf.

Types

type GzipHandler

type GzipHandler struct {

	// OnError is a hook you can provide to GzipHandler if you want to
	// handle cases where the handler can't process a request or has
	// encountered an error while processing it.
	//
	// If not set, will default to DefaultOnError
	OnError func(err error, w http.ResponseWriter, r *http.Request)
	// contains filtered or unexported fields
}

GzipHandler wraps a handler. Before passing a HTTP transaction to the underlying handler, it will try to compress the response writer.

This handler supports both short lived and long lived HTTP, which makes it appropriate to serve streamed data.

func NewHandler

func NewHandler(h http.Handler) *GzipHandler

NewHandler wraps h with a GzipHandler.

func (*GzipHandler) ServeHTTP

func (g *GzipHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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