make proxy ctx independent of each other module. (patch for discusstion)

This commit is contained in:
Zhidao HONG 2025-07-16 08:05:01 +00:00
parent 0c3897bb70
commit 50525837be
3 changed files with 28 additions and 28 deletions

View File

@ -24,6 +24,24 @@
#define NGX_HTTP_PROXY_COOKIE_SAMESITE_OFF 0x0400 #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_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_reinit_request(ngx_http_request_t *r);
static ngx_int_t ngx_http_proxy_body_output_filter(void *data, ngx_chain_t *in); 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 #endif
} else { } 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; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
} }
@ -938,7 +956,7 @@ ngx_http_proxy_handler(ngx_http_request_t *r)
ngx_int_t 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) ngx_http_proxy_loc_conf_t *plcf)
{ {
u_char *p; 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)); u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t));
if (u->resolved == NULL) { if (u->resolved == NULL) {

View File

@ -120,26 +120,8 @@ typedef struct {
} ngx_http_proxy_loc_conf_t; } ngx_http_proxy_loc_conf_t;
typedef struct { ngx_int_t ngx_http_proxy_eval(ngx_http_request_t *r,
ngx_http_status_t status; ngx_http_proxy_vars_t *vars, ngx_http_proxy_loc_conf_t *plcf);
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);
#if (NGX_HTTP_CACHE) #if (NGX_HTTP_CACHE)
ngx_int_t ngx_http_proxy_create_key(ngx_http_request_t *r); ngx_int_t ngx_http_proxy_create_key(ngx_http_request_t *r);
#endif #endif

View File

@ -35,7 +35,7 @@ typedef struct {
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_http_v2_proxy_state_e state;
ngx_uint_t frame_state; ngx_uint_t frame_state;
@ -229,14 +229,14 @@ ngx_http_v2_proxy_handler(ngx_http_request_t *r)
u = r->upstream; u = r->upstream;
if (plcf->proxy_lengths == NULL) { if (plcf->proxy_lengths == NULL) {
ctx->ctx.vars = plcf->vars; ctx->vars = plcf->vars;
u->schema = plcf->vars.schema; u->schema = plcf->vars.schema;
#if (NGX_HTTP_SSL) #if (NGX_HTTP_SSL)
u->ssl = plcf->ssl; u->ssl = plcf->ssl;
#endif #endif
} else { } 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; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
} }
@ -335,7 +335,7 @@ ngx_http_v2_proxy_create_request(ngx_http_request_t *r)
/* :authority header */ /* :authority header */
host = &ctx->ctx.vars.host_header; host = &ctx->vars.host_header;
/* TODO authority */ /* TODO authority */
if (1) { if (1) {