mirror of
https://github.com/caddyserver/caddy.git
synced 2025-06-05 12:00:29 +08:00
Rewrite: Use middleware.Replacer.
Bug fix for regexps starting with '/'.
This commit is contained in:
@ -3,6 +3,7 @@ package middleware
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -40,6 +41,7 @@ func NewReplacer(r *http.Request, rr *responseRecorder, emptyValue string) Repla
|
||||
"{host}": r.Host,
|
||||
"{path}": r.URL.Path,
|
||||
"{query}": r.URL.RawQuery,
|
||||
"{frag}": r.URL.Fragment,
|
||||
"{fragment}": r.URL.Fragment,
|
||||
"{proto}": r.Proto,
|
||||
"{remote}": func() string {
|
||||
@ -63,6 +65,14 @@ func NewReplacer(r *http.Request, rr *responseRecorder, emptyValue string) Repla
|
||||
"{when}": func() string {
|
||||
return time.Now().Format(timeFormat)
|
||||
}(),
|
||||
"{file}": func() string {
|
||||
_, file := path.Split(r.URL.Path)
|
||||
return file
|
||||
}(),
|
||||
"{dir}": func() string {
|
||||
dir, _ := path.Split(r.URL.Path)
|
||||
return dir
|
||||
}(),
|
||||
},
|
||||
emptyValue: emptyValue,
|
||||
}
|
||||
|
Reference in New Issue
Block a user