March 13, 2020 11:32AM
# HG changeset patch
# User agile6v <liuwei19@xiaomi.com>
# Date 1584110606 -28800
# Fri Mar 13 22:43:26 2020 +0800
# Node ID e4a0277cab79865fde6fefeed9374154449e6948
# Parent 4eb606b4a5b521603c23223cf8863f3999df743c
mirror directive supports variable.

diff -r 4eb606b4a5b5 -r e4a0277cab79 src/http/modules/ngx_http_mirror_module.c
--- a/src/http/modules/ngx_http_mirror_module.c Tue Mar 03 18:04:21 2020 +0300
+++ b/src/http/modules/ngx_http_mirror_module.c Fri Mar 13 22:43:26 2020 +0800
@@ -149,17 +149,28 @@
static ngx_int_t
ngx_http_mirror_handler_internal(ngx_http_request_t *r)
{
- ngx_str_t *name;
+ ngx_str_t val;
ngx_uint_t i;
ngx_http_request_t *sr;
ngx_http_mirror_loc_conf_t *mlcf;
+ ngx_http_complex_value_t *pcv;

mlcf = ngx_http_get_module_loc_conf(r, ngx_http_mirror_module);

- name = mlcf->mirror->elts;
+ pcv = mlcf->mirror->elts;

for (i = 0; i < mlcf->mirror->nelts; i++) {
- if (ngx_http_subrequest(r, &name[i], &r->args, &sr, NULL,
+ if (ngx_http_complex_value(r, &pcv[i], &val) != NGX_OK) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ if (val.len == 0
+ || (val.len == 3 && ngx_strncmp(val.data, "off", 3) == 0))
+ {
+ continue;
+ }
+
+ if (ngx_http_subrequest(r, &val, &r->args, &sr, NULL,
NGX_HTTP_SUBREQUEST_BACKGROUND)
!= NGX_OK)
{
@@ -208,9 +219,10 @@
static char *
ngx_http_mirror(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
- ngx_http_mirror_loc_conf_t *mlcf = conf;
-
- ngx_str_t *value, *s;
+ ngx_http_mirror_loc_conf_t *mlcf = conf;
+ ngx_http_complex_value_t *pcv, cv;
+ ngx_http_compile_complex_value_t ccv;
+ ngx_str_t *value;

value = cf->args->elts;

@@ -227,19 +239,30 @@
return "is duplicate";
}

+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
+
+ ccv.cf = cf;
+ ccv.value = &value[1];
+ ccv.complex_value = &cv;
+
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
+
if (mlcf->mirror == NGX_CONF_UNSET_PTR) {
- mlcf->mirror = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
+ mlcf->mirror = ngx_array_create(cf->pool, 4,
+ sizeof(ngx_http_complex_value_t));
if (mlcf->mirror == NULL) {
return NGX_CONF_ERROR;
}
}

- s = ngx_array_push(mlcf->mirror);
- if (s == NULL) {
+ pcv = ngx_array_push(mlcf->mirror);
+ if (pcv == NULL) {
return NGX_CONF_ERROR;
}

- *s = value[1];
+ *pcv = cv;

return NGX_CONF_OK;
}_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Mirror directive supports variable Attachments

agile6v 466 March 13, 2020 11:32AM

Re: [PATCH] Mirror directive supports variable

Roman Arutyunyan 146 March 30, 2020 08:38AM

Re: [PATCH] Mirror directive supports variable

Roman Arutyunyan 132 March 31, 2020 02:04AM

Re: [PATCH] Mirror directive supports variable

agile6v 203 April 01, 2020 07:58PM

Re: [PATCH] Mirror directive supports variable

Maxim Dounin 162 April 03, 2020 07:24AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 169
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready