| 1 | |
| 2 | * react-router v8.3.0
|
| 3 | *
|
| 4 | * Copyright (c) Remix Software Inc.
|
| 5 | *
|
| 6 | * This source code is licensed under the MIT license found in the
|
| 7 | * LICENSE.md file in the root directory of this source tree.
|
| 8 | *
|
| 9 | * @license MIT
|
| 10 | */
|
| 11 |
|
| 12 | async function createRequestInit(request) {
|
| 13 | let init = { signal: request.signal };
|
| 14 | if (request.method !== "GET") {
|
| 15 | init.method = request.method;
|
| 16 | let contentType = request.headers.get("Content-Type");
|
| 17 | if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
| 18 | init.headers = { "Content-Type": contentType };
|
| 19 | init.body = JSON.stringify(await request.json());
|
| 20 | } else if (contentType && /\btext\/plain\b/.test(contentType)) {
|
| 21 | init.headers = { "Content-Type": contentType };
|
| 22 | init.body = await request.text();
|
| 23 | } else if (contentType && /\bapplication\/x-www-form-urlencoded\b/.test(contentType)) init.body = new URLSearchParams(await request.text());
|
| 24 | else init.body = await request.formData();
|
| 25 | }
|
| 26 | return init;
|
| 27 | }
|
| 28 |
|
| 29 | export { createRequestInit };
|