Add the ability to toggle filtering URL parameters passed to page providers.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Captain ALM 2022-07-15 13:28:29 +01:00
parent ac08289073
commit 7ec2e01e43
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
3 changed files with 32 additions and 9 deletions

View File

@ -1,8 +1,9 @@
package conf package conf
type ServeYaml struct { type ServeYaml struct {
DataStorage string `yaml:"dataStorage"` DataStorage string `yaml:"dataStorage"`
Domains []string `yaml:"domains"` Domains []string `yaml:"domains"`
RangeSupported bool `yaml:"rangeSupported"` RangeSupported bool `yaml:"rangeSupported"`
CacheSettings CacheSettingsYaml `yaml:"cacheSettings"` FilterURLQueries bool `yaml:"filterURLQueries"`
CacheSettings CacheSettingsYaml `yaml:"cacheSettings"`
} }

13
config.example.yml Normal file
View File

@ -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

View File

@ -19,6 +19,7 @@ type PageHandler struct {
PageProviders map[string]PageProvider PageProviders map[string]PageProvider
pageContentsCacheRWMutex *sync.RWMutex pageContentsCacheRWMutex *sync.RWMutex
RangeSupported bool RangeSupported bool
FilterURLQueries bool
CacheSettings conf.CacheSettingsYaml CacheSettings conf.CacheSettingsYaml
} }
@ -40,6 +41,7 @@ func NewPageHandler(config conf.ServeYaml) *PageHandler {
PageProviders: GetProviders(config.CacheSettings.EnableTemplateCaching, config.DataStorage), PageProviders: GetProviders(config.CacheSettings.EnableTemplateCaching, config.DataStorage),
pageContentsCacheRWMutex: theMutex, pageContentsCacheRWMutex: theMutex,
RangeSupported: config.RangeSupported, RangeSupported: config.RangeSupported,
FilterURLQueries: config.FilterURLQueries,
CacheSettings: config.CacheSettings, CacheSettings: config.CacheSettings,
} }
} }
@ -162,7 +164,10 @@ func (ph *PageHandler) GetCleanQuery(request *http.Request) (url.Values, string)
return make(url.Values), "" return make(url.Values), ""
} }
supportedKeys := provider.GetSupportedURLParameters() supportedKeys := provider.GetSupportedURLParameters()
toDelete := make([]string, len(toClean)) var toDelete []string
if ph.FilterURLQueries {
toDelete = make([]string, len(toClean))
}
theSize := 0 theSize := 0
theQuery := "" theQuery := ""
for s, v := range toClean { for s, v := range toClean {
@ -174,8 +179,10 @@ func (ph *PageHandler) GetCleanQuery(request *http.Request) (url.Values, string)
} }
} }
if noExist { if noExist {
toDelete[theSize] = s if ph.FilterURLQueries {
theSize++ toDelete[theSize] = s
theSize++
}
} else { } else {
for _, i := range v { for _, i := range v {
if i == "" { if i == "" {
@ -186,8 +193,10 @@ func (ph *PageHandler) GetCleanQuery(request *http.Request) (url.Values, string)
} }
} }
} }
for i := 0; i < theSize; i++ { if ph.FilterURLQueries {
delete(toClean, toDelete[i]) for i := 0; i < theSize; i++ {
delete(toClean, toDelete[i])
}
} }
return toClean, strings.TrimRight(theQuery, "&") return toClean, strings.TrimRight(theQuery, "&")
} }