|
|
7f6d46 |
diff --git a/docs/manual/mod/mod_session.html.en b/docs/manual/mod/mod_session.html.en
|
|
|
7f6d46 |
index 96a61e6..4ecc97d 100644
|
|
|
7f6d46 |
--- a/docs/manual/mod/mod_session.html.en
|
|
|
7f6d46 |
+++ b/docs/manual/mod/mod_session.html.en
|
|
|
7f6d46 |
@@ -69,6 +69,7 @@
|
|
|
7f6d46 |
SessionHeader
|
|
|
7f6d46 |
SessionInclude
|
|
|
7f6d46 |
SessionMaxAge
|
|
|
7f6d46 |
+ SessionExpiryUpdateInterval
|
|
|
7f6d46 |
|
|
|
7f6d46 |
Topics
|
|
|
7f6d46 |
|
|
|
7f6d46 |
@@ -494,6 +495,37 @@ AuthName realm
|
|
|
7f6d46 |
|
|
|
7f6d46 |
Setting the maxage to zero disables session expiry.
|
|
|
7f6d46 |
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+Description:Define the number of seconds a session's expiry may change without the session being updated
|
|
|
7f6d46 |
+Syntax:SessionExpiryUpdateInterval interval
|
|
|
7f6d46 |
+Default:SessionExpiryUpdateInterval 0 (always update)
|
|
|
7f6d46 |
+Context:server config, virtual host, directory, .htaccess
|
|
|
7f6d46 |
+Module:mod_session
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+ The SessionExpiryUpdateInterval directive allows
|
|
|
7f6d46 |
+ sessions to avoid the cost associated with writing the session each request
|
|
|
7f6d46 |
+ when only the expiry time has changed. This can be used to make a website
|
|
|
7f6d46 |
+ more efficient or reduce load on a database when using
|
|
|
7f6d46 |
+ <module>mod_session_dbd</module>. The session is always written if the data
|
|
|
7f6d46 |
+ stored in the session has changed or the expiry has changed by more than the
|
|
|
7f6d46 |
+ configured interval.
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+ Setting the interval to zero disables this directive, and the session
|
|
|
7f6d46 |
+ expiry is refreshed for each request.
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+ This directive only has an effect when combined with SessionMaxAge to enable session
|
|
|
7f6d46 |
+ expiry. Sessions without an expiry are only written when the data stored in
|
|
|
7f6d46 |
+ the session has changed.
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+ Warning
|
|
|
7f6d46 |
+ Because the session expiry may not be refreshed with each request, it's
|
|
|
7f6d46 |
+ possible for sessions to expire up to interval seconds early.
|
|
|
7f6d46 |
+ Using a small interval usually provides sufficient savings while having a
|
|
|
7f6d46 |
+ minimal effect on expiry resolution.
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
|
|
|
7f6d46 |
|
|
|
7f6d46 |
|
|
|
7f6d46 |
diff --git a/modules/session/mod_session.c b/modules/session/mod_session.c
|
|
|
7f6d46 |
index 3e73c7a..83bf3fc 100644
|
|
|
7f6d46 |
--- a/modules/session/mod_session.c
|
|
|
7f6d46 |
+++ b/modules/session/mod_session.c
|
|
|
7f6d46 |
@@ -177,6 +177,7 @@ static apr_status_t ap_session_save(request_rec * r, session_rec * z)
|
|
|
7f6d46 |
{
|
|
|
7f6d46 |
if (z) {
|
|
|
7f6d46 |
apr_time_t now = apr_time_now();
|
|
|
7f6d46 |
+ apr_time_t initialExpiry = z->expiry;
|
|
|
7f6d46 |
int rv = 0;
|
|
|
7f6d46 |
|
|
|
7f6d46 |
session_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
|
|
|
7f6d46 |
@@ -202,6 +203,17 @@ static apr_status_t ap_session_save(request_rec * r, session_rec * z)
|
|
|
7f6d46 |
z->maxage = dconf->maxage;
|
|
|
7f6d46 |
}
|
|
|
7f6d46 |
|
|
|
7f6d46 |
+ /* don't save if the only change is the expiry by a small amount */
|
|
|
7f6d46 |
+ if (!z->dirty && dconf->expiry_update_time
|
|
|
7f6d46 |
+ && (z->expiry - initialExpiry < dconf->expiry_update_time)) {
|
|
|
7f6d46 |
+ return APR_SUCCESS;
|
|
|
7f6d46 |
+ }
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+ /* also don't save sessions that didn't change at all */
|
|
|
7f6d46 |
+ if (!z->dirty && !z->maxage) {
|
|
|
7f6d46 |
+ return APR_SUCCESS;
|
|
|
7f6d46 |
+ }
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
/* encode the session */
|
|
|
7f6d46 |
rv = ap_run_session_encode(r, z);
|
|
|
7f6d46 |
if (OK != rv) {
|
|
|
7f6d46 |
@@ -544,6 +556,10 @@ static void *merge_session_dir_config(apr_pool_t * p, void *basev, void *addv)
|
|
|
7f6d46 |
new->env_set = add->env_set || base->env_set;
|
|
|
7f6d46 |
new->includes = apr_array_append(p, base->includes, add->includes);
|
|
|
7f6d46 |
new->excludes = apr_array_append(p, base->excludes, add->excludes);
|
|
|
7f6d46 |
+ new->expiry_update_time = (add->expiry_update_set == 0)
|
|
|
7f6d46 |
+ ? base->expiry_update_time
|
|
|
7f6d46 |
+ : add->expiry_update_time;
|
|
|
7f6d46 |
+ new->expiry_update_set = add->expiry_update_set || base->expiry_update_set;
|
|
|
7f6d46 |
|
|
|
7f6d46 |
return new;
|
|
|
7f6d46 |
}
|
|
|
7f6d46 |
@@ -613,6 +629,21 @@ static const char *add_session_exclude(cmd_parms * cmd, void *dconf, const char
|
|
|
7f6d46 |
return NULL;
|
|
|
7f6d46 |
}
|
|
|
7f6d46 |
|
|
|
7f6d46 |
+static const char *
|
|
|
7f6d46 |
+ set_session_expiry_update(cmd_parms * parms, void *dconf, const char *arg)
|
|
|
7f6d46 |
+{
|
|
|
7f6d46 |
+ session_dir_conf *conf = dconf;
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+ conf->expiry_update_time = atoi(arg);
|
|
|
7f6d46 |
+ if (conf->expiry_update_time < 0) {
|
|
|
7f6d46 |
+ return "SessionExpiryUpdateInterval must be positive or nul";
|
|
|
7f6d46 |
+ }
|
|
|
7f6d46 |
+ conf->expiry_update_time = apr_time_from_sec(conf->expiry_update_time);
|
|
|
7f6d46 |
+ conf->expiry_update_set = 1;
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
+ return NULL;
|
|
|
7f6d46 |
+}
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
|
|
|
7f6d46 |
static const command_rec session_cmds[] =
|
|
|
7f6d46 |
{
|
|
|
7f6d46 |
@@ -628,6 +659,9 @@ static const command_rec session_cmds[] =
|
|
|
7f6d46 |
"URL prefixes to include in the session. Defaults to all URLs"),
|
|
|
7f6d46 |
AP_INIT_TAKE1("SessionExclude", add_session_exclude, NULL, RSRC_CONF|OR_AUTHCFG,
|
|
|
7f6d46 |
"URL prefixes to exclude from the session. Defaults to no URLs"),
|
|
|
7f6d46 |
+ AP_INIT_TAKE1("SessionExpiryUpdateInterval", set_session_expiry_update, NULL, RSRC_CONF|OR_AUTHCFG,
|
|
|
7f6d46 |
+ "time interval for which a session's expiry time may change "
|
|
|
7f6d46 |
+ "without having to be rewritten. Zero to disable"),
|
|
|
7f6d46 |
{NULL}
|
|
|
7f6d46 |
};
|
|
|
7f6d46 |
|
|
|
7f6d46 |
diff --git a/modules/session/mod_session.h b/modules/session/mod_session.h
|
|
|
7f6d46 |
index a6dd5e9..bdeb532 100644
|
|
|
7f6d46 |
--- a/modules/session/mod_session.h
|
|
|
7f6d46 |
+++ b/modules/session/mod_session.h
|
|
|
7f6d46 |
@@ -115,6 +115,9 @@ typedef struct {
|
|
|
7f6d46 |
* URLs included if empty */
|
|
|
7f6d46 |
apr_array_header_t *excludes; /* URL prefixes to be excluded. No
|
|
|
7f6d46 |
* URLs excluded if empty */
|
|
|
7f6d46 |
+ apr_time_t expiry_update_time; /* seconds the session expiry may change and
|
|
|
7f6d46 |
+ * not have to be rewritten */
|
|
|
7f6d46 |
+ int expiry_update_set;
|
|
|
7f6d46 |
} session_dir_conf;
|
|
|
7f6d46 |
|
|
|
7f6d46 |
/**
|
|
|
7f6d46 |
diff --git a/modules/session/mod_session_cookie.c b/modules/session/mod_session_cookie.c
|
|
|
7f6d46 |
index 6a02322..4aa75e4 100644
|
|
|
7f6d46 |
--- a/modules/session/mod_session_cookie.c
|
|
|
7f6d46 |
+++ b/modules/session/mod_session_cookie.c
|
|
|
7f6d46 |
@@ -60,9 +60,6 @@ static apr_status_t session_cookie_save(request_rec * r, session_rec * z)
|
|
|
7f6d46 |
session_cookie_dir_conf *conf = ap_get_module_config(r->per_dir_config,
|
|
|
7f6d46 |
&session_cookie_module);
|
|
|
7f6d46 |
|
|
|
7f6d46 |
- /* don't cache auth protected pages */
|
|
|
7f6d46 |
- apr_table_addn(r->headers_out, "Cache-Control", "no-cache");
|
|
|
7f6d46 |
-
|
|
|
7f6d46 |
/* create RFC2109 compliant cookie */
|
|
|
7f6d46 |
if (conf->name_set) {
|
|
|
7f6d46 |
if (z->encoded && z->encoded[0]) {
|
|
|
7f6d46 |
@@ -162,6 +159,9 @@ static apr_status_t session_cookie_load(request_rec * r, session_rec ** z)
|
|
|
7f6d46 |
/* put the session in the notes so we don't have to parse it again */
|
|
|
7f6d46 |
apr_table_setn(m->notes, note, (char *)zz);
|
|
|
7f6d46 |
|
|
|
7f6d46 |
+ /* don't cache auth protected pages */
|
|
|
7f6d46 |
+ apr_table_addn(r->headers_out, "Cache-Control", "no-cache, private");
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
return OK;
|
|
|
7f6d46 |
|
|
|
7f6d46 |
}
|
|
|
7f6d46 |
diff --git a/modules/session/mod_session_dbd.c b/modules/session/mod_session_dbd.c
|
|
|
7f6d46 |
index cf65e5a..20ef72e 100644
|
|
|
7f6d46 |
--- a/modules/session/mod_session_dbd.c
|
|
|
7f6d46 |
+++ b/modules/session/mod_session_dbd.c
|
|
|
7f6d46 |
@@ -243,6 +243,9 @@ static apr_status_t session_dbd_load(request_rec * r, session_rec ** z)
|
|
|
7f6d46 |
/* put the session in the notes so we don't have to parse it again */
|
|
|
7f6d46 |
apr_table_setn(m->notes, note, (char *)zz);
|
|
|
7f6d46 |
|
|
|
7f6d46 |
+ /* don't cache pages with a session */
|
|
|
7f6d46 |
+ apr_table_addn(r->headers_out, "Cache-Control", "no-cache, private");
|
|
|
7f6d46 |
+
|
|
|
7f6d46 |
return OK;
|
|
|
7f6d46 |
|
|
|
7f6d46 |
}
|
|
|
7f6d46 |
@@ -407,9 +410,6 @@ static apr_status_t session_dbd_save(request_rec * r, session_rec * z)
|
|
|
7f6d46 |
if (conf->name_set || conf->name2_set) {
|
|
|
7f6d46 |
char *oldkey = NULL, *newkey = NULL;
|
|
|
7f6d46 |
|
|
|
7f6d46 |
- /* don't cache pages with a session */
|
|
|
7f6d46 |
- apr_table_addn(r->headers_out, "Cache-Control", "no-cache");
|
|
|
7f6d46 |
-
|
|
|
7f6d46 |
/* if the session is new or changed, make a new session ID */
|
|
|
7f6d46 |
if (z->uuid) {
|
|
|
7f6d46 |
oldkey = apr_pcalloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1);
|
|
|
7f6d46 |
@@ -456,7 +456,7 @@ static apr_status_t session_dbd_save(request_rec * r, session_rec * z)
|
|
|
7f6d46 |
else if (conf->peruser) {
|
|
|
7f6d46 |
|
|
|
7f6d46 |
/* don't cache pages with a session */
|
|
|
7f6d46 |
- apr_table_addn(r->headers_out, "Cache-Control", "no-cache");
|
|
|
7f6d46 |
+ apr_table_addn(r->headers_out, "Cache-Control", "no-cache, private");
|
|
|
7f6d46 |
|
|
|
7f6d46 |
if (r->user) {
|
|
|
7f6d46 |
ret = dbd_save(r, r->user, r->user, z->encoded, z->expiry);
|