ngx_array_t *headers_source;
ngx_str_t host;
- ngx_uint_t host_set;
+ ngx_http_complex_value_t *host_value;
ngx_array_t *grpc_lengths;
ngx_array_t *grpc_values;
key_len, val_len, uri_len;
uintptr_t escape;
ngx_buf_t *b;
+ ngx_str_t host;
ngx_uint_t i, next;
ngx_chain_t *cl, *body;
ngx_list_part_t *part;
/* :authority header */
- if (!glcf->host_set) {
- if (ctx->host.len > NGX_HTTP_V2_MAX_FIELD) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "too long http2 host: \"%V\"", &ctx->host);
- return NGX_ERROR;
- }
+ host.len = 0;
- len += 1 + NGX_HTTP_V2_INT_OCTETS + ctx->host.len;
+ if (glcf->host_value
+ && ngx_http_complex_value(r, glcf->host_value, &host) != NGX_OK)
+ {
+ return NGX_ERROR;
+ }
- if (tmp_len < ctx->host.len) {
- tmp_len = ctx->host.len;
- }
+ if (host.len == 0) {
+ host = ctx->host;
+ }
+
+ if (host.len > NGX_HTTP_V2_MAX_FIELD) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "too long http2 host: \"%V\"", &host);
+ return NGX_ERROR;
+ }
+
+ len += 1 + NGX_HTTP_V2_INT_OCTETS + host.len;
+
+ if (tmp_len < host.len) {
+ tmp_len = host.len;
}
/* other headers */
"grpc header: \":path: %V\"", &r->uri);
}
- if (!glcf->host_set) {
- *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_AUTHORITY_INDEX);
- b->last = ngx_http_v2_write_value(b->last, ctx->host.data,
- ctx->host.len, tmp);
+ *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_AUTHORITY_INDEX);
+ b->last = ngx_http_v2_write_value(b->last, host.data, host.len, tmp);
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "grpc header: \":authority: %V\"", &ctx->host);
- }
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "grpc header: \":authority: %V\"", &host);
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
* conf->headers.values = NULL;
* conf->headers.hash = { NULL, 0 };
* conf->host = { 0, NULL };
- * conf->host_set = 0;
+ * conf->host_value = NULL;
* conf->ssl = 0;
* conf->ssl_protocols = 0;
* conf->ssl_ciphers = { 0, NULL };
if (conf->headers_source == prev->headers_source) {
conf->headers = prev->headers;
- conf->host_set = prev->host_set;
+ conf->host_value = prev->host_value;
}
rc = ngx_http_grpc_init_headers(cf, conf, &conf->headers,
&& conf->headers_source == prev->headers_source)
{
prev->headers = conf->headers;
- prev->host_set = conf->host_set;
+ prev->host_value = conf->host_value;
}
return NGX_CONF_OK;
ngx_http_grpc_init_headers(ngx_conf_t *cf, ngx_http_grpc_loc_conf_t *conf,
ngx_http_grpc_headers_t *headers, ngx_keyval_t *default_headers)
{
- u_char *p;
- size_t size;
- uintptr_t *code;
- ngx_uint_t i;
- ngx_array_t headers_names, headers_merged;
- ngx_keyval_t *src, *s, *h;
- ngx_hash_key_t *hk;
- ngx_hash_init_t hash;
- ngx_http_script_compile_t sc;
- ngx_http_script_copy_code_t *copy;
+ u_char *p;
+ size_t size;
+ uintptr_t *code;
+ ngx_uint_t i;
+ ngx_array_t headers_names, headers_merged;
+ ngx_keyval_t *src, *s, *h;
+ ngx_hash_key_t *hk;
+ ngx_hash_init_t hash;
+ ngx_http_script_compile_t sc;
+ ngx_http_script_copy_code_t *copy;
+ ngx_http_compile_complex_value_t ccv;
if (headers->hash.buckets) {
return NGX_OK;
if (src[i].key.len == 4
&& ngx_strncasecmp(src[i].key.data, (u_char *) "Host", 4) == 0)
{
- conf->host_set = 1;
+ conf->host_value = ngx_pcalloc(cf->pool,
+ sizeof(ngx_http_complex_value_t));
+ if (conf->host_value == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
+
+ ccv.cf = cf;
+ ccv.value = &src[i].value;
+ ccv.complex_value = conf->host_value;
+
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
+ continue;
}
s = ngx_array_push(&headers_merged);
static ngx_keyval_t ngx_http_proxy_headers[] = {
- { ngx_string("Host"), ngx_string("$proxy_internal_host") },
+ { ngx_string("Host"), ngx_string("") },
{ ngx_string("Connection"), ngx_string("") },
{ ngx_string("Proxy-Connection"), ngx_string("") },
{ ngx_string("Content-Length"), ngx_string("$proxy_internal_body_length") },
#if (NGX_HTTP_CACHE)
static ngx_keyval_t ngx_http_proxy_cache_headers[] = {
- { ngx_string("Host"), ngx_string("$proxy_internal_host") },
+ { ngx_string("Host"), ngx_string("") },
{ ngx_string("Connection"), ngx_string("") },
{ ngx_string("Proxy-Connection"), ngx_string("") },
{ ngx_string("Content-Length"), ngx_string("$proxy_internal_body_length") },
{ ngx_string("proxy_add_via"), NULL, NULL, 0, NGX_HTTP_VAR_NOHASH, 0 },
#endif
- { ngx_string("proxy_internal_host"), NULL,
- ngx_http_proxy_host_variable, 1,
- NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
-
{ ngx_string("proxy_internal_body_length"), NULL,
ngx_http_proxy_internal_body_length_variable, 0,
NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- ctx->legacy = 1;
-
ngx_http_set_ctx(r, ctx, ngx_http_proxy_module);
u = r->upstream;
key_len, val_len;
uintptr_t escape;
ngx_buf_t *b;
- ngx_str_t method;
+ ngx_str_t method, host;
ngx_uint_t i, unparsed_uri;
ngx_chain_t *cl, *body;
ngx_list_part_t *part;
ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+ host.len = 0;
+
+ if (plcf->host_value
+ && ngx_http_complex_value(r, plcf->host_value, &host) != NGX_OK)
+ {
+ return NGX_ERROR;
+ }
+
+ if (plcf->host_value == NULL
+ || (host.len == 0 && plcf->http_version == NGX_HTTP_VERSION_11))
+ {
+ host = ctx->vars.host_header;
+ }
+
if (method.len == 4
&& ngx_strncasecmp(method.data, (u_char *) "HEAD", 4) == 0)
{
ctx->internal_body_length = r->headers_in.content_length_n;
}
+ if (host.len) {
+ len += sizeof("Host: ") - 1 + host.len + sizeof(CRLF) - 1;
+ }
+
le.ip = headers->lengths->elts;
le.request = r;
le.flushed = 1;
sizeof(ngx_http_proxy_version) - 1);
}
+ if (host.len) {
+ b->last = ngx_cpymem(b->last, "Host: ", sizeof("Host: ") - 1);
+ b->last = ngx_cpymem(b->last, host.data, host.len);
+ *b->last++ = CR; *b->last++ = LF;
+ }
+
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
e.ip = headers->values->elts;
return NGX_OK;
}
- if (data == 1 && !ctx->legacy) {
- v->not_found = 1;
- return NGX_OK;
- }
-
v->len = ctx->vars.host_header.len;
v->valid = 1;
v->no_cacheable = 0;
* conf->headers.values = NULL;
* conf->headers.hash = { NULL, 0 };
* conf->headers_cache.lengths = NULL;
- * conf->host_set = 0;
+ * conf->host_value = NULL;
* conf->headers_cache.values = NULL;
* conf->headers_cache.hash = { NULL, 0 };
* conf->body_lengths = NULL;
#if (NGX_HTTP_CACHE)
conf->headers_cache = prev->headers_cache;
#endif
- conf->host_set = prev->host_set;
+ conf->host_value = prev->host_value;
}
rc = ngx_http_proxy_init_headers(cf, conf, &conf->headers,
#if (NGX_HTTP_CACHE)
prev->headers_cache = conf->headers_cache;
#endif
- prev->host_set = conf->host_set;
+ prev->host_value = conf->host_value;
}
return NGX_CONF_OK;
ngx_http_proxy_init_headers(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *conf,
ngx_http_proxy_headers_t *headers, ngx_keyval_t *default_headers)
{
- u_char *p;
- size_t size;
- uintptr_t *code;
- ngx_uint_t i;
- ngx_array_t headers_names, headers_merged;
- ngx_keyval_t *src, *s, *h;
- ngx_hash_key_t *hk;
- ngx_hash_init_t hash;
- ngx_http_script_compile_t sc;
- ngx_http_script_copy_code_t *copy;
+ u_char *p;
+ size_t size;
+ uintptr_t *code;
+ ngx_uint_t i;
+ ngx_array_t headers_names, headers_merged;
+ ngx_keyval_t *src, *s, *h;
+ ngx_hash_key_t *hk;
+ ngx_hash_init_t hash;
+ ngx_http_script_compile_t sc;
+ ngx_http_script_copy_code_t *copy;
+ ngx_http_compile_complex_value_t ccv;
if (headers->hash.buckets) {
return NGX_OK;
if (src[i].key.len == 4
&& ngx_strncasecmp(src[i].key.data, (u_char *) "Host", 4) == 0)
{
- conf->host_set = 1;
+ conf->host_value = ngx_pcalloc(cf->pool,
+ sizeof(ngx_http_complex_value_t));
+ if (conf->host_value == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
+
+ ccv.cf = cf;
+ ccv.value = &src[i].value;
+ ccv.complex_value = conf->host_value;
+
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
+ continue;
}
s = ngx_array_push(&headers_merged);
ngx_http_proxy_headers_t headers_cache;
#endif
ngx_array_t *headers_source;
- ngx_uint_t host_set;
+ ngx_http_complex_value_t *host_value;
ngx_array_t *proxy_lengths;
ngx_array_t *proxy_values;
unsigned head:1;
unsigned internal_chunked:1;
unsigned header_sent:1;
- unsigned legacy:1;
} ngx_http_proxy_ctx_t;
loc_len, body_len;
uintptr_t escape;
ngx_buf_t *b;
- ngx_str_t method, *host;
+ ngx_str_t method, host;
ngx_uint_t i, next, unparsed_uri;
ngx_chain_t *cl, *body;
ngx_list_part_t *part;
/* :authority header */
- host = &ctx->ctx.vars.host_header;
+ host.len = 0;
- if (!plcf->host_set) {
- if (host->len > NGX_HTTP_V2_MAX_FIELD) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "too long http2 host: \"%V\"", host);
- return NGX_ERROR;
- }
+ if (plcf->host_value
+ && ngx_http_complex_value(r, plcf->host_value, &host) != NGX_OK)
+ {
+ return NGX_ERROR;
+ }
- len += 1 + NGX_HTTP_V2_INT_OCTETS + host->len;
+ if (host.len == 0) {
+ host = ctx->ctx.vars.host_header;
+ }
- if (tmp_len < host->len) {
- tmp_len = host->len;
- }
+ if (host.len > NGX_HTTP_V2_MAX_FIELD) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "too long http2 host: \"%V\"", &host);
+ return NGX_ERROR;
+ }
+
+ len += 1 + NGX_HTTP_V2_INT_OCTETS + host.len;
+
+ if (tmp_len < host.len) {
+ tmp_len = host.len;
}
/* other headers */
val_tmp);
}
- if (!plcf->host_set) {
- *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_AUTHORITY_INDEX);
- b->last = ngx_http_v2_write_value(b->last, host->data, host->len, tmp);
+ *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_AUTHORITY_INDEX);
+ b->last = ngx_http_v2_write_value(b->last, host.data, host.len, tmp);
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http proxy header: \":authority: %V\"", host);
- }
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "http proxy header: \":authority: %V\"", &host);
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));