mirror of
https://github.com/caddyserver/caddy.git
synced 2025-06-04 19:24:42 +08:00
Add request placeholder support for querying request cookies. (#1392)
* Add request placeholder support for querying request cookies. This adds the ability to query the request cookies for placeholders using the syntax "@cookiename". For example, this would allow rewriting based on a cookie: rewrite { if @version is 'dev' to /dev/index.html } * Switch cookie special char from @ to : * Switch special char for cookies from : to ~
This commit is contained in:
@ -198,6 +198,13 @@ func (r *replacer) getSubstitution(key string) string {
|
||||
}
|
||||
}
|
||||
}
|
||||
// next check for cookies
|
||||
if key[1] == '~' {
|
||||
name := key[2 : len(key)-1]
|
||||
if cookie, err := r.request.Cookie(name); err == nil {
|
||||
return cookie.Value
|
||||
}
|
||||
}
|
||||
|
||||
// search default replacements in the end
|
||||
switch key {
|
||||
|
Reference in New Issue
Block a user