Skip to content

Commit

Permalink
prevent allocation for http.NoBody
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Dec 8, 2022
1 parent 0a56685 commit bcadbe9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"hash"
"io"
"net/http"
"strings"
)

Expand Down Expand Up @@ -139,8 +140,10 @@ func hashbody(h hash.Hash, getbody func() (io.ReadCloser, error)) (string, error
return "", err
}
defer r.Close()
if _, err := io.Copy(h, r); err != nil {
return "", err
if r != http.NoBody {
if _, err := io.Copy(h, r); err != nil {
return "", err
}
}
}
return hex.EncodeToString(h.Sum(nil)), nil
Expand Down

0 comments on commit bcadbe9

Please sign in to comment.