From 50525837bec8c2c291274a3d8ef1a77b43321a71 Mon Sep 17 00:00:00 2001 From: Zhidao HONG Date: Wed, 16 Jul 2025 08:05:01 +0000 Subject: [PATCH] make proxy ctx independent of each other module. (patch for discusstion) --- src/http/modules/ngx_http_proxy_module.c | 26 ++++++++++++++++++++---- src/http/modules/ngx_http_proxy_module.h | 22 ++------------------ src/http/v2/ngx_http_v2_proxy_module.c | 8 ++++---- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index 57ccbc033..675e547fc 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -24,6 +24,24 @@ #define NGX_HTTP_PROXY_COOKIE_SAMESITE_OFF 0x0400 +typedef struct { + ngx_http_status_t status; + ngx_http_chunked_t chunked; + ngx_http_proxy_vars_t vars; + off_t internal_body_length; + + ngx_chain_t *free; + ngx_chain_t *busy; + + ngx_buf_t *trailers; + + unsigned head:1; + unsigned internal_chunked:1; + unsigned header_sent:1; + unsigned connection_type:2; +} ngx_http_proxy_ctx_t; + + static ngx_int_t ngx_http_proxy_create_request(ngx_http_request_t *r); static ngx_int_t ngx_http_proxy_reinit_request(ngx_http_request_t *r); static ngx_int_t ngx_http_proxy_body_output_filter(void *data, ngx_chain_t *in); @@ -872,7 +890,7 @@ ngx_http_proxy_handler(ngx_http_request_t *r) #endif } else { - if (ngx_http_proxy_eval(r, ctx, plcf) != NGX_OK) { + if (ngx_http_proxy_eval(r, &ctx->vars, plcf) != NGX_OK) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } } @@ -938,7 +956,7 @@ ngx_http_proxy_handler(ngx_http_request_t *r) ngx_int_t -ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx, +ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_vars_t *vars, ngx_http_proxy_loc_conf_t *plcf) { u_char *p; @@ -1015,9 +1033,9 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx, } } - ctx->vars.key_start = u->schema; + vars->key_start = u->schema; - ngx_http_proxy_set_vars(&url, &ctx->vars); + ngx_http_proxy_set_vars(&url, vars); u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t)); if (u->resolved == NULL) { diff --git a/src/http/modules/ngx_http_proxy_module.h b/src/http/modules/ngx_http_proxy_module.h index 8bc75334a..b141dace8 100644 --- a/src/http/modules/ngx_http_proxy_module.h +++ b/src/http/modules/ngx_http_proxy_module.h @@ -120,26 +120,8 @@ typedef struct { } ngx_http_proxy_loc_conf_t; -typedef struct { - ngx_http_status_t status; - ngx_http_chunked_t chunked; - ngx_http_proxy_vars_t vars; - off_t internal_body_length; - - ngx_chain_t *free; - ngx_chain_t *busy; - - ngx_buf_t *trailers; - - unsigned head:1; - unsigned internal_chunked:1; - unsigned header_sent:1; - unsigned connection_type:2; -} ngx_http_proxy_ctx_t; - - -ngx_int_t ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx, - ngx_http_proxy_loc_conf_t *plcf); +ngx_int_t ngx_http_proxy_eval(ngx_http_request_t *r, + ngx_http_proxy_vars_t *vars, ngx_http_proxy_loc_conf_t *plcf); #if (NGX_HTTP_CACHE) ngx_int_t ngx_http_proxy_create_key(ngx_http_request_t *r); #endif diff --git a/src/http/v2/ngx_http_v2_proxy_module.c b/src/http/v2/ngx_http_v2_proxy_module.c index 8fdece197..9dab67886 100644 --- a/src/http/v2/ngx_http_v2_proxy_module.c +++ b/src/http/v2/ngx_http_v2_proxy_module.c @@ -35,7 +35,7 @@ typedef struct { typedef struct { - ngx_http_proxy_ctx_t ctx; /* must be first */ + ngx_http_proxy_vars_t vars; ngx_http_v2_proxy_state_e state; ngx_uint_t frame_state; @@ -229,14 +229,14 @@ ngx_http_v2_proxy_handler(ngx_http_request_t *r) u = r->upstream; if (plcf->proxy_lengths == NULL) { - ctx->ctx.vars = plcf->vars; + ctx->vars = plcf->vars; u->schema = plcf->vars.schema; #if (NGX_HTTP_SSL) u->ssl = plcf->ssl; #endif } else { - if (ngx_http_proxy_eval(r, &ctx->ctx, plcf) != NGX_OK) { + if (ngx_http_proxy_eval(r, &ctx->vars, plcf) != NGX_OK) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } } @@ -335,7 +335,7 @@ ngx_http_v2_proxy_create_request(ngx_http_request_t *r) /* :authority header */ - host = &ctx->ctx.vars.host_header; + host = &ctx->vars.host_header; /* TODO authority */ if (1) {