12345678910111213141516171819202122232425262728293031323334353637 |
- package gzip
- import (
- "compress/gzip"
- "github.com/gin-gonic/gin"
- )
- const (
- BestCompression = gzip.BestCompression
- BestSpeed = gzip.BestSpeed
- DefaultCompression = gzip.DefaultCompression
- NoCompression = gzip.NoCompression
- )
- func Gzip(level int, options ...Option) gin.HandlerFunc {
- return newGzipHandler(level, options...).Handle
- }
- type gzipWriter struct {
- gin.ResponseWriter
- writer *gzip.Writer
- }
- func (g *gzipWriter) WriteString(s string) (int, error) {
- return g.writer.Write([]byte(s))
- }
- func (g *gzipWriter) Write(data []byte) (int, error) {
- return g.writer.Write(data)
- }
- // Fix: https://github.com/mholt/caddy/issues/38
- func (g *gzipWriter) WriteHeader(code int) {
- g.Header().Del("Content-Length")
- g.ResponseWriter.WriteHeader(code)
- }
|