Skip to content

Commit

Permalink
Add DumpRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jun 2, 2023
1 parent e02e5ee commit 3841c8c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package httpx

import (
"encoding/json"
"fmt"
"net/http"
"net/http/httputil"
)

// Error for a request.
Expand Down Expand Up @@ -43,3 +45,11 @@ func ErrorResponse(w http.ResponseWriter, code int, err error) {
w.WriteHeader(code)
w.Write(raw)
}

func DumpRequest(r *http.Request) string {
raw, err := httputil.DumpRequest(r, true)
if err != nil {
return fmt.Errorf("dump error: %#v", err).Error()
}
return fmt.Sprintf("%#v", string(raw))
}

0 comments on commit 3841c8c

Please sign in to comment.