MCPcopy Create free account
hub / github.com/kataras/iris / GetBody

Function GetBody

context/context.go:2637–2652  ·  view source on GitHub ↗

GetBody reads and returns the request body.

(r *http.Request, resetBody bool)

Source from the content-addressed store, hash-verified

2635
2636// GetBody reads and returns the request body.
2637func GetBody(r *http.Request, resetBody bool) ([]byte, func(), error) {
2638 data, err := io.ReadAll(r.Body)
2639 if err != nil {
2640 return nil, nil, err
2641 }
2642
2643 if resetBody {
2644 // * remember, Request.Body has no Bytes(), we have to consume them first
2645 // and after re-set them to the body, this is the only solution.
2646 return data, func() {
2647 setBody(r, data)
2648 }, nil
2649 }
2650
2651 return data, emptyFunc, nil
2652}
2653
2654func setBody(r *http.Request, data []byte) {
2655 r.Body = io.NopCloser(bytes.NewBuffer(data))

Callers 3

GetFormFunction · 0.85
GetBodyMethod · 0.85
ReadMultipartRelatedMethod · 0.85

Calls 1

setBodyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…