forked from cadey/xesite
cmd/site: add X-Git-Rev header to all outgoing requests
This commit is contained in:
parent
5a5b7083b4
commit
ce25d9fbfd
|
@ -65,12 +65,17 @@ type Site struct {
|
||||||
xffmw *xff.XFF
|
xffmw *xff.XFF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gitRev = os.Getenv("GIT_REV")
|
||||||
|
|
||||||
func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := opname.With(r.Context(), "site.ServeHTTP")
|
ctx := opname.With(r.Context(), "site.ServeHTTP")
|
||||||
ctx = ln.WithF(ctx, ln.F{
|
ctx = ln.WithF(ctx, ln.F{
|
||||||
"user_agent": r.Header.Get("User-Agent"),
|
"user_agent": r.Header.Get("User-Agent"),
|
||||||
})
|
})
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
if gitRev != "" {
|
||||||
|
w.Header().Add("X-Git-Rev", gitRev)
|
||||||
|
}
|
||||||
|
|
||||||
middleware.RequestID(s.xffmw.Handler(ex.HTTPLog(s.mux))).ServeHTTP(w, r)
|
middleware.RequestID(s.xffmw.Handler(ex.HTTPLog(s.mux))).ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue