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

Using $echo_it inside if-clause doesn't work. #78

Closed silentHoo closed 6 years ago

silentHoo commented 6 years ago

I try to use echo_foreach_split to get each request header from the incoming request but only want to set one header on the response. Is this a bug or is this impossible this way?

I tried it like this with:

# curl -i localhost:8080/echoback -H 'any_specific_header_i_want_to_whitelist: any-value'

  location /echoback {
      echo_foreach_split '\n' $echo_client_request_headers;
        if ($echo_it ~ 'any_specific_header_i_want_to_whitelist') {
          echo "yep, found!";
          # $my_extracted_header_value = "any-value";
        }
      echo_end;

      # more_set_headers "any_specific_header_i_want_to_whitelist: $my_extracted_header_value";
    }

Isn't this possible due to the underlying pointer structure used here? Or I'm doing it wrong?

duzhe commented 6 years ago

nginx configuration is NOT a programing language, you'd better not putting complex logic in it。try lua-nginx-module。

in nginx configuration file, config commands run at several phase sequentially, "if" command run at REWRITE phase, "echo_foreach_split" command run at CONTENT phase, so , it not working as your expected。

silentHoo commented 6 years ago

Thanks @duzhe I've mixed it together, now I've found a working solution with lua.