feat: 调试开关打开时记录全部接口响应
This commit is contained in:
@@ -879,13 +879,16 @@ func (c *Client) get(ctx context.Context, rawURL, referer string) ([]byte, strin
|
||||
func (c *Client) do(req *http.Request) ([]byte, string, error) {
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
debugHTTP(req, nil, nil, err)
|
||||
return nil, "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
buf, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
|
||||
if err != nil {
|
||||
debugHTTP(req, resp, nil, err)
|
||||
return nil, "", err
|
||||
}
|
||||
debugHTTP(req, resp, buf, nil)
|
||||
if req.URL != nil && req.URL.Hostname() == "login.10086.cn" {
|
||||
for _, ck := range resp.Cookies() {
|
||||
if ck.Name == "lgToken" && ck.Value != "" {
|
||||
@@ -894,17 +897,8 @@ func (c *Client) do(req *http.Request) ([]byte, string, error) {
|
||||
}
|
||||
}
|
||||
if resp.StatusCode >= 400 && !strings.Contains(resp.Header.Get("Content-Type"), "json") {
|
||||
if debugRequest(req) {
|
||||
debugf("%s %s -> %d 失败", req.Method, req.URL.String(), resp.StatusCode)
|
||||
}
|
||||
return nil, "", fmt.Errorf("网站返回 %d", resp.StatusCode)
|
||||
}
|
||||
if debugRequest(req) {
|
||||
debugf("%s %s -> %d Set-Cookie [%s]", req.Method, req.URL.String(), resp.StatusCode, debugSetCookies(resp))
|
||||
if !strings.Contains(resp.Header.Get("Content-Type"), "image") {
|
||||
debugBody(req.URL.Path, buf)
|
||||
}
|
||||
}
|
||||
return buf, resp.Header.Get("Content-Type"), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user