@ruiapp/rapid-core 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1427,31 +1427,37 @@ class RapidRequest {
1427
1427
  return;
1428
1428
  }
1429
1429
  const requestMethod = this.method;
1430
- if (requestMethod === "POST" || requestMethod === "PUT" || requestMethod === "PATCH") {
1431
- const req = this.#raw;
1432
- const contentType = this.#headers.get("Content-Type") || "application/json";
1433
- if (contentType.includes("json")) {
1434
- this.#body = {
1435
- type: "json",
1436
- value: await req.json(),
1437
- };
1438
- }
1439
- else if (contentType.startsWith("application/x-www-form-urlencoded")) {
1440
- const bodyText = await req.text();
1441
- this.#body = {
1442
- type: "form",
1443
- value: qs__default["default"].parse(bodyText),
1444
- };
1445
- }
1446
- else if (contentType.startsWith("multipart/form-data")) {
1447
- this.#body = {
1448
- type: "form-data",
1449
- value: await parseFormDataBody(req),
1450
- };
1451
- }
1430
+ if (requestMethod !== "POST" && requestMethod !== "PUT" && requestMethod !== "PATCH") {
1431
+ this.#body = null;
1432
+ this.#bodyParsed = true;
1433
+ return;
1452
1434
  }
1453
- else {
1435
+ const contentLength = parseInt(this.#headers.get("Content-Length") || "0", 10);
1436
+ if (!contentLength) {
1454
1437
  this.#body = null;
1438
+ this.#bodyParsed = true;
1439
+ return;
1440
+ }
1441
+ const req = this.#raw;
1442
+ const contentType = this.#headers.get("Content-Type") || "application/json";
1443
+ if (contentType.includes("json")) {
1444
+ this.#body = {
1445
+ type: "json",
1446
+ value: await req.json(),
1447
+ };
1448
+ }
1449
+ else if (contentType.startsWith("application/x-www-form-urlencoded")) {
1450
+ const bodyText = await req.text();
1451
+ this.#body = {
1452
+ type: "form",
1453
+ value: qs__default["default"].parse(bodyText),
1454
+ };
1455
+ }
1456
+ else if (contentType.startsWith("multipart/form-data")) {
1457
+ this.#body = {
1458
+ type: "form-data",
1459
+ value: await parseFormDataBody(req),
1460
+ };
1455
1461
  }
1456
1462
  this.#bodyParsed = true;
1457
1463
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -36,28 +36,37 @@ export class RapidRequest {
36
36
  }
37
37
 
38
38
  const requestMethod = this.method;
39
- if (requestMethod === "POST" || requestMethod === "PUT" || requestMethod === "PATCH") {
40
- const req = this.#raw;
41
- const contentType = this.#headers.get("Content-Type") || "application/json";
42
- if (contentType.includes("json")) {
43
- this.#body = {
44
- type: "json",
45
- value: await req.json(),
46
- };
47
- } else if (contentType.startsWith("application/x-www-form-urlencoded")) {
48
- const bodyText = await req.text();
49
- this.#body = {
50
- type: "form",
51
- value: qs.parse(bodyText),
52
- };
53
- } else if (contentType.startsWith("multipart/form-data")) {
54
- this.#body = {
55
- type: "form-data",
56
- value: await parseFormDataBody(req),
57
- };
58
- }
59
- } else {
39
+ if (requestMethod !== "POST" && requestMethod !== "PUT" && requestMethod !== "PATCH") {
60
40
  this.#body = null;
41
+ this.#bodyParsed = true;
42
+ return;
43
+ }
44
+
45
+ const contentLength = parseInt(this.#headers.get("Content-Length") || "0", 10);
46
+ if (!contentLength) {
47
+ this.#body = null;
48
+ this.#bodyParsed = true;
49
+ return;
50
+ }
51
+
52
+ const req = this.#raw;
53
+ const contentType = this.#headers.get("Content-Type") || "application/json";
54
+ if (contentType.includes("json")) {
55
+ this.#body = {
56
+ type: "json",
57
+ value: await req.json(),
58
+ };
59
+ } else if (contentType.startsWith("application/x-www-form-urlencoded")) {
60
+ const bodyText = await req.text();
61
+ this.#body = {
62
+ type: "form",
63
+ value: qs.parse(bodyText),
64
+ };
65
+ } else if (contentType.startsWith("multipart/form-data")) {
66
+ this.#body = {
67
+ type: "form-data",
68
+ value: await parseFormDataBody(req),
69
+ };
61
70
  }
62
71
  this.#bodyParsed = true;
63
72
  }