mirror of
https://github.com/lammertb/libhttp.git
synced 2025-12-22 04:02:04 +03:00
Configuration for Cache-Control: max-age
Experimental configuration option "_experimental_static_file_max_age" for tests. TODO: rename this option and documetent it in UserManual.md This also addresses the "Caching" issue of #201
This commit is contained in:
@@ -1097,8 +1097,9 @@ enum {
|
|||||||
#endif
|
#endif
|
||||||
ACCESS_CONTROL_ALLOW_ORIGIN,
|
ACCESS_CONTROL_ALLOW_ORIGIN,
|
||||||
ERROR_PAGES,
|
ERROR_PAGES,
|
||||||
CONFIG_TCP_NODELAY, /* Prepended CONFIG_ to avoid conflict with the socket
|
CONFIG_TCP_NODELAY, /* Prepended CONFIG_ to avoid conflict with the
|
||||||
option typedef TCP_NODELAY */
|
* socket option typedef TCP_NODELAY. */
|
||||||
|
STATIC_FILE_MAX_AGE,
|
||||||
|
|
||||||
NUM_OPTIONS
|
NUM_OPTIONS
|
||||||
};
|
};
|
||||||
@@ -1169,6 +1170,9 @@ static struct mg_option config_options[] = {
|
|||||||
{"access_control_allow_origin", CONFIG_TYPE_STRING, "*"},
|
{"access_control_allow_origin", CONFIG_TYPE_STRING, "*"},
|
||||||
{"error_pages", CONFIG_TYPE_DIRECTORY, NULL},
|
{"error_pages", CONFIG_TYPE_DIRECTORY, NULL},
|
||||||
{"tcp_nodelay", CONFIG_TYPE_NUMBER, "0"},
|
{"tcp_nodelay", CONFIG_TYPE_NUMBER, "0"},
|
||||||
|
{"_experimental_static_file_max_age",
|
||||||
|
CONFIG_TYPE_NUMBER,
|
||||||
|
"3600"}, /* TODO: redefine parameter */
|
||||||
|
|
||||||
{NULL, CONFIG_TYPE_UNKNOWN, NULL}};
|
{NULL, CONFIG_TYPE_UNKNOWN, NULL}};
|
||||||
|
|
||||||
@@ -2172,13 +2176,13 @@ send_no_cache_header(struct mg_connection *conn)
|
|||||||
static int
|
static int
|
||||||
send_static_cache_header(struct mg_connection *conn)
|
send_static_cache_header(struct mg_connection *conn)
|
||||||
{
|
{
|
||||||
/* TODO: Get max age (in seconds) for static files from conn->ctx */
|
int max_age = atoi(conn->ctx->config[STATIC_FILE_MAX_AGE]);
|
||||||
int max_age = 60 /* + conn->ctx.TODO */;
|
|
||||||
|
|
||||||
if (max_age <= 0) {
|
if (max_age <= 0) {
|
||||||
return send_no_cache_header(conn);
|
return send_no_cache_header(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use "Cache-Control: max-age" instead of "Expires" header.
|
||||||
|
* Reason: see https://www.mnot.net/blog/2007/05/15/expires_max-age */
|
||||||
return mg_printf(conn, "Cache-Control: max-age=%u\r\n", max_age);
|
return mg_printf(conn, "Cache-Control: max-age=%u\r\n", max_age);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user