2010-11-04 08:18:26 +03:00
|
|
|
# vim:set ft= ts=4 sw=4 et fdm=marker:
|
|
|
|
|
2013-12-06 02:46:51 +04:00
|
|
|
use Test::Nginx::Socket::Lua;
|
2010-11-04 08:18:26 +03:00
|
|
|
|
|
|
|
#worker_connections(1014);
|
|
|
|
#master_process_enabled(1);
|
|
|
|
#log_level('warn');
|
|
|
|
|
2011-12-16 18:30:04 +04:00
|
|
|
repeat_each(2);
|
2010-11-04 08:18:26 +03:00
|
|
|
|
2015-08-11 08:18:14 +03:00
|
|
|
plan tests => repeat_each() * (blocks() * 3 + 38);
|
2010-11-04 08:18:26 +03:00
|
|
|
|
|
|
|
#no_diff();
|
2011-09-30 22:47:09 +04:00
|
|
|
no_long_string();
|
2010-11-04 08:18:26 +03:00
|
|
|
|
|
|
|
run_tests();
|
|
|
|
|
|
|
|
__DATA__
|
|
|
|
|
|
|
|
=== TEST 1: set response content-type header
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.content_type = "text/my-plain";
|
|
|
|
ngx.say("Hi");
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
Content-Type: text/my-plain
|
|
|
|
--- response_body
|
|
|
|
Hi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 2: set response content-type header
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.content_length = "text/my-plain";
|
|
|
|
ngx.say("Hi");
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_body_like: 500 Internal Server Error
|
|
|
|
--- response_headers
|
|
|
|
Content-Type: text/html
|
|
|
|
--- error_code: 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 3: set response content-type header
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.content_length = 3
|
|
|
|
ngx.say("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
Content-Length: 3
|
2011-10-19 13:07:47 +04:00
|
|
|
--- response_body chop
|
|
|
|
Hel
|
2010-11-04 08:18:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 4: set response content-type header
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.status = 302;
|
2013-01-23 05:52:06 +04:00
|
|
|
ngx.header["Location"] = "http://agentzh.org/foo";
|
2010-11-04 08:18:26 +03:00
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
2013-01-23 05:52:06 +04:00
|
|
|
Location: http://agentzh.org/foo
|
2010-11-04 08:18:26 +03:00
|
|
|
--- response_body
|
|
|
|
--- error_code: 302
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 5: set response content-type header
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.content_length = 3
|
|
|
|
ngx.header.content_length = nil
|
|
|
|
ngx.say("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
!Content-Length
|
|
|
|
--- response_body
|
|
|
|
Hello
|
|
|
|
|
2010-11-05 08:09:16 +03:00
|
|
|
|
|
|
|
|
2010-11-05 09:58:42 +03:00
|
|
|
=== TEST 6: set multi response content-type header
|
2010-11-05 08:09:16 +03:00
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["X-Foo"] = {"a", "bc"}
|
|
|
|
ngx.say("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- raw_response_headers_like chomp
|
2011-10-20 18:37:26 +04:00
|
|
|
X-Foo: a\r\n.*?X-Foo: bc\r\n
|
2010-11-05 08:09:16 +03:00
|
|
|
--- response_body
|
|
|
|
Hello
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-05 09:58:42 +03:00
|
|
|
=== TEST 7: set response content-type header
|
2010-11-05 08:09:16 +03:00
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.content_type = {"a", "bc"}
|
|
|
|
ngx.say("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
Content-Type: bc
|
|
|
|
--- response_body
|
|
|
|
Hello
|
|
|
|
|
2010-11-05 09:58:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 8: set multi response content-type header and clears it
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["X-Foo"] = {"a", "bc"}
|
|
|
|
ngx.header["X-Foo"] = {}
|
|
|
|
ngx.say("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
!X-Foo
|
|
|
|
--- response_body
|
|
|
|
Hello
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 9: set multi response content-type header and clears it
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["X-Foo"] = {"a", "bc"}
|
|
|
|
ngx.header["X-Foo"] = nil
|
|
|
|
ngx.say("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
!X-Foo
|
|
|
|
--- response_body
|
|
|
|
Hello
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 10: set multi response content-type header (multiple times)
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["X-Foo"] = {"a", "bc"}
|
|
|
|
ngx.header["X-Foo"] = {"a", "abc"}
|
|
|
|
ngx.say("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- raw_response_headers_like chomp
|
2011-10-20 18:37:26 +04:00
|
|
|
X-Foo: a\r\n.*?X-Foo: abc\r\n
|
2010-11-05 09:58:42 +03:00
|
|
|
--- response_body
|
|
|
|
Hello
|
|
|
|
|
2011-05-19 13:55:45 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 11: clear first, then add
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Foo"] = {}
|
|
|
|
ngx.header["Foo"] = {"a", "b"}
|
|
|
|
ngx.send_headers()
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- raw_response_headers_like eval
|
|
|
|
".*Foo: a\r
|
|
|
|
Foo: b.*"
|
|
|
|
--- response_body
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 12: first add, then clear, then add again
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Foo"] = {"c", "d"}
|
|
|
|
ngx.header["Foo"] = {}
|
|
|
|
ngx.header["Foo"] = {"a", "b"}
|
|
|
|
ngx.send_headers()
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- raw_response_headers_like eval
|
|
|
|
".*Foo: a\r
|
|
|
|
Foo: b.*"
|
|
|
|
--- response_body
|
|
|
|
|
2011-05-27 09:28:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 13: names are the same in the beginning (one value per key)
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Foox"] = "barx"
|
|
|
|
ngx.header["Fooy"] = "bary"
|
|
|
|
ngx.send_headers()
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
Foox: barx
|
|
|
|
Fooy: bary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 14: names are the same in the beginning (multiple values per key)
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Foox"] = {"conx1", "conx2" }
|
|
|
|
ngx.header["Fooy"] = {"cony1", "cony2" }
|
|
|
|
ngx.send_headers()
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
Foox: conx1, conx2
|
|
|
|
Fooy: cony1, cony2
|
|
|
|
|
2011-08-16 07:27:03 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 15: set header after ngx.print
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
default_type "text/plain";
|
|
|
|
content_by_lua '
|
|
|
|
ngx.print("hello")
|
|
|
|
ngx.header.content_type = "text/foo"
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
2013-01-12 03:34:35 +04:00
|
|
|
--- response_body chop
|
|
|
|
hello
|
2012-02-15 17:43:12 +04:00
|
|
|
--- error_log
|
|
|
|
attempt to set ngx.header.HEADER after sending out response headers
|
|
|
|
--- no_error_log eval
|
|
|
|
["alert", "warn"]
|
2011-08-16 07:27:03 +04:00
|
|
|
|
2011-09-11 19:56:24 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 16: get content-type header after ngx.print
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
default_type "text/my-plain";
|
|
|
|
content_by_lua '
|
|
|
|
ngx.print("hello, ")
|
|
|
|
ngx.say(ngx.header.content_type)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
Content-Type: text/my-plain
|
|
|
|
--- response_body
|
|
|
|
hello, text/my-plain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 17: get content-length header
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.content_length = 2;
|
|
|
|
ngx.say(ngx.header.content_length);
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
Content-Length: 2
|
|
|
|
--- response_body
|
|
|
|
2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 18: get content-length header
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.foo = "bar";
|
|
|
|
ngx.say(ngx.header.foo);
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
foo: bar
|
|
|
|
--- response_body
|
|
|
|
bar
|
|
|
|
|
2011-09-12 06:56:46 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 19: get content-length header (proxy)
|
|
|
|
--- config
|
|
|
|
location /main {
|
|
|
|
set $footer '';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port/echo;
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.var.footer = ngx.header.content_length
|
|
|
|
';
|
|
|
|
echo_after_body $footer;
|
|
|
|
}
|
|
|
|
location /echo {
|
|
|
|
content_by_lua 'ngx.print("Hello")';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /main
|
|
|
|
--- response_headers
|
|
|
|
!Content-Length
|
|
|
|
--- response_body
|
|
|
|
Hello5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 20: set and get content-length header (proxy)
|
|
|
|
--- config
|
|
|
|
location /main {
|
|
|
|
set $footer '';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port/echo;
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.header.content_length = 27
|
|
|
|
ngx.var.footer = ngx.header.content_length
|
|
|
|
';
|
|
|
|
echo_after_body $footer;
|
|
|
|
}
|
|
|
|
location /echo {
|
|
|
|
content_by_lua 'ngx.print("Hello")';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /main
|
|
|
|
--- response_headers
|
|
|
|
!Content-Length
|
|
|
|
--- response_body
|
|
|
|
Hello27
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 21: get content-type header (proxy)
|
|
|
|
--- config
|
|
|
|
location /main {
|
|
|
|
set $footer '';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port/echo;
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.var.footer = ngx.header.content_type
|
|
|
|
';
|
|
|
|
echo_after_body $footer;
|
|
|
|
}
|
|
|
|
location /echo {
|
|
|
|
default_type 'abc/foo';
|
|
|
|
content_by_lua 'ngx.print("Hello")';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /main
|
|
|
|
--- response_headers
|
|
|
|
Content-Type: abc/foo
|
|
|
|
--- response_body
|
|
|
|
Helloabc/foo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 22: set and get content-type header (proxy)
|
|
|
|
--- config
|
|
|
|
location /main {
|
|
|
|
set $footer '';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port/echo;
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.header.content_type = "text/blah"
|
|
|
|
ngx.var.footer = ngx.header.content_type
|
|
|
|
';
|
|
|
|
echo_after_body $footer;
|
|
|
|
}
|
|
|
|
location /echo {
|
|
|
|
default_type 'abc/foo';
|
|
|
|
content_by_lua 'ngx.print("Hello")';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /main
|
|
|
|
--- response_headers
|
|
|
|
Content-Type: text/blah
|
|
|
|
--- response_body
|
|
|
|
Hellotext/blah
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 23: get user header (proxy)
|
|
|
|
--- config
|
|
|
|
location /main {
|
|
|
|
set $footer '';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port/echo;
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.var.footer = ngx.header.baz
|
|
|
|
';
|
|
|
|
echo_after_body $footer;
|
|
|
|
}
|
|
|
|
location /echo {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.baz = "bah"
|
|
|
|
ngx.print("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /main
|
|
|
|
--- response_headers
|
|
|
|
baz: bah
|
|
|
|
--- response_body
|
|
|
|
Hellobah
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 24: set and get user header (proxy)
|
|
|
|
--- config
|
|
|
|
location /main {
|
|
|
|
set $footer '';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port/echo;
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.header.baz = "foo"
|
|
|
|
ngx.var.footer = ngx.header.baz
|
|
|
|
';
|
|
|
|
echo_after_body $footer;
|
|
|
|
}
|
|
|
|
location /echo {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.baz = "bah"
|
|
|
|
ngx.print("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /main
|
|
|
|
--- response_headers
|
|
|
|
baz: foo
|
|
|
|
--- response_body
|
|
|
|
Hellofoo
|
|
|
|
|
2011-09-12 18:50:04 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 25: get multiple user header (proxy)
|
|
|
|
--- config
|
|
|
|
location /main {
|
|
|
|
set $footer '';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port/echo;
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.var.footer = table.concat(ngx.header.baz, ", ")
|
|
|
|
';
|
|
|
|
echo_after_body $footer;
|
|
|
|
}
|
|
|
|
location /echo {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.baz = {"bah", "blah"}
|
|
|
|
ngx.print("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /main
|
|
|
|
--- raw_response_headers_like eval
|
|
|
|
"baz: bah\r
|
|
|
|
.*?baz: blah"
|
|
|
|
--- response_body
|
|
|
|
Hellobah, blah
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 26: set and get multiple user header (proxy)
|
|
|
|
--- config
|
|
|
|
location /main {
|
|
|
|
set $footer '';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port/echo;
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.header.baz = {"foo", "baz"}
|
|
|
|
ngx.var.footer = table.concat(ngx.header.baz, ", ")
|
|
|
|
';
|
|
|
|
echo_after_body $footer;
|
|
|
|
}
|
|
|
|
location /echo {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.baz = {"bah", "hah"}
|
|
|
|
ngx.print("Hello")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /main
|
|
|
|
--- raw_response_headers_like eval
|
|
|
|
"baz: foo\r
|
|
|
|
.*?baz: baz"
|
|
|
|
--- response_body
|
|
|
|
Hellofoo, baz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 27: get non-existant header
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.say(ngx.header.foo);
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
!foo
|
|
|
|
--- response_body
|
|
|
|
nil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 28: get non-existant header
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.foo = {"bah", "baz", "blah"}
|
|
|
|
ngx.header.foo = nil
|
|
|
|
ngx.say(ngx.header.foo);
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
!foo
|
|
|
|
--- response_body
|
|
|
|
nil
|
|
|
|
|
2011-09-15 05:04:25 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 29: override domains in the cookie
|
|
|
|
--- config
|
|
|
|
location /foo {
|
|
|
|
echo hello;
|
|
|
|
add_header Set-Cookie 'foo=bar; Domain=backend.int';
|
|
|
|
add_header Set-Cookie 'baz=bah; Domain=backend.int';
|
|
|
|
}
|
|
|
|
|
|
|
|
location /main {
|
|
|
|
proxy_pass http://127.0.0.1:$server_port/foo;
|
|
|
|
header_filter_by_lua '
|
|
|
|
local cookies = ngx.header.set_cookie
|
|
|
|
if not cookies then return end
|
|
|
|
if type(cookies) ~= "table" then cookies = {cookies} end
|
|
|
|
local newcookies = {}
|
|
|
|
for i, val in ipairs(cookies) do
|
|
|
|
local newval = string.gsub(val, "([dD]omain)=[%w_-\\\\.]+",
|
|
|
|
"%1=external.domain.com")
|
|
|
|
table.insert(newcookies, newval)
|
|
|
|
end
|
|
|
|
ngx.header.set_cookie = newcookies
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /main
|
|
|
|
--- response_headers
|
|
|
|
Set-Cookie: foo=bar; Domain=external.domain.com, baz=bah; Domain=external.domain.com
|
|
|
|
--- response_body
|
|
|
|
hello
|
|
|
|
|
2011-09-30 22:47:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 30: set single value to cache-control
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.cache_control = "private"
|
|
|
|
ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
Cache-Control: private
|
|
|
|
--- response_body
|
|
|
|
Cache-Control: private
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 31: set multi values to cache-control
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.cache_control = { "private", "no-store" }
|
|
|
|
ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
Cache-Control: private, no-store
|
2013-06-11 03:33:05 +04:00
|
|
|
--- response_body_like chop
|
|
|
|
^Cache-Control: private[;,] no-store$
|
2011-09-30 22:47:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 32: set multi values to cache-control and override it with a single value
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.cache_control = { "private", "no-store" }
|
|
|
|
ngx.header.cache_control = { "no-cache" }
|
|
|
|
ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
|
|
|
|
ngx.say("Cache-Control: ", ngx.header.cache_control)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
Cache-Control: no-cache
|
|
|
|
--- response_body
|
|
|
|
Cache-Control: no-cache
|
|
|
|
Cache-Control: no-cache
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 33: set multi values to cache-control and override it with multiple values
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.cache_control = { "private", "no-store" }
|
|
|
|
ngx.header.cache_control = { "no-cache", "blah", "foo" }
|
|
|
|
ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
|
2013-08-03 06:16:05 +04:00
|
|
|
ngx.say("Cache-Control: ", table.concat(ngx.header.cache_control, ", "))
|
2011-09-30 22:47:09 +04:00
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
Cache-Control: no-cache, blah, foo
|
2013-06-11 03:33:05 +04:00
|
|
|
--- response_body_like chop
|
|
|
|
^Cache-Control: no-cache[;,] blah[;,] foo
|
|
|
|
Cache-Control: no-cache[;,] blah[;,] foo$
|
2014-07-14 05:44:14 +04:00
|
|
|
--- no_error_log
|
|
|
|
[error]
|
2011-09-30 22:47:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 34: set the www-authenticate response header
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.www_authenticate = "blah"
|
|
|
|
ngx.say("WWW-Authenticate: ", ngx.var.sent_http_www_authenticate)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
WWW-Authenticate: blah
|
|
|
|
--- response_body
|
|
|
|
WWW-Authenticate: blah
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-13 07:08:57 +04:00
|
|
|
=== TEST 35: set and clear the www-authenticate response header
|
2011-09-30 22:47:09 +04:00
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.foo = "blah"
|
|
|
|
ngx.header.foo = nil
|
|
|
|
ngx.say("Foo: ", ngx.var.sent_http_foo)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
!Foo
|
|
|
|
--- response_body
|
|
|
|
Foo: nil
|
|
|
|
|
2011-11-09 16:27:10 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 36: set multi values to cache-control and override it with multiple values (to reproduce a bug)
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.cache_control = { "private", "no-store", "foo", "bar", "baz" }
|
2011-11-09 17:48:27 +04:00
|
|
|
ngx.header.cache_control = {}
|
|
|
|
ngx.send_headers()
|
2011-11-09 16:27:10 +04:00
|
|
|
ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
|
|
|
|
';
|
2011-11-09 17:48:27 +04:00
|
|
|
add_header Cache-Control "blah";
|
2011-11-09 16:27:10 +04:00
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
2011-11-09 17:48:27 +04:00
|
|
|
Cache-Control: blah
|
2011-11-09 16:27:10 +04:00
|
|
|
--- response_body
|
2011-11-09 17:48:27 +04:00
|
|
|
Cache-Control: blah
|
2011-11-09 16:27:10 +04:00
|
|
|
|
2012-02-07 07:56:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 37: set last-modified and return 304
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Last-Modified"] = ngx.http_time(1290079655)
|
2012-02-07 08:59:23 +04:00
|
|
|
ngx.say(ngx.header["Last-Modified"])
|
2012-02-07 07:56:08 +04:00
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- more_headers
|
|
|
|
If-Modified-Since: Thu, 18 Nov 2010 11:27:35 GMT
|
|
|
|
--- response_headers
|
|
|
|
Last-Modified: Thu, 18 Nov 2010 11:27:35 GMT
|
|
|
|
--- error_code: 304
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 38: set last-modified and return 200
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Last-Modified"] = ngx.http_time(1290079655)
|
2012-02-07 08:59:23 +04:00
|
|
|
ngx.say(ngx.header["Last-Modified"])
|
2012-02-07 07:56:08 +04:00
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- more_headers
|
|
|
|
If-Modified-Since: Thu, 18 Nov 2010 11:27:34 GMTT
|
|
|
|
--- response_headers
|
|
|
|
Last-Modified: Thu, 18 Nov 2010 11:27:35 GMT
|
|
|
|
--- response_body
|
|
|
|
Thu, 18 Nov 2010 11:27:35 GMT
|
|
|
|
|
2012-05-17 07:44:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 39: set response content-encoding header should bypass ngx_http_gzip_filter_module
|
|
|
|
--- config
|
|
|
|
default_type text/plain;
|
|
|
|
gzip on;
|
|
|
|
gzip_min_length 1;
|
|
|
|
gzip_types text/plain;
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.content_encoding = "gzip";
|
|
|
|
ngx.say("Hello, world, my dear friend!");
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- more_headers
|
|
|
|
Accept-Encoding: gzip
|
|
|
|
--- response_headers
|
|
|
|
Content-Type: text/plain
|
|
|
|
--- response_body
|
|
|
|
Hello, world, my dear friend!
|
|
|
|
|
2012-06-14 15:17:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 40: no transform underscores (write)
|
|
|
|
--- config
|
|
|
|
lua_transform_underscores_in_response_headers off;
|
|
|
|
location = /t {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.foo_bar = "Hello"
|
|
|
|
ngx.say(ngx.header.foo_bar)
|
|
|
|
ngx.say(ngx.header["foo-bar"])
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- raw_response_headers_like eval
|
|
|
|
"\r\nfoo_bar: Hello\r\n"
|
|
|
|
--- response_body
|
|
|
|
Hello
|
|
|
|
nil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 41: with transform underscores (write)
|
|
|
|
--- config
|
|
|
|
lua_transform_underscores_in_response_headers on;
|
|
|
|
location = /t {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.foo_bar = "Hello"
|
|
|
|
ngx.say(ngx.header.foo_bar)
|
|
|
|
ngx.say(ngx.header["foo-bar"])
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- raw_response_headers_like eval
|
|
|
|
"\r\nfoo-bar: Hello\r\n"
|
|
|
|
--- response_body
|
|
|
|
Hello
|
|
|
|
Hello
|
|
|
|
|
2013-01-03 00:00:11 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 42: github issue #199: underscores in lua variables
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.content_type = "text/my-plain"
|
|
|
|
|
|
|
|
local results = {}
|
|
|
|
results.something = "hello"
|
|
|
|
results.content_type = "anything"
|
|
|
|
results.somehing_else = "hi"
|
|
|
|
|
2015-03-06 01:06:03 +03:00
|
|
|
local arr = {}
|
|
|
|
for k in pairs(results) do table.insert(arr, k) end
|
|
|
|
table.sort(arr)
|
|
|
|
for i, k in ipairs(arr) do
|
|
|
|
ngx.say(k .. ": " .. results[k])
|
2013-01-03 00:00:11 +04:00
|
|
|
end
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
Content-Type: text/my-plain
|
|
|
|
|
|
|
|
--- response_body
|
2015-03-06 01:06:03 +03:00
|
|
|
content_type: anything
|
2013-01-03 00:00:11 +04:00
|
|
|
somehing_else: hi
|
|
|
|
something: hello
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
2013-08-02 06:00:11 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 43: set multiple response header
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
for i = 1, 50 do
|
|
|
|
ngx.header["X-Direct-" .. i] = "text/my-plain-" .. i;
|
|
|
|
end
|
|
|
|
|
|
|
|
ngx.say(ngx.header["X-Direct-50"]);
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_body
|
|
|
|
text/my-plain-50
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 44: set multiple response header and then reset and then clear
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
for i = 1, 50 do
|
|
|
|
ngx.header["X-Direct-" .. i] = "text/my-plain-" .. i;
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, 50 do
|
|
|
|
ngx.header["X-Direct-" .. i] = "text/my-plain"
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, 50 do
|
|
|
|
ngx.header["X-Direct-" .. i] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
ngx.say("ok");
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_body
|
|
|
|
ok
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
2014-07-14 05:44:14 +04:00
|
|
|
--- timeout: 10
|
2013-08-02 06:00:11 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 45: set response content-type header for multiple times
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.content_type = "text/my-plain";
|
|
|
|
ngx.header.content_type = "text/my-plain-2";
|
|
|
|
ngx.say("Hi");
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
Content-Type: text/my-plain-2
|
|
|
|
--- response_body
|
|
|
|
Hi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 46: set Last-Modified response header for multiple times
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.last_modified = ngx.http_time(1290079655)
|
|
|
|
ngx.header.last_modified = ngx.http_time(1290079654)
|
|
|
|
ngx.say("ok");
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
Last-Modified: Thu, 18 Nov 2010 11:27:34 GMT
|
|
|
|
--- response_body
|
|
|
|
ok
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 47: set Last-Modified response header and then clear
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.last_modified = ngx.http_time(1290079655)
|
|
|
|
ngx.header.last_modified = nil
|
|
|
|
ngx.say("ok");
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_headers
|
|
|
|
!Last-Modified
|
|
|
|
--- response_body
|
|
|
|
ok
|
|
|
|
|
2013-08-03 06:16:05 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 48: github #20: segfault caused by the nasty optimization in the nginx core (write)
|
|
|
|
--- config
|
|
|
|
location = /t/ {
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.header.foo = 1
|
|
|
|
';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port;
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- more_headers
|
|
|
|
Foo: bar
|
|
|
|
Bah: baz
|
2013-08-04 09:28:09 +04:00
|
|
|
--- response_headers
|
|
|
|
Location: http://localhost:$ServerPort/t/
|
2013-08-03 06:16:05 +04:00
|
|
|
--- response_body_like: 301 Moved Permanently
|
|
|
|
--- error_code: 301
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 49: github #20: segfault caused by the nasty optimization in the nginx core (read)
|
|
|
|
--- config
|
|
|
|
location = /t/ {
|
|
|
|
header_filter_by_lua '
|
|
|
|
local v = ngx.header.foo
|
|
|
|
';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port;
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- more_headers
|
|
|
|
Foo: bar
|
|
|
|
Bah: baz
|
|
|
|
--- response_body_like: 301 Moved Permanently
|
2013-08-04 09:28:09 +04:00
|
|
|
--- response_headers
|
|
|
|
Location: http://localhost:$ServerPort/t/
|
|
|
|
--- error_code: 301
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 50: github #20: segfault caused by the nasty optimization in the nginx core (read Location)
|
|
|
|
--- config
|
|
|
|
location = /t/ {
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.header.Foo = ngx.header.location
|
|
|
|
';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port;
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- more_headers
|
|
|
|
Foo: bar
|
|
|
|
Bah: baz
|
|
|
|
--- response_headers
|
|
|
|
Location: http://localhost:$ServerPort/t/
|
|
|
|
Foo: /t/
|
|
|
|
--- response_body_like: 301 Moved Permanently
|
|
|
|
--- error_code: 301
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 51: github #20: segfault caused by the nasty optimization in the nginx core (set Foo and read Location)
|
|
|
|
--- config
|
|
|
|
location = /t/ {
|
|
|
|
header_filter_by_lua '
|
|
|
|
ngx.header.Foo = 3
|
|
|
|
ngx.header.Foo = ngx.header.location
|
|
|
|
';
|
|
|
|
proxy_pass http://127.0.0.1:$server_port;
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- more_headers
|
|
|
|
Foo: bar
|
|
|
|
Bah: baz
|
|
|
|
--- response_headers
|
|
|
|
Location: http://localhost:$ServerPort/t/
|
|
|
|
Foo: /t/
|
|
|
|
--- response_body_like: 301 Moved Permanently
|
2013-08-03 06:16:05 +04:00
|
|
|
--- error_code: 301
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
2013-10-12 21:38:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 52: case sensitive cache-control header
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["cache-Control"] = "private"
|
|
|
|
ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- raw_response_headers_like chop
|
|
|
|
cache-Control: private
|
|
|
|
--- response_body
|
|
|
|
Cache-Control: private
|
|
|
|
|
2013-10-12 22:02:51 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 53: clear Cache-Control when there was no Cache-Control
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Cache-Control"] = nil
|
|
|
|
ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- raw_response_headers_unlike eval
|
|
|
|
qr/Cache-Control/i
|
|
|
|
--- response_body
|
|
|
|
Cache-Control: nil
|
|
|
|
|
2013-11-06 03:11:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 54: set response content-type header
|
|
|
|
--- config
|
|
|
|
location /read {
|
|
|
|
content_by_lua '
|
|
|
|
local s = "content_type"
|
|
|
|
local v = ngx.header[s]
|
|
|
|
ngx.say("s = ", s)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /read
|
|
|
|
--- response_body
|
|
|
|
s = content_type
|
|
|
|
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
2014-01-05 02:21:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 55: set a number header name
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header[32] = "private"
|
|
|
|
ngx.say("32: ", ngx.var.sent_http_32)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
32: private
|
|
|
|
--- response_body
|
|
|
|
32: private
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 56: set a number header name (in a table value)
|
|
|
|
--- config
|
|
|
|
location /lua {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.foo = {32}
|
|
|
|
ngx.say("foo: ", ngx.var.sent_http_foo)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /lua
|
|
|
|
--- response_headers
|
|
|
|
foo: 32
|
|
|
|
--- response_body
|
|
|
|
foo: 32
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
2014-02-27 03:14:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 57: random access resp headers
|
|
|
|
--- config
|
|
|
|
location /resp-header {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Foo"] = "bar"
|
|
|
|
ngx.header["Bar"] = "baz"
|
|
|
|
ngx.say("Foo: ", ngx.resp.get_headers()["Foo"] or "nil")
|
|
|
|
ngx.say("foo: ", ngx.resp.get_headers()["foo"] or "nil")
|
|
|
|
ngx.say("Bar: ", ngx.resp.get_headers()["Bar"] or "nil")
|
|
|
|
ngx.say("bar: ", ngx.resp.get_headers()["bar"] or "nil")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /resp-header
|
|
|
|
--- response_headers
|
|
|
|
Foo: bar
|
|
|
|
Bar: baz
|
|
|
|
--- response_body
|
|
|
|
Foo: bar
|
|
|
|
foo: bar
|
|
|
|
Bar: baz
|
|
|
|
bar: baz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 58: iterating through raw resp headers
|
|
|
|
--- config
|
|
|
|
location /resp-header {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Foo"] = "bar"
|
|
|
|
ngx.header["Bar"] = "baz"
|
|
|
|
local h = {}
|
|
|
|
for k, v in pairs(ngx.resp.get_headers(nil, true)) do
|
|
|
|
h[k] = v
|
|
|
|
end
|
|
|
|
ngx.say("Foo: ", h["Foo"] or "nil")
|
|
|
|
ngx.say("foo: ", h["foo"] or "nil")
|
|
|
|
ngx.say("Bar: ", h["Bar"] or "nil")
|
|
|
|
ngx.say("bar: ", h["bar"] or "nil")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /resp-header
|
|
|
|
--- response_headers
|
|
|
|
Foo: bar
|
|
|
|
Bar: baz
|
|
|
|
--- response_body
|
|
|
|
Foo: bar
|
|
|
|
foo: nil
|
|
|
|
Bar: baz
|
|
|
|
bar: nil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 59: removed response headers
|
|
|
|
--- config
|
|
|
|
location /resp-header {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Foo"] = "bar"
|
|
|
|
ngx.header["Foo"] = nil
|
|
|
|
ngx.header["Bar"] = "baz"
|
|
|
|
ngx.say("Foo: ", ngx.resp.get_headers()["Foo"] or "nil")
|
|
|
|
ngx.say("foo: ", ngx.resp.get_headers()["foo"] or "nil")
|
|
|
|
ngx.say("Bar: ", ngx.resp.get_headers()["Bar"] or "nil")
|
|
|
|
ngx.say("bar: ", ngx.resp.get_headers()["bar"] or "nil")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /resp-header
|
|
|
|
--- response_headers
|
|
|
|
!Foo
|
|
|
|
Bar: baz
|
|
|
|
--- response_body
|
|
|
|
Foo: nil
|
|
|
|
foo: nil
|
|
|
|
Bar: baz
|
|
|
|
bar: baz
|
|
|
|
|
2014-08-12 23:55:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 60: built-in Content-Type header
|
|
|
|
--- main_config
|
|
|
|
--- config
|
|
|
|
location = /t {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.say("hi")
|
|
|
|
';
|
|
|
|
|
|
|
|
header_filter_by_lua '
|
|
|
|
local hs = ngx.resp.get_headers()
|
|
|
|
print("my Content-Type: ", hs["Content-Type"])
|
2015-06-20 19:19:21 +03:00
|
|
|
print("my content-type: ", hs["content-type"])
|
|
|
|
print("my content_type: ", hs["content_type"])
|
2014-08-12 23:55:56 +04:00
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
hi
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
[alert]
|
|
|
|
--- error_log
|
|
|
|
my Content-Type: text/plain
|
2015-06-20 19:19:21 +03:00
|
|
|
my content-type: text/plain
|
|
|
|
my content_type: text/plain
|
2014-08-12 23:55:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 61: built-in Content-Length header
|
|
|
|
--- main_config
|
|
|
|
--- config
|
|
|
|
location = /t {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.say("hi")
|
|
|
|
';
|
|
|
|
|
|
|
|
header_filter_by_lua '
|
|
|
|
local hs = ngx.resp.get_headers()
|
|
|
|
print("my Content-Length: ", hs["Content-Length"])
|
2015-06-20 19:19:21 +03:00
|
|
|
print("my content-length: ", hs["content-length"])
|
|
|
|
print("my content_length: ", hs.content_length)
|
2014-08-12 23:55:56 +04:00
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t HTTP/1.0
|
|
|
|
--- response_body
|
|
|
|
hi
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
[alert]
|
|
|
|
--- error_log
|
|
|
|
my Content-Length: 3
|
2015-06-20 19:19:21 +03:00
|
|
|
my content-length: 3
|
|
|
|
my content_length: 3
|
2014-08-12 23:55:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 62: built-in Connection header
|
|
|
|
--- main_config
|
|
|
|
--- config
|
|
|
|
location = /t {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.say("hi")
|
|
|
|
';
|
|
|
|
|
|
|
|
header_filter_by_lua '
|
|
|
|
local hs = ngx.resp.get_headers()
|
|
|
|
print("my Connection: ", hs["Connection"])
|
2015-06-20 19:19:21 +03:00
|
|
|
print("my connection: ", hs["connection"])
|
2014-08-12 23:55:56 +04:00
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t HTTP/1.0
|
|
|
|
--- response_body
|
|
|
|
hi
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
[alert]
|
|
|
|
--- error_log
|
|
|
|
my Connection: close
|
2015-06-20 19:19:21 +03:00
|
|
|
my connection: close
|
2014-08-12 23:55:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 63: built-in Transfer-Encoding header (chunked)
|
|
|
|
--- main_config
|
|
|
|
--- config
|
|
|
|
location = /t {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.say("hi")
|
|
|
|
';
|
|
|
|
|
|
|
|
body_filter_by_lua '
|
|
|
|
local hs = ngx.resp.get_headers()
|
|
|
|
print("my Transfer-Encoding: ", hs["Transfer-Encoding"])
|
2015-06-20 19:19:21 +03:00
|
|
|
print("my transfer-encoding: ", hs["transfer-encoding"])
|
|
|
|
print("my transfer_encoding: ", hs.transfer_encoding)
|
2014-08-12 23:55:56 +04:00
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
hi
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
[alert]
|
|
|
|
--- error_log
|
|
|
|
my Transfer-Encoding: chunked
|
2015-06-20 19:19:21 +03:00
|
|
|
my transfer-encoding: chunked
|
2014-08-12 23:55:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 64: built-in Transfer-Encoding header (none)
|
|
|
|
--- main_config
|
|
|
|
--- config
|
|
|
|
location = /t {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.say("hi")
|
|
|
|
';
|
|
|
|
|
|
|
|
body_filter_by_lua '
|
|
|
|
local hs = ngx.resp.get_headers()
|
|
|
|
print("my Transfer-Encoding: ", hs["Transfer-Encoding"])
|
2015-06-20 19:19:21 +03:00
|
|
|
print("my transfer-encoding: ", hs["transfer-encoding"])
|
|
|
|
print("my transfer_encoding: ", hs.transfer_encoding)
|
2014-08-12 23:55:56 +04:00
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t HTTP/1.0
|
|
|
|
--- response_body
|
|
|
|
hi
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
[alert]
|
|
|
|
--- error_log
|
|
|
|
my Transfer-Encoding: nil
|
2015-06-20 19:19:21 +03:00
|
|
|
my transfer-encoding: nil
|
|
|
|
my transfer_encoding: nil
|
2014-08-12 23:55:56 +04:00
|
|
|
|
2015-02-06 02:42:38 +03:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 65: set Location (no host)
|
|
|
|
--- config
|
|
|
|
location = /t {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.location = "/foo/bar"
|
|
|
|
return ngx.exit(301)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_headers
|
|
|
|
Location: /foo/bar
|
|
|
|
--- response_body_like: 301 Moved Permanently
|
|
|
|
--- error_code: 301
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 66: set Location (with host)
|
|
|
|
--- config
|
|
|
|
location = /t {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header.location = "http://test.com/foo/bar"
|
|
|
|
return ngx.exit(301)
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_headers
|
|
|
|
Location: http://test.com/foo/bar
|
|
|
|
--- response_body_like: 301 Moved Permanently
|
|
|
|
--- error_code: 301
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
2015-08-11 08:18:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
=== TEST 67: ngx.header["Content-Type"] with ngx_gzip
|
|
|
|
--- config
|
|
|
|
gzip on;
|
|
|
|
gzip_min_length 1;
|
|
|
|
location = /test2 {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Content-Type"] = "text/html; charset=utf-8"
|
|
|
|
ngx.say("test")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /test2
|
|
|
|
--- more_headers
|
|
|
|
Accept-Encoding: gzip
|
|
|
|
--- response_headers
|
|
|
|
Content-Encoding: gzip
|
|
|
|
Content-Type: text/html; charset=utf-8
|
|
|
|
--- response_body_like chomp
|
|
|
|
[^[:ascii:]]+
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 68: ngx.header["Content-Type"] with "; blah"
|
|
|
|
--- config
|
|
|
|
location = /test2 {
|
|
|
|
content_by_lua '
|
|
|
|
ngx.header["Content-Type"] = "; blah"
|
|
|
|
ngx.say("test")
|
|
|
|
';
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /test2
|
|
|
|
--- response_headers
|
|
|
|
!Content-Encoding
|
|
|
|
Content-Type: ; blah
|
|
|
|
--- response_body
|
|
|
|
test
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|