From 61ab44352906ae598fce12e47dbd7af9d17988cf Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 16 Jan 2017 15:40:24 -0800 Subject: adding gzip_disabled config setting --- system/admin/config/config.go | 8 ++++++++ system/api/handlers.go | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/admin/config/config.go b/system/admin/config/config.go index ba12515..3605514 100644 --- a/system/admin/config/config.go +++ b/system/admin/config/config.go @@ -17,6 +17,7 @@ type Config struct { ClientSecret string `json:"client_secret"` Etag string `json:"etag"` DisableCORS bool `json:"cors_disabled"` + DisableGZIP bool `json:"gzip_disabled"` CacheInvalidate []string `json:"cache"` } @@ -82,6 +83,13 @@ func (c *Config) MarshalEditor() ([]byte, error) { "true": "Disable", }), }, + editor.Field{ + View: editor.Checkbox("DisableGZIP", c, map[string]string{ + "label": "Disable GZIP (will increase server speed, but also bandwidth)", + }, map[string]string{ + "true": "Disable", + }), + }, editor.Field{ View: editor.Checkbox("CacheInvalidate", c, map[string]string{ "label": "Invalidate cache on save", diff --git a/system/api/handlers.go b/system/api/handlers.go index c3421f9..9292e15 100644 --- a/system/api/handlers.go +++ b/system/api/handlers.go @@ -323,6 +323,11 @@ func Record(next http.HandlerFunc) http.HandlerFunc { // Gzip wraps a HandlerFunc to compress responses when possible func Gzip(next http.HandlerFunc) http.HandlerFunc { return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + if db.ConfigCache("gzip_disabled").(bool) == true { + next.ServeHTTP(res, req) + return + } + // check if req header content-encoding supports gzip if strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") { // gzip response data @@ -330,7 +335,6 @@ func Gzip(next http.HandlerFunc) http.HandlerFunc { gzres := gzipResponseWriter{res, gzip.NewWriter(res)} next.ServeHTTP(gzres, req) - return } -- cgit v1.2.3