2022-01-05 00:09:11 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httputil"
|
2022-01-06 09:39:25 +00:00
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2022-01-05 00:09:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func LoggingMiddleware(prefix string, next http.HandlerFunc) http.HandlerFunc {
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2022-01-10 23:34:59 +00:00
|
|
|
log.Tracef("[%s] %s %s", prefix, r.Method, r.URL.Path)
|
2022-01-05 00:09:11 +01:00
|
|
|
log.Tracef("[%s]\n%s", prefix, dump(r))
|
|
|
|
|
r.BasicAuth()
|
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func dump(r *http.Request) string {
|
|
|
|
|
x, err := httputil.DumpRequest(r, true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return string(x)
|
|
|
|
|
}
|