github.com/argoproj/argo-cd@v1.8.7/util/http/http.go (about) 1 package http 2 3 import ( 4 "fmt" 5 "net/http" 6 "net/http/httputil" 7 "strings" 8 9 log "github.com/sirupsen/logrus" 10 ) 11 12 // MakeCookieMetadata generates a string representing a Web cookie. Yum! 13 func MakeCookieMetadata(key, value string, flags ...string) (string, error) { 14 components := []string{ 15 fmt.Sprintf("%s=%s", key, value), 16 } 17 components = append(components, flags...) 18 header := strings.Join(components, "; ") 19 20 const maxLength = 4093 21 headerLength := len(header) 22 if headerLength > maxLength { 23 return "", fmt.Errorf("invalid cookie, at %d long it is longer than the max length of %d", headerLength, maxLength) 24 } 25 return header, nil 26 } 27 28 // DebugTransport is a HTTP Client Transport to enable debugging 29 type DebugTransport struct { 30 T http.RoundTripper 31 } 32 33 func (d DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) { 34 reqDump, err := httputil.DumpRequest(req, true) 35 if err != nil { 36 return nil, err 37 } 38 log.Printf("%s", reqDump) 39 40 resp, err := d.T.RoundTrip(req) 41 if err != nil { 42 return nil, err 43 } 44 45 respDump, err := httputil.DumpResponse(resp, true) 46 if err != nil { 47 _ = resp.Body.Close() 48 return nil, err 49 } 50 log.Printf("%s", respDump) 51 return resp, nil 52 }