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
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"`
}

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
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, "&")
}