openresty / test-nginx

Data-driven test scaffold for Nginx C module and OpenResty Lua library development
http://search.cpan.org/dist/Test-Nginx
438 stars 105 forks source link

Case insensitive `response_headers` #126

Open jloh opened 2 years ago

jloh commented 2 years ago

Hi all, thanks for the fantastic framework!

I recently ran into an issue where I've been testing to make sure a specific set of headers are not sent on some responses but it turns out the negative header matching this test suite does is case sensitive. You can replicate it using this below test case:

use Test::Nginx::Socket 'no_plan';
use Cwd qw(cwd);

my $pwd = cwd();

our $HttpConfig = qq{
    lua_package_path "$pwd/lib/?.lua;;";
};

no_long_string();
no_diff();
run_tests();

__DATA__
=== TEST 1: header case matters
--- http_config eval
"$::HttpConfig"
--- config
    location /t {
        content_by_lua_block {
            ngx.header["X-Powered-By"] = "hello"
            ngx.header["via"] = "server-1"
            ngx.say("OK")
        }
    }
--- request
GET /t
--- no_error_log
[error]
--- response_headers
! x-powered-by

I would expect this test to fail since x-powered-by is sent on the response, its just under X-Powered-By. Is there a flag I can enable to make sure these matches are case insensitive? Note that replacing ! x-powered-by with ! X-Powered-By does cause the test to fail since it matches a header on the response.

I tried doing something like this:

--- response_headers_filter
lc

But it appears response_headers_filter isn't a thing, only response_body_filter which is understandable.

Any help would be fantastic, thanks in advance!