wangluozhe / requests

用于快速请求HTTP或HTTPS,并支持修改ja3、ja4指纹
GNU General Public License v3.0
430 stars 100 forks source link

steam 响应处理建议 #68

Open bincooo opened 5 months ago

bincooo commented 5 months ago

你好,可否在遇到stream响应头时不要读取body?

https://github.com/wangluozhe/requests/blob/ac53c643373710472bab5eb5f69474248a834175/sessions.go#L465

stream := strings.Contains(resp.Header.Get("Content-Type"), "application/stream") ||
        strings.Contains(resp.Header.Get("Content-Type"), "text/event-stream")

if stream {
        response := &models.Response{
            Url:        preq.Url,
            Headers:    resp.Header,
            Cookies:    resp.Cookies(),
            Text:       "",
            Content:    nil,
            Body:       resp.Body,
            StatusCode: resp.StatusCode,
            History:    []*models.Response{},
            Request:    req,
        }
        if resp.Cookies() != nil {
            u, _ := url2.Parse(preq.Url)
            s.Cookies.SetCookies(u, resp.Cookies())
        }
        return response, nil
}

这应该还缺了编码处理,可添加这部分处理进项目嘛 ?