h3 1.6.2 → 1.6.4

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/README.md CHANGED
@@ -98,7 +98,7 @@ Routes are internally stored in a [Radix Tree](https://en.wikipedia.org/wiki/Rad
98
98
 
99
99
  ```js
100
100
  // Handle can directly return object or Promise<object> for JSON response
101
- app.use('/api', eventHandler((event) => ({ url: event.node.req.url }))
101
+ app.use('/api', eventHandler((event) => ({ url: event.node.req.url })))
102
102
 
103
103
  // We can have better matching other than quick prefix match
104
104
  app.use('/odd', eventHandler(() => 'Is odd!'), { match: url => url.substr(1) % 2 })
@@ -121,7 +121,7 @@ app.use('/api', eventHandler((event) => proxyRequest('https://example.com', {
121
121
  cookiePathRewrite: {
122
122
  "/": "/api"
123
123
  },
124
- }))
124
+ })))
125
125
 
126
126
  // Legacy middleware with 3rd argument are automatically promisified
127
127
  app.use(fromNodeMiddleware((req, res, next) => { req.setHeader('x-foo', 'bar'); next() }))
package/dist/index.cjs CHANGED
@@ -276,13 +276,13 @@ const ParsedBodySymbol = Symbol.for("h3ParsedBody");
276
276
  const PayloadMethods$1 = ["PATCH", "POST", "PUT", "DELETE"];
277
277
  function readRawBody(event, encoding = "utf8") {
278
278
  assertMethod(event, PayloadMethods$1);
279
- if (RawBodySymbol in event.node.req) {
280
- const promise2 = Promise.resolve(event.node.req[RawBodySymbol]);
279
+ const _rawBody = event.node.req[RawBodySymbol] || event.node.req.body;
280
+ if (_rawBody) {
281
+ const promise2 = Promise.resolve(
282
+ Buffer.isBuffer(_rawBody) ? _rawBody : Buffer.from(_rawBody)
283
+ );
281
284
  return encoding ? promise2.then((buff) => buff.toString(encoding)) : promise2;
282
285
  }
283
- if ("body" in event.node.req) {
284
- return Promise.resolve(event.node.req.body);
285
- }
286
286
  if (!Number.parseInt(event.node.req.headers["content-length"] || "")) {
287
287
  return Promise.resolve(void 0);
288
288
  }
@@ -305,7 +305,7 @@ async function readBody(event) {
305
305
  if (ParsedBodySymbol in event.node.req) {
306
306
  return event.node.req[ParsedBodySymbol];
307
307
  }
308
- const body = await readRawBody(event);
308
+ const body = await readRawBody(event, "utf8");
309
309
  if (event.node.req.headers["content-type"] === "application/x-www-form-urlencoded") {
310
310
  const form = new URLSearchParams(body);
311
311
  const parsedForm = /* @__PURE__ */ Object.create(null);
package/dist/index.mjs CHANGED
@@ -274,13 +274,13 @@ const ParsedBodySymbol = Symbol.for("h3ParsedBody");
274
274
  const PayloadMethods$1 = ["PATCH", "POST", "PUT", "DELETE"];
275
275
  function readRawBody(event, encoding = "utf8") {
276
276
  assertMethod(event, PayloadMethods$1);
277
- if (RawBodySymbol in event.node.req) {
278
- const promise2 = Promise.resolve(event.node.req[RawBodySymbol]);
277
+ const _rawBody = event.node.req[RawBodySymbol] || event.node.req.body;
278
+ if (_rawBody) {
279
+ const promise2 = Promise.resolve(
280
+ Buffer.isBuffer(_rawBody) ? _rawBody : Buffer.from(_rawBody)
281
+ );
279
282
  return encoding ? promise2.then((buff) => buff.toString(encoding)) : promise2;
280
283
  }
281
- if ("body" in event.node.req) {
282
- return Promise.resolve(event.node.req.body);
283
- }
284
284
  if (!Number.parseInt(event.node.req.headers["content-length"] || "")) {
285
285
  return Promise.resolve(void 0);
286
286
  }
@@ -303,7 +303,7 @@ async function readBody(event) {
303
303
  if (ParsedBodySymbol in event.node.req) {
304
304
  return event.node.req[ParsedBodySymbol];
305
305
  }
306
- const body = await readRawBody(event);
306
+ const body = await readRawBody(event, "utf8");
307
307
  if (event.node.req.headers["content-type"] === "application/x-www-form-urlencoded") {
308
308
  const form = new URLSearchParams(body);
309
309
  const parsedForm = /* @__PURE__ */ Object.create(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h3",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "Tiny JavaScript Server",
5
5
  "repository": "unjs/h3",
6
6
  "license": "MIT",
@@ -24,16 +24,16 @@
24
24
  "defu": "^6.1.2",
25
25
  "destr": "^1.2.2",
26
26
  "iron-webcrypto": "^0.6.0",
27
- "radix3": "^1.0.0",
27
+ "radix3": "^1.0.1",
28
28
  "ufo": "^1.1.1",
29
29
  "uncrypto": "^0.1.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "0x": "^5.5.0",
33
33
  "@types/express": "^4.17.17",
34
- "@types/node": "^18.15.3",
34
+ "@types/node": "^18.15.10",
35
35
  "@types/supertest": "^2.0.12",
36
- "@vitest/coverage-c8": "^0.29.2",
36
+ "@vitest/coverage-c8": "^0.29.7",
37
37
  "autocannon": "^7.10.0",
38
38
  "changelogen": "^0.5.1",
39
39
  "connect": "^3.7.0",
@@ -44,13 +44,13 @@
44
44
  "jiti": "^1.18.2",
45
45
  "listhen": "^1.0.4",
46
46
  "node-fetch-native": "^1.0.2",
47
- "prettier": "^2.8.4",
47
+ "prettier": "^2.8.7",
48
48
  "supertest": "^6.3.3",
49
- "typescript": "^4.9.5",
49
+ "typescript": "^5.0.2",
50
50
  "unbuild": "^1.1.2",
51
- "vitest": "^0.29.2"
51
+ "vitest": "^0.29.7"
52
52
  },
53
- "packageManager": "pnpm@7.29.3",
53
+ "packageManager": "pnpm@8.0.0",
54
54
  "scripts": {
55
55
  "build": "unbuild",
56
56
  "dev": "vitest",