diff --git a/gen_router.go b/gen_router.go index f8244d0e..8ad99391 100644 --- a/gen_router.go +++ b/gen_router.go @@ -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/": diff --git a/router_gen/main.go b/router_gen/main.go index 1347fcf0..0eb3660b 100644 --- a/router_gen/main.go +++ b/router_gen/main.go @@ -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) diff --git a/router_gen/routes.go b/router_gen/routes.go index ef16b908..b1e38b33 100644 --- a/router_gen/routes.go +++ b/router_gen/routes.go @@ -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"),