Fixed a bug where gzip spits out garbage bytes when it's disabled.

Disabled Gzip on the Control Panel Backup Page.
This commit is contained in:
Azareal 2018-08-22 17:10:29 +10:00
parent 0d96f4efac
commit 146aa3aaad
3 changed files with 17 additions and 3 deletions

View File

@ -892,7 +892,11 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Content-Type", "text/html")
gz := gzip.NewWriter(w)
defer gz.Close()
defer func() {
if w.Header().Get("Content-Encoding") == "gzip" {
gz.Close()
}
}()
w = gzipResponseWriter{Writer: gz, ResponseWriter: w}
}
router.routeSwitch(w, req, user, prefix, extraData)
@ -1421,6 +1425,12 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
return
}
gzw, ok := w.(gzipResponseWriter)
if ok {
w = gzw.ResponseWriter
w.Header().Del("Content-Type")
w.Header().Del("Content-Encoding")
}
counters.RouteViewCounter.Bump(73)
err = panel.Backups(w,req,user,extraData)
case "/panel/logs/regs/":

View File

@ -663,7 +663,11 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Content-Type", "text/html")
gz := gzip.NewWriter(w)
defer gz.Close()
defer func() {
if w.Header().Get("Content-Encoding") == "gzip" {
gz.Close()
}
}()
w = gzipResponseWriter{Writer: gz, ResponseWriter: w}
}
router.routeSwitch(w, req, user, prefix, extraData)

View File

@ -210,7 +210,7 @@ func buildPanelRoutes() {
Action("routePanelGroupsEditPermsSubmit", "/panel/groups/edit/perms/submit/", "extraData"),
Action("routePanelGroupsCreateSubmit", "/panel/groups/create/"),
View("panel.Backups", "/panel/backups/", "extraData").Before("SuperAdminOnly"), // TODO: Tests for this
View("panel.Backups", "/panel/backups/", "extraData").Before("SuperAdminOnly").NoGzip(), // TODO: Tests for this
View("panel.LogsRegs", "/panel/logs/regs/"),
View("panel.LogsMod", "/panel/logs/mod/"),
View("panel.Debug", "/panel/debug/").Before("AdminOnly"),