Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0e4574

Browse files
committed
Do not apply compression when StatusCode is set to 204 or 304.
Some http clients will react unfavoriably to compression when there must not be any response body.
1 parent ed3ec0f commit f0e4574

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

compress.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ type CompressResponseWriter struct {
4545

4646
func CompressFilter(c *Controller, fc []Filter) {
4747
if Config.BoolDefault("results.compressed", false) {
48-
writer := CompressResponseWriter{c.Response.Out, nil, "", false, make(chan bool, 1), nil, false}
49-
writer.DetectCompressionType(c.Request, c.Response)
50-
w, ok := c.Response.Out.(http.CloseNotifier)
51-
if ok {
52-
writer.parentNotify = w.CloseNotify()
48+
if c.Response.Status != http.StatusNoContent && c.Response.Status != http.StatusNotModified {
49+
writer := CompressResponseWriter{c.Response.Out, nil, "", false, make(chan bool, 1), nil, false}
50+
writer.DetectCompressionType(c.Request, c.Response)
51+
w, ok := c.Response.Out.(http.CloseNotifier)
52+
if ok {
53+
writer.parentNotify = w.CloseNotify()
54+
}
55+
c.Response.Out = &writer
5356
}
54-
c.Response.Out = &writer
5557
}
5658
fc[0](c, fc[1:])
5759
}

0 commit comments

Comments
 (0)