(c *Client, r *Request)
| 245 | } |
| 246 | |
| 247 | func 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 | |
| 295 | func 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) |
no test coverage detected
searching dependent graphs…