const vary … const acceptEncoding … const contentEncoding … const contentType … const contentLength … type codings … const DefaultQValue … const DefaultMinSize … var gzipWriterPools … func init() { … } // poolIndex maps a compression level to its index into gzipWriterPools. It // assumes that level is a valid gzip compression level. func poolIndex(level int) int { … } func addLevelPool(level int) { … } type GzipResponseWriter … type GzipResponseWriterWithCloseNotify … func (w GzipResponseWriterWithCloseNotify) CloseNotify() <-chan bool { … } // Write appends data to the gzip writer. func (w *GzipResponseWriter) Write(b []byte) (int, error) { … } // startGzip initializes a GZIP writer and writes the buffer. func (w *GzipResponseWriter) startGzip() error { … } // startPlain writes to sent bytes and buffer the underlying ResponseWriter without gzip. func (w *GzipResponseWriter) startPlain() error { … } // WriteHeader just saves the response code until close or GZIP effective writes. func (w *GzipResponseWriter) WriteHeader(code int) { … } // init graps a new gzip writer from the gzipWriterPool and writes the correct // content encoding header. func (w *GzipResponseWriter) init() { … } // Close will close the gzip.Writer and will put it back in the gzipWriterPool. func (w *GzipResponseWriter) Close() error { … } // Flush flushes the underlying *gzip.Writer and then the underlying // http.ResponseWriter if it is an http.Flusher. This makes GzipResponseWriter // an http.Flusher. func (w *GzipResponseWriter) Flush() { … } // Hijack implements http.Hijacker. If the underlying ResponseWriter is a // Hijacker, its Hijack method is returned. Otherwise an error is returned. func (w *GzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { … } var _ … // MustNewGzipLevelHandler behaves just like NewGzipLevelHandler except that in // an error case it panics rather than returning an error. func MustNewGzipLevelHandler(level int) func(http.Handler) http.Handler { … } // NewGzipLevelHandler returns a wrapper function (often known as middleware) // which can be used to wrap an HTTP handler to transparently gzip the response // body if the client supports it (via the Accept-Encoding header). Responses will // be encoded at the given gzip compression level. An error will be returned only // if an invalid gzip compression level is given, so if one can ensure the level // is valid, the returned error can be safely ignored. func NewGzipLevelHandler(level int) (func(http.Handler) http.Handler, error) { … } // NewGzipLevelAndMinSize behave as NewGzipLevelHandler except it let the caller // specify the minimum size before compression. func NewGzipLevelAndMinSize(level, minSize int) (func(http.Handler) http.Handler, error) { … } func GzipHandlerWithOpts(opts ...option) (func(http.Handler) http.Handler, error) { … } type parsedContentType … // equals returns whether this content type matches another content type. func (pct parsedContentType) equals(mediaType string, params map[string]string) bool { … } type config … func (c *config) validate() error { … } type option … func MinSize(size int) option { … } func CompressionLevel(level int) option { … } // ContentTypes specifies a list of content types to compare // the Content-Type header to before compressing. If none // match, the response will be returned as-is. // // Content types are compared in a case-insensitive, whitespace-ignored // manner. // // A MIME type without any other directive will match a content type // that has the same MIME type, regardless of that content type's other // directives. I.e., "text/html" will match both "text/html" and // "text/html; charset=utf-8". // // A MIME type with any other directive will only match a content type // that has the same MIME type and other directives. I.e., // "text/html; charset=utf-8" will only match "text/html; charset=utf-8". // // By default, responses are gzipped regardless of // Content-Type. func ContentTypes(types []string) option { … } // GzipHandler wraps an HTTP handler, to transparently gzip the response body if // the client supports it (via the Accept-Encoding header). This will compress at // the default compression level. func GzipHandler(h http.Handler) http.Handler { … } // acceptsGzip returns true if the given HTTP request indicates that it will // accept a gzipped response. func acceptsGzip(r *http.Request) bool { … } // returns true if we've been configured to compress the specific content type. func handleContentType(contentTypes []parsedContentType, ct string) bool { … } // parseEncodings attempts to parse a list of codings, per RFC 2616, as might // appear in an Accept-Encoding header. It returns a map of content-codings to // quality values, and an error containing the errors encountered. It's probably // safe to ignore those, because silently ignoring errors is how the internet // works. // // See: http://tools.ietf.org/html/rfc2616#section-14.3. func parseEncodings(s string) (codings, error) { … } // parseCoding parses a single conding (content-coding with an optional qvalue), // as might appear in an Accept-Encoding header. It attempts to forgive minor // formatting errors. func parseCoding(s string) (coding string, qvalue float64, err error) { … }