Skip to content

Commit

Permalink
Close the http body of HEAD simulated by GET
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Oct 24, 2024
1 parent adb25df commit e9aed8e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions crproxy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package crproxy

import (
"bytes"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -436,18 +435,17 @@ func emptyTagsList(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, emptyTagsList)
}

var emptyBody = io.NopCloser(bytes.NewBuffer([]byte{}))

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

func (c *CRProxy) doWithAuth(cli *http.Client, r *http.Request, host string) (*http.Response, error) {
Expand Down

0 comments on commit e9aed8e

Please sign in to comment.