mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-23 11:33:37 +08:00
Merge f6c0ff96d82a3c945dbadc03b47c9ec6c5b6da9f into 1bd0ecf2d3e08da37efa270bb7be20c1eddb0d68
This commit is contained in:
commit
58294dc391
@ -955,6 +955,9 @@ func (c *Context) ShouldBindBodyWith(obj any, bb binding.BindingBody) (err error
|
||||
}
|
||||
}
|
||||
if body == nil {
|
||||
if c.Request.Body == nil {
|
||||
return errors.New("cannot read nil body")
|
||||
}
|
||||
body, err = io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -2772,6 +2772,15 @@ func TestContextShouldBindBodyWith(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextShouldBindBodyWithNilBody(t *testing.T) {
|
||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||
c.Request = &http.Request{}
|
||||
|
||||
var obj struct{}
|
||||
err := c.ShouldBindBodyWithJSON(&obj)
|
||||
assert.EqualError(t, err, "cannot read nil body")
|
||||
}
|
||||
|
||||
func TestContextShouldBindBodyWithJSON(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user