[nginx-site] Documented Age header handling.

2024-07-31 Thread Maxim Dounin
details:   http://freenginx.org/hg/nginx-site/rev/ca4c8ac67c0e
branches:  
changeset: 3092:ca4c8ac67c0e
user:  Maxim Dounin 
date:  Wed Jul 31 18:33:11 2024 +0300
description:
Documented Age header handling.

diffstat:

 xml/en/docs/http/ngx_http_fastcgi_module.xml  |  12 +---
 xml/en/docs/http/ngx_http_proxy_module.xml|  12 +---
 xml/en/docs/http/ngx_http_scgi_module.xml |  12 +---
 xml/en/docs/http/ngx_http_upstream_module.xml |   8 +++-
 xml/en/docs/http/ngx_http_uwsgi_module.xml|  12 +---
 xml/ru/docs/http/ngx_http_fastcgi_module.xml  |  16 +++-
 xml/ru/docs/http/ngx_http_proxy_module.xml|  16 +++-
 xml/ru/docs/http/ngx_http_scgi_module.xml |  16 +++-
 xml/ru/docs/http/ngx_http_upstream_module.xml |   8 +++-
 xml/ru/docs/http/ngx_http_uwsgi_module.xml|  16 +++-
 10 files changed, 94 insertions(+), 34 deletions(-)

diffs (410 lines):

diff --git a/xml/en/docs/http/ngx_http_fastcgi_module.xml 
b/xml/en/docs/http/ngx_http_fastcgi_module.xml
--- a/xml/en/docs/http/ngx_http_fastcgi_module.xml
+++ b/xml/en/docs/http/ngx_http_fastcgi_module.xml
@@ -10,7 +10,7 @@
 
+rev="55">
 
 
 
@@ -649,6 +649,12 @@ with another value, such a response will
 taking into account the corresponding request header fields (1.7.7).
 
 
+
+If the header includes the Age field
+and caching time is set with the Cache-Control field,
+caching time is reduced accordingly (1.27.3).
+
+
 
 Processing of one or more of these response header fields can be disabled
 using the  directive.
@@ -766,7 +772,7 @@ The following fields can be ignored: X-Accel-Buffering (1.1.6),
 X-Accel-Charset (1.1.6), Expires,
 Cache-Control, Set-Cookie (0.8.44),
-and Vary (1.7.7).
+Vary (1.7.7), and Age (1.27.3).
 
 
 
@@ -777,7 +783,7 @@ effect:
 
 X-Accel-Expires, Expires,
 Cache-Control, Set-Cookie,
-and Vary
+Vary, and Age
 set the parameters of response caching;
 
 
diff --git a/xml/en/docs/http/ngx_http_proxy_module.xml 
b/xml/en/docs/http/ngx_http_proxy_module.xml
--- a/xml/en/docs/http/ngx_http_proxy_module.xml
+++ b/xml/en/docs/http/ngx_http_proxy_module.xml
@@ -10,7 +10,7 @@
 
+rev="78">
 
 
 
@@ -667,6 +667,12 @@ with another value, such a response will
 taking into account the corresponding request header fields (1.7.7).
 
 
+
+If the header includes the Age field
+and caching time is set with the Cache-Control field,
+caching time is reduced accordingly (1.27.3).
+
+
 
 Processing of one or more of these response header fields can be disabled
 using the  directive.
@@ -1011,7 +1017,7 @@ The following fields can be ignored: X-Accel-Buffering (1.1.6),
 X-Accel-Charset (1.1.6), Expires,
 Cache-Control, Set-Cookie (0.8.44),
-and Vary (1.7.7).
+Vary (1.7.7), and Age (1.27.3).
 
 
 
@@ -1022,7 +1028,7 @@ effect:
 
 X-Accel-Expires, Expires,
 Cache-Control, Set-Cookie,
-and Vary
+Vary, and Age
 set the parameters of response caching;
 
 
diff --git a/xml/en/docs/http/ngx_http_scgi_module.xml 
b/xml/en/docs/http/ngx_http_scgi_module.xml
--- a/xml/en/docs/http/ngx_http_scgi_module.xml
+++ b/xml/en/docs/http/ngx_http_scgi_module.xml
@@ -10,7 +10,7 @@
 
+rev="43">
 
 
 
@@ -640,6 +640,12 @@ with another value, such a response will
 taking into account the corresponding request header fields (1.7.7).
 
 
+
+If the header includes the Age field
+and caching time is set with the Cache-Control field,
+caching time is reduced accordingly (1.27.3).
+
+
 
 Processing of one or more of these response header fields can be disabled
 using the  directive.
@@ -731,7 +737,7 @@ The following fields can be ignored: X-Accel-Buffering (1.1.6),
 X-Accel-Charset (1.1.6), Expires,
 Cache-Control, Set-Cookie (0.8.44),
-and Vary (1.7.7).
+Vary (1.7.7), and Age (1.27.3).
 
 
 
