[PATCH 04 of 12] Upstream: simplified ngx_http_upstream_process_header()
Maxim Dounin
mdounin at mdounin.ru
Fri Aug 8 20:08:59 UTC 2025
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1754683248 -10800
# Fri Aug 08 23:00:48 2025 +0300
# Node ID 367106bfe31eddfa021fab9403fcefdc8243bf72
# Parent 533246d275487cfbc51111e7ee05d0c014dd7d78
Upstream: simplified ngx_http_upstream_process_header().
This restores the simple loop structure which was somewhat screwed up
in 9237:41db21d1ca7c, and also removes some commented out artifacts of
the past.
Note that checking c->read->ready before the first c->recv() is not
required, since ngx_http_upstream_process_header() is an event handler
and it cannot be called multiple times in a loop.
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -2469,25 +2469,11 @@ ngx_http_upstream_process_header(ngx_htt
for ( ;; ) {
- if (c->read->ready) {
- n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);
-
- } else {
- n = NGX_AGAIN;
- }
+ n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);
if (n == NGX_AGAIN) {
-#if 0
- ngx_add_timer(rev, u->read_timeout);
-#endif
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- return;
+ rc = NGX_AGAIN;
+ break;
}
if (n == 0) {
@@ -2501,15 +2487,8 @@ ngx_http_upstream_process_header(ngx_htt
}
u->state->bytes_received += n;
-
u->buffer.last += n;
-#if 0
- u->valid_header_in = 0;
-
- u->peer.cached = 0;
-#endif
-
rc = u->process_header(r);
if (rc == NGX_AGAIN) {
@@ -2523,12 +2502,26 @@ ngx_http_upstream_process_header(ngx_htt
return;
}
+ if (!c->read->ready) {
+ break;
+ }
+
continue;
}
break;
}
+ if (rc == NGX_AGAIN) {
+ if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
+ ngx_http_upstream_finalize_request(r, u,
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ return;
+ }
+
if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
return;
More information about the nginx-devel
mailing list