UnmarshalJSONRequest into the given interface pointer. Returns an error JSON response if there was a problem unmarshalling. Calling this function consumes the request body.
(req *http.Request, iface interface{})
| 27 | // UnmarshalJSONRequest into the given interface pointer. Returns an error JSON response if |
| 28 | // there was a problem unmarshalling. Calling this function consumes the request body. |
| 29 | func UnmarshalJSONRequest(req *http.Request, iface interface{}) *util.JSONResponse { |
| 30 | // encoding/json allows invalid utf-8, matrix does not |
| 31 | // https://matrix.org/docs/spec/client_server/r0.6.1#api-standards |
| 32 | body, err := io.ReadAll(req.Body) |
| 33 | if err != nil { |
| 34 | util.GetLogger(req.Context()).WithError(err).Error("io.ReadAll failed") |
| 35 | resp := jsonerror.InternalServerError() |
| 36 | return &resp |
| 37 | } |
| 38 | |
| 39 | return UnmarshalJSON(body, iface) |
| 40 | } |
| 41 | |
| 42 | func UnmarshalJSON(body []byte, iface interface{}) *util.JSONResponse { |
| 43 | if !utf8.Valid(body) { |
nothing calls this directly
no test coverage detected