From f3449a8af53c8dcb51e1b82199ec66348d518d7e Mon Sep 17 00:00:00 2001 From: xtne6f Date: Sun, 5 Jun 2016 08:03:27 +0900 Subject: [PATCH] More compliant 304 response --- src/civetweb.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/civetweb.c b/src/civetweb.c index 54a1439e..fd5cd0f5 100644 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -6756,16 +6756,19 @@ handle_static_file_request(struct mg_connection *conn, static void -handle_not_modified_static_file_request(struct mg_connection *conn) +handle_not_modified_static_file_request(struct mg_connection *conn, + struct file *filep) { - char date[64]; + char date[64], lm[64], etag[64]; time_t curtime = time(NULL); - if (conn == NULL) { + if (conn == NULL || filep == NULL) { return; } conn->status_code = 304; gmt_time_string(date, sizeof(date), &curtime); + gmt_time_string(lm, sizeof(lm), &filep->last_modified); + construct_etag(etag, sizeof(etag), filep); (void)mg_printf(conn, "HTTP/1.1 %d %s\r\n" @@ -6775,9 +6778,12 @@ handle_not_modified_static_file_request(struct mg_connection *conn) date); send_static_cache_header(conn); (void)mg_printf(conn, - "Content-Length: 0\r\n" + "Last-Modified: %s\r\n" + "Etag: %s\r\n" "Connection: %s\r\n" "\r\n", + lm, + etag, suggest_connection_header(conn)); } @@ -10326,7 +10332,7 @@ handle_file_based_request(struct mg_connection *conn, #if !defined(NO_CACHING) } else if ((!conn->in_error_handler) && is_not_modified(conn, file)) { /* Send 304 "Not Modified" - this must not send any body data */ - handle_not_modified_static_file_request(conn); + handle_not_modified_static_file_request(conn, file); #endif /* !NO_CACHING */ } else { handle_static_file_request(conn, path, file, NULL);