openresty / openresty/test-nginx

Case insensitive `response_headers`

Open
#126 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
456
Forks
112
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Test::Nginx::Socket response_headers matcher and reproduce the supplied test case using the response_headers directive. Check how negated header names are compared, then verify that matching treats header-name casing equivalently while preserving the existing failure for a present header.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.