From 715d9b39b7d49c3a3ec9c0ea078ae1ae98eb98d1 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Fri, 23 Feb 2024 14:58:37 +0100 Subject: [PATCH] Send 404 properly in http header if file not found --- src/elogd.cxx | 71 ++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/elogd.cxx b/src/elogd.cxx index d81d0667..e68a0a06 100755 --- a/src/elogd.cxx +++ b/src/elogd.cxx @@ -7423,9 +7423,16 @@ int scan_attributes(char *logbook) /*------------------------------------------------------------------*/ -void show_http_header(LOGBOOK *lbs, BOOL expires, const char *cookie) { +void show_http_header(LOGBOOK *lbs, BOOL expires, const char *cookie, int code) { char str[256]; + if (code == 401) + rsprintf("HTTP/1.1 401 Unauthorized\r\n"); + else if (code == 404) + rsprintf("HTTP/1.1 404 Not Found\r\n"); + else + rsprintf("HTTP/1.1 200 Document follows\r\n"); + rsprintf("HTTP/1.1 200 Document follows\r\n"); rsprintf("Server: ELOG HTTP %s-%s\r\n", VERSION, git_revision()); @@ -7469,13 +7476,13 @@ void show_plain_header(int size, const char *file_name) { rsprintf("\r\n"); } -void show_html_header(LOGBOOK *lbs, BOOL expires, const char *title, BOOL close_head, BOOL rss_feed, const char *cookie, - int embed_css, int refresh) { +void show_html_header(LOGBOOK *lbs, BOOL expires, const char *title, BOOL close_head, + BOOL rss_feed, const char *cookie, int embed_css, int refresh, int code) { int i, n; char css[1000], str[1000], media[1000], file_name[256]; char css_list[MAX_N_LIST][NAME_LENGTH]; - show_http_header(lbs, expires, cookie); + show_http_header(lbs, expires, cookie, code); /* DOCTYPE */ rsprintf("\n"); @@ -7583,7 +7590,7 @@ void show_browser(char *br) { void show_standard_header(LOGBOOK *lbs, BOOL expires, const char *title, const char *path, BOOL rss_feed, const char *cookie, const char *script, int refresh) { if (script) { - show_html_header(lbs, expires, title, FALSE, rss_feed, cookie, FALSE, refresh); + show_html_header(lbs, expires, title, FALSE, rss_feed, cookie, FALSE, refresh, 200); rsprintf("