github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/client-s3-trace_v2.go (about) 1 // Copyright (c) 2015-2022 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "net/http" 22 "net/http/httputil" 23 "strings" 24 25 "github.com/minio/mc/pkg/httptracer" 26 "github.com/minio/pkg/v2/console" 27 ) 28 29 // traceV2 - tracing structure for signature version '2'. 30 type traceV2 struct{} 31 32 // newTraceV2 - initialize Trace structure 33 func newTraceV2() httptracer.HTTPTracer { 34 return traceV2{} 35 } 36 37 // Request - Trace HTTP Request 38 func (t traceV2) Request(req *http.Request) (err error) { 39 origAuth := req.Header.Get("Authorization") 40 41 if strings.TrimSpace(origAuth) != "" { 42 // Authorization (S3 v2 signature) Format: 43 // Authorization: AWS AKIAJVA5BMMU2RHO6IO1:Y10YHUZ0DTUterAUI6w3XKX7Iqk= 44 45 // Set a temporary redacted auth 46 req.Header.Set("Authorization", "AWS **REDACTED**:**REDACTED**") 47 48 var reqTrace []byte 49 reqTrace, err = httputil.DumpRequestOut(req, false) // Only display header 50 if err == nil { 51 console.Debug(string(reqTrace)) 52 } 53 54 // Undo 55 req.Header.Set("Authorization", origAuth) 56 } 57 return err 58 } 59 60 // Response - Trace HTTP Response 61 func (t traceV2) Response(resp *http.Response) (err error) { 62 var respTrace []byte 63 // For errors we make sure to dump response body as well. 64 if resp.StatusCode != http.StatusOK && 65 resp.StatusCode != http.StatusPartialContent && 66 resp.StatusCode != http.StatusNoContent { 67 respTrace, err = httputil.DumpResponse(resp, true) 68 } else { 69 respTrace, err = httputil.DumpResponse(resp, false) 70 } 71 if err == nil { 72 console.Debug(string(respTrace)) 73 } 74 75 if resp.TLS != nil { 76 printTLSCertInfo(resp.TLS) 77 } 78 79 return err 80 }