cmd/site: add X-Git-Rev header to all outgoing requests

This commit is contained in:
Cadey Ratio 2019-06-05 14:00:57 +00:00
parent 5a5b7083b4
commit ce25d9fbfd
1 changed files with 5 additions and 0 deletions

View File

@ -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)
} }