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
11 changes: 11 additions & 0 deletions gateway/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,20 @@ func (gw *Handle) getPayloadFromRequest(r *http.Request) ([]byte, error) {
start := time.Now()
defer gw.bodyReadTimeStat.Since(start)

//This line limits the reader to maxReqSize + 1 before reading the whole content.
r.Body = http.MaxBytesReader(nil,
r.Body,int64(gw.conf.maxReqSize.Load())+1
)

payload, err := io.ReadAll(r.Body)
_ = r.Body.Close()
if err != nil {

//This snippet of code returns the specific error from MaxBytesReader
if err.Error() == "http: request body too large" {
return nil,errors.New(response.RequestBodyTooLarge)
}

gw.logger.Errorn(
"Error reading request body",
logger.NewStringField("Content-Length", r.Header.Get("Content-Length")),
Expand Down