mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: make logging middleware respect proxy headers
This commit is contained in:
parent
c6139e5366
commit
4f7cc3c57e
@ -39,10 +39,21 @@ func (lg *LoggingMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
r.URL.String(),
|
r.URL.String(),
|
||||||
duration,
|
duration,
|
||||||
ww.BytesWritten(),
|
ww.BytesWritten(),
|
||||||
r.RemoteAddr,
|
readUserIP(r),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readUserIP(r *http.Request) string {
|
||||||
|
ip := r.Header.Get("X-Real-Ip")
|
||||||
|
if ip == "" {
|
||||||
|
ip = r.Header.Get("X-Forwarded-For")
|
||||||
|
}
|
||||||
|
if ip == "" {
|
||||||
|
ip = r.RemoteAddr
|
||||||
|
}
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|
||||||
// The below writer-wrapping code has been lifted from
|
// The below writer-wrapping code has been lifted from
|
||||||
// https://github.com/zenazn/goji/blob/master/web/middleware/logger.go - because
|
// https://github.com/zenazn/goji/blob/master/web/middleware/logger.go - because
|
||||||
// it does exactly what is needed, and it's unlikely to change in any
|
// it does exactly what is needed, and it's unlikely to change in any
|
||||||
|
Loading…
Reference in New Issue
Block a user