From 8d06fe0a94a42d72dfd4fc4eba86b69fce5022d8 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 18 Dec 2020 20:14:38 +0700 Subject: http: print client request if debug value is equal or greater than 2 If user set DEBUG environment variable or debug.Valeu to 2 or greater, the http Client will print the request (header and body) to the standard output. --- lib/http/client.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/http/client.go b/lib/http/client.go index e132cdc5..fbed90fc 100644 --- a/lib/http/client.go +++ b/lib/http/client.go @@ -20,11 +20,13 @@ import ( "mime/multipart" "net" "net/http" + "net/http/httputil" "net/url" "strings" "time" "github.com/shuLhan/share" + "github.com/shuLhan/share/lib/debug" ) const ( @@ -222,6 +224,14 @@ func (client *Client) doRequest( httpReq.Header.Set(HeaderContentType, contentType) } + if debug.Value >= 2 { + dump, err := httputil.DumpRequestOut(httpReq, true) + if err != nil { + log.Printf("doRequest: " + err.Error()) + } + fmt.Printf("%s", dump) + } + httpRes, err = client.Client.Do(httpReq) if err != nil { return nil, nil, err -- cgit v1.3