1 Star 1 Fork 0

k3x/urlx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dump.go 737 Bytes
一键复制 编辑 原始数据 按行查看 历史
k3x 提交于 2022-01-24 13:31 +08:00 . sync
package urlx
import (
"bytes"
"io"
"net/http"
"net/http/httputil"
)
var (
dumpBR = []byte{'\n'}
dumpLine = append(bytes.Repeat([]byte("-"), 70), dumpBR...)
)
func Dump(w io.Writer, reqBody, respBody bool) ProcessMw {
return func(next Process) Process {
return func(resp *http.Response) error {
w.Write(dumpLine)
reqDump, err := httputil.DumpRequest(resp.Request, reqBody)
if err != nil {
w.Write([]byte(err.Error()))
} else {
w.Write(reqDump)
}
w.Write(dumpBR)
w.Write(dumpLine)
resDump, _ := httputil.DumpResponse(resp, respBody)
if err != nil {
w.Write([]byte(err.Error()))
} else {
w.Write(resDump)
}
w.Write(dumpBR)
w.Write(dumpLine)
return next(resp)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/k3x/urlx.git
git@gitee.com:k3x/urlx.git
k3x
urlx
urlx
master

搜索帮助