Fetch the repository succeeded.
package client
import (
"fmt"
"gitee.com/micro-tools/wf/internal/utils"
"io/ioutil"
"net/http"
"net/http/httputil"
"gitee.com/micro-tools/wf/util/gconv"
)
// dumpTextFormat is the format of the dumped raw string
const dumpTextFormat = `+---------------------------------------------+
| %s |
+---------------------------------------------+
%s
%s
`
// getResponseBody returns the text of the response body.
func getResponseBody(res *http.Response) string {
if res.Body == nil {
return ""
}
bodyContent, _ := ioutil.ReadAll(res.Body)
res.Body = utils.NewReadCloser(bodyContent, true)
return gconv.UnsafeBytesToStr(bodyContent)
}
// RawRequest returns the raw content of the request.
func (r *Response) RawRequest() string {
// Response can be nil.
if r == nil {
return ""
}
if r.request == nil {
return ""
}
// DumpRequestOut writes more request headers than DumpRequest, such as User-Agent.
bs, err := httputil.DumpRequestOut(r.request, false)
if err != nil {
return ""
}
return fmt.Sprintf(
dumpTextFormat,
"REQUEST ",
gconv.UnsafeBytesToStr(bs),
r.requestBody,
)
}
// RawResponse returns the raw content of the response.
func (r *Response) RawResponse() string {
// Response might be nil.
if r == nil || r.Response == nil {
return ""
}
bs, err := httputil.DumpResponse(r.Response, false)
if err != nil {
return ""
}
return fmt.Sprintf(
dumpTextFormat,
"RESPONSE",
gconv.UnsafeBytesToStr(bs),
getResponseBody(r.Response),
)
}
// Raw returns the raw text of the request and the response.
func (r *Response) Raw() string {
return fmt.Sprintf("%s\n%s", r.RawRequest(), r.RawResponse())
}
// RawDump outputs the raw text of the request and the response to stdout.
func (r *Response) RawDump() {
fmt.Println(r.Raw())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。