1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-09 03:22:45 +03:00

More compliant 304 response

This commit is contained in:
xtne6f
2016-06-05 08:03:27 +09:00
committed by bel
parent bf9ceb86f8
commit f3449a8af5

View File

@@ -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);