From 7acbe17776a4133a08c7b5f502dc4a8fc40b2aef Mon Sep 17 00:00:00 2001 From: Vladimir Homutov Date: Fri, 7 Apr 2017 16:28:15 +0300 Subject: 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). --- src/http/modules/ngx_http_upstream_sticky_module.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/http/modules') 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, -- cgit