Skip to content

Commit

Permalink
Fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Nov 27, 2024
1 parent 0d25b09 commit 6e21fb9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions crproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,22 @@ func emptyTagsList(w http.ResponseWriter, r *http.Request) {
}

func (c *CRProxy) do(cli *http.Client, r *http.Request) (resp *http.Response, err error) {
if !c.allowHeadMethod && r.Method == http.MethodHead {
forHead := !c.allowHeadMethod && r.Method == http.MethodHead
if forHead {
r.Method = http.MethodGet
defer func() {
r.Method = http.MethodHead
resp.Body.Close()
resp.Body = http.NoBody
}()
}
resp, err = cli.Do(r)
if err != nil {
return nil, err
}

if forHead {
r.Method = http.MethodHead
if resp.Body != nil {
resp.Body.Close()
}
resp.Body = http.NoBody
}
return resp, err
}

Expand Down

0 comments on commit 6e21fb9

Please sign in to comment.