Add cache control to make sure new pages are served on session timeout

This commit is contained in:
logicog
2025-12-01 18:26:46 +01:00
parent 4e4e6a55ba
commit 0722b147fe
2 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -579,7 +579,7 @@ void httpd_appcall(void)
slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: "); slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: ");
slen += strtox(outbuf + slen, mime_strings[f_data[entry].mime]); slen += strtox(outbuf + slen, mime_strings[f_data[entry].mime]);
slen += strtox(outbuf + slen, "\r\nCache-Control: max-age=2592000\r\n\r\n"); slen += strtox(outbuf + slen, "\r\nCache-Control: max-age=60, must-revalidate\r\n\r\n");
len_left = f_data[entry].len; len_left = f_data[entry].len;
if (len_left > (TCP_OUTBUF_SIZE - slen)) { if (len_left > (TCP_OUTBUF_SIZE - slen)) {
cont_len = len_left - (TCP_OUTBUF_SIZE - slen); cont_len = len_left - (TCP_OUTBUF_SIZE - slen);
+5 -4
View File
@@ -113,6 +113,7 @@ void send_status(int s)
struct json_object *ports, *v; struct json_object *ports, *v;
const char *jstring; const char *jstring;
char *header = "HTTP/1.1 200 OK\r\n" char *header = "HTTP/1.1 200 OK\r\n"
"Cache-Control: no-cache\r\n"
"Content-Type: application/json; charset=UTF-8\r\n\r\n"; "Content-Type: application/json; charset=UTF-8\r\n\r\n";
printf("Sending status.\n"); printf("Sending status.\n");
@@ -300,7 +301,7 @@ void send_to_login(int socket) {
void send_unauthorized(int socket) { void send_unauthorized(int socket) {
char *response = "HTTP/1.1 301 Unauthorized\r\n\r\n"; char *response = "HTTP/1.1 401 Unauthorized\r\n\r\n";
write(socket, response, strlen(response)); write(socket, response, strlen(response));
} }
@@ -497,7 +498,7 @@ void launch(struct Server *server)
goto done; goto done;
} }
if (!authenticated && !is_word(&buffer[5], "/login")) { if (!authenticated && !is_word(&buffer[5], "/login")) {
send_to_login(new_socket); send_unauthorized(new_socket);
goto done; goto done;
} }
printf("Bytes read %ld\n", bytesRead); printf("Bytes read %ld\n", bytesRead);
@@ -525,8 +526,7 @@ void launch(struct Server *server)
"Set-Cookie: session=" SESSION_ID "; SameSite=Strict\r\n"; "Set-Cookie: session=" SESSION_ID "; SameSite=Strict\r\n";
} else { } else {
response = "HTTP/1.1 302 Found\r\n" response = "HTTP/1.1 302 Found\r\n"
"Location: login.html\r\n" "Location: login.html\r\n\r\n";
"Content-Type: text/html\r\n\r\n";
} }
write(new_socket, response, strlen(response)); write(new_socket, response, strlen(response));
goto done; goto done;
@@ -595,6 +595,7 @@ void launch(struct Server *server)
} }
} }
char *response = "HTTP/1.1 200 OK\r\n" char *response = "HTTP/1.1 200 OK\r\n"
"Cache-Control: max-age=60, must-revalidate\r\n"
"Content-Type: "; "Content-Type: ";
write(new_socket, response, strlen(response)); write(new_socket, response, strlen(response));