Documentation ¶
Index ¶
- Constants
- func CompressionLevel(level int) option
- func ContentTypes(types []string) option
- func GzipHandler(h http.Handler) http.Handler
- func GzipHandlerWithOpts(opts ...option) (func(http.Handler) http.Handler, error)
- func MinSize(size int) option
- func MustNewGzipLevelHandler(level int) func(http.Handler) http.Handler
- func NewGzipLevelAndMinSize(level, minSize int) (func(http.Handler) http.Handler, error)
- func NewGzipLevelHandler(level int) (func(http.Handler) http.Handler, error)
- type GzipResponseWriter
- func (w *GzipResponseWriter) Close() error
- func (w *GzipResponseWriter) Flush()
- func (w *GzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *GzipResponseWriter) Push(target string, opts *http.PushOptions) error
- func (w *GzipResponseWriter) Write(b []byte) (int, error)
- func (w *GzipResponseWriter) WriteHeader(code int)
Constants ¶
const ( // DefaultQValue is the default qvalue to assign to an encoding if no explicit qvalue is set. // This is actually kind of ambiguous in RFC 2616, so hopefully it's correct. // The examples seem to indicate that it is. DefaultQValue = 1.0 // DefaultMinSize defines the minimum size to reach to enable compression. // It's 512 bytes. DefaultMinSize = 512 )
Variables ¶
This section is empty.
Functions ¶
func CompressionLevel ¶
func CompressionLevel(level int) option
func ContentTypes ¶
func ContentTypes(types []string) option
func GzipHandler ¶
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 GzipHandlerWithOpts ¶
func MustNewGzipLevelHandler ¶
MustNewGzipLevelHandler behaves just like NewGzipLevelHandler except that in an error case it panics rather than returning an error.
func NewGzipLevelAndMinSize ¶
NewGzipLevelAndMinSize behave as NewGzipLevelHandler except it let the caller specify the minimum size before compression.
func NewGzipLevelHandler ¶
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.
Types ¶
type GzipResponseWriter ¶
type GzipResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
GzipResponseWriter provides an http.ResponseWriter interface, which gzips bytes before writing them to the underlying response. This doesn't close the writers, so don't forget to do that. It can be configured to skip response smaller than minSize.
func (*GzipResponseWriter) Close ¶
func (w *GzipResponseWriter) Close() error
Close will close the gzip.Writer and will put it back in the gzipWriterPool.
func (*GzipResponseWriter) Flush ¶
func (w *GzipResponseWriter) Flush()
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 (*GzipResponseWriter) Hijack ¶
func (w *GzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements http.Hijacker. If the underlying ResponseWriter is a Hijacker, its Hijack method is returned. Otherwise an error is returned.
func (*GzipResponseWriter) Push ¶
func (w *GzipResponseWriter) Push(target string, opts *http.PushOptions) error
Push initiates an HTTP/2 server push. Push returns ErrNotSupported if the client has disabled push or if push is not supported on the underlying connection.
func (*GzipResponseWriter) Write ¶
func (w *GzipResponseWriter) Write(b []byte) (int, error)
Write appends data to the gzip writer.
func (*GzipResponseWriter) WriteHeader ¶
func (w *GzipResponseWriter) WriteHeader(code int)
WriteHeader just saves the response code until close or GZIP effective writes.