aboutsummaryrefslogtreecommitdiff
path: root/lib/http
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-12-18 20:14:38 +0700
committerShulhan <m.shulhan@gmail.com>2020-12-18 20:14:38 +0700
commit8d06fe0a94a42d72dfd4fc4eba86b69fce5022d8 (patch)
tree91c75d536c34ce7b748040d2ecad17fd5849f877 /lib/http
parent6a2d049cc385d825cb2c48f7c36d96990da92c6c (diff)
downloadpakakeh.go-8d06fe0a94a42d72dfd4fc4eba86b69fce5022d8.tar.xz
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.
Diffstat (limited to 'lib/http')
-rw-r--r--lib/http/client.go10
1 files changed, 10 insertions, 0 deletions
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