Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ func requestLogger(c *Client, r *Request) error {
}

reqLog := "\n---------------------- REQUEST LOG -----------------------\n" +
fmt.Sprintf("%s %s %s\n", r.Method, rr.URL.RequestURI(), rr.Proto) +
fmt.Sprintf("HOST : %s\n", rr.URL.Host) +
fmt.Sprintf("HEADERS:\n") +
composeHeaders(rl.Header) + "\n" +
fmt.Sprintf("BODY :\n%v\n", rl.Body) +
fmt.Sprintf("%s %s %s\n", r.Method, rr.URL.RequestURI(), rr.Proto) +
fmt.Sprintf("HOST: %s\n", rr.URL.Host) +
fmt.Sprintf("HEADERS:\n%s\n", composeHeaders(rl.Header)) +
fmt.Sprintf("COOKIES:\n%s\n", composeCookies(c.GetClient().Jar, *rr.URL)) +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthewpoer Just remembered one thing. This method focuses on Cookies from Jar and creates a section called COOKIES. Since cookies get separate section in the debug log. I think its better to read request header cookies added by the user into the cookies section finally remove the request header Cookie from headers section. Let me know your thoughts.

fmt.Sprintf("BODY:\n%v\n", rl.Body) +
"----------------------------------------------------------\n"

c.Log.Print(reqLog)
Expand Down
15 changes: 14 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"mime/multipart"
"net/http"
"net/textproto"
"net/url"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -255,10 +256,22 @@ func closeq(v interface{}) {

func sliently(_ ...interface{}) {}

func composeCookies(jar http.CookieJar, url url.URL) string {
var str []string
for _, k := range jar.Cookies(&url) {
v := strings.TrimSpace(fmt.Sprintf("\t%s: %s", k.Name, k.Value))
str = append(str, "\t"+v)
}
return strings.Join(str, "\n")
}

func composeHeaders(hdrs http.Header) string {
var str []string
for _, k := range sortHeaderKeys(hdrs) {
str = append(str, fmt.Sprintf("%25s: %s", k, strings.Join(hdrs[k], ", ")))
v := strings.TrimSpace(fmt.Sprintf("%25s: %s", k, strings.Join(hdrs[k], ", ")))
if v != "" {
str = append(str, "\t"+v)
}
}
return strings.Join(str, "\n")
}
Expand Down