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

Skip to content

Commit 9f1075f

Browse files
committed
Merge pull request revel#888 from birkirb/change_compression_handling
Change compression handling
2 parents b18328d + 073e6f2 commit 9f1075f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

compress.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@ type CompressResponseWriter struct {
4444
}
4545

4646
func CompressFilter(c *Controller, fc []Filter) {
47+
fc[0](c, fc[1:])
4748
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()
49+
if c.Response.Status != http.StatusNoContent && c.Response.Status != http.StatusNotModified {
50+
writer := CompressResponseWriter{c.Response.Out, nil, "", false, make(chan bool, 1), nil, false}
51+
writer.DetectCompressionType(c.Request, c.Response)
52+
w, ok := c.Response.Out.(http.CloseNotifier)
53+
if ok {
54+
writer.parentNotify = w.CloseNotify()
55+
}
56+
c.Response.Out = &writer
57+
} else {
58+
TRACE.Printf("Compression disabled for response status (%d)", c.Response.Status)
5359
}
54-
c.Response.Out = &writer
5560
}
56-
fc[0](c, fc[1:])
5761
}
5862

5963
func (c CompressResponseWriter) CloseNotify() <-chan bool {

0 commit comments

Comments
 (0)