From 7ec2e01e435cef52a7e8b7d2a6df147e0d6c3f1d Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Fri, 15 Jul 2022 13:28:29 +0100 Subject: [PATCH] Add the ability to toggle filtering URL parameters passed to page providers. --- conf/serve.go | 9 +++++---- config.example.yml | 13 +++++++++++++ pageHandler/page-handler.go | 19 ++++++++++++++----- 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 config.example.yml diff --git a/conf/serve.go b/conf/serve.go index 19fb367..96a4125 100644 --- a/conf/serve.go +++ b/conf/serve.go @@ -1,8 +1,9 @@ package conf type ServeYaml struct { - DataStorage string `yaml:"dataStorage"` - Domains []string `yaml:"domains"` - RangeSupported bool `yaml:"rangeSupported"` - CacheSettings CacheSettingsYaml `yaml:"cacheSettings"` + DataStorage string `yaml:"dataStorage"` + Domains []string `yaml:"domains"` + RangeSupported bool `yaml:"rangeSupported"` + FilterURLQueries bool `yaml:"filterURLQueries"` + CacheSettings CacheSettingsYaml `yaml:"cacheSettings"` } diff --git a/config.example.yml b/config.example.yml new file mode 100644 index 0000000..a8afee8 --- /dev/null +++ b/config.example.yml @@ -0,0 +1,13 @@ +listen: + webNetwork: "tcp4" + web: ":8080" + webMethod: "http" + identify: true +serve: + rangeSupported: true + cacheSettings: + enableContentsCaching: true + enableContentsCachePurge: true + maxAge: 3600 + notModifiedUsingLastModified: true + notModifiedUsingETags: true \ No newline at end of file diff --git a/pageHandler/page-handler.go b/pageHandler/page-handler.go index bcc764b..58726a4 100644 --- a/pageHandler/page-handler.go +++ b/pageHandler/page-handler.go @@ -19,6 +19,7 @@ type PageHandler struct { PageProviders map[string]PageProvider pageContentsCacheRWMutex *sync.RWMutex RangeSupported bool + FilterURLQueries bool CacheSettings conf.CacheSettingsYaml } @@ -40,6 +41,7 @@ func NewPageHandler(config conf.ServeYaml) *PageHandler { PageProviders: GetProviders(config.CacheSettings.EnableTemplateCaching, config.DataStorage), pageContentsCacheRWMutex: theMutex, RangeSupported: config.RangeSupported, + FilterURLQueries: config.FilterURLQueries, CacheSettings: config.CacheSettings, } } @@ -162,7 +164,10 @@ func (ph *PageHandler) GetCleanQuery(request *http.Request) (url.Values, string) return make(url.Values), "" } supportedKeys := provider.GetSupportedURLParameters() - toDelete := make([]string, len(toClean)) + var toDelete []string + if ph.FilterURLQueries { + toDelete = make([]string, len(toClean)) + } theSize := 0 theQuery := "" for s, v := range toClean { @@ -174,8 +179,10 @@ func (ph *PageHandler) GetCleanQuery(request *http.Request) (url.Values, string) } } if noExist { - toDelete[theSize] = s - theSize++ + if ph.FilterURLQueries { + toDelete[theSize] = s + theSize++ + } } else { for _, i := range v { if i == "" { @@ -186,8 +193,10 @@ func (ph *PageHandler) GetCleanQuery(request *http.Request) (url.Values, string) } } } - for i := 0; i < theSize; i++ { - delete(toClean, toDelete[i]) + if ph.FilterURLQueries { + for i := 0; i < theSize; i++ { + delete(toClean, toDelete[i]) + } } return toClean, strings.TrimRight(theQuery, "&") }