From 50d3bcdee22c0b59d7e1bff254445a0b9a779113 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 10 Apr 2024 19:56:11 +0200 Subject: [PATCH] fix(use): Set request readable encoding to utf-8 Closes #118 --- src/use/express.ts | 1 + src/use/http.ts | 1 + src/use/http2.ts | 1 + src/use/koa.ts | 1 + 4 files changed, 4 insertions(+) diff --git a/src/use/express.ts b/src/use/express.ts index ab2722d..4098b52 100644 --- a/src/use/express.ts +++ b/src/use/express.ts @@ -132,6 +132,7 @@ function toRequest( } return new Promise((resolve) => { let body = ''; + req.setEncoding('utf-8'); req.on('data', (chunk) => (body += chunk)); req.on('end', () => resolve(body)); }); diff --git a/src/use/http.ts b/src/use/http.ts index 8a51c93..b83aa21 100644 --- a/src/use/http.ts +++ b/src/use/http.ts @@ -142,6 +142,7 @@ function toRequest( body: () => new Promise((resolve) => { let body = ''; + req.setEncoding('utf-8'); req.on('data', (chunk) => (body += chunk)); req.on('end', () => resolve(body)); }), diff --git a/src/use/http2.ts b/src/use/http2.ts index 900d7ec..3332596 100644 --- a/src/use/http2.ts +++ b/src/use/http2.ts @@ -176,6 +176,7 @@ function toRequest( body: () => new Promise((resolve) => { let body = ''; + req.setEncoding('utf-8'); req.on('data', (chunk) => (body += chunk)); req.on('end', () => resolve(body)); }), diff --git a/src/use/koa.ts b/src/use/koa.ts index ddde151..0d29b8a 100644 --- a/src/use/koa.ts +++ b/src/use/koa.ts @@ -126,6 +126,7 @@ export function createHandler( } return new Promise((resolve) => { let body = ''; + ctx.req.setEncoding('utf-8'); ctx.req.on('data', (chunk) => (body += chunk)); ctx.req.on('end', () => resolve(body)); });