-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdump.go
More file actions
36 lines (33 loc) · 888 Bytes
/
dump.go
File metadata and controls
36 lines (33 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httputil"
"time"
)
func dumpRequest(req *http.Request) string {
s := ""
if *debugFlag {
dump, err := httputil.DumpRequest(req, true)
s = "Request:\n>>>>>>>>>>>>>>>>>\n" + string(dump) + "\n"
if err != nil {
s = s + "\n" + "Request Dump Error: " + err.Error() + "\n"
}
s = s + "<<<<<<<<<<<<<<<<<\n"
}
return s
}
func dumpResponse(reqDump string, resp *http.Response) {
if *debugFlag {
s := reqDump
dump, err := httputil.DumpResponse(resp, true)
s = s + "\nResponse:\n>>>>>>>>>>>>>>>>>\n" + string(dump) + "\n"
if err != nil {
s = s + "\n" + "Response Dump Error: " + err.Error() + "\n"
}
s = s + "<<<<<<<<<<<<<<<<<\n"
filename := fmt.Sprintf("%s\\log\\%s.dump", basePath, time.Now().Format("2006-01-02T15-04-05-999999999Z07-00"))
_ = ioutil.WriteFile(filename, []byte(s), 0644)
}
}