From dcbb8d97f44a2fc38364ba71c028d660d7ea3593 Mon Sep 17 00:00:00 2001 From: cirospaciari Date: Fri, 23 Feb 2024 16:07:24 -0300 Subject: [PATCH] fix renderMissing --- src/bun.js/api/server.zig | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index a40842a408..dd024fae1a 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -1408,6 +1408,12 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp ctx.flags.has_written_status = true; ctx.end("", ctx.shouldCloseConnection()); } else { + // avoid writing the status again and missmatching the content-length + if (ctx.flags.has_written_status) { + ctx.end("", ctx.shouldCloseConnection()); + return; + } + if (ctx.flags.is_web_browser_navigation) { resp.writeStatus("200 OK"); ctx.flags.has_written_status = true; @@ -1418,11 +1424,12 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp ctx.end(welcome_page_html_gz, ctx.shouldCloseConnection()); return; } - - if (!ctx.flags.has_written_status) - resp.writeStatus("200 OK"); + const missing_content = "Welcome to Bun! To get started, return a Response object."; + resp.writeStatus("200 OK"); + resp.writeHeader("content-type", MimeType.text.value); + resp.writeHeaderInt("content-length", missing_content.len); ctx.flags.has_written_status = true; - ctx.end("Welcome to Bun! To get started, return a Response object.", ctx.shouldCloseConnection()); + ctx.end(missing_content, ctx.shouldCloseConnection()); } } }