From 1c8579e668ffa09d6df143d28e294e8cb3fd6808 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 18 Aug 2024 19:06:15 +0200 Subject: [PATCH] Fix headers not being correctly handled for Kepler-style Lua server pages Signed-off-by: DL6ER --- src/webserver/civetweb/mod_lua.inl | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/webserver/civetweb/mod_lua.inl b/src/webserver/civetweb/mod_lua.inl index b3ad4b14..3ad3ba75 100644 --- a/src/webserver/civetweb/mod_lua.inl +++ b/src/webserver/civetweb/mod_lua.inl @@ -641,17 +641,22 @@ run_lsp_kepler(struct mg_connection *conn, /* Only send a HTML header, if this is the top level page. * If this page is included by some mg.include calls, do not add a * header. */ - if(conn->status_code < 0) - mg_printf(conn, "HTTP/1.1 200 OK\r\n"); - else - mg_printf(conn, "HTTP/1.1 %d %s\r\n", conn->status_code, mg_get_response_code_text(conn, conn->status_code)); + + /* Initialize a new HTTP response, either with some-predefined + * status code (e.g. 404 if this is called from an error + * handler) or with 200 OK */ + mg_response_header_start(conn, conn->status_code > 0 ? conn->status_code : 200); + + /* Add additional headers */ send_no_cache_header(conn); send_additional_header(conn); - mg_printf(conn, - "Date: %s\r\n" - "Connection: close\r\n" - "Content-Type: text/html; charset=utf-8\r\n\r\n", - date); + send_cors_header(conn); + + /* Add content type */ + mg_response_header_add(conn, "Content-Type", "text/html; charset=utf-8", -1); + + /* Send the HTTP response (status and all headers) */ + mg_response_header_send(conn); } data.begin = p;