Body binds the request body into the struct, map[string]string and map[string][]string. Returns *BindError on parse failure (manual mode) or *Error with status 400 (auto-handling mode). It supports decoding the following content types based on the Content-Type header: application/json, application/x
(out any)
| 395 | // If none of the content types above are matched, it'll take a look custom binders by checking the MIMETypes() method of custom binder. |
| 396 | // If there is no custom binder for mime type of body, it will return a ErrUnprocessableEntity error. |
| 397 | func (b *Bind) Body(out any) error { |
| 398 | // Get content-type |
| 399 | ctype := utils.UnsafeString(utilsbytes.UnsafeToLower(b.ctx.RequestCtx().Request.Header.ContentType())) |
| 400 | ctype = binder.FilterFlags(utils.ParseVendorSpecificContentType(ctype)) |
| 401 | |
| 402 | // Check custom binders |
| 403 | binders := b.ctx.App().customBinders |
| 404 | for _, customBinder := range binders { |
| 405 | if slices.Contains(customBinder.MIMETypes(), ctype) { |
| 406 | if err := b.returnBindErr(customBinder.Parse(b.ctx, out), BindSourceBody); err != nil { |
| 407 | return err |
| 408 | } |
| 409 | return b.validateStruct(out) |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | // Parse body accordingly |
| 414 | switch ctype { |
| 415 | case MIMEApplicationJSON: |
| 416 | return b.JSON(out) |
| 417 | case MIMEApplicationMsgPack: |
| 418 | return b.MsgPack(out) |
| 419 | case MIMETextXML, MIMEApplicationXML: |
| 420 | return b.XML(out) |
| 421 | case MIMEApplicationCBOR: |
| 422 | return b.CBOR(out) |
| 423 | case MIMEApplicationForm, MIMEMultipartForm: |
| 424 | return b.Form(out) |
| 425 | } |
| 426 | |
| 427 | // No suitable content type found |
| 428 | return ErrUnprocessableEntity |
| 429 | } |
| 430 | |
| 431 | // All binds values from URI params, the request body, the query string, |
| 432 | // headers, and cookies into the provided struct in precedence order. |
nothing calls this directly
no test coverage detected