From 9b49e5578ff76b5abba07ea75f2e5c60a6d0f958 Mon Sep 17 00:00:00 2001 From: Joao Alves Date: Wed, 22 Sep 2021 09:05:59 +0100 Subject: [PATCH] Added lang to html. Lazy calculation of static page size. --- inc/http_staticpage.h | 5 +++-- src/lib/http.c | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/inc/http_staticpage.h b/inc/http_staticpage.h index 9ef05d2..43f8e39 100644 --- a/inc/http_staticpage.h +++ b/inc/http_staticpage.h @@ -1,6 +1,6 @@ const char *content_static_page = \ "" \ - "" \ + "" \ "" \ " " \ " uts-server" \ @@ -45,7 +45,6 @@ const char *content_static_page = " border-radius: 2px;" \ " padding: 10px 24px;" \ " margin: 0 auto;" \ - " display: inline;" \ " box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, " \ "0, 0.19);" \ " margin: 0 auto;" \ @@ -115,3 +114,5 @@ const char *content_static_page = "" \ "" \ ""; + +int static_page_size = 0; diff --git a/src/lib/http.c b/src/lib/http.c index afabbd7..c1efd96 100644 --- a/src/lib/http.c +++ b/src/lib/http.c @@ -195,14 +195,16 @@ int rfc3161_handler(struct mg_connection *conn, void *context) { free(content); } else { // default reply if we don't have a time-stamp request - content_length = strlen(content_static_page); + if (static_page_size == 0) { + static_page_size = strlen(content_static_page); + } mg_printf(conn, "HTTP/1.1 200 OK\r\n" "Content-Type: text/html\r\n" "Content-Length: %d\r\n" "\r\n", - (int)content_length); - mg_write(conn, content_static_page, content_length); + (int)static_page_size); + mg_write(conn, content_static_page, static_page_size); } // initialize a serial_id if not created by create_response if (serial_id == NULL) {