@@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua;
44
55repeat_each(2 );
66
7- plan tests => repeat_each() * 163 ;
7+ plan tests => repeat_each() * 181 ;
88
99# $ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
1010
@@ -1374,3 +1374,246 @@ looking up Lua code cache with key 'nhlf_042c9b3a136fbacbbd0e4b9ad10896b7'
13741374--- log_level: debug
13751375--- no_error_log
13761376[error]
1377+
1378+
1379+
1380+ === TEST 34: variables in rewrite_by_lua_file's file path
1381+ --- config
1382+ location ~ ^/lua/(.+)$ {
1383+ rewrite_by_lua_file html/ $1 . lua;
1384+ }
1385+
1386+ location /main {
1387+ echo_location / lua/ a;
1388+ echo_location / lua/ b;
1389+ echo_location / lua/ a;
1390+ echo_location / lua/ a;
1391+ echo_location / lua/ b;
1392+ }
1393+ --- user_files
1394+ >>> a.lua
1395+ ngx.say(" a" )
1396+ >>> b.lua
1397+ ngx.say(" b" )
1398+ --- request
1399+ GET /main
1400+ --- response_body
1401+ a
1402+ b
1403+ a
1404+ a
1405+ b
1406+ --- no_error_log
1407+ [error]
1408+
1409+
1410+
1411+ === TEST 35: variables in access_by_lua_file's file path
1412+ --- config
1413+ location ~ ^/lua/(.+)$ {
1414+ access_by_lua_file html/ $1 . lua;
1415+
1416+ content_by_lua_block {
1417+ return
1418+ }
1419+ }
1420+
1421+ location ~ ^/proxy/(.+)$ {
1422+ proxy_pass http: // 127.0 . 0. 1: $ server_port / lua/ $1 ;
1423+ }
1424+
1425+ location /main {
1426+ content_by_lua_block {
1427+ local res1, res2, res3, res4, res5 = ngx. location. capture_multi{
1428+ { " /proxy/a" },
1429+ { " /proxy/b" },
1430+ { " /proxy/a" },
1431+ { " /proxy/a" },
1432+ { " /proxy/b" },
1433+ }
1434+
1435+ ngx. say (res1. body )
1436+ ngx. say (res2. body )
1437+ ngx. say (res3. body )
1438+ ngx. say (res4. body )
1439+ ngx. say (res5. body )
1440+ }
1441+ }
1442+ --- user_files
1443+ >>> a.lua
1444+ ngx.print(" a" )
1445+ >>> b.lua
1446+ ngx.print(" b" )
1447+ --- request
1448+ GET /main
1449+ --- response_body
1450+ a
1451+ b
1452+ a
1453+ a
1454+ b
1455+ --- no_error_log
1456+ [error]
1457+
1458+
1459+
1460+ === TEST 36: variables in content_by_lua_file's file path
1461+ --- config
1462+ location ~ ^/lua/(.+)$ {
1463+ content_by_lua_file html/ $1 . lua;
1464+ }
1465+
1466+ location /main {
1467+ echo_location / lua/ a;
1468+ echo_location / lua/ b;
1469+ echo_location / lua/ a;
1470+ echo_location / lua/ a;
1471+ echo_location / lua/ b;
1472+ }
1473+ --- user_files
1474+ >>> a.lua
1475+ ngx.say(" a" )
1476+ >>> b.lua
1477+ ngx.say(" b" )
1478+ --- request
1479+ GET /main
1480+ --- response_body
1481+ a
1482+ b
1483+ a
1484+ a
1485+ b
1486+ --- no_error_log
1487+ [error]
1488+
1489+
1490+
1491+ === TEST 37: variables in header_filter_by_lua_file's file path
1492+ --- config
1493+ location ~ ^/lua/(.+)$ {
1494+ return 200 ;
1495+
1496+ header_filter_by_lua_file html/ $1 . lua;
1497+ }
1498+
1499+ location ~ ^/proxy/(.+)$ {
1500+ proxy_pass http: // 127.0 . 0. 1: $ server_port / lua/ $1 ;
1501+ }
1502+
1503+ location /main {
1504+ content_by_lua_block {
1505+ local res1, res2, res3, res4, res5 = ngx. location. capture_multi{
1506+ { " /proxy/a" },
1507+ { " /proxy/b" },
1508+ { " /proxy/a" },
1509+ { " /proxy/a" },
1510+ { " /proxy/b" },
1511+ }
1512+
1513+ ngx. say (res1. header. match )
1514+ ngx. say (res2. header. match )
1515+ ngx. say (res3. header. match )
1516+ ngx. say (res4. header. match )
1517+ ngx. say (res5. header. match )
1518+ }
1519+ }
1520+ --- user_files
1521+ >>> a.lua
1522+ ngx.header.match = " a"
1523+ >>> b.lua
1524+ ngx.header.match = " b"
1525+ --- request
1526+ GET /main
1527+ --- response_body
1528+ a
1529+ b
1530+ a
1531+ a
1532+ b
1533+ --- no_error_log
1534+ [error]
1535+
1536+
1537+
1538+ === TEST 38: variables in body_filter_by_lua_file's file path
1539+ --- config
1540+ location ~ ^/lua/(.+)$ {
1541+ echo hello;
1542+
1543+ body_filter_by_lua_file html/ $1 . lua;
1544+ }
1545+
1546+ location /main {
1547+ echo_location / lua/ a;
1548+ echo_location / lua/ b;
1549+ echo_location / lua/ a;
1550+ echo_location / lua/ a;
1551+ echo_location / lua/ b;
1552+ }
1553+ --- user_files
1554+ >>> a.lua
1555+ ngx.arg[1] = " a\n"
1556+ ngx.arg[2] = true
1557+ >>> b.lua
1558+ ngx.arg[1] = " b\n"
1559+ ngx.arg[2] = true
1560+ --- request
1561+ GET /main
1562+ --- response_body
1563+ a
1564+ b
1565+ a
1566+ a
1567+ b
1568+ --- no_error_log
1569+ [error]
1570+
1571+
1572+
1573+ === TEST 39: variables in log_by_lua_file's file path
1574+ --- config
1575+ log_subrequest on;
1576+
1577+ location ~ ^/lua/(.+)$ {
1578+ echo hello;
1579+
1580+ log_by_lua_file html/ $1 . lua;
1581+ }
1582+
1583+ location /main {
1584+ echo_location / lua/ a;
1585+ echo_location / lua/ b;
1586+ echo_location / lua/ a;
1587+ echo_location / lua/ a;
1588+ echo_location / lua/ b;
1589+ }
1590+ --- user_files
1591+ >>> a.lua
1592+ ngx.log(ngx.NOTICE, " grep me: a" )
1593+ >>> b.lua
1594+ ngx.log(ngx.NOTICE, " grep me: b" )
1595+ --- request
1596+ GET /main
1597+ --- ignore_response_body
1598+ --- grep_error_log eval: qr/grep me: ([ab])/
1599+ --- grep_error_log_out eval
1600+ [
1601+ " grep me: a
1602+ grep me: b
1603+ grep me: a
1604+ grep me: a
1605+ grep me: b
1606+ " ,
1607+ " grep me: a
1608+ grep me: b
1609+ grep me: a
1610+ grep me: a
1611+ grep me: b
1612+ grep me: a
1613+ grep me: b
1614+ grep me: a
1615+ grep me: a
1616+ grep me: b
1617+ " ]
1618+ --- no_error_log
1619+ [error]
0 commit comments