@@ -14,6 +14,8 @@ our $HttpConfig = qq{
1414 require (" luacov.runner" ). init()
1515 end
1616 }
17+
18+ underscores_in_headers On;
1719} ;
1820
1921no_long_string();
@@ -22,40 +24,38 @@ no_diff();
2224run_tests();
2325
2426__DATA__
25- === TEST 1 : Test header normalisation
27+ === TEST 1 : Unit test header normalisation
2628-- - http_config eval: $::HttpConfig
2729-- - config
2830location = /a {
2931 content_by_lua_block {
3032 local headers = require (" resty.http_headers" ). new ()
3133
32- headers. x_a_header = " a"
33- headers[" x-b-header" ] = " b"
34- headers[" X-C-Header" ] = " c"
35- headers[" X_d-HEAder" ] = " d"
34+ headers[" content-length" ] = " a"
35+ headers[" TRANSFER-ENCODING" ] = " b"
36+ headers[" SSL_CLIENT_CERTIFICATE" ] = " foo"
3637
37- ngx . say (headers[" X-A-Header " ])
38- ngx . say (headers . x_b_header )
38+ assert (headers[" coNtENt-LENgth " ] == headers[ " content-length " ],
39+ " header values should match " )
3940
40- for k,v in pairs (headers) do
41- ngx. say (k, " : " , v)
42- end
41+ assert(headers[" transfer-encoding" ] == headers[" TRANSFER-ENCODING" ],
42+ " header values should match" )
43+
44+ assert(headers[" ssl_client_certificate" ] == headers[" SSL_CLIENT_CERTIFICATE" ],
45+ " header values should match" )
46+
47+ assert(headers[" SSL-CLIENT-CERTIFICATE" ] ~ = headers[" SSL_CLIENT_CERTIFICATE" ],
48+ " underscores are separate to hyphens" )
4349 }
4450}
4551--- request
4652GET /a
4753-- - response_body
48- a
49- b
50- x-b-header: b
51- x-a-header: a
52- X -d-HEAder: d
53- X -C-Header: c
5454-- - no_error_log
5555[error]
5656
5757
58- === TEST 2 : Test headers can be accessed in all cases
58+ === TEST 2 : Integration test headers normalisation
5959-- - http_config eval: $::HttpConfig
6060-- - config
6161location = /a {
@@ -71,7 +71,6 @@ location = /a {
7171 ngx. status = res. status
7272 ngx. say (res. headers[" X-Foo-Header" ])
7373 ngx. say (res. headers[" x-fOo-heaDeR" ])
74- ngx. say (res. headers. x_foo_header)
7574
7675 httpc: close()
7776 }
@@ -87,12 +86,11 @@ GET /a
8786-- - response_body
8887bar
8988bar
90- bar
9189-- - no_error_log
9290[error]
9391
9492
95- === TEST 3 : Test request headers are normalised
93+ === TEST 3 : Integration test request headers normalisation
9694-- - http_config eval: $::HttpConfig
9795-- - config
9896location = /a {
@@ -105,7 +103,7 @@ location = /a {
105103 path = " /b" ,
106104 headers = {
107105 [" uSeR-AgENT" ] = " test_user_agent" ,
108- x_foo = " bar" ,
106+ [ " X_Foo " ] = " bar" ,
109107 },
110108 }
111109
@@ -118,7 +116,7 @@ location = /a {
118116location = /b {
119117 content_by_lua_block {
120118 ngx. say (ngx. req. get_headers()[" User-Agent" ])
121- ngx. say (ngx. req. get_headers()[" X-Foo " ])
119+ ngx. say (ngx. req. get_headers(nil, true )[" X_Foo " ])
122120 }
123121}
124122-- - request
@@ -141,7 +139,6 @@ location = /a {
141139 headers[" X-A-HEAder" ] = " b"
142140
143141 for k,v in pairs (headers) do
144- ngx. log (ngx. DEBUG, k, " : " , v)
145142 ngx. header[k] = v
146143 end
147144 }
0 commit comments