@@ -742,7 +748,7 @@ effect:
 
 X-Accel-Expires, Expires,
 Cache-Control, Set-Cookie,
-and Vary
+Vary, and Age
 set the parameters of response caching;
 
 
diff --git a/xml/en/docs/http/ngx_http_upstream_module.xml 
b/xml/en/docs/http/ngx_http_upstream_module.xml
--- a/xml/en/docs/http/ngx_http_upstream_module.xml
+++ b/xml/en/docs/http/ngx_http_upstream_module.xml
@@ -10,7 +10,7 @@
 
+rev="91">
 
 
 
@@ -574,6 +574,12 @@ are separated by commas and colons like 
 $upstream_addr variable.
 
 
+$upstream_cache_age
+
+
+age of the cache item (1.27.3).
+
+
 $upstream_cache_key
 
 
diff --git a/xml/en/docs/http/ngx_http_uwsgi_module.xml 
b/xml/en/docs/http/ngx_http_uwsgi_module.xml
--- a/xml/en/docs/http/ngx_http_uwsgi_module.xml
+++ b/xml/en/docs/http/ngx_http_uwsgi_module.xml
@@ -10,7 +10,7 @@
 
+rev="52">
 
 
 
@@ -640,6 +640,12 @@ with another value, such a response will
 taking into account the corresponding request header fields (1.7.7).
 
 
+
+If the header includes the Age field
+and caching time is set with the Cache-Control field,
+caching time is reduced accordingly (1.27.3).
+
+
 
 Processing of one or more of these response header fields can be di

[nginx] Keepalive connections now respect lingering_timeout on s...

2024-07-31 Thread Maxim Dounin
details:   http://freenginx.org/hg/nginx/rev/3c71158f5a34
branches:  
changeset: 9307:3c71158f5a34
user:  Maxim Dounin 
date:  Wed Jul 31 17:50:58 2024 +0300
description:
Keepalive connections now respect lingering_timeout on shutdown.

During graceful shutdown keepalive connections are now closed only after
at least lingering_timeout of inactivity.  To do so, c->idle is only
set on keepalive connections after lingering_timeout expires.

This ensures that the connection close race will less likely result in
connections being reset when a client sends a request at the same time
when the connection is closed by ngx_close_idle_connections() during
graceful shutdown.

diffstat:

 src/http/ngx_http_request.c |  40 +---
 src/http/ngx_http_request.h |   2 ++
 2 files changed, 35 insertions(+), 7 deletions(-)

diffs (83 lines):

diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -3099,6 +3099,7 @@ ngx_http_set_keepalive(ngx_http_request_
 {
 inttcp_nodelay;
 ngx_buf_t *b, *f;
+ngx_msec_t timer;
 ngx_chain_t   *cl, *ln;
 ngx_event_t   *rev, *wev;
 ngx_connection_t  *c;
@@ -3299,10 +3300,19 @@ ngx_http_set_keepalive(ngx_http_request_
 r->http_state = NGX_HTTP_KEEPALIVE_STATE;
 #endif
 
-c->idle = 1;
 ngx_reusable_connection(c, 1);
 
-ngx_add_timer(rev, clcf->keepalive_timeout);
+if (clcf->lingering_close
+&& clcf->lingering_timeout > 0)
+{
+timer = ngx_min(clcf->keepalive_timeout, clcf->lingering_timeout);
+hc->keepalive_timeout = clcf->keepalive_timeout - timer;
+ngx_add_timer(rev, timer);
+
+} else {
+c->idle = 1;
+ngx_add_timer(rev, clcf->keepalive_timeout);
+}
 
 if (rev->ready) {
 ngx_post_event(rev, &ngx_posted_events);
@@ -3313,16 +3323,32 @@ ngx_http_set_keepalive(ngx_http_request_
 static void
 ngx_http_keepalive_handler(ngx_event_t *rev)
 {
-size_t size;
-ssize_tn;
-ngx_buf_t *b;
-ngx_connection_t  *c;
+size_t  size;
+ssize_t n;
+ngx_buf_t  *b;
+ngx_connection_t   *c;
+ngx_http_connection_t  *hc;
 
 c = rev->data;
 
 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http keepalive handler");
 
-if (rev->timedout || c->close) {
+if (rev->timedout) {
+if (c->idle || ngx_exiting) {
+ngx_http_close_connection(c);
+return;
+}
+
+hc = c->data;
+
+c->idle = 1;
+rev->timedout = 0;
+ngx_add_timer(rev, hc->keepalive_timeout);
+
+return;
+}
+
+if (c->close) {
 ngx_http_close_connection(c);
 return;
 }
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -332,6 +332,8 @@ typedef struct {
 
 ngx_chain_t  *free;
 
+ngx_msec_tkeepalive_timeout;
+
 unsigned  ssl:1;
 unsigned  proxy_protocol:1;
 } ngx_http_connection_t;