Welcome! Log In Create A New Profile

Advanced

Re: [PATCH] Mirror directive supports variable

Roman Arutyunyan
March 30, 2020 08:38AM
Hello,

On Fri, Mar 13, 2020 at 11:29:51PM +0800, 一江春水,向东流 wrote:
> # 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))

There's one issue with this line which introduces inconsistency.
Currently specifying "off" disables inheriting mirrors on a certain level.
Also it cannot be specified together with other mirror directives.
But now, if "off" is evaluated from a complex value, the behavior is very
different, this mirror is just ignored in runtime, but other mirrors work fine.

> + {
> + 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


--
Roman Arutyunyan
_______________________________________________
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 145 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: 137
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