2021-01-10 19:52:54 +00:00
|
|
|
package remote
|
2021-01-08 22:43:03 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Logs the request into the debug log with all of the important request bits.
|
|
|
|
// The authorization key will be cleaned up before being output.
|
|
|
|
func debugLogRequest(req *http.Request) {
|
2021-01-10 22:00:28 +00:00
|
|
|
if l, ok := log.Log.(*log.Logger); ok && l.Level != log.DebugLevel {
|
|
|
|
return
|
|
|
|
}
|
2021-01-08 22:43:03 +00:00
|
|
|
headers := make(map[string][]string)
|
|
|
|
for k, v := range req.Header {
|
2021-01-10 22:00:28 +00:00
|
|
|
if k != "Authorization" || len(v) == 0 || len(v[0]) == 0 {
|
2021-01-08 22:43:03 +00:00
|
|
|
headers[k] = v
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-01-10 22:00:28 +00:00
|
|
|
headers[k] = []string{"(redacted)"}
|
2021-01-08 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"method": req.Method,
|
|
|
|
"endpoint": req.URL.String(),
|
|
|
|
"headers": headers,
|
|
|
|
}).Debug("making request to external HTTP endpoint")
|
|
|
|
}
|