| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 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 };
|