No functional changes. This will be used by the following patches.
src/http/ngx_http_upstream.c | 133 +++++++++++++++++++++++------------------- 1 files changed, 74 insertions(+), 59 deletions(-)
# HG changeset patch # User Vladimir Khomutov <v...@wbsrv.ru> # Date 1703082747 -10800 # Wed Dec 20 17:32:27 2023 +0300 # Node ID f8275ecea4a7b18ae128f4e622ec50aa139cc6e1 # Parent e1c4b57622ea1d8b65db495e88f3cd7c0c5f95ea Upstream: refactored upstream initialization. No functional changes. This will be used by the following patches. 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 @@ -1,5 +1,6 @@ /* + * Copyright (C) 2023 Web Server LLC * Copyright (C) Igor Sysoev * Copyright (C) Nginx, Inc. */ @@ -37,6 +38,8 @@ static void ngx_http_upstream_check_brok ngx_event_t *ev); static void ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u); +static ngx_int_t ngx_http_upstream_configure(ngx_http_request_t *r, + ngx_http_upstream_t *u, ngx_connection_t *c); static ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u); static void ngx_http_upstream_send_request(ngx_http_request_t *r, @@ -1527,9 +1530,8 @@ ngx_http_upstream_check_broken_connectio static void ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) { - ngx_int_t rc; - ngx_connection_t *c; - ngx_http_core_loc_conf_t *clcf; + ngx_int_t rc; + ngx_connection_t *c; r->connection->log->action = "connecting to upstream"; @@ -1587,16 +1589,6 @@ ngx_http_upstream_connect(ngx_http_reque c->write->handler = ngx_http_upstream_handler; c->read->handler = ngx_http_upstream_handler; - u->write_event_handler = ngx_http_upstream_send_request_handler; - u->read_event_handler = ngx_http_upstream_process_header; - - c->sendfile &= r->connection->sendfile; - u->output.sendfile = c->sendfile; - - if (r->connection->tcp_nopush == NGX_TCP_NOPUSH_DISABLED) { - c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; - } - if (c->pool == NULL) { /* we need separate pool here to be able to cache SSL connections */ @@ -1614,52 +1606,17 @@ ngx_http_upstream_connect(ngx_http_reque c->read->log = c->log; c->write->log = c->log; - /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ - - clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - - u->writer.out = NULL; - u->writer.last = &u->writer.out; - u->writer.connection = c; - u->writer.limit = clcf->sendfile_max_chunk; - - if (u->request_sent) { - if (ngx_http_upstream_reinit(r, u) != NGX_OK) { - ngx_http_upstream_finalize_request(r, u, - NGX_HTTP_INTERNAL_SERVER_ERROR); - return; - } - } - - if (r->request_body - && r->request_body->buf - && r->request_body->temp_file - && r == r->main) - { - /* - * the r->request_body->buf can be reused for one request only, - * the subrequests should allocate their own temporary bufs - */ - - u->output.free = ngx_alloc_chain_link(r->pool); - if (u->output.free == NULL) { - ngx_http_upstream_finalize_request(r, u, - NGX_HTTP_INTERNAL_SERVER_ERROR); - return; - } - - u->output.free->buf = r->request_body->buf; - u->output.free->next = NULL; - u->output.allocated = 1; - - r->request_body->buf->pos = r->request_body->buf->start; - r->request_body->buf->last = r->request_body->buf->start; - r->request_body->buf->tag = u->output.tag; - } - - u->request_sent = 0; - u->request_body_sent = 0; - u->request_body_blocked = 0; + c->sendfile &= r->connection->sendfile; + + if (r->connection->tcp_nopush == NGX_TCP_NOPUSH_DISABLED) { + c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; + } + + if (ngx_http_upstream_configure(r, u, c) != NGX_OK) { + ngx_http_upstream_finalize_request(r, u, + NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } if (rc == NGX_AGAIN) { ngx_add_timer(c->write, u->conf->connect_timeout); @@ -1679,6 +1636,64 @@ ngx_http_upstream_connect(ngx_http_reque } +static ngx_int_t +ngx_http_upstream_configure(ngx_http_request_t *r, ngx_http_upstream_t *u, + ngx_connection_t *c) +{ + ngx_http_core_loc_conf_t *clcf; + + u->write_event_handler = ngx_http_upstream_send_request_handler; + u->read_event_handler = ngx_http_upstream_process_header; + + u->output.sendfile = c->sendfile; + + /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ + + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + + u->writer.out = NULL; + u->writer.last = &u->writer.out; + u->writer.connection = c; + u->writer.limit = clcf->sendfile_max_chunk; + + if (u->request_sent) { + if (ngx_http_upstream_reinit(r, u) != NGX_OK) { + return NGX_ERROR; + } + } + + if (r->request_body + && r->request_body->buf + && r->request_body->temp_file + && r == r->main) + { + /* + * the r->request_body->buf can be reused for one request only, + * the subrequests should allocate their own temporary bufs + */ + + u->output.free = ngx_alloc_chain_link(r->pool); + if (u->output.free == NULL) { + return NGX_ERROR; + } + + u->output.free->buf = r->request_body->buf; + u->output.free->next = NULL; + u->output.allocated = 1; + + r->request_body->buf->pos = r->request_body->buf->start; + r->request_body->buf->last = r->request_body->buf->start; + r->request_body->buf->tag = u->output.tag; + } + + u->request_sent = 0; + u->request_body_sent = 0; + u->request_body_blocked = 0; + + return NGX_OK; +} + + #if (NGX_HTTP_SSL) static void
_______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel