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:
Augusto Roman
2017-02-15 21:59:24 -07:00
committed by Matt Holt
parent bdb61f4a1d
commit dc3efc939c
2 changed files with 14 additions and 1 deletions

View File

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