From 764ec60d42e5ef83789e603df4629a82b67b4979 Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Wed, 20 Nov 2024 17:36:40 -0800 Subject: [PATCH] actually encode things --- src/js/node/http.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/js/node/http.ts b/src/js/node/http.ts index bad9df628a..5edb5e58cb 100644 --- a/src/js/node/http.ts +++ b/src/js/node/http.ts @@ -2120,9 +2120,11 @@ const ServerResponse_writeDeprecated = function _write(chunk, encoding, callback if (!$isCallable(callback)) { callback = undefined; } + if (encoding && encoding !== "buffer") { + chunk = Buffer.from(chunk, encoding); + } if (this.destroyed || this.finished) { if (chunk) { - console.error("???"); emitErrorNextTickIfErrorListenerNT(this, $ERR_STREAM_WRITE_AFTER_END("Cannot write after end"), callback); } return false; @@ -2203,13 +2205,16 @@ function ServerResponse_finalDeprecated(chunk, encoding, callback) { if (!$isCallable(callback)) { callback = undefined; } + if (this.destroyed || this.finished) { if (chunk) { emitErrorNextTickIfErrorListenerNT(this, $ERR_STREAM_WRITE_AFTER_END("Cannot write after end"), callback); } return false; } - + if (encoding && encoding !== "buffer") { + chunk = Buffer.from(chunk, encoding); + } const req = this.req; const shouldEmitClose = req && req.emit && !this[finishedSymbol]; if (!this.headersSent) {