openresty / echo-nginx-module

An Nginx module for bringing the power of "echo", "sleep", "time" and more to Nginx's config file
http://wiki.nginx.org/NginxHttpEchoModule
BSD 2-Clause "Simplified" License
1.17k stars 254 forks source link

Unable to use variables as arguments to `echo_subrequest` #34

Closed musically-ut closed 10 years ago

musically-ut commented 10 years ago

With this config:

    location ~ ^/delay/(?<delay>[0-9.]+)/(?<originalURL>.*)$ {
        # echo_blocking_sleep $delay;
        echo_subrequest '$echo_request_method ' '/$originalURL' -q '$args';
    }

When I try to execute:

curl -v 'http://localhost/delay/0.343/api/?a=b'

I get this in my errors.log:

unknown option for echo_subrequest_async: a=b

However, if I replace the first argument to echo_subrequest directive with a static string:

        echo_subrequest 'GET' '/$originalURL' -q '$args';

The subrequest executes as intended.


It seems that ngx_http_echo_eval_cmd_args falters a bit if the first argument passed to it is a variable (i.e. value[i].lengths != NULL). In that case, it continues to expect opts (expects_opts remains 1) and it misinterprets the -q as an opt instead of an arg in the third iteration.

agentzh commented 10 years ago

@musically-ut Thank you for the report! Just fixed in git master. Please try it out :)

musically-ut commented 10 years ago

Thanks for the fix! :+1: