mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
Add HEAD request to fetch Content-Length
This commit is contained in:
parent
2113205123
commit
06191e52e5
1 changed files with 16 additions and 0 deletions
|
|
@ -150,6 +150,22 @@ func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
|
|||
|
||||
client := createHTTPClient(mode)
|
||||
|
||||
// 发送HEAD请求, 预获取Content-Length
|
||||
headReq := client.R()
|
||||
setRequestHeaders(c, headReq)
|
||||
|
||||
headResp, err := headReq.Head(u)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
}
|
||||
defer headResp.Body.Close()
|
||||
|
||||
if err := HandleResponseSize(headResp, cfg, c); err != nil {
|
||||
logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
}
|
||||
|
||||
body, err := readRequestBody(c)
|
||||
if err != nil {
|
||||
HandleError(c, err.Error())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue