(body, contentType, valueFormatFn)
| 1459 | } |
| 1460 | |
| 1461 | function parseBody(body, contentType, valueFormatFn) { |
| 1462 | if (contentType === 'text/plain' || !body) { |
| 1463 | return valueFormatFn && body ? valueFormatFn(body) : body; |
| 1464 | } |
| 1465 | |
| 1466 | const parsed = parseString(body, valueFormatFn); |
| 1467 | |
| 1468 | switch (contentType) { |
| 1469 | case 'multipart/form-data': |
| 1470 | return Object.keys(parsed).reduce((p, c) => { |
| 1471 | p.append(c, parsed[c]); |
| 1472 | return p; |
| 1473 | }, new FormData()); |
| 1474 | case 'application/x-www-form-urlencoded': |
| 1475 | return Object.keys(parsed).reduce((p, c) => { |
| 1476 | return p ? `${p}&${c}=${parsed[c]}` : `${c}=${parsed[c]}`; |
| 1477 | }); |
| 1478 | } |
| 1479 | |
| 1480 | return parsed; |
| 1481 | } |
| 1482 | |
| 1483 | function formatBodyFun(contentType, body) { |
| 1484 | if (!body) return {}; |
no test coverage detected