From c6ef898c4667836ee7a74ca1ae8d5989dbc31b60 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 20 Mar 2023 21:50:40 +0100 Subject: [PATCH] Fix Content-Length calculation in HTTPServerConnection::send when using non-ascii utf-8 characters. --- modules/http_server_simple/http_server_simple.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/http_server_simple/http_server_simple.cpp b/modules/http_server_simple/http_server_simple.cpp index c9616f407..2b2a42a1b 100644 --- a/modules/http_server_simple/http_server_simple.cpp +++ b/modules/http_server_simple/http_server_simple.cpp @@ -172,8 +172,10 @@ void HTTPServerConnection::send_redirect(Ref request, const St void HTTPServerConnection::send(Ref request) { String body = request->get_compiled_body(); + CharString body_cs = body.utf8(); + String s = "HTTP/1.1 " + HTTPServerEnums::get_status_code_header_string(request->get_status_code()) + "\r\n"; - s += "Content-Length: " + itos(body.size()) + "\r\n"; + s += "Content-Length: " + itos(body_cs.length()) + "\r\n"; s += "Content-type: text/html\r\n"; if (has_more_messages()) {