Skip to content

Commit 8008016

Browse files
committed
Fix HTTP Header Buffer
1 parent 1dbce39 commit 8008016

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/webui.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7533,6 +7533,9 @@ static void _webui_http_send_header(
75337533

75347534
#ifdef WEBUI_LOG
75357535
printf("[Core]\t\t_webui_http_send_header([%zu])\n", win->num);
7536+
printf("[Core]\t\t_webui_http_send_header() -> mime_type: [%s]\n", mime_type);
7537+
printf("[Core]\t\t_webui_http_send_header() -> body_len: [%zu]\n", body_len);
7538+
printf("[Core]\t\t_webui_http_send_header() -> cache: [%d]\n", cache);
75367539
#endif
75377540

75387541
const char* no_cache = "no-cache, no-store, must-revalidate, private, max-age=0";
@@ -7575,13 +7578,12 @@ static void _webui_http_send_header(
75757578
}
75767579
}
75777580

7578-
// [header][body]
7579-
size_t buffer_len = (128 + body_len);
7580-
char* buffer = (char*)_webui_malloc(buffer_len);
7581+
// [header only]
7582+
char buffer[1024] = {0};
75817583
int to_send = 0;
75827584
if (set_cookies) {
75837585
// Header with auth cookies
7584-
to_send = WEBUI_SN_PRINTF_DYN(buffer, buffer_len,
7586+
to_send = WEBUI_SN_PRINTF_STATIC(buffer, sizeof(buffer),
75857587
"HTTP/1.1 200 OK\r\n"
75867588
"Set-Cookie: webui_auth=%s; Path=/; HttpOnly; SameSite=Strict\r\n"
75877589
"Access-Control-Allow-Origin: *\r\n"
@@ -7595,7 +7597,7 @@ static void _webui_http_send_header(
75957597
}
75967598
else {
75977599
// Header without auth cookies
7598-
to_send = WEBUI_SN_PRINTF_DYN(buffer, buffer_len,
7600+
to_send = WEBUI_SN_PRINTF_DYN(buffer, sizeof(buffer),
75997601
"HTTP/1.1 200 OK\r\n"
76007602
"Access-Control-Allow-Origin: *\r\n"
76017603
"Cache-Control: %s\r\n"
@@ -7606,9 +7608,14 @@ static void _webui_http_send_header(
76067608
);
76077609
}
76087610

7611+
#ifdef WEBUI_LOG
7612+
printf("---[ HTTP Header ]-----------------\n");
7613+
printf("%s\n", buffer);
7614+
printf("-----------------------------------\n");
7615+
#endif
7616+
76097617
// Send
76107618
mg_write(client, buffer, to_send);
7611-
_webui_free_mem((void*)buffer);
76127619
}
76137620

76147621
static void _webui_http_send_file(

0 commit comments

Comments
 (0)