Browse Source

Fix header generation for Lua Server Pages (Kepler syntax).

The currently used code has send_no_cache_header() and send_additional_header() but NOT actually a call to mg_response_header_send(). When NO_RESPONSE_BUFFERING is not set (default), this merely adds the additional headers to the buffer but does not send them. As a final call to mg_response_header_send() was indeed missing here, they are never sent causing, e.g., headers added through the "additional_headers" config string to be ignored for Kepler LSP. Similarly, CORS and cache-control headers were missing in this case.

Signed-off-by: DL6ER <dl6er@dl6er.de>
DL6ER 10 months ago
parent
commit
616830868f
1 changed files with 13 additions and 9 deletions
  1. 13 9
      src/mod_lua.inl

+ 13 - 9
src/mod_lua.inl

@@ -641,17 +641,21 @@ run_lsp_kepler(struct mg_connection *conn,
 		/* Only send a HTML header, if this is the top level page.
 		/* 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
 		 * If this page is included by some mg.include calls, do not add a
 		 * header. */
 		 * 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_no_cache_header(conn);
 		send_additional_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);
+
+		/* 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;
 	data.begin = p;