Skip to content

Commit

Permalink
fix: copy request context.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored and traefiker committed May 14, 2018
1 parent 69f3889 commit b98c459
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion middlewares/accesslog/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ func openAccessLogFile(filePath string) (*os.File, error) {
// GetLogDataTable gets the request context object that contains logging data.
// This creates data as the request passes through the middleware chain.
func GetLogDataTable(req *http.Request) *LogData {
return req.Context().Value(DataTableKey).(*LogData)
if ld, ok := req.Context().Value(DataTableKey).(*LogData); ok {
return ld
}
log.Errorf("%s is nil", DataTableKey)
return &LogData{Core: make(CoreLogData)}
}

func (l *LogHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
Expand Down
3 changes: 2 additions & 1 deletion middlewares/errorpages/error_pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request, next http.
utils.CopyHeaders(pageReq.Header, req.Header)
utils.CopyHeaders(w.Header(), recorder.Header())
w.WriteHeader(recorder.GetCode())
h.backendHandler.ServeHTTP(w, pageReq)

h.backendHandler.ServeHTTP(w, pageReq.WithContext(req.Context()))
return
}
}
Expand Down

0 comments on commit b98c459

Please sign in to comment.