1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
# vi:filetype=
use lib 'lib';
use Test::Nginx::Socket;
plan tests => 2 * blocks();
#$Test::Nginx::LWP::LogLevel = 'debug';
run_tests();
__DATA__
=== TEST 1: sanity (hit)
--- config
location ^~ /if {
set $res miss;
if ($arg_val ~* '^a') {
set $res hit;
echo $res;
}
echo $res;
}
--- request
GET /if?val=abc
--- response_body
hit
=== TEST 2: sanity (miss)
--- config
location ^~ /if {
set $res miss;
if ($arg_val ~* '^a') {
set $res hit;
echo $res;
}
echo $res;
}
--- request
GET /if?val=bcd
--- response_body
miss
=== TEST 3: proxy in if (hit)
--- config
location ^~ /if {
set $res miss;
if ($arg_val ~* '^a') {
set $res hit;
proxy_pass $scheme://127.0.0.1:$server_port/foo?res=$res;
}
proxy_pass $scheme://127.0.0.1:$server_port/foo?res=$res;
}
location /foo {
echo "res = $arg_res";
}
--- request
GET /if?val=abc
--- response_body
res = hit
=== TEST 4: proxy in if (miss)
--- config
location ^~ /if {
set $res miss;
if ($arg_val ~* '^a') {
set $res hit;
proxy_pass $scheme://127.0.0.1:$server_port/foo?res=$res;
}
proxy_pass $scheme://127.0.0.1:$server_port/foo?res=$res;
}
location /foo {
echo "res = $arg_res";
}
--- request
GET /if?val=bcd
--- response_body
res = miss
=== TEST 5: if too long url (hit)
--- config
location /foo {
if ($request_uri ~ '.{20,}') {
echo too long;
}
echo ok;
}
--- request
GET /foo?a=12345678901234567890
--- response_body
too long
=== TEST 6: if too long url (miss)
--- config
location /foo {
if ($request_uri ~ '.{20,}') {
echo too long;
}
echo ok;
}
--- request
GET /foo?a=1234567890
--- response_body
ok
=== TEST 7: echo should be inherited by if blocks
--- config
location /foo {
if ($uri ~ 'foo') {
}
echo ok;
}
--- request
GET /foo
--- response_body
ok
=== TEST 8: echo_after_body and echo_before_body should be inherited by if blocks
--- config
location /foo {
if ($uri ~ 'foo') {
}
echo_before_body -n 'hello';
echo_location /comma;
echo_after_body 'world';
}
location = /comma {
internal;
echo -n ', ';
}
--- request
GET /foo
--- response_body
hello, world
|