Skip to content

Commit

Permalink
Display request header in anonymous mode (#2733)
Browse files Browse the repository at this point in the history
Currently if authorization header is missing, then request is not displayed
This resulted in just the response being displayed, in anonymous mode.

This PR fixes that issue.
  • Loading branch information
kannappanr authored Apr 5, 2019
1 parent b5b7a56 commit ea46914
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cmd/client-s3-trace_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func newTraceV4() httptracer.HTTPTracer {
func (t traceV4) Request(req *http.Request) (err error) {
origAuth := req.Header.Get("Authorization")

printTrace := func() error {
reqTrace, rerr := httputil.DumpRequestOut(req, false) // Only display header
if rerr == nil {
console.Debug(string(reqTrace))
}
return rerr
}

if strings.TrimSpace(origAuth) != "" {
// Authorization (S3 v4 signature) Format:
// Authorization: AWS4-HMAC-SHA256 Credential=AKIAJNACEGBGMXBHLEZA/20150524/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=bbfaa693c626021bcb5f911cd898a1a30206c1fad6bad1e0eb89e282173bd24c
Expand All @@ -53,14 +61,12 @@ func (t traceV4) Request(req *http.Request) (err error) {
// Set a temporary redacted auth
req.Header.Set("Authorization", newAuth)

var reqTrace []byte
reqTrace, err = httputil.DumpRequestOut(req, false) // Only display header
if err == nil {
console.Debug(string(reqTrace))
}
err = printTrace()

// Undo
req.Header.Set("Authorization", origAuth)
} else {
err = printTrace()
}
return err
}
Expand Down

0 comments on commit ea46914

Please sign in to comment.