go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

The request body is truncated if it exceeds 8MB

Open LGQ17 opened this issue 6 months ago • 3 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior, if applicable:

  1. The code is

rest\httpx\requests.go reader := io.LimitReader(r.Body, maxBodyLen)


2. The error is


**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environments (please complete the following information):**
- OS: [e.g. Linux]
- go-zero version [e.g. 1.2.1]
- goctl version [e.g. 1.2.1, optional]

**More description**
Add any other context about the problem here.

LGQ17 avatar May 26 '25 11:05 LGQ17

// ParseJsonBody parses the post request which contains json in body. func ParseJsonBody(r *http.Request, v any) error { if withJsonBody(r) { reader := io.LimitReader(r.Body, maxBodyLen) return mapping.UnmarshalJsonReader(reader, v) }

return mapping.UnmarshalJsonMap(nil, v)

}

LGQ17 avatar May 26 '25 11:05 LGQ17

There is MaxBytes in config, you can set the max body length.

kevwan avatar May 28 '25 03:05 kevwan

maxBodyLen is a constant,use in httpx.Parse. setting MaxBytes does not solve the @kevwan

There is MaxBytes in config, you can set the max body length.

LGQ17 avatar May 28 '25 06:05 LGQ17