Documentation
¶
Index ¶
- Constants
- func BrotliHandler(h http.Handler) http.Handler
- func BrotliHandlerWithOpts(opts ...option) (func(http.Handler) http.Handler, error)
- func CompressionLevel(level int) option
- func MinSize(size int) option
- func MustNewBrotliLevelHandler(level int) func(http.Handler) http.Handler
- func NewBrotliLevelAndMinSize(level, minSize int) (func(http.Handler) http.Handler, error)
- func NewBrotliLevelHandler(level int) (func(http.Handler) http.Handler, error)
- type BrotliResponseWriter
- type BrotliResponseWriterWithCloseNotify
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 is the default minimum size until we enable brotli compression. // 1500 bytes is the MTU size for the internet since that is the largest size allowed at the network layer. // If you take a file that is 1300 bytes and compress it to 800 bytes, it’s still transmitted in that same 1500 byte packet regardless, so you’ve gained nothing. // That being the case, you should restrict the brotli compression to files with a size greater than a single packet, 1400 bytes (1.4KB) is a safe value. DefaultMinSize = 1400 )
Variables ¶
This section is empty.
Functions ¶
func BrotliHandler ¶
BrotliHandler wraps an HTTP handler, to transparently brotli the response body if the client supports it (via the Accept-Encoding header). This will compress at the default compression level.
func BrotliHandlerWithOpts ¶
func CompressionLevel ¶
func CompressionLevel(level int) option
func MustNewBrotliLevelHandler ¶
MustNewBrotliLevelHandler behaves just like NewBrotliLevelHandler except that in an error case it panics rather than returning an error.
func NewBrotliLevelAndMinSize ¶
NewBrotliLevelAndMinSize behave as NewBrotliLevelHandler except it let the caller specify the minimum size before compression.
func NewBrotliLevelHandler ¶
NewBrotliLevelHandler returns a wrapper function (often known as middleware) which can be used to wrap an HTTP handler to transparently brotli the response body if the client supports it (via the Accept-Encoding header). Responses will be encoded at the given brotli compression level. An error will be returned only if an invalid brotli compression level is given, so if one can ensure the level is valid, the returned error can be safely ignored.
Types ¶
type BrotliResponseWriter ¶
type BrotliResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
func (*BrotliResponseWriter) Close ¶
func (w *BrotliResponseWriter) Close() error
Close will close the brotli.Writer and will put it back in the brotliWriterPool.
func (*BrotliResponseWriter) Flush ¶
func (w *BrotliResponseWriter) Flush()
Flush flushes the underlying *brotli.Writer and then the underlying http.ResponseWriter if it is an http.Flusher. This makes BrotliResponseWriter an http.Flusher.
func (*BrotliResponseWriter) Hijack ¶
func (w *BrotliResponseWriter) 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 (*BrotliResponseWriter) WriteHeader ¶
func (w *BrotliResponseWriter) WriteHeader(code int)
WriteHeader just saves the response code until close or Brotli effective writes.
type BrotliResponseWriterWithCloseNotify ¶
type BrotliResponseWriterWithCloseNotify struct {
*BrotliResponseWriter
}
func (BrotliResponseWriterWithCloseNotify) CloseNotify ¶
func (w BrotliResponseWriterWithCloseNotify) CloseNotify() <-chan bool