MCPcopy Index your code
hub / github.com/imroc/req / parseRequestBody

Function parseRequestBody

middleware.go:247–293  ·  view source on GitHub ↗
(c *Client, r *Request)

Source from the content-addressed store, hash-verified

245}
246
247func parseRequestBody(c *Client, r *Request) (err error) {
248 if c.isPayloadForbid(r.Method) {
249 r.marshalBody = nil
250 r.Body = nil
251 r.GetBody = nil
252 return
253 }
254 // handle multipart
255 if r.isMultiPart {
256 return handleMultiPart(c, r)
257 }
258
259 // handle form data
260 if len(c.FormData) > 0 {
261 r.SetFormDataFromValues(c.FormData)
262 }
263
264 if len(r.FormData) > 0 {
265 handleFormData(r)
266 return
267 } else if len(r.OrderedFormData) > 0 {
268 handleOrderedFormData(r)
269 return
270 }
271
272 // handle marshal body
273 if r.marshalBody != nil {
274 err = handleMarshalBody(c, r)
275 if err != nil {
276 return
277 }
278 }
279
280 if r.Body == nil {
281 return
282 }
283 // body is in-memory []byte, so we can guess content type
284
285 if c.Headers != nil && c.Headers.Get(header.ContentType) != "" { // ignore if content type set at client-level
286 return
287 }
288 if r.getHeader(header.ContentType) != "" { // ignore if content-type set at request-level
289 return
290 }
291 r.SetContentType(http.DetectContentType(r.Body))
292 return
293}
294
295func unmarshalBody(c *Client, r *Response, v any) (err error) {
296 body, err := r.ToBytes() // in case req.SetResult or req.SetError with client.DisableAutoReadResponse(true)

Callers 1

handleDigestAuthFuncFunction · 0.85

Calls 9

handleMultiPartFunction · 0.85
handleFormDataFunction · 0.85
handleOrderedFormDataFunction · 0.85
handleMarshalBodyFunction · 0.85
isPayloadForbidMethod · 0.80
SetFormDataFromValuesMethod · 0.80
getHeaderMethod · 0.80
SetContentTypeMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…