// Response - Trace HTTP Response func (t Trace) Response(res *http.Response) (err error) { resTrace, err := httputil.DumpResponse(res, false) // Only display header if err == nil { console.Debug(string(resTrace)) } return err }
// Request - Trace HTTP Request func (t Trace) Request(req *http.Request) (err error) { origAuth := req.Header.Get("Authorization") // 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 // Strip out access-key-id from: Credential=<access-key-id>/<date>/<aws-region>/<aws-service>/aws4_request regCred := regexp.MustCompile("Credential=([A-Z]+)/") newAuth := regCred.ReplaceAllString(origAuth, "Credential=**REDACTED**/") // Strip out 256-bit signature from: Signature=<256-bit signature> regSign := regexp.MustCompile("Signature=([[0-9a-f]+)") newAuth = regSign.ReplaceAllString(newAuth, "Signature=**REDACTED**") // Set a temporary redacted auth req.Header.Set("Authorization", newAuth) reqTrace, err := httputil.DumpRequestOut(req, false) // Only display header if err == nil { console.Debug(string(reqTrace)) } // Undo req.Header.Set("Authorization", origAuth) return err }
// Request - Trace HTTP Request func (t Trace) Request(req *http.Request) (err error) { origAuth := req.Header.Get("Authorization") if strings.TrimSpace(origAuth) != "" { // Authorization (S3 v2 signature) Format: // Authorization: AWS AKIAJVA5BMMU2RHO6IO1:Y10YHUZ0DTUterAUI6w3XKX7Iqk= // Set a temporary redacted auth req.Header.Set("Authorization", "AWS **REDACTED**:**REDACTED**") var reqTrace []byte reqTrace, err = httputil.DumpRequestOut(req, false) // Only display header if err == nil { console.Debug(string(reqTrace)) } // Undo req.Header.Set("Authorization", origAuth) } return err }