From 6768ea1c34cea5d99233ace6b34cca495d49f8ec Mon Sep 17 00:00:00 2001 From: Nicholas Schamberg Date: Thu, 27 May 2021 13:49:45 +0300 Subject: [PATCH 1/2] multipart/form-data fixes --- src/request.js | 2 +- src/server.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/request.js b/src/request.js index ceee460..ceedec4 100644 --- a/src/request.js +++ b/src/request.js @@ -33,7 +33,7 @@ class HttpRequest extends Readable { } _read (size) { - return this.slice(0, size) + return this.slice ? this.slice(0, size) : size } } diff --git a/src/server.js b/src/server.js index b7bb963..c9c2a69 100644 --- a/src/server.js +++ b/src/server.js @@ -34,6 +34,11 @@ module.exports = (config = {}) => { const method = reqWrapper.method if (method !== 'HEAD') { // 0http's low checks also that method !== 'GET', but many users would send request body with GET, unfortunately res.onData((bytes, isLast) => { + + if (!bytes.byteLength) { + if (!isLast) return + return handler(reqWrapper, resWrapper) + } const chunk = Buffer.from(bytes) if (isLast) { reqWrapper.push(chunk) From 5e89283b3fbb20e1c01f3115888e3677f8668e50 Mon Sep 17 00:00:00 2001 From: Nicholas Schamberg Date: Thu, 27 May 2021 13:52:22 +0300 Subject: [PATCH 2/2] lint --- src/server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server.js b/src/server.js index c9c2a69..acf004a 100644 --- a/src/server.js +++ b/src/server.js @@ -34,7 +34,6 @@ module.exports = (config = {}) => { const method = reqWrapper.method if (method !== 'HEAD') { // 0http's low checks also that method !== 'GET', but many users would send request body with GET, unfortunately res.onData((bytes, isLast) => { - if (!bytes.byteLength) { if (!isLast) return return handler(reqWrapper, resWrapper)