You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose the original url query is xxx=iii, the middleware func above would change it to xxx=yyy, but it does not work.
The downstream func calls c.Query("xxx"), and still receives iii.
This is because when c.Query("xxx") is called, it uses querycache first. But querycache is immutable after created. As:
// GetQueryArray returns a slice of strings for a given query key, plus
// a boolean value whether at least one value exists for the given key.
func (c *Context) GetQueryArray(key string) (values []string, ok bool) {
c.initQueryCache()
values, ok = c.queryCache[key]
return
}
func (c *Context) initQueryCache() {
if c.queryCache == nil {
if c.Request != nil {
c.queryCache = c.Request.URL.Query()
} else {
c.queryCache = url.Values{}
}
}
}
Formcache has the same issue as querycache's.
Expectations
Above middleware func will output the correct result.
Gin provides an exportable func, such that user can enable, disable or reset querycache or formcache.
Actual result
Not working as query cache is not mutable. The query parameters are not successfully modified.
Environment
go version: 1.16
gin version (or commit ref): github.com/gin-gonic/gin v1.8.1
operating system: Linux/AMD64
The text was updated successfully, but these errors were encountered:
queryCache becomes immutable after first initializing, but sometimes middlewares may change RawQuery (at least modification is allowed), so there is inconsistency between queryCache and RawQuery.
Description
Allow user to configure querycache & formcache settings (enable/disable or reset them)
How to reproduce
Suppose the original url query is
xxx=iii
, the middleware func above would change it toxxx=yyy
, but it does not work.The downstream func calls
c.Query("xxx")
, and still receivesiii
.This is because when
c.Query("xxx")
is called, it uses querycache first. But querycache is immutable after created. As:Formcache has the same issue as querycache's.
Expectations
Actual result
Not working as query cache is not mutable. The query parameters are not successfully modified.
Environment
The text was updated successfully, but these errors were encountered: