Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import (
"bufio"
"bytes"
"io"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -71,7 +72,27 @@

bufReader := bufio.NewReader(buf)

return http.ReadResponse(bufReader, req)
res, err := http.ReadResponse(bufReader, req)
if err != nil {
return res, err
}

// Ensure the full response body is read to avoid truncation issues.
// http.ReadResponse may not fully populate the body for all buffer types.
if res.Body != nil {
bodyBytes, err := io.ReadAll(res.Body)
res.Body.Close()

Check failure on line 84 in core/core.go

View workflow job for this annotation

GitHub Actions / Validate quality (core)

Error return value of `res.Body.Close` is not checked (errcheck)
if err != nil {

Check failure on line 85 in core/core.go

View workflow job for this annotation

GitHub Actions / Validate quality (core)

missing whitespace above this line (invalid statement above if) (wsl_v5)
return res, err
}
res.Body = http.NoBody

Check failure on line 88 in core/core.go

View workflow job for this annotation

GitHub Actions / Validate quality (core)

missing whitespace above this line (invalid statement above assign) (wsl_v5)
if len(bodyBytes) > 0 {
res.Body = io.NopCloser(bytes.NewReader(bodyBytes))
res.ContentLength = int64(len(bodyBytes))
}
}

return res, nil
}

func MappingElection(provider Storer, item []byte, req *http.Request, validator *Revalidator, logger Logger) (resultFresh *http.Response, resultStale *http.Response, e error) {
Expand Down
Loading