mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-13 10:42:16 -04:00
Support for placeholders in fastcgi env vars.
This commit is contained in:
@@ -127,6 +127,11 @@ func NewReplacer(r *http.Request, rr *ResponseRecorder, emptyValue string) Repla
|
||||
// Replace performs a replacement of values on s and returns
|
||||
// the string with the replaced values.
|
||||
func (r *replacer) Replace(s string) string {
|
||||
// Do not attempt replacements if no placeholder is found.
|
||||
if !strings.ContainsAny(s, "{}") {
|
||||
return s
|
||||
}
|
||||
|
||||
// Make response placeholders now
|
||||
if r.responseRecorder != nil {
|
||||
r.replacements["{status}"] = strconv.Itoa(r.responseRecorder.status)
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestNewReplacer(t *testing.T) {
|
||||
if got, want := v.replacements["{status}"], ""; got != want {
|
||||
t.Errorf("Expected status to NOT be set before Replace() is called; was: %s", got)
|
||||
}
|
||||
rep.Replace("foobar")
|
||||
rep.Replace("{foobar}")
|
||||
if got, want := v.replacements["{status}"], "200"; got != want {
|
||||
t.Errorf("Expected status to be %s, was: %s", want, got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user