aboutsummaryrefslogtreecommitdiff
path: root/run_response.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-02-05 01:07:44 +0700
committerShulhan <ms@kilabit.info>2024-02-05 03:22:09 +0700
commita36a4a365b30ff4f331f5b9e5e08b5c98257aff5 (patch)
tree349d6e2b9c0bffe99b7d3d81a4acb55887dfa281 /run_response.go
parent30bbaec568592dbe8e23fa56068d4df06be90753 (diff)
downloadgorankusu-a36a4a365b30ff4f331f5b9e5e08b5c98257aff5.tar.xz
all: add type to customize how to dump HTTP request and response
The HTTPRequestDumper define an handler to convert [http.Request] into [RunResponse] DumpRequest. The HTTPResponseDumper define an handler to convert [http.Response] into [RunResponse] DumpResponse.
Diffstat (limited to 'run_response.go')
-rw-r--r--run_response.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/run_response.go b/run_response.go
index 0586c6e..5dffd16 100644
--- a/run_response.go
+++ b/run_response.go
@@ -7,7 +7,6 @@ import (
"fmt"
"io"
"net/http"
- "net/http/httputil"
libhttp "github.com/shuLhan/share/lib/http"
)
@@ -27,8 +26,8 @@ type RunResponse struct {
// SetHTTPRequest dump the HTTP request including body into the DumpRequest
// field.
-func (rres *RunResponse) SetHTTPRequest(req *http.Request) (err error) {
- rres.DumpRequest, err = httputil.DumpRequest(req, true)
+func (rres *RunResponse) SetHTTPRequest(dumper HTTPRequestDumper, req *http.Request) (err error) {
+ rres.DumpRequest, err = dumper(req)
if err != nil {
return fmt.Errorf(`SetHTTPRequest: %w`, err)
}
@@ -37,13 +36,13 @@ func (rres *RunResponse) SetHTTPRequest(req *http.Request) (err error) {
// SetHTTPResponse dump the HTTP response including body into the DumpResponse
// field.
-func (rres *RunResponse) SetHTTPResponse(res *http.Response) (err error) {
+func (rres *RunResponse) SetHTTPResponse(dumper HTTPResponseDumper, res *http.Response) (err error) {
var logp = `SetHTTPResponse`
rres.ResponseStatus = res.Status
rres.ResponseStatusCode = res.StatusCode
- rres.DumpResponse, err = httputil.DumpResponse(res, true)
+ rres.DumpResponse, err = dumper(res)
if err != nil {
return fmt.Errorf("%s: %w", logp, err)
}