summaryrefslogtreecommitdiffhomepage
path: root/src/http
diff options
context:
space:
mode:
authorVladimir Homutov <vl@nginx.com>2017-04-07 16:28:15 +0300
committerAleksei Bavshin <a.bavshin@f5.com>2026-03-09 11:08:30 -0600
commit7acbe17776a4133a08c7b5f502dc4a8fc40b2aef (patch)
tree1eae0601b2f9e44961e9b84e70fa0c91d132ed08 /src/http
parentc988a6e2c13fc37cfc09d11a492540cd4e44163a (diff)
downloadnginx-7acbe17776a4133a08c7b5f502dc4a8fc40b2aef.tar.gz
nginx-7acbe17776a4133a08c7b5f502dc4a8fc40b2aef.tar.bz2
Sticky: added the "max-age" attribute to cookie.
RFC 6265 defines "Max-Age" cookie attribute in section 5.2.2. If the "expires" option is passed to the "sticky" directive, "max-age" attribute will appear in cookies set by the module with corresponding value in seconds. For the special "max" value of the "expires" option, corresponding "max-age" attribute value will be set to 315360000 seconds (10 years, similar to how its done in headers_filter module for the "Cache-Control" header).
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_upstream_sticky_module.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/http/modules/ngx_http_upstream_sticky_module.c b/src/http/modules/ngx_http_upstream_sticky_module.c
index 1b6f19309..4c768a250 100644
--- a/src/http/modules/ngx_http_upstream_sticky_module.c
+++ b/src/http/modules/ngx_http_upstream_sticky_module.c
@@ -149,7 +149,8 @@ static char *ngx_http_upstream_sticky_learn(ngx_conf_t *cf,
ngx_http_upstream_srv_conf_t *us);
-static u_char expires[] = "; expires=Thu, 31-Dec-37 23:55:55 GMT";
+static u_char expires[] =
+ "; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=315360000";
static u_char httponly[] = "; httponly";
static u_char secure[] = "; secure";
@@ -566,7 +567,7 @@ ngx_http_upstream_sticky_cookie_insert(ngx_peer_connection_t *pc,
}
if (stcf->cookie_expires != (time_t) NGX_CONF_UNSET) {
- len += sizeof(expires) - 1;
+ len += sizeof(expires) - 1 + NGX_TIME_T_LEN;
}
if (stcf->cookie_httponly) {
@@ -594,6 +595,7 @@ ngx_http_upstream_sticky_cookie_insert(ngx_peer_connection_t *pc,
} else {
p = ngx_cpymem(p, "; expires=", 10);
p = ngx_http_cookie_time(p, ngx_time() + stcf->cookie_expires);
+ p = ngx_sprintf(p, "; max-age=%T", stcf->cookie_expires);
}
}
@@ -610,7 +612,7 @@ ngx_http_upstream_sticky_cookie_insert(ngx_peer_connection_t *pc,
p = ngx_copy(p, secure, sizeof(secure) - 1);
}
- ngx_memcpy(p, stcf->cookie_path.data, stcf->cookie_path.len);
+ p = ngx_cpymem(p, stcf->cookie_path.data, stcf->cookie_path.len);
cookie = stp->cookie;
@@ -628,7 +630,7 @@ ngx_http_upstream_sticky_cookie_insert(ngx_peer_connection_t *pc,
stp->cookie = cookie;
}
- cookie->value.len = len;
+ cookie->value.len = p - data;
cookie->value.data = data;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,