Add {upstream} placeholder when proxy middleware is used (closes #531)

Middlewares can now make their own placeholders that may be useful in
logging, on a per-request basis. Proxy is the first one to do this.
This commit is contained in:
Matthew Holt
2016-03-20 21:56:13 -06:00
parent 3f49b32086
commit f23d8cb37f
8 changed files with 109 additions and 40 deletions
+3
View File
@@ -89,6 +89,9 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
}
proxy := host.ReverseProxy
r.Host = host.Name
if rr, ok := w.(*middleware.ResponseRecorder); ok && rr.Replacer != nil {
rr.Replacer.Set("upstream", host.Name)
}
if baseURL, err := url.Parse(host.Name); err == nil {
r.Host = baseURL.Host