util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 5 Imported by: 14

README

lib-compose/util

Common middleware handlers.

NewGzipHandler

Transparently gzip the response body if the client supports it (via the Accept-Encoding header) and the response Content-type starts with one of GzipCompressableTypes.

In difference to the most implementations found in the web, we do the decision of compression in the Writer, when the Content-Type is determined.

Documentation

Index

Constants

View Source
const X_FORWARDED_HOST_HEADER_KEY = "X-Forwarded-Host"

Variables

View Source
var GzipCompressableTypes = []string{
	"text/",
	"application/json",
	"application/xhtml+xml",
	"application/xml",
	"image/svg+xml",
	"application/javascript",
	"application/font-woff",
}

Functions

func NewGzipHandler

func NewGzipHandler(h http.Handler) http.Handler

Transparently gzip the response body if the client supports it (via the Accept-Encoding header) and the response Content-type starts with one of GzipCompressableTypes.

In difference to the most implementations found in the web, we do the decision of compression in the Writer, when the Content-Type is determined.

func ReadCookieValue

func ReadCookieValue(h http.Header, cookieName string) (string, bool)

taken and adapted from net/http

Types

type ForwardedHostHandler

type ForwardedHostHandler struct {
	Next http.Handler
}

func NewForwardedHostHandler

func NewForwardedHostHandler(next http.Handler) *ForwardedHostHandler

func (*ForwardedHostHandler) ServeHTTP

func (p *ForwardedHostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type GzipResponseWriter

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

func NewGzipResponseWriter

func NewGzipResponseWriter(w http.ResponseWriter) *GzipResponseWriter

func (*GzipResponseWriter) Close

func (grw *GzipResponseWriter) Close()

func (*GzipResponseWriter) Write

func (grw *GzipResponseWriter) Write(b []byte) (int, error)

func (*GzipResponseWriter) WriteHeader

func (grw *GzipResponseWriter) WriteHeader(code int)

Jump to

Keyboard shortcuts

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