tweak
This commit is contained in:
parent
2ae62855cc
commit
87b53fb8ec
1 changed files with 8 additions and 7 deletions
|
|
@ -28,15 +28,16 @@ func (rw *gzipResponseWriter) WriteHeader(statusCode int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Middleware(c *router.Context) {
|
func Middleware(c *router.Context) {
|
||||||
if strings.Contains(c.Req.Header.Get("Accept-Encoding"), "gzip") {
|
if !strings.Contains(c.Req.Header.Get("Accept-Encoding"), "gzip") {
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
gz := &gzipResponseWriter{out: gzip.NewWriter(c.Out), src: c.Out}
|
gz := &gzipResponseWriter{out: gzip.NewWriter(c.Out), src: c.Out}
|
||||||
defer gz.out.Close()
|
defer gz.out.Close()
|
||||||
|
|
||||||
c.Out.Header().Set("Content-Encoding", "gzip")
|
c.Out.Header().Set("Content-Encoding", "gzip")
|
||||||
c.Out = gz
|
c.Out = gz
|
||||||
c.Next()
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue