diff options
| author | Shulhan <ms@kilabit.info> | 2024-02-16 00:40:17 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-02-16 01:38:51 +0700 |
| commit | a79914376206191870fbd19992de32dd60daad0b (patch) | |
| tree | 5ca7ed2db54bb799da2d119a29f6989f706ab887 /http_request_dumper.go | |
| parent | 2deaf8c4cc0f941e9c0f2c9fc079d86c1d6a8d61 (diff) | |
| download | gorankusu-a79914376206191870fbd19992de32dd60daad0b.tar.xz | |
all: change the signature of default request/response dumper
Instead of function that use the signature of HTTPRequestDumper/
HTTPResponseDumper; change it to function that _return_ HTTPRequestDumper/
HTTPResponseDumper.
In this way, the documentation can show the clear relation between
function and its type.
Diffstat (limited to 'http_request_dumper.go')
| -rw-r--r-- | http_request_dumper.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/http_request_dumper.go b/http_request_dumper.go index 9029693..6dd15bc 100644 --- a/http_request_dumper.go +++ b/http_request_dumper.go @@ -14,16 +14,18 @@ import ( // [RunResponse] DumpRequest. type HTTPRequestDumper func(req *http.Request) ([]byte, error) -// DumpHTTPRequest define default [HTTPRequestDumper] that convert +// DefaultRequestDumper define default [HTTPRequestDumper] that convert // [http.Request] with its body to stream of bytes using // [httputil.DumpRequest]. // -// The returned dump have CRLF ("\r\n") replaced with single LF ("\n"). -func DumpHTTPRequest(req *http.Request) (raw []byte, err error) { - raw, err = httputil.DumpRequestOut(req, true) - if err != nil { - return nil, fmt.Errorf(`DumpHTTPRequest: %w`, err) +// The returned bytes have CRLF ("\r\n") replaced with single LF ("\n"). +func DefaultRequestDumper() HTTPRequestDumper { + return func(req *http.Request) (raw []byte, err error) { + raw, err = httputil.DumpRequestOut(req, true) + if err != nil { + return nil, fmt.Errorf(`DefaultRequestDumper: %w`, err) + } + raw = bytes.ReplaceAll(raw, []byte{'\r', '\n'}, []byte{'\n'}) + return raw, nil } - raw = bytes.ReplaceAll(raw, []byte{'\r', '\n'}, []byte{'\n'}) - return raw, nil } |
