mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
redact http authorization header in debug log output
This commit is contained in:
parent
0c0e7b6957
commit
0936d864a4
@ -76,6 +76,12 @@ func RoundTripper(upstream http.RoundTripper) http.RoundTripper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tr loggingRoundTripper) RoundTrip(req *http.Request) (res *http.Response, err error) {
|
func (tr loggingRoundTripper) RoundTrip(req *http.Request) (res *http.Response, err error) {
|
||||||
|
// save original auth and redact it
|
||||||
|
origAuth, hasAuth := req.Header["Authorization"]
|
||||||
|
if hasAuth {
|
||||||
|
req.Header["Authorization"] = []string{"**redacted**"}
|
||||||
|
}
|
||||||
|
|
||||||
trace, err := httputil.DumpRequestOut(req, false)
|
trace, err := httputil.DumpRequestOut(req, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log("DumpRequestOut() error: %v\n", err)
|
Log("DumpRequestOut() error: %v\n", err)
|
||||||
@ -83,6 +89,11 @@ func (tr loggingRoundTripper) RoundTrip(req *http.Request) (res *http.Response,
|
|||||||
Log("------------ HTTP REQUEST -----------\n%s", trace)
|
Log("------------ HTTP REQUEST -----------\n%s", trace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restore auth
|
||||||
|
if hasAuth {
|
||||||
|
req.Header["Authorization"] = origAuth
|
||||||
|
}
|
||||||
|
|
||||||
res, err = tr.RoundTripper.RoundTrip(req)
|
res, err = tr.RoundTripper.RoundTrip(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log("RoundTrip() returned error: %v", err)
|
Log("RoundTrip() returned error: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user