Skip to content

Commit

Permalink
Merge pull request revel#888 from birkirb/change_compression_handling
Browse files Browse the repository at this point in the history
Change compression handling
  • Loading branch information
brendensoares committed Mar 22, 2015
2 parents b18328d + 073e6f2 commit 9f1075f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ type CompressResponseWriter struct {
}

func CompressFilter(c *Controller, fc []Filter) {
fc[0](c, fc[1:])
if Config.BoolDefault("results.compressed", false) {
writer := CompressResponseWriter{c.Response.Out, nil, "", false, make(chan bool, 1), nil, false}
writer.DetectCompressionType(c.Request, c.Response)
w, ok := c.Response.Out.(http.CloseNotifier)
if ok {
writer.parentNotify = w.CloseNotify()
if c.Response.Status != http.StatusNoContent && c.Response.Status != http.StatusNotModified {
writer := CompressResponseWriter{c.Response.Out, nil, "", false, make(chan bool, 1), nil, false}
writer.DetectCompressionType(c.Request, c.Response)
w, ok := c.Response.Out.(http.CloseNotifier)
if ok {
writer.parentNotify = w.CloseNotify()
}
c.Response.Out = &writer
} else {
TRACE.Printf("Compression disabled for response status (%d)", c.Response.Status)
}
c.Response.Out = &writer
}
fc[0](c, fc[1:])
}

func (c CompressResponseWriter) CloseNotify() <-chan bool {
Expand Down

0 comments on commit 9f1075f

Please sign in to comment.