diff --git a/src/deps/src/lua-nginx-module/t/.gitignore b/src/deps/src/lua-nginx-module/t/.gitignore
deleted file mode 100644
index 317074111..000000000
--- a/src/deps/src/lua-nginx-module/t/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-servroot
-
diff --git a/src/deps/src/lua-nginx-module/t/000--init.t b/src/deps/src/lua-nginx-module/t/000--init.t
deleted file mode 100644
index 0016e1448..000000000
--- a/src/deps/src/lua-nginx-module/t/000--init.t
+++ /dev/null
@@ -1,81 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
-
-our $http_config = <<'_EOC_';
- # lua-resty-string is required for lua-resty-mysql
- lua_package_path "../lua-resty-rsa/lib/?.lua;../lua-resty-mysql/lib/?.lua;../lua-resty-string/lib/?.lua;;";
-_EOC_
-
-no_shuffle();
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: conv_uid - drop table
---- http_config eval: $::http_config
---- config
- location = /init {
- content_by_lua_block {
- local mysql = require "resty.mysql"
- local db = assert(mysql:new())
- local ok, err, errcode, sqlstate = db:connect{
- host = "127.0.0.1",
- port = $TEST_NGINX_MYSQL_PORT,
- database = "ngx_test",
- user = "ngx_test",
- password = "ngx_test",
- charset = "utf8",
- }
-
- local queries = {
- "DROP TABLE IF EXISTS conv_uid",
- "CREATE TABLE conv_uid(id serial primary key, new_uid integer, old_uid integer)",
- "INSERT INTO conv_uid(old_uid,new_uid) VALUES(32,56),(35,78)",
- }
-
- for _, query in ipairs(queries) do
- local ok, err = db:query(query)
- if not ok then
- ngx.say("failed to run mysql query \"", query, "\": ", err)
- return
- end
- end
-
- ngx.say("done!")
- }
- }
---- request
-GET /init
---- response_body
-done!
---- timeout: 10
---- no_error_log
-[error]
-
-
-
-=== TEST 2: flush data from memcached
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
-GET /flush
---- error_code: 200
---- response_body eval
-"OK\r
-"
---- timeout: 10
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/000-sanity.t b/src/deps/src/lua-nginx-module/t/000-sanity.t
deleted file mode 100644
index 87854ef99..000000000
--- a/src/deps/src/lua-nginx-module/t/000-sanity.t
+++ /dev/null
@@ -1,33 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => blocks() * repeat_each() * 2;
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity (integer)
---- config
- location /lua {
- echo 2;
- }
---- request
-GET /lua
---- response_body
-2
-
-
-
-=== TEST 2: sanity (string)
---- config
- location /lua {
- echo "helloworld";
- }
---- request
-GET /lua
---- response_body
-helloworld
diff --git a/src/deps/src/lua-nginx-module/t/001-set.t b/src/deps/src/lua-nginx-module/t/001-set.t
deleted file mode 100644
index 009159e48..000000000
--- a/src/deps/src/lua-nginx-module/t/001-set.t
+++ /dev/null
@@ -1,812 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 5);
-
-#log_level("warn");
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple set (integer)
---- config
- location /lua {
- set_by_lua $res "return 1+1";
- echo $res;
- }
---- request
-GET /lua
---- response_body
-2
---- no_error_log
-[error]
-
-
-
-=== TEST 2: simple set (string)
---- config
- location /lua {
- set_by_lua $res "return 'hello' .. 'world'";
- echo $res;
- }
---- request
-GET /lua
---- response_body
-helloworld
---- no_error_log
-[error]
-
-
-
-=== TEST 3: internal only
---- config
- location /lua {
- set_by_lua $res "local function fib(n) if n > 2 then return fib(n-1)+fib(n-2) else return 1 end end return fib(10)";
- echo $res;
- }
---- request
-GET /lua
---- response_body
-55
---- no_error_log
-[error]
-
-
-
-=== TEST 4: inlined script with arguments
---- config
- location /lua {
- set_by_lua $res "return ngx.arg[1] + ngx.arg[2]" $arg_a $arg_b;
- echo $res;
- }
---- request
-GET /lua?a=1&b=2
---- response_body
-3
---- no_error_log
-[error]
-
-
-
-=== TEST 5: fib by arg
---- config
- location /fib {
- set_by_lua $res "local function fib(n) if n > 2 then return fib(n-1)+fib(n-2) else return 1 end end return fib(tonumber(ngx.arg[1]))" $arg_n;
- echo $res;
- }
---- request
-GET /fib?n=10
---- response_body
-55
---- no_error_log
-[error]
-
-
-
-=== TEST 6: adder
---- config
- location = /adder {
- set_by_lua $res
- "local a = tonumber(ngx.arg[1])
- local b = tonumber(ngx.arg[2])
- return a + b" $arg_a $arg_b;
-
- echo $res;
- }
---- request
-GET /adder?a=25&b=75
---- response_body
-100
---- no_error_log
-[error]
-
-
-
-=== TEST 7: read nginx variables directly from within Lua
---- config
- location = /set-both {
- set $b 32;
- set_by_lua $a "return tonumber(ngx.var.b) + 1";
-
- echo "a = $a";
- }
---- request
-GET /set-both
---- response_body
-a = 33
---- no_error_log
-[error]
-
-
-
-=== TEST 8: set nginx variables directly from within Lua
---- config
- location = /set-both {
- set $b "";
- set_by_lua $a "ngx.var.b = 32; return 7";
-
- echo "a = $a";
- echo "b = $b";
- }
---- request
-GET /set-both
---- response_body
-a = 7
-b = 32
---- no_error_log
-[error]
-
-
-
-=== TEST 9: set non-existent nginx variables
---- config
- location = /set-both {
- #set $b "";
- set_by_lua $a "ngx.var.b = 32; return 7";
-
- echo "a = $a";
- }
---- request
-GET /set-both
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-variable "b" not found for writing; maybe it is a built-in variable that is not changeable or you forgot to use "set $b '';" in the config file to define it first
-
-
-
-=== TEST 10: set quote sql str
---- config
- location = /set {
- set $a "";
- set_by_lua $a "return ngx.quote_sql_str(ngx.var.a)";
- echo $a;
- }
---- request
-GET /set
---- response_body
-''
---- no_error_log
-[error]
-
-
-
-=== TEST 11: set md5
---- config
- location = /md5 {
- set_by_lua $a 'return ngx.md5("hello")';
- echo $a;
- }
---- request
-GET /md5
---- response_body
-5d41402abc4b2a76b9719d911017c592
---- no_error_log
-[error]
-
-
-
-=== TEST 12: no ngx.print
---- config
- location /lua {
- set_by_lua $res "ngx.print(32) return 1";
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 13: no ngx.say
---- config
- location /lua {
- set_by_lua $res "ngx.say(32) return 1";
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 14: no ngx.flush
---- config
- location /lua {
- set_by_lua $res "ngx.flush()";
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 15: no ngx.eof
---- config
- location /lua {
- set_by_lua $res "ngx.eof()";
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 16: no ngx.send_headers
---- config
- location /lua {
- set_by_lua $res "ngx.send_headers()";
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 17: no ngx.location.capture
---- config
- location /lua {
- set_by_lua $res 'ngx.location.capture("/sub")';
- echo $res;
- }
-
- location /sub {
- echo sub;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 18: no ngx.location.capture_multi
---- config
- location /lua {
- set_by_lua $res 'ngx.location.capture_multi{{"/sub"}}';
- echo $res;
- }
-
- location /sub {
- echo sub;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 19: no ngx.exit
---- config
- location /lua {
- set_by_lua $res 'ngx.exit(0)';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 20: no ngx.redirect
---- config
- location /lua {
- set_by_lua $res 'ngx.redirect("/blah")';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 21: no ngx.exec
---- config
- location /lua {
- set_by_lua $res 'ngx.exec("/blah")';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 22: no ngx.req.set_uri(uri, true)
---- config
- location /lua {
- set_by_lua $res 'ngx.req.set_uri("/blah", true)';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 23: ngx.req.set_uri(uri) exists
---- config
- location /lua {
- set_by_lua $res 'ngx.req.set_uri("/blah") return 1';
- echo $uri;
- }
---- request
-GET /lua
---- response_body
-/blah
---- no_error_log
-[error]
-
-
-
-=== TEST 24: no ngx.req.read_body()
---- config
- location /lua {
- set_by_lua $res 'ngx.req.read_body()';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/(?:API disabled in the context of set_by_lua\*|http3 requests are not supported without content-length header)/ms
-
-
-
-=== TEST 25: no ngx.req.socket()
---- config
- location /lua {
- set_by_lua $res 'return ngx.req.socket()';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-my $err_log;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $err_log = "http v3 not supported yet";
-} else {
- $err_log = "API disabled in the context of set_by_lua*";
-}
-
-$err_log;
-
-
-
-=== TEST 26: no ngx.socket.tcp()
---- config
- location /lua {
- set_by_lua $res 'return ngx.socket.tcp()';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 27: no ngx.socket.connect()
---- config
- location /lua {
- set_by_lua $res 'return ngx.socket.connect("127.0.0.1", 80)';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-API disabled in the context of set_by_lua*
-
-
-
-=== TEST 28: set $limit_rate (variables with set_handler)
---- config
- location /lua {
- set $limit_rate 1000;
- rewrite_by_lua '
- ngx.var.limit_rate = 180;
- ';
- echo "limit rate = $limit_rate";
- }
---- request
- GET /lua
---- response_body
-limit rate = 180
---- no_error_log
-[error]
-
-
-
-=== TEST 29: set $args and read $query_string
---- config
- location /lua {
- set $args 'hello';
- rewrite_by_lua '
- ngx.var.args = "world";
- ';
- echo $query_string;
- }
---- request
- GET /lua
---- response_body
-world
---- no_error_log
-[error]
-
-
-
-=== TEST 30: set $arg_xxx
---- config
- location /lua {
- rewrite_by_lua '
- ngx.var.arg_foo = "world";
- ';
- echo $arg_foo;
- }
---- request
- GET /lua?foo=3
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-variable "arg_foo" not found for writing; maybe it is a built-in variable that is not changeable or you forgot to use "set $arg_foo '';" in the config file to define it first
-
-
-
-=== TEST 31: symbol $ in lua code of set_by_lua
---- config
- location /lua {
- set_by_lua $res 'return "$unknown"';
- echo $res;
- }
---- request
- GET /lua
---- response_body
-$unknown
---- no_error_log
-[error]
-
-
-
-=== TEST 32: symbol $ in lua code of set_by_lua_file
---- config
- location /lua {
- set_by_lua_file $res html/a.lua;
- echo $res;
- }
---- user_files
->>> a.lua
-return "$unknown"
---- request
- GET /lua
---- response_body
-$unknown
---- no_error_log
-[error]
-
-
-
-=== TEST 33: external script files with arguments
---- config
- location /lua {
- set_by_lua_file $res html/a.lua $arg_a $arg_b;
- echo $res;
- }
---- user_files
->>> a.lua
-return ngx.arg[1] + ngx.arg[2]
---- request
-GET /lua?a=5&b=2
---- response_body
-7
---- no_error_log
-[error]
-
-
-
-=== TEST 34: variables in set_by_lua_file's file path
---- config
- location /lua {
- set $path "html/a.lua";
- set_by_lua_file $res $path $arg_a $arg_b;
- echo $res;
- }
---- user_files
->>> a.lua
-return ngx.arg[1] + ngx.arg[2]
---- request
-GET /lua?a=5&b=2
---- response_body
-7
---- no_error_log
-[error]
-
-
-
-=== TEST 35: lua error (string)
---- config
- location /lua {
- set_by_lua $res 'error("Bad")';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-failed to run set_by_lua*: set_by_lua(nginx.conf:40):1: Bad
-
-
-
-=== TEST 36: lua error (nil)
---- config
- location /lua {
- set_by_lua $res 'error(nil)';
- echo $res;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-failed to run set_by_lua*: unknown reason
-
-
-
-=== TEST 37: globals are shared in all requests.
---- config
- location /lua {
- set_by_lua_block $res {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.INFO, "old foo: ", foo)
- foo = foo + 1
- end
- return foo
- }
- echo $res;
- }
---- request
-GET /lua
---- response_body_like chomp
-\A[12]
-\z
---- no_error_log
-[error]
---- grep_error_log eval: qr/(old foo: \d+|writing a global Lua variable \('\w+'\))/
---- grep_error_log_out eval
-["writing a global Lua variable \('foo'\)\n", "old foo: 1\n"]
-
-
-
-=== TEST 38: user modules using ngx.arg
---- http_config
- lua_package_path "$prefix/html/?.lua;;";
---- config
- location /lua {
- set_by_lua $res 'local foo = require "foo" return foo.go()' $arg_a $arg_b;
- echo $res;
- }
---- user_files
->>> foo.lua
-module("foo", package.seeall)
-
-function go()
- return ngx.arg[1] + ngx.arg[2]
-end
---- request
-GET /lua?a=1&b=2
---- response_body
-3
---- no_error_log
-[error]
-
-
-
-=== TEST 39: server scope (inline)
---- config
- location /lua {
- set $a "[$res]";
- echo $a;
- }
- set_by_lua $res "return 1+1";
---- request
-GET /lua
---- response_body
-[2]
---- no_error_log
-[error]
-
-
-
-=== TEST 40: server if scope (inline)
---- config
- location /lua {
- set $a "[$res]";
- echo $a;
- }
- if ($arg_name = "jim") {
- set_by_lua $res "return 1+1";
- }
---- request
-GET /lua?name=jim
---- response_body
-[2]
---- no_error_log
-[error]
-
-
-
-=== TEST 41: location if scope (inline)
---- config
- location /lua {
- if ($arg_name = "jim") {
- set_by_lua $res "return 1+1";
- set $a "[$res]";
- echo $a;
- }
- }
---- request
-GET /lua?name=jim
---- response_body
-[2]
---- no_error_log
-[error]
-
-
-
-=== TEST 42: server scope (file)
---- config
- location /lua {
- set $a "[$res]";
- echo $a;
- }
- set_by_lua_file $res html/a.lua;
---- user_files
->>> a.lua
-return 1+1
---- request
-GET /lua
---- response_body
-[2]
---- no_error_log
-[error]
-
-
-
-=== TEST 43: server if scope (file)
---- config
- location /lua {
- set $a "[$res]";
- echo $a;
- }
- if ($arg_name = "jim") {
- set_by_lua_file $res html/a.lua;
- }
---- request
-GET /lua?name=jim
---- user_files
->>> a.lua
-return 1+1
---- response_body
-[2]
---- no_error_log
-[error]
-
-
-
-=== TEST 44: location if scope (file)
---- config
- location /lua {
- if ($arg_name = "jim") {
- set_by_lua_file $res html/a.lua;
- set $a "[$res]";
- echo $a;
- }
- }
---- user_files
->>> a.lua
-return 1+1
---- request
-GET /lua?name=jim
---- response_body
-[2]
---- no_error_log
-[error]
-
-
-
-=== TEST 45: backtrace
---- config
- location /t {
- set_by_lua $a '
- local bar
- local foo
- function foo()
- bar()
- end
-
- function bar()
- error("something bad happened")
- end
-
- foo()
- ';
- echo ok;
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-something bad happened
-stack traceback:
-in function 'error'
-in function 'bar'
-in function 'foo'
-
-
-
-=== TEST 46: Lua file does not exist
---- config
- location /lua {
- set_by_lua_file $a html/test2.lua;
- }
---- user_files
->>> test.lua
-v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/failed to load external Lua file ".*?test2\.lua": cannot open .*? No such file or directory/
diff --git a/src/deps/src/lua-nginx-module/t/002-content.t b/src/deps/src/lua-nginx-module/t/002-content.t
deleted file mode 100644
index eb9d587f8..000000000
--- a/src/deps/src/lua-nginx-module/t/002-content.t
+++ /dev/null
@@ -1,1122 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2 + 32);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: basic print
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- content_by_lua '
- local ok, err = ngx.print("Hello, Lua!\\n")
- if not ok then
- ngx.log(ngx.ERR, "print failed: ", err)
- end
- ';
- }
---- request
-GET /lua
---- response_body
-Hello, Lua!
---- no_error_log
-[error]
---- grep_error_log eval: qr/lua caching unused lua thread|lua reusing cached lua thread/
---- grep_error_log_out eval
-[
- "lua caching unused lua thread\n",
- "lua reusing cached lua thread
-lua caching unused lua thread
-",
-]
-
-
-
-=== TEST 2: basic say
---- config
- location /say {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- content_by_lua '
- local ok, err = ngx.say("Hello, Lua!")
- if not ok then
- ngx.log(ngx.ERR, "say failed: ", err)
- return
- end
- local ok, err = ngx.say("Yay! ", 123)
- if not ok then
- ngx.log(ngx.ERR, "say failed: ", err)
- return
- end
- ';
- }
---- request
-GET /say
---- response_body
-Hello, Lua!
-Yay! 123
---- no_error_log
-[error]
-
-
-
-=== TEST 3: no ngx.echo
---- config
- location /lua {
- content_by_lua 'ngx.echo("Hello, Lua!\\n")';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/content_by_lua\(nginx\.conf:\d+\):1: attempt to call field 'echo' \(a nil value\)/
-
-
-
-=== TEST 4: variable
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- content_by_lua 'local v = ngx.var["request_uri"] ngx.print("request_uri: ", v, "\\n")';
- }
---- request
-GET /lua?a=1&b=2
---- response_body
-request_uri: /lua?a=1&b=2
-
-
-
-=== TEST 5: variable (file)
---- config
- location /lua {
- content_by_lua_file html/test.lua;
- }
---- user_files
->>> test.lua
-local v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- response_body
-request_uri: /lua?a=1&b=2
-
-
-
-=== TEST 6: calc expression
---- config
- location /lua {
- content_by_lua_file html/calc.lua;
- }
---- user_files
->>> calc.lua
-local function uri_unescape(uri)
- local function convert(hex)
- return string.char(tonumber("0x"..hex))
- end
- local s = string.gsub(uri, "%%([0-9a-fA-F][0-9a-fA-F])", convert)
- return s
-end
-
-local function eval_exp(str)
- return loadstring("return "..str)()
-end
-
-local exp_str = ngx.var["arg_exp"]
--- print("exp: '", exp_str, "'\n")
-local status, res
-status, res = pcall(uri_unescape, exp_str)
-if not status then
- ngx.print("error: ", res, "\n")
- return
-end
-status, res = pcall(eval_exp, res)
-if status then
- ngx.print("result: ", res, "\n")
-else
- ngx.print("error: ", res, "\n")
-end
---- request
-GET /lua?exp=1%2B2*math.sin(3)%2Fmath.exp(4)-math.sqrt(2)
---- response_body
-result: -0.4090441561579
-
-
-
-=== TEST 7: read $arg_xxx
---- config
- location = /lua {
- content_by_lua 'local who = ngx.var.arg_who
- ngx.print("Hello, ", who, "!")';
- }
---- request
-GET /lua?who=agentzh
---- response_body chomp
-Hello, agentzh!
-
-
-
-=== TEST 8: capture location
---- config
- location /other {
- echo "hello, world";
- }
-
- location /lua {
- content_by_lua 'local res = ngx.location.capture("/other"); ngx.print("status=", res.status, " "); ngx.print("body=", res.body)';
- }
---- request
-GET /lua
---- response_body
-status=200 body=hello, world
-
-
-
-ei= TEST 9: capture non-existed location
---- config
- location /lua {
- content_by_lua 'local res = ngx.location.capture("/other"); ngx.print("status=", res.status)';
- }
---- request
-GET /lua
---- response_body: status=404
-
-
-
-=== TEST 9: invalid capture location (not as expected...)
---- config
- location /lua {
- content_by_lua 'local res = ngx.location.capture("*(#*"); ngx.say("res=", res.status)';
- }
---- request
-GET /lua
---- response_body
-res=404
-
-
-
-=== TEST 10: nil is "nil"
---- config
- location /lua {
- content_by_lua 'ngx.say(nil)';
- }
---- request
-GET /lua
---- response_body
-nil
-
-
-
-=== TEST 11: write boolean
---- config
- location /lua {
- content_by_lua 'ngx.say(true, " ", false)';
- }
---- request
-GET /lua
---- response_body
-true false
-
-
-
-=== TEST 12: bad argument type to ngx.location.capture
---- config
- location /lua {
- content_by_lua 'ngx.location.capture(nil)';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 13: capture location (default 0);
---- config
- location /recur {
- content_by_lua '
- local num = tonumber(ngx.var.arg_num) or 0;
- ngx.print("num is: ", num, "\\n");
-
- if (num > 0) then
- local res = ngx.location.capture("/recur?num="..tostring(num - 1));
- ngx.print("status=", res.status, " ");
- ngx.print("body=", res.body, "\\n");
- else
- ngx.print("end\\n");
- end
- ';
- }
---- request
-GET /recur
---- response_body
-num is: 0
-end
-
-
-
-=== TEST 14: capture location
---- config
- location /recur {
- content_by_lua '
- local num = tonumber(ngx.var.arg_num) or 0;
- ngx.print("num is: ", num, "\\n");
-
- if (num > 0) then
- local res = ngx.location.capture("/recur?num="..tostring(num - 1));
- ngx.print("status=", res.status, " ");
- ngx.print("body=", res.body);
- else
- ngx.print("end\\n");
- end
- ';
- }
---- request
-GET /recur?num=3
---- response_body
-num is: 3
-status=200 body=num is: 2
-status=200 body=num is: 1
-status=200 body=num is: 0
-end
-
-
-
-=== TEST 15: setting nginx variables from within Lua
---- config
- location /set {
- set $a "";
- content_by_lua 'ngx.var.a = 32; ngx.say(ngx.var.a)';
- add_header Foo $a;
- }
---- request
-GET /set
---- response_headers
-Foo: 32
---- response_body
-32
-
-
-
-=== TEST 16: nginx quote sql string 1
---- config
- location /set {
- set $a 'hello\n\r\'"\\';
- content_by_lua 'ngx.say(ngx.quote_sql_str(ngx.var.a))';
- }
---- request
-GET /set
---- response_body
-'hello\n\r\'\"\\'
-
-
-
-=== TEST 17: nginx quote sql string 2
---- config
-location /set {
- set $a "hello\n\r'\"\\";
- content_by_lua 'ngx.say(ngx.quote_sql_str(ngx.var.a))';
-}
---- request
-GET /set
---- response_body
-'hello\n\r\'\"\\'
-
-
-
-=== TEST 18: use dollar
---- config
-location /set {
- content_by_lua '
- local s = "hello 112";
- ngx.say(string.find(s, "%d+$"))';
-}
---- request
-GET /set
---- response_body
-79
-
-
-
-=== TEST 19: subrequests do not share variables of main requests by default
---- config
-location /sub {
- echo $a;
-}
-location /parent {
- set $a 12;
- content_by_lua 'local res = ngx.location.capture("/sub"); ngx.print(res.body)';
-}
---- request
-GET /parent
---- response_body eval: "\n"
-
-
-
-=== TEST 20: subrequests can share variables of main requests
---- config
-location /sub {
- echo $a;
-}
-location /parent {
- set $a 12;
- content_by_lua '
- local res = ngx.location.capture(
- "/sub",
- { share_all_vars = true }
- );
- ngx.print(res.body)
- ';
-}
---- request
-GET /parent
---- response_body
-12
-
-
-
-=== TEST 21: main requests use subrequests' variables
---- config
-location /sub {
- set $a 12;
-}
-location /parent {
- content_by_lua '
- local res = ngx.location.capture("/sub", { share_all_vars = true });
- ngx.say(ngx.var.a)
- ';
-}
---- request
-GET /parent
---- response_body
-12
-
-
-
-=== TEST 22: main requests do NOT use subrequests' variables
---- config
-location /sub {
- set $a 12;
-}
-location /parent {
- content_by_lua '
- local res = ngx.location.capture("/sub", { share_all_vars = false });
- ngx.say(ngx.var.a)
- ';
-}
---- request
-GET /parent
---- response_body_like eval: "\n"
-
-
-
-=== TEST 23: capture location headers
---- config
- location /other {
- default_type 'foo/bar';
- echo "hello, world";
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", res.header["Content-Type"]);
- ';
- }
---- request
-GET /lua
---- response_body
-type: foo/bar
-
-
-
-=== TEST 24: capture location multi-value headers
---- config
- location /other {
- #echo "hello, world";
- content_by_lua '
- ngx.header["Set-Cookie"] = {"a", "hello, world", "foo"}
- local ok, err = ngx.eof()
- if not ok then
- ngx.log(ngx.ERR, "eof failed: ", err)
- return
- end
- ';
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", type(res.header["Set-Cookie"]));
- ngx.say("len: ", #res.header["Set-Cookie"]);
- ngx.say("value: ", table.concat(res.header["Set-Cookie"], "|"))
- ';
- }
---- request
-GET /lua
---- response_body
-type: table
-len: 3
-value: a|hello, world|foo
---- no_error_log
-[error]
-
-
-
-=== TEST 25: capture location headers
---- config
- location /other {
- default_type 'foo/bar';
- content_by_lua '
- ngx.header.Bar = "Bah";
- ';
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", res.header["Content-Type"]);
- ngx.say("Bar: ", res.header["Bar"]);
- ';
- }
---- request
-GET /lua
---- response_body
-type: foo/bar
-Bar: Bah
-
-
-
-=== TEST 26: capture location headers
---- config
- location /other {
- default_type 'foo/bar';
- content_by_lua '
- ngx.header.Bar = "Bah";
- ngx.header.Bar = nil;
- ';
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", res.header["Content-Type"]);
- ngx.say("Bar: ", res.header["Bar"] or "nil");
- ';
- }
---- request
-GET /lua
---- response_body
-type: foo/bar
-Bar: nil
-
-
-
-=== TEST 27: HTTP 1.0 response
---- config
- location /lua {
- content_by_lua '
- local data = "hello, world"
- -- ngx.header["Content-Length"] = #data
- -- ngx.header.content_length = #data
- ngx.print(data)
- ';
- }
- location /main {
- proxy_pass http://127.0.0.1:$server_port/lua;
- }
---- request
-GET /main
---- response_headers
-Content-Length: 12
---- response_body chop
-hello, world
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 28: multiple eof
---- config
- location /lua {
- content_by_lua '
- ngx.say("Hi")
-
- local ok, err = ngx.eof()
- if not ok then
- ngx.log(ngx.WARN, "eof failed: ", err)
- return
- end
-
- ok, err = ngx.eof()
- if not ok then
- ngx.log(ngx.WARN, "eof failed: ", err)
- return
- end
-
- ';
- }
---- request
-GET /lua
---- response_body
-Hi
---- no_error_log
-[error]
---- error_log
-eof failed: seen eof
-
-
-
-=== TEST 29: nginx vars in script path
---- config
- location ~ ^/lua/(.+)$ {
- content_by_lua_file html/$1.lua;
- }
---- user_files
->>> calc.lua
-local a,b = ngx.var.arg_a, ngx.var.arg_b
-ngx.say(a+b)
---- request
-GET /lua/calc?a=19&b=81
---- response_body
-100
-
-
-
-=== TEST 30: nginx vars in script path
---- config
- location ~ ^/lua/(.+)$ {
- content_by_lua_file html/$1.lua;
- }
- location /main {
- echo_location /lua/sum a=3&b=2;
- echo_location /lua/diff a=3&b=2;
- }
---- user_files
->>> sum.lua
-local a,b = ngx.var.arg_a, ngx.var.arg_b
-ngx.say(a+b)
->>> diff.lua
-local a,b = ngx.var.arg_a, ngx.var.arg_b
-ngx.say(a-b)
---- request
-GET /main
---- response_body
-5
-1
-
-
-
-=== TEST 31: basic print (HEAD + HTTP 1.1)
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- content_by_lua 'ngx.print("Hello, Lua!\\n")';
- }
---- request
-HEAD /lua
---- response_body
-
-
-
-=== TEST 32: basic print (HEAD + HTTP 1.0)
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- content_by_lua '
- ngx.print("Hello, Lua!\\n")
- ';
- }
---- request
-HEAD /lua HTTP/1.0
---- response_headers
-!Content-Length
---- response_body
-
-
-
-=== TEST 33: headers_sent & HEAD
---- config
- location /lua {
- content_by_lua '
- ngx.say(ngx.headers_sent)
- local ok, err = ngx.flush()
- if not ok then
- ngx.log(ngx.WARN, "failed to flush: ", err)
- return
- end
- ngx.say(ngx.headers_sent)
- ';
- }
---- request
-HEAD /lua
---- response_body
---- no_error_log
-[error]
---- error_log
-failed to flush: header only
-
-
-
-=== TEST 34: HEAD & ngx.say
---- config
- location /lua {
- content_by_lua '
- ngx.send_headers()
- local ok, err = ngx.say(ngx.headers_sent)
- if not ok then
- ngx.log(ngx.WARN, "failed to say: ", err)
- return
- end
- ';
- }
---- request
-HEAD /lua
---- response_body
---- no_error_log
-[error]
---- error_log
-failed to say: header only
-
-
-
-=== TEST 35: ngx.eof before ngx.say
---- config
- location /lua {
- content_by_lua '
- local ok, err = ngx.eof()
- if not ok then
- ngx.log(ngx.ERR, "eof failed: ", err)
- return
- end
-
- ok, err = ngx.say(ngx.headers_sent)
- if not ok then
- ngx.log(ngx.WARN, "failed to say: ", err)
- return
- end
- ';
- }
---- request
-GET /lua
---- response_body
---- no_error_log
-[error]
---- error_log
-failed to say: seen eof
-
-
-
-=== TEST 36: headers_sent + GET
---- config
- location /lua {
- content_by_lua '
- -- print("headers sent: ", ngx.headers_sent)
- ngx.say(ngx.headers_sent)
- ngx.say(ngx.headers_sent)
- -- ngx.flush()
- ngx.say(ngx.headers_sent)
- ';
- }
---- request
-GET /lua
---- response_body
-false
-true
-true
-
-
-
-=== TEST 37: HTTP 1.0 response with Content-Length
---- config
- location /lua {
- content_by_lua '
- local data = "hello,\\nworld\\n"
- ngx.header["Content-Length"] = #data
- ngx.say("hello,")
- ngx.flush()
- -- ngx.location.capture("/sleep")
- ngx.say("world")
- ';
- }
- location /sleep {
- echo_sleep 2;
- }
- location /main {
- proxy_pass http://127.0.0.1:$server_port/lua;
- }
---- request
-GET /main
---- response_headers
-Content-Length: 13
---- response_body
-hello,
-world
---- timeout: 5
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 38: ngx.print table arguments (github issue #54)
---- config
- location /t {
- content_by_lua 'ngx.print({10, {0, 5}, 15}, 32)';
- }
---- request
- GET /t
---- response_body chop
-10051532
-
-
-
-=== TEST 39: ngx.say table arguments (github issue #54)
---- config
- location /t {
- content_by_lua 'ngx.say({10, {0, "5"}, 15}, 32)';
- }
---- request
- GET /t
---- response_body
-10051532
-
-
-
-=== TEST 40: Lua file does not exist
---- config
- location /lua {
- content_by_lua_file html/test2.lua;
- }
---- user_files
->>> test.lua
-local v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- response_body_like: 404 Not Found
---- error_code: 404
---- error_log eval
-qr/failed to load external Lua file ".*?test2\.lua": cannot open .*? No such file or directory/
-
-
-
-=== TEST 41: .lua file with shebang
---- config
- location /lua {
- content_by_lua_file html/test.lua;
- }
---- user_files
->>> test.lua
-#!/bin/lua
-
-ngx.say("line ", debug.getinfo(1).currentline)
---- request
-GET /lua?a=1&b=2
---- response_body
-line 3
---- no_error_log
-[error]
-
-
-
-=== TEST 42: syntax error in inlined Lua code
---- config
- location /lua {
- content_by_lua 'for end';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/failed to load inlined Lua code: content_by_lua\(nginx.conf:40\)/
-
-
-
-=== TEST 43: syntax error in content_by_lua_block
---- config
- location /lua {
-
- content_by_lua_block {
- 'for end';
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/failed to load inlined Lua code: content_by_lua\(nginx.conf:41\)/
-
-
-
-=== TEST 44: syntax error in second content_by_lua_block
---- config
- location /foo {
- content_by_lua_block {
- 'for end';
- }
- }
-
- location /lua {
- content_by_lua_block {
- 'for end';
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/failed to load inlined Lua code: content_by_lua\(nginx.conf:46\)/
-
-
-
-=== TEST 45: syntax error in thrid content_by_lua_block
---- config
- location /foo {
- content_by_lua_block {
- 'for end';
- }
- }
-
- location /bar {
- content_by_lua_block {
- 'for end';
- }
- }
-
- location /lua {
- content_by_lua_block {
- 'for end';
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/failed to load inlined Lua code: content_by_lua\(nginx.conf:52\)/
-
-
-
-=== TEST 46: syntax error in included file
---- config
- location /foo {
- content_by_lua_block {
- 'for end';
- }
- }
-
- location /bar {
- content_by_lua_block {
- 'for end';
- }
- }
-
- include ../html/lua.conf;
---- user_files
->>> lua.conf
- location /lua {
- content_by_lua_block {
- 'for end';
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-failed to load inlined Lua code: content_by_lua(../html/lua.conf:2):2: unexpected symbol near ''for end''
-
-
-
-=== TEST 47: syntax error with very long filename
---- config
- location /foo {
- content_by_lua_block {
- 'for end';
- }
- }
-
- location /bar {
- content_by_lua_block {
- 'for end';
- }
- }
-
- include ../html/1234567890123456789012345678901234.conf;
---- user_files
->>> 1234567890123456789012345678901234.conf
- location /lua {
- content_by_lua_block {
- 'for end';
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-failed to load inlined Lua code: content_by_lua(...234567890123456789012345678901234.conf:2)
-
-
-
-=== TEST 48: syntax error in /tmp/lua.conf
---- config
- location /foo {
- content_by_lua_block {
- 'for end';
- }
- }
-
- location /bar {
- content_by_lua_block {
- 'for end';
- }
- }
-
- include /tmp/lua.conf;
---- user_files
->>> /tmp/lua.conf
- location /lua {
- content_by_lua_block {
- 'for end';
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-failed to load inlined Lua code: content_by_lua(/tmp/lua.conf:2)
-
-
-
-=== TEST 49: syntax error in /tmp/12345678901234567890123456789012345.conf
---- config
- location /foo {
- content_by_lua_block {
- 'for end';
- }
- }
-
- location /bar {
- content_by_lua_block {
- 'for end';
- }
- }
-
- include /tmp/12345678901234567890123456789012345.conf;
-
---- user_files
->>> /tmp/12345678901234567890123456789012345.conf
- location /lua {
- content_by_lua_block {
- 'for end';
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-failed to load inlined Lua code: content_by_lua(...345678901234567890123456789012345.conf:2)
-
-
-
-=== TEST 50: the error line number greater than 9
---- config
- location /foo {
- content_by_lua_block {
- 'for end';
- }
- }
-
- location /bar {
- content_by_lua_block {
- 'for end';
- }
- }
-
- include /tmp/12345678901234567890123456789012345.conf;
-
---- user_files
->>> /tmp/12345678901234567890123456789012345.conf
- location /lua {
-
-
-
-
-
-
-
-
-
-
-
-
- content_by_lua_block {
- 'for end';
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-failed to load inlined Lua code: content_by_lua(...45678901234567890123456789012345.conf:14)
-
-
-
-=== TEST 51: Lua file permission denied
---- config
- location /lua {
- content_by_lua_file /etc/shadow;
- }
---- request
-GET /lua
---- response_body_like: 503 Service Temporarily Unavailable
---- error_code: 503
-
-
-
-=== TEST 52: send_header trigger filter finalize does not clear the ctx
---- config
- location /lua {
- content_by_lua_block {
- ngx.header["Last-Modified"] = ngx.http_time(ngx.time())
- ngx.send_headers()
- local phase = ngx.get_phase()
- }
- header_filter_by_lua_block {
- ngx.header["X-Hello-World"] = "Hello World"
- }
- }
---- request
-GET /lua
---- more_headers
-If-Unmodified-Since: Wed, 01 Jan 2020 07:28:00 GMT
---- error_code: 412
---- no_error_log
-unknown phase: 0
diff --git a/src/deps/src/lua-nginx-module/t/003-errors.t b/src/deps/src/lua-nginx-module/t/003-errors.t
deleted file mode 100644
index ad3a506da..000000000
--- a/src/deps/src/lua-nginx-module/t/003-errors.t
+++ /dev/null
@@ -1,128 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(1);
-
-plan tests => blocks() * repeat_each() * 2;
-
-#$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
-
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: syntax error in lua code chunk
---- config
- location /lua {
- set_by_lua $res "local a
- a = a+;
- return a";
- echo $res;
- }
---- request
-GET /lua
---- error_code: 500
---- response_body_like: 500 Internal Server Error
-
-
-
-=== TEST 2: syntax error in lua file
---- config
- location /lua {
- set_by_lua_file $res 'html/test.lua';
- echo $res;
- }
---- user_files
->>> test.lua
-local a
-a = 3 +;
-return a
---- request
-GET /lua
---- error_code: 500
---- response_body_like: 500 Internal Server Error
-
-
-
-=== TEST 3: syntax error in lua file (from Guang Feng)
---- config
- location /lua {
- set $res '[{"a":32},{"b":64}]';
- #set $res '[{"friend_userid":1750146},{"friend_userid":1750150},{"friend_userid":1750153},{"friend_userid":1750166},{"friend_userid":1750181},{"friend_userid":1750186},{"friend_userid":1750195},{"friend_userid":1750232}]';
- set_by_lua_file $list 'html/test.lua' $res;
- #set_by_lua_file $list 'html/feed.lua' $res;
- echo $list;
- }
---- user_files
->>> test.lua
--- local j = require('json')
-local p = ngx.arg[1]
-return p
->>> feed.lua
-local s = require("json")
-local function explode(d,p)
- local t, ll
- t={}
- ll=0
- if(#p == 1) then return p end
- while true do
- l=string.find(p,d,ll+1,true)
- if l~=nil then
- table.insert(t, string.sub(p,ll,l-1))
- ll=l+1
- else
- table.insert(t, string.sub(p,ll))
- break
- end
- end
-return t
- end
-
-local a = explode(',', string.sub(ngx.arg[1], 2, -1))
-local x = {}
-for i,v in ipairs(a) do table.insert(x,s.decode(v).friend_userid) end
-return table.concat(x,',')
---- request
-GET /lua
---- response_body
-[{"a":32},{"b":64}]
-
-
-
-=== TEST 4: 500 in subrequest
---- config
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/err")
- ngx.say(res.status);
- ';
- }
- location /err {
- return 500;
- }
---- request
-GET /main
---- response_body
-500
-
-
-
-=== TEST 5: drizzle_pass 500 in subrequest
---- config
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/err")
- ngx.say(res.status);
- ';
- }
- location /err {
- set $back 'blah-blah';
- drizzle_pass $back;
- }
---- request
-GET /main
---- response_body
-500
diff --git a/src/deps/src/lua-nginx-module/t/004-require.t b/src/deps/src/lua-nginx-module/t/004-require.t
deleted file mode 100644
index 17e1d57c9..000000000
--- a/src/deps/src/lua-nginx-module/t/004-require.t
+++ /dev/null
@@ -1,211 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#log_level('warn');
-
-#master_on();
-#repeat_each(120);
-repeat_each(2);
-
-plan tests => blocks() * repeat_each() * 2;
-
-our $HtmlDir = html_dir;
-#warn $html_dir;
-
-#$ENV{LUA_PATH} = "$html_dir/?.lua";
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /main {
- echo_location /load;
- echo_location /check;
- echo_location /check;
- }
-
- location /load {
- content_by_lua '
- package.loaded.foo = nil;
- collectgarbage()
- local foo = require "foo";
- foo.hi()
- ';
- }
-
- location /check {
- content_by_lua '
- local foo = package.loaded.foo
- if foo then
- ngx.say("found")
- foo.hi()
- else
- ngx.say("not found")
- end
- ';
- }
---- request
-GET /main
---- user_files
->>> foo.lua
-module(..., package.seeall);
-
-ngx.say("loading");
-
-function hi ()
- ngx.say("hello, foo")
-end;
---- response_body
-loading
-hello, foo
-found
-hello, foo
-found
-hello, foo
-
-
-
-=== TEST 2: sanity
---- http_config eval
- "lua_package_cpath '$::HtmlDir/?.so';"
---- config
- location /main {
- content_by_lua '
- ngx.print(package.cpath);
- ';
- }
---- request
-GET /main
---- user_files
---- response_body_like: ^[^;]+/servroot(_\d+)?/html/\?\.so$
-
-
-
-=== TEST 3: expand default path (after)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;;';"
---- config
- location /main {
- content_by_lua '
- ngx.print(package.path);
- ';
- }
---- request
-GET /main
---- response_body_like: ^[^;]+/servroot(_\d+)?/html/\?\.lua;(.+\.lua)?;*$
-
-
-
-=== TEST 4: expand default cpath (after)
---- http_config eval
- "lua_package_cpath '$::HtmlDir/?.so;;';"
---- config
- location /main {
- content_by_lua '
- ngx.print(package.cpath);
- ';
- }
---- request
-GET /main
---- response_body_like: ^[^;]+/servroot(_\d+)?/html/\?\.so;(.+\.so)?;*$
-
-
-
-=== TEST 5: expand default path (before)
---- http_config eval
- "lua_package_path ';;$::HtmlDir/?.lua';"
---- config
- location /main {
- content_by_lua '
- ngx.print(package.path);
- ';
- }
---- request
-GET /main
---- response_body_like: ^(.+\.lua)?;*?[^;]+/servroot(_\d+)?/html/\?\.lua$
-
-
-
-=== TEST 6: expand default cpath (before)
---- http_config eval
- "lua_package_cpath ';;$::HtmlDir/?.so';"
---- config
- location /main {
- content_by_lua '
- ngx.print(package.cpath);
- ';
- }
---- request
-GET /main
---- response_body_like: ^(.+\.so)?;*?[^;]+/servroot(_\d+)?/html/\?\.so$
-
-
-
-=== TEST 7: require "ngx" (content_by_lua)
---- config
- location /ngx {
- content_by_lua '
- local ngx = require "ngx"
- ngx.say("hello, world")
- ';
- }
---- request
-GET /ngx
---- response_body
-hello, world
-
-
-
-=== TEST 8: require "ngx" (set_by_lua)
---- config
- location /ngx {
- set_by_lua $res '
- local ngx = require "ngx"
- return ngx.escape_uri(" ")
- ';
- echo $res;
- }
---- request
-GET /ngx
---- response_body
-%20
-
-
-
-=== TEST 9: require "ndk" (content_by_lua)
---- config
- location /ndk {
- content_by_lua '
- local ndk = require "ndk"
- local res = ndk.set_var.set_escape_uri(" ")
- ngx.say(res)
- ';
- }
---- request
-GET /ndk
---- response_body
-%20
-
-
-
-=== TEST 10: require "ndk" (set_by_lua)
---- config
- location /ndk {
- set_by_lua $res '
- local ndk = require "ndk"
- return ndk.set_var.set_escape_uri(" ")
- ';
- echo $res;
- }
---- request
-GET /ndk
---- response_body
-%20
diff --git a/src/deps/src/lua-nginx-module/t/005-exit.t b/src/deps/src/lua-nginx-module/t/005-exit.t
deleted file mode 100644
index 0783c6929..000000000
--- a/src/deps/src/lua-nginx-module/t/005-exit.t
+++ /dev/null
@@ -1,828 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#repeat_each(20000);
-#repeat_each(200);
-repeat_each(2);
-#master_on();
-#workers(1);
-#log_level('debug');
-#log_level('warn');
-#worker_connections(1024);
-
-plan tests => repeat_each() * (blocks() * 3 + 2);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
-
-our $LuaCpath = $ENV{LUA_CPATH} ||
- '/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;';
-
-#$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
-
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: throw 403
---- config
- location /lua {
- content_by_lua "ngx.exit(403);ngx.say('hi')";
- }
---- request
-GET /lua
---- error_code: 403
---- response_body_like: 403 Forbidden
---- no_error_log
-[error]
-
-
-
-=== TEST 2: throw 404
---- config
- location /lua {
- content_by_lua "ngx.exit(404);ngx.say('hi');";
- }
---- request
-GET /lua
---- error_code: 404
---- response_body_like: 404 Not Found
---- no_error_log
-[error]
-
-
-
-=== TEST 3: throw 404 after sending the header and partial body
---- config
- location /lua {
- content_by_lua "ngx.say('hi');ngx.exit(404);ngx.say(', you')";
- }
---- request
-GET /lua
---- error_log
-attempt to set status 404 via ngx.exit after sending out the response status 200
---- no_error_log
-[alert]
---- response_body
-hi
-
-
-
-=== TEST 4: working with ngx_auth_request (succeeded)
---- config
- location /auth {
- content_by_lua "
- if ngx.var.user == 'agentzh' then
- ngx.eof();
- else
- ngx.exit(403)
- end";
- }
- location /api {
- set $user $arg_user;
- auth_request /auth;
-
- echo "Logged in";
- }
---- request
-GET /api?user=agentzh
---- error_code: 200
---- response_body
-Logged in
---- no_error_log
-[error]
-
-
-
-=== TEST 5: working with ngx_auth_request (failed)
---- config
- location /auth {
- content_by_lua "
- if ngx.var.user == 'agentzh' then
- ngx.eof();
- else
- ngx.exit(403)
- end";
- }
- location /api {
- set $user $arg_user;
- auth_request /auth;
-
- echo "Logged in";
- }
---- request
-GET /api?user=agentz
---- error_code: 403
---- response_body_like: 403 Forbidden
---- no_error_log
-[error]
-
-
-
-=== TEST 6: working with ngx_auth_request (simplest form, w/o ngx_memc)
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
---- http_config eval
-"
- lua_package_cpath '$::LuaCpath';
- upstream backend {
- drizzle_server 127.0.0.1:\$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-"
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /conv-uid-mysql {
- internal;
-
- set $key "conv-uid-$arg_uid";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- drizzle_query "select new_uid as uid from conv_uid where old_uid=$arg_uid";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /conv-uid {
- internal;
- content_by_lua_file 'html/foo.lua';
- }
- location /api {
- set $uid $arg_uid;
- auth_request /conv-uid;
-
- echo "Logged in $uid";
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local old_uid = ngx.var.uid
--- print('about to run sr')
-local res = ngx.location.capture('/conv-uid-mysql?uid=' .. old_uid)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
--- print('just have run sr: ' .. res.body)
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].uid or
- not string.match(res[1].uid, '^%d+$')) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.uid = res[1].uid;
--- print('done')
---- request
-GET /api?uid=32
---- response_body
-Logged in 56
---- no_error_log
-[error]
-
-
-
-=== TEST 7: working with ngx_auth_request (simplest form)
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
---- http_config eval
-"
- lua_package_cpath '$::LuaCpath';
- upstream backend {
- drizzle_server 127.0.0.1:\$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-"
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /conv-uid-mysql {
- internal;
-
- set $key "conv-uid-$arg_uid";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- drizzle_query "select new_uid as uid from conv_uid where old_uid=$arg_uid";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /conv-uid {
- internal;
- content_by_lua_file 'html/foo.lua';
- }
- location /api {
- set $uid $arg_uid;
- auth_request /conv-uid;
-
- echo "Logged in $uid";
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local old_uid = ngx.var.uid
--- print('about to run sr')
-local res = ngx.location.capture('/conv-uid-mysql?uid=' .. old_uid)
--- print('just have run sr' .. res.body)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].uid or
- not string.match(res[1].uid, '^%d+$')) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.uid = res[1].uid;
--- print('done')
---- request
-GET /api?uid=32
---- response_body
-Logged in 56
---- no_error_log
-[error]
-
-
-
-=== TEST 8: working with ngx_auth_request
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
---- http_config eval
-"
- lua_package_cpath '$::LuaCpath';
- upstream backend {
- drizzle_server 127.0.0.1:\$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-
- upstream memc_a {
- server 127.0.0.1:\$TEST_NGINX_MEMCACHED_PORT;
- }
-
- upstream memc_b {
- server 127.0.0.1:\$TEST_NGINX_MEMCACHED_PORT;
- }
-
- upstream_list memc_cluster memc_a memc_b;
-"
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- set_hashed_upstream $backend memc_cluster $arg_key;
- memc_pass $backend;
- }
-
- location /conv-uid-mysql {
- internal;
-
- set $key "conv-uid-$arg_uid";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- drizzle_query "select new_uid as uid from conv_uid where old_uid=$arg_uid";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /conv-uid {
- internal;
- content_by_lua_file 'html/foo.lua';
- }
- location /api {
- set $uid $arg_uid;
- auth_request /conv-uid;
-
- echo "Logged in $uid";
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local old_uid = ngx.var.uid
--- print('about to run sr')
-local res = ngx.location.capture('/conv-uid-mysql?uid=' .. old_uid)
--- print('just have run sr' .. res.body)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].uid or
- not string.match(res[1].uid, '^%d+$')) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.uid = res[1].uid;
--- print('done')
---- request
-GET /api?uid=32
---- response_body
-Logged in 56
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 9: working with ngx_auth_request
---- http_config
- upstream backend {
- drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-
- upstream memc_a {
- server 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- keepalive 300;
- }
-
- #upstream_list memc_cluster memc_a memc_b;
-
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- #set_hashed_upstream $backend memc_cluster $arg_key;
- memc_pass memc_a;
- }
-
- location /conv-mysql {
- internal;
-
- set $key "conv-uri-$query_string";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- set_quote_sql_str $seo_uri $query_string;
- drizzle_query "select url from my_url_map where seo_url=$seo_uri";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /conv-uid {
- internal;
- content_by_lua_file 'html/foo.lua';
- }
-
- location /baz {
- set $my_uri $uri;
- auth_request /conv-uid;
-
- echo_exec /jump $my_uri;
- }
-
- location /jump {
- internal;
- rewrite ^ $query_string? redirect;
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local seo_uri = ngx.var.my_uri
--- print('about to run sr')
-local res = ngx.location.capture('/conv-mysql?' .. seo_uri)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].url) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.my_uri = res[1].url;
--- print('done')
---- request
-GET /baz
---- response_body_like: 302
---- error_code: 302
---- response_headers
-Location: http://localhost:$ServerPort/foo/bar
---- SKIP
-
-
-
-=== TEST 10: throw 0
---- config
- location /lua {
- content_by_lua "ngx.say('Hi'); ngx.eof(); ngx.exit(0);ngx.say('world')";
- }
---- request
-GET /lua
---- error_code: 200
---- response_body
-Hi
---- no_error_log
-[error]
-
-
-
-=== TEST 11: pcall safe
---- config
- location /lua {
- content_by_lua '
- local function f ()
- ngx.say("hello")
- ngx.exit(200)
- end
-
- pcall(f)
- ngx.say("world")
- ';
- }
---- request
-GET /lua
---- error_code: 200
---- response_body
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 12: 501 Method Not Implemented
---- config
- location /lua {
- content_by_lua '
- ngx.exit(501)
- ';
- }
---- request
-GET /lua
---- error_code: 501
---- response_body_like: 501 (?:Method )?Not Implemented
---- no_error_log
-[error]
-
-
-
-=== TEST 13: 501 Method Not Implemented
---- config
- location /lua {
- content_by_lua '
- ngx.exit(ngx.HTTP_METHOD_NOT_IMPLEMENTED)
- ';
- }
---- request
-GET /lua
---- error_code: 501
---- response_body_like: 501 (?:Method )?Not Implemented
---- no_error_log
-[error]
-
-
-
-=== TEST 14: throw 403 after sending out headers with 200
---- config
- location /lua {
- rewrite_by_lua '
- ngx.send_headers()
- ngx.say("Hello World")
- ngx.exit(403)
- ';
- }
---- request
-GET /lua
---- response_body
-Hello World
---- error_log
-attempt to set status 403 via ngx.exit after sending out the response status 200
---- no_error_log
-[alert]
-
-
-
-=== TEST 15: throw 403 after sending out headers with 403
---- config
- location /lua {
- rewrite_by_lua '
- ngx.status = 403
- ngx.send_headers()
- ngx.say("Hello World")
- ngx.exit(403)
- ';
- }
---- request
-GET /lua
---- response_body
-Hello World
---- error_code: 403
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 16: throw 403 after sending out headers with 403 (HTTP 1.0 buffering)
---- config
- location /t {
- rewrite_by_lua '
- ngx.status = 403
- ngx.say("Hello World")
- ngx.exit(403)
- ';
- }
---- request
-GET /t HTTP/1.0
---- response_body
-Hello World
---- error_code: 403
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 17: throw 444 after sending out responses (HTTP 1.0)
---- config
- location /lua {
- content_by_lua "
- ngx.say('ok');
- return ngx.exit(444)
- ";
- }
---- request
-GET /lua HTTP/1.0
---- ignore_response
---- log_level: debug
---- no_error_log
-lua sending HTTP 1.0 response headers
-[error]
-
-
-
-=== TEST 18: throw 499 after sending out responses (HTTP 1.0)
---- config
- location /lua {
- content_by_lua "
- ngx.say('ok');
- return ngx.exit(499)
- ";
- }
---- request
-GET /lua HTTP/1.0
---- ignore_response
---- log_level: debug
---- no_error_log
-lua sending HTTP 1.0 response headers
-[error]
-
-
-
-=== TEST 19: throw 408 after sending out responses (HTTP 1.0)
---- config
- location /lua {
- content_by_lua "
- ngx.say('ok');
- return ngx.exit(408)
- ";
- }
---- request
-GET /lua HTTP/1.0
---- ignore_response
---- log_level: debug
---- no_error_log
-lua sending HTTP 1.0 response headers
-[error]
-
-
-
-=== TEST 20: exit(201) with custom response body
---- config
- location = /t {
- content_by_lua "
- ngx.status = 201
- ngx.say('ok');
- return ngx.exit(201)
- ";
- }
---- request
- GET /t
---- ignore_response
---- log_level: debug
---- no_error_log
-lua sending HTTP 1.0 response headers
-[error]
-[alert]
-
-
-
-=== TEST 21: exit 403 in header filter
---- config
- location = /t {
- content_by_lua "ngx.say('hi');";
- header_filter_by_lua '
- return ngx.exit(403)
- ';
- }
---- request
-GET /t
---- error_code: 403
---- response_body_like: 403 Forbidden
---- no_error_log
-[error]
-
-
-
-=== TEST 22: exit 201 in header filter
---- config
- lingering_close always;
- location = /t {
- content_by_lua "ngx.say('hi');";
- header_filter_by_lua '
- return ngx.exit(201)
- ';
- }
---- request
-GET /t
---- error_code: 201
---- response_body
---- no_error_log
-[error]
-
-
-
-=== TEST 23: exit both in header filter and content handler
---- config
- location = /t {
- content_by_lua "ngx.status = 201 ngx.say('hi') ngx.exit(201)";
- header_filter_by_lua '
- return ngx.exit(201)
- ';
- }
---- request
-GET /t
---- error_code: 201
---- stap2
-/*
-F(ngx_http_send_header) {
- printf("=== %d\n", $r->headers_out->status)
- print_ubacktrace()
-}
-*/
-F(ngx_http_lua_header_filter_inline) {
- printf("=== %d\n", $r->headers_out->status)
- print_ubacktrace()
-}
-F(ngx_http_lua_header_filter_by_chunk).return {
- if ($return == -1) {
- printf("====== header filter by chunk\n")
- print_ubacktrace()
- }
-}
---- stap_out
---- response_body
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 24: exit 444 in header filter
---- config
- location = /t {
- content_by_lua "ngx.say('hello world');";
- header_filter_by_lua '
- return ngx.exit(444)
- ';
- }
---- request
-GET /t
---- error_code: 444
---- response_body
---- no_error_log
-[error]
-
-
-
-=== TEST 25: 501 Method Not Implemented
---- config
- location /lua {
- content_by_lua '
- ngx.exit(ngx.HTTP_NOT_IMPLEMENTED)
- ';
- }
---- request
-GET /lua
---- error_code: 501
---- response_body_like: 501 (?:Method )?Not Implemented
---- no_error_log
-[error]
-
-
-
-=== TEST 26: accepts NGX_OK
---- config
- location = /t {
- content_by_lua_block {
- ngx.exit(ngx.OK)
- }
- }
---- request
-GET /t
---- response_body
---- no_error_log
-[error]
-
-
-
-=== TEST 27: accepts NGX_ERROR
---- config
- location = /t {
- content_by_lua_block {
- ngx.exit(ngx.ERROR)
- }
- }
---- request
-GET /t
---- error_code:
---- response_body
---- no_error_log
-[error]
---- curl_error
-curl: (95) HTTP/3 stream 0 reset by server
-
-
-
-=== TEST 28: accepts NGX_DECLINED
---- config
- location = /t {
- content_by_lua_block {
- ngx.exit(ngx.DECLINED)
- }
- }
---- request
-GET /t
---- error_code:
---- response_body
---- no_error_log
-[error]
---- curl_error
-curl: (95) HTTP/3 stream 0 reset by server
-
-
-
-=== TEST 29: refuses NGX_AGAIN
---- config
- location = /t {
- content_by_lua_block {
- ngx.exit(ngx.AGAIN)
- }
- }
---- request
-GET /t
---- error_code: 500
---- response_body_like: 500 Internal Server Error
---- error_log eval
-qr/\[error\] .*? bad argument to 'ngx.exit': does not accept NGX_AGAIN or NGX_DONE/
-
-
-
-=== TEST 30: refuses NGX_DONE
---- config
- location = /t {
- content_by_lua_block {
- ngx.exit(ngx.DONE)
- }
- }
---- request
-GET /t
---- error_code: 500
---- response_body_like: 500 Internal Server Error
---- error_log eval
-qr/\[error\] .*? bad argument to 'ngx.exit': does not accept NGX_AGAIN or NGX_DONE/
diff --git a/src/deps/src/lua-nginx-module/t/006-escape.t b/src/deps/src/lua-nginx-module/t/006-escape.t
deleted file mode 100644
index 28714ab89..000000000
--- a/src/deps/src/lua-nginx-module/t/006-escape.t
+++ /dev/null
@@ -1,330 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 4);
-
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: escape uri in set_by_lua
---- config
- location /escape {
- set_by_lua $res "return ngx.escape_uri('a ä½ ')";
- echo $res;
- }
---- request
-GET /escape
---- response_body
-a%20%E4%BD%A0
-
-
-
-=== TEST 2: unescape uri in set_by_lua
---- config
- location /unescape {
- set_by_lua $res "return ngx.unescape_uri('a%20%e4%bd%a0')";
- echo $res;
- }
---- request
-GET /unescape
---- response_body
-a ä½
-
-
-
-=== TEST 3: escape uri in content_by_lua
---- config
- location /escape {
- content_by_lua "ngx.say(ngx.escape_uri('a ä½ '))";
- }
---- request
-GET /escape
---- response_body
-a%20%E4%BD%A0
-
-
-
-=== TEST 4: unescape uri in content_by_lua
---- config
- location /unescape {
- content_by_lua "ngx.say(ngx.unescape_uri('a%20%e4%bd%a0'))";
- }
---- request
-GET /unescape
---- response_body
-a ä½
-
-
-
-=== TEST 5: escape uri in set_by_lua
---- config
- location /escape {
- set_by_lua $res "return ngx.escape_uri('a+b')";
- echo $res;
- }
---- request
-GET /escape
---- response_body
-a%2Bb
-
-
-
-=== TEST 6: escape uri in set_by_lua
---- config
- location /escape {
- set_by_lua $res "return ngx.escape_uri('\"a/b={}:<>;&[]\\\\^')";
- echo $res;
- }
---- request
-GET /escape
---- response_body
-%22a%2Fb%3D%7B%7D%3A%3C%3E%3B%26%5B%5D%5C%5E
-
-
-
-=== TEST 7: escape uri in set_by_lua
---- config
- location /escape {
- echo hello;
- header_filter_by_lua '
- ngx.header.baz = ngx.escape_uri(" ")
- ';
- }
---- request
-GET /escape
---- response_headers
-baz: %20
---- response_body
-hello
-
-
-
-=== TEST 8: escape a string that cannot be escaped
---- config
- location /escape {
- set_by_lua $res "return ngx.escape_uri('abc')";
- echo $res;
- }
---- request
-GET /escape
---- response_body
-abc
-
-
-
-=== TEST 9: escape an empty string that cannot be escaped
---- config
- location /escape {
- set_by_lua $res "return ngx.escape_uri('')";
- echo $res;
- }
---- request
-GET /escape
---- response_body eval: "\n"
-
-
-
-=== TEST 10: escape nil
---- config
- location /escape {
- set_by_lua $res "return ngx.escape_uri(nil)";
- echo "[$res]";
- }
---- request
-GET /escape
---- response_body
-[]
-
-
-
-=== TEST 11: escape numbers
---- config
- location /escape {
- set_by_lua $res "return ngx.escape_uri(32)";
- echo "[$res]";
- }
---- request
-GET /escape
---- response_body
-[32]
-
-
-
-=== TEST 12: unescape nil
---- config
- location = /t {
- set_by_lua $res "return ngx.unescape_uri(nil)";
- echo "[$res]";
- }
---- request
-GET /t
---- response_body
-[]
-
-
-
-=== TEST 13: unescape numbers
---- config
- location = /t {
- set_by_lua $res "return ngx.unescape_uri(32)";
- echo "[$res]";
- }
---- request
-GET /t
---- response_body
-[32]
-
-
-
-=== TEST 14: reserved chars
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.escape_uri("-_.!~*'()"))
- ngx.say(ngx.escape_uri(",$@|`"))
- }
- }
---- request
-GET /lua
---- response_body
--_.!~*'()
-%2C%24%40%7C%60
---- no_error_log
-[error]
-
-
-
-=== TEST 15: escape type argument
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.escape_uri("https://www.google.com", 0))
- ngx.say(ngx.escape_uri("https://www.google.com/query?q=test", 0))
- ngx.say(ngx.escape_uri("https://www.google.com/query?\r\nq=test", 0))
- ngx.say(ngx.escape_uri("-_.~!*'();:@&=+$,/?#", 0))
- ngx.say(ngx.escape_uri("<>[]{}\\\" ", 0))
- }
- }
---- request
-GET /lua
---- response_body
-https://www.google.com
-https://www.google.com/query%3Fq=test
-https://www.google.com/query%3F%0D%0Aq=test
--_.~!*'();:@&=+$,/%3F%23
-<>[]{}\"%20
---- no_error_log
-[error]
-
-
-
-=== TEST 16: escape type argument
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.escape_uri("https://www.google.com/?t=abc@ :", 0))
- ngx.say(ngx.escape_uri("https://www.google.com/?t=abc@ :", 1))
- ngx.say(ngx.escape_uri("https://www.google.com/?t=abc@ :", 2))
- ngx.say(ngx.escape_uri("https://www.google.com/?t=abc@ :", 3))
- ngx.say(ngx.escape_uri("https://www.google.com/?t=abc@ :", 4))
- ngx.say(ngx.escape_uri("https://www.google.com/?t=abc@ :", 5))
- ngx.say(ngx.escape_uri("https://www.google.com/?t=abc@ :", 6))
- }
- }
---- request
-GET /lua
---- response_body
-https://www.google.com/%3Ft=abc@%20:
-https://www.google.com/%3Ft=abc@%20:
-https%3A%2F%2Fwww.google.com%2F%3Ft%3Dabc%40%20%3A
-https://www.google.com/?t=abc@%20:
-https://www.google.com/?t=abc@%20:
-https://www.google.com/?t=abc@%20:
-https://www.google.com/?t=abc@%20:
---- no_error_log
-[error]
-
-
-
-=== TEST 17: escape type out of range
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.escape_uri("https://www.google.com", -1))
- }
- }
---- request
-GET /lua
---- error_code: 500
---- error_log eval
-qr/\[error\] \d+#\d+: \*\d+ lua entry thread aborted: runtime error: "type" \-1 out of range/
-
-
-
-=== TEST 18: escape type out of range
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.escape_uri("https://www.google.com", 10))
- }
- }
---- request
-GET /lua
---- error_code: 500
---- error_log eval
-qr/\[error\] \d+#\d+: \*\d+ lua entry thread aborted: runtime error: "type" 10 out of range/
-
-
-
-=== TEST 19: escape type not integer
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.escape_uri("https://www.google.com", true))
- }
- }
---- request
-GET /lua
---- error_code: 500
---- error_log eval
-qr/\[error\] \d+#\d+: \*\d+ lua entry thread aborted: runtime error: "type" is not a number/
-
-
-
-=== TEST 20: invalid unescape sequences
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.unescape_uri("%ua%%20%au"))
- }
- }
---- request
-GET /lua
---- response_body
-%ua% %au
-
-
-
-=== TEST 21: invalid unescape sequences where remain length less than 2
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.unescape_uri("%a")) -- first character is good
- ngx.say(ngx.unescape_uri("%u")) -- first character is bad
- ngx.say(ngx.unescape_uri("%"))
- ngx.say(ngx.unescape_uri("good%20job%"))
- }
- }
---- request
-GET /lua
---- response_body
-%a
-%u
-%
-good job%
diff --git a/src/deps/src/lua-nginx-module/t/007-md5.t b/src/deps/src/lua-nginx-module/t/007-md5.t
deleted file mode 100644
index 2ae9efb25..000000000
--- a/src/deps/src/lua-nginx-module/t/007-md5.t
+++ /dev/null
@@ -1,102 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: set md5 hello
---- config
- location = /md5 {
- content_by_lua 'ngx.say(ngx.md5("hello"))';
- }
---- request
-GET /md5
---- response_body
-5d41402abc4b2a76b9719d911017c592
-
-
-
-=== TEST 2: nil string to ngx.md5
---- config
- location = /md5 {
- content_by_lua 'ngx.say(ngx.md5(nil))';
- }
---- request
-GET /md5
---- response_body
-d41d8cd98f00b204e9800998ecf8427e
-
-
-
-=== TEST 3: null string to ngx.md5
---- config
- location /md5 {
- content_by_lua 'ngx.say(ngx.md5(""))';
- }
---- request
-GET /md5
---- response_body
-d41d8cd98f00b204e9800998ecf8427e
-
-
-
-=== TEST 4: use ngx.md5 in set_by_lua
---- config
- location = /md5 {
- set_by_lua $a 'return ngx.md5("hello")';
- echo $a;
- }
---- request
-GET /md5
---- response_body
-5d41402abc4b2a76b9719d911017c592
-
-
-
-=== TEST 5: use ngx.md5 in set_by_lua (nil)
---- config
- location = /md5 {
- set_by_lua $a 'return ngx.md5(nil)';
- echo $a;
- }
---- request
-GET /md5
---- response_body
-d41d8cd98f00b204e9800998ecf8427e
-
-
-
-=== TEST 6: use ngx.md5 in set_by_lua (null string)
---- config
- location /md5 {
- set_by_lua $a 'return ngx.md5("")';
- echo $a;
- }
---- request
-GET /md5
---- response_body
-d41d8cd98f00b204e9800998ecf8427e
-
-
-
-=== TEST 7: md5(number)
---- config
- location = /md5 {
- content_by_lua 'ngx.say(ngx.md5(45))';
- }
---- request
-GET /md5
---- response_body
-6c8349cc7260ae62e3b1396831a8398f
diff --git a/src/deps/src/lua-nginx-module/t/008-today.t b/src/deps/src/lua-nginx-module/t/008-today.t
deleted file mode 100644
index ec2f4338e..000000000
--- a/src/deps/src/lua-nginx-module/t/008-today.t
+++ /dev/null
@@ -1,38 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: use ngx.today in content_by_lua
---- config
- location = /today {
- content_by_lua 'ngx.say(ngx.today())';
- }
---- request
-GET /today
---- response_body_like: ^\d{4}-\d{2}-\d{2}$
-
-
-
-=== TEST 2: use ngx.today in set_by_lua
---- config
- location = /today {
- set_by_lua $a 'return ngx.today()';
- echo $a;
- }
---- request
-GET /today
---- response_body_like: ^\d{4}-\d{2}-\d{2}$
diff --git a/src/deps/src/lua-nginx-module/t/009-log.t b/src/deps/src/lua-nginx-module/t/009-log.t
deleted file mode 100644
index 4446c7127..000000000
--- a/src/deps/src/lua-nginx-module/t/009-log.t
+++ /dev/null
@@ -1,570 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('debug'); # to ensure any log-level can be outputted
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 4);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: test log-level STDERR
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- ngx.log(ngx.STDERR, "hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 2: test log-level EMERG
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- ngx.log(ngx.EMERG, "hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[emerg\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 3: test log-level ALERT
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- ngx.log(ngx.ALERT, "hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[alert\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 4: test log-level CRIT
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- ngx.log(ngx.CRIT, "hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[crit\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 5: test log-level ERR
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- ngx.log(ngx.ERR, "hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[error\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 6: test log-level WARN
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- ngx.log(ngx.WARN, "hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[warn\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 7: test log-level NOTICE
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- ngx.log(ngx.NOTICE, "hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[notice\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 8: test log-level INFO
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- ngx.log(ngx.INFO, "hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[info\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 9: test log-level DEBUG
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- ngx.log(ngx.DEBUG, "hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[debug\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 10: regression test print()
---- config
- location /log {
- content_by_lua '
- ngx.say("before log")
- print("hello, log", 1234, 3.14159)
- ngx.say("after log")
- ';
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[notice\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: hello, log12343.14159/
-
-
-
-=== TEST 11: print(nil)
---- config
- location /log {
- content_by_lua '
- print()
- print(nil)
- print("nil: ", nil)
- ngx.say("hi");
- ';
- }
---- request
-GET /log
---- response_body
-hi
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):2: ,/,
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):3: nil,/,
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):4: nil: nil,/,
-]
-
-
-
-=== TEST 12: ngx.log in set_by_lua
---- config
- location /log {
- set_by_lua $a '
- ngx.log(ngx.ERR, "HELLO")
- return 32;
- ';
- echo $a;
- }
---- request
-GET /log
---- response_body
-32
---- error_log eval
-qr/\[error\] \S+: \S+ \[lua\] set_by_lua\(nginx.conf:43\):2: HELLO,/
-
-
-
-=== TEST 13: test booleans and nil
---- config
- location /log {
- set_by_lua $a '
- ngx.log(ngx.ERR, true, false, nil)
- return 32;
- ';
- echo $a;
- }
---- request
-GET /log
---- response_body
-32
---- error_log eval
-qr/\[error\] \S+: \S+ \[lua\] set_by_lua\(nginx.conf:43\):2: truefalsenil,/
-
-
-
-=== TEST 14: test table with metamethod
---- config
- location /log {
- content_by_lua_block {
- ngx.say("before log")
- local t = setmetatable({v = "value"}, {
- __tostring = function(self)
- return "tostring "..self.v
- end
- })
- ngx.log(ngx.ERR, t)
- ngx.say("after log")
- }
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[error\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):8: tostring value,/
-
-
-
-=== TEST 15: test table without metamethod
---- config
- location /log {
- content_by_lua_block {
- ngx.log(ngx.ERR, {})
- ngx.say("done")
- }
- }
---- request
-GET /log
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad argument #1 to 'log' (expected table to have __tostring metamethod)
-
-
-
-=== TEST 16: test tables mixed with other types
---- config
- location /log {
- content_by_lua_block {
- ngx.say("before log")
- local t = setmetatable({v = "value"}, {
- __tostring = function(self)
- return "tostring: "..self.v
- end
- })
- ngx.log(ngx.ERR, t, " hello ", t)
- ngx.say("after log")
- }
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[error\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):8: tostring: value hello tostring: value,/
-
-
-
-=== TEST 17: test print with tables
---- config
- location /log {
- content_by_lua_block {
- ngx.say("before log")
- local t = setmetatable({v = "value"}, {
- __tostring = function(self)
- return "tostring: "..self.v
- end
- })
- print(t, " hello ", t)
- ngx.say("after log")
- }
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[notice\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):8: tostring: value hello tostring: value,/
-
-
-
-=== TEST 18: print() in header filter
---- config
- location /log {
- header_filter_by_lua '
- print("hello world")
- ngx.header.foo = 32
- ';
- echo hi;
- }
---- request
-GET /log
---- response_headers
-foo: 32
---- error_log eval
-qr/\[notice\] .*? \[lua\] header_filter_by_lua\(nginx.conf:43\):2: hello world/
---- response_body
-hi
-
-
-
-=== TEST 19: ngx.log in header filter
---- config
- location /log {
- header_filter_by_lua '
- ngx.log(ngx.ERR, "howdy, lua!")
- ngx.header.foo = 32
- ';
- echo hi;
- }
---- request
-GET /log
---- response_headers
-foo: 32
---- response_body
-hi
---- error_log eval
-qr/\[error\] .*? \[lua\] header_filter_by_lua\(nginx.conf:43\):2: howdy, lua!/
-
-
-
-=== TEST 20: ngx.log big data
---- config
- location /log {
- content_by_lua '
- ngx.log(ngx.ERR, "a" .. string.rep("h", 1970) .. "b")
- ngx.say("hi")
- ';
- }
---- request
-GET /log
---- response_headers
---- error_log eval
-[qr/ah{1970}b/]
-
-
-
-=== TEST 21: ngx.log in Lua function calls & inlined lua
---- config
- location /log {
- content_by_lua '
- local foo
- local bar
- function foo()
- bar()
- end
-
- function bar()
- ngx.log(ngx.ERR, "hello, log", 1234, 3.14159)
- end
-
- foo()
- ngx.say("done")
- ';
- }
---- request
-GET /log
---- response_body
-done
---- error_log eval
-qr/\[error\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):9: bar\(\): hello, log12343.14159/
-
-
-
-=== TEST 22: ngx.log in Lua function tail-calls & inlined lua
---- config
- location /log {
- content_by_lua '
- local foo
- local bar
- function foo()
- return bar(5)
- end
-
- function bar(n)
- if n < 1 then
- ngx.log(ngx.ERR, "hello, log", 1234, 3.14159)
- return n
- end
-
- return bar(n - 1)
- end
-
- foo()
- ngx.say("done")
- ';
- }
---- request
-GET /log
---- response_body
-done
---- error_log eval
-qr/\[error\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):10:(?: foo\(\):)? hello, log12343.14159/
-
-
-
-=== TEST 23: ngx.log in Lua files
---- config
- location /log {
- content_by_lua_file 'html/test.lua';
- }
---- user_files
->>> test.lua
-local foo
-local bar
-function foo()
- bar()
-end
-
-function bar()
- ngx.log(ngx.ERR, "hello, log", 1234, 3.14159)
-end
-
-foo()
-ngx.say("done")
-
---- request
-GET /log
---- response_body
-done
---- error_log eval
-qr/\[error\] \S+: \S+ \[lua\] test.lua:8: bar\(\): hello, log12343.14159/
-
-
-
-=== TEST 24: ngx.log with bad levels (ngx.ERROR, -1)
---- config
- location /log {
- content_by_lua '
- ngx.log(ngx.ERROR, "hello lua")
- ngx.say("done")
- ';
- }
---- request
-GET /log
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad log level: -1
-
-
-
-=== TEST 25: ngx.log with bad levels (9)
---- config
- location /log {
- content_by_lua '
- ngx.log(9, "hello lua")
- ngx.say("done")
- ';
- }
---- request
-GET /log
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad log level: 9
-
-
-
-=== TEST 26: \0 in the log message
---- config
- location = /t {
- content_by_lua '
- ngx.log(ngx.WARN, "hello\\0world")
- ngx.say("ok")
- ';
- }
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- error_log eval
-"2: hello\0world, client: "
-
-
-
-=== TEST 27: test log-level STDERR
-Note: maximum number of digits after the decimal-point character is 13
---- config
- location /log {
- content_by_lua_block {
- ngx.say("before log")
- ngx.log(ngx.STDERR, 3.14159265357939723846)
- ngx.say("after log")
- }
- }
---- request
-GET /log
---- response_body
-before log
-after log
---- error_log eval
-qr/\[\] \S+: \S+ \[lua\] content_by_lua\(nginx\.conf:\d+\):3: 3.1415926535794/
diff --git a/src/deps/src/lua-nginx-module/t/010-request_body.t b/src/deps/src/lua-nginx-module/t/010-request_body.t
deleted file mode 100644
index c47f9fc13..000000000
--- a/src/deps/src/lua-nginx-module/t/010-request_body.t
+++ /dev/null
@@ -1,291 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('debug'); # to ensure any log-level can be outputted
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: test reading request body
---- config
- location /echo_body {
- lua_need_request_body on;
- content_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff"
-
-
-
-=== TEST 2: test not reading request body
---- config
- location /echo_body {
- lua_need_request_body off;
- content_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 3: test default setting (not reading request body)
---- config
- location /echo_body {
- content_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 4: test main conf
---- http_config
- lua_need_request_body on;
---- config
- location /echo_body {
- content_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff"
-
-
-
-=== TEST 5: test server conf
---- config
- lua_need_request_body on;
-
- location /echo_body {
- content_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff"
-
-
-
-=== TEST 6: test override main conf
---- http_config
- lua_need_request_body on;
---- config
- location /echo_body {
- lua_need_request_body off;
- content_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 7: test override server conf
---- config
- lua_need_request_body on;
-
- location /echo_body {
- lua_need_request_body off;
- content_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 8: test override server conf
---- config
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/hi;
- }
- location /hi {
- echo_request_body;
- }
- location /echo_body {
- lua_need_request_body off;
- content_by_lua '
- ngx.say(ngx.var.request_body or "nil")
- local res = ngx.location.capture(
- "/proxy",
- { method = ngx.HTTP_POST,
- body = ngx.var.request_body })
-
- ngx.say(res.status)
- ';
- }
---- request eval
-"POST /echo_body
-"
---- response_body
-nil
-200
-
-
-
-=== TEST 9: empty POST body
---- config
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/hi;
- }
- location /hi {
- echo_request_body;
- }
- location /echo_body {
- lua_need_request_body on;
- content_by_lua '
- ngx.say(ngx.var.request_body or "nil")
- local res = ngx.location.capture(
- "/proxy",
- { method = ngx.HTTP_POST,
- body = ngx.var.request_body })
-
- ngx.say(res.status)
- ';
- }
---- request eval
-"POST /echo_body
-"
---- response_body
-nil
-200
-
-
-
-=== TEST 10: on disk request body
---- config
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/hi;
- }
- location /hi {
- echo_request_body;
- }
- location /echo_body {
- lua_need_request_body on;
-
- client_max_body_size 100k;
- client_body_buffer_size 1;
- sendfile on;
-
- content_by_lua '
- local res = ngx.location.capture(
- "/proxy",
- { method = ngx.HTTP_POST,
- body = ngx.var.request_body })
- ngx.print(res.body)
- ';
- }
---- request eval
-"POST /echo_body
-" . ('a' x 1024)
---- response_body chomp
-
-
-
-=== TEST 11: no modify main request content-length
---- config
- location /foo {
- content_by_lua '
- ngx.location.capture("/other", {body = "hello"})
- ngx.say(ngx.req.get_headers()["Content-Length"] or "nil")
- ';
- }
- location /other {
- echo hi;
- }
---- request
-POST /foo
-hi
---- response_body
-2
-
-
-
-=== TEST 12: Expect: 100-Continue
---- config
- location /echo_body {
- lua_need_request_body on;
- content_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- }
---- request
-POST /echo_body
-hello world
---- more_headers
-Expect: 100-Continue
---- ignore_response
---- no_error_log
-[error]
-[alert]
-http finalize request: 500, "/echo_body?" a:1, c:2
-http finalize request: 500, "/echo_body?" a:1, c:0
---- log_level: debug
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 13: test reading the first n bytes of request body
---- config
- location /echo_body {
- lua_need_request_body on;
- content_by_lua_block {
- local data = ngx.req.get_body_data(1)
- ngx.say(data)
- }
- }
---- request
-POST /echo_body
-hello
---- response_body
-h
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
diff --git a/src/deps/src/lua-nginx-module/t/011-md5_bin.t b/src/deps/src/lua-nginx-module/t/011-md5_bin.t
deleted file mode 100644
index dc0fd9c9b..000000000
--- a/src/deps/src/lua-nginx-module/t/011-md5_bin.t
+++ /dev/null
@@ -1,170 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-
-#md5_bin_bin is hard to test, so convert it to hex mode
-
-__DATA__
-
-=== TEST 1: set md5_bin hello ????xxoo
---- config
- location = /md5_bin {
- content_by_lua 'local a = string.gsub(ngx.md5_bin("hello"), ".", function (c)
- return string.format("%02x", string.byte(c))
- end); ngx.say(a)';
- }
---- request
-GET /md5_bin
---- response_body
-5d41402abc4b2a76b9719d911017c592
-
-
-
-=== TEST 2: set md5_bin hello ????xxoo
---- config
- location = /md5_bin {
- content_by_lua 'ngx.say(string.len(ngx.md5_bin("hello")))';
- }
---- request
-GET /md5_bin
---- response_body
-16
-
-
-
-=== TEST 3: set md5_bin hello
---- config
- location = /md5_bin {
- content_by_lua '
- local s = ngx.md5_bin("hello")
- s = string.gsub(s, ".", function (c)
- return string.format("%02x", string.byte(c))
- end)
- ngx.say(s)
- ';
- }
---- request
-GET /md5_bin
---- response_body
-5d41402abc4b2a76b9719d911017c592
-
-
-
-=== TEST 4: nil string to ngx.md5_bin
---- config
- location = /md5_bin {
- content_by_lua '
- local s = ngx.md5_bin(nil)
- s = string.gsub(s, ".", function (c)
- return string.format("%02x", string.byte(c))
- end)
- ngx.say(s)
- ';
- }
---- request
-GET /md5_bin
---- response_body
-d41d8cd98f00b204e9800998ecf8427e
-
-
-
-=== TEST 5: null string to ngx.md5_bin
---- config
- location /md5_bin {
- content_by_lua '
- local s = ngx.md5_bin("")
- s = string.gsub(s, ".", function (c)
- return string.format("%02x", string.byte(c))
- end)
- ngx.say(s)
- ';
- }
---- request
-GET /md5_bin
---- response_body
-d41d8cd98f00b204e9800998ecf8427e
-
-
-
-=== TEST 6: use ngx.md5_bin in set_by_lua
---- config
- location = /md5_bin {
- set_by_lua $a 'return string.gsub(ngx.md5_bin("hello"), ".", function (c)
- return string.format("%02x", string.byte(c))
- end)';
- echo $a;
- }
---- request
-GET /md5_bin
---- response_body
-5d41402abc4b2a76b9719d911017c592
-
-
-
-=== TEST 7: use ngx.md5_bin in set_by_lua (nil)
---- config
- location = /md5_bin {
- set_by_lua $a '
- local s = ngx.md5_bin(nil)
- s = string.gsub(s, ".", function (c)
- return string.format("%02x", string.byte(c))
- end)
- return s
- ';
- echo $a;
- }
---- request
-GET /md5_bin
---- response_body
-d41d8cd98f00b204e9800998ecf8427e
-
-
-
-=== TEST 8: use ngx.md5_bin in set_by_lua (null string)
---- config
- location /md5_bin {
- set_by_lua $a '
- local s = ngx.md5_bin("")
- s = string.gsub(s, ".", function (c)
- return string.format("%02x", string.byte(c))
- end)
- return s
- ';
- echo $a;
- }
---- request
-GET /md5_bin
---- response_body
-d41d8cd98f00b204e9800998ecf8427e
-
-
-
-=== TEST 9: md5_bin(number)
---- config
- location = /t {
- content_by_lua '
- local s = ngx.md5_bin(45)
- s = string.gsub(s, ".", function (c)
- return string.format("%02x", string.byte(c))
- end)
- ngx.say(s)
-
- ';
- }
---- request
-GET /t
---- response_body
-6c8349cc7260ae62e3b1396831a8398f
diff --git a/src/deps/src/lua-nginx-module/t/012-now.t b/src/deps/src/lua-nginx-module/t/012-now.t
deleted file mode 100644
index 58851879d..000000000
--- a/src/deps/src/lua-nginx-module/t/012-now.t
+++ /dev/null
@@ -1,118 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: use ngx.localtime in content_by_lua
---- config
- location = /now {
- content_by_lua 'ngx.say(ngx.localtime())';
- }
---- request
-GET /now
---- response_body_like: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$
-
-
-
-=== TEST 2: use ngx.localtime in set_by_lua
---- config
- location = /now {
- set_by_lua $a 'return ngx.localtime()';
- echo $a;
- }
---- request
-GET /now
---- response_body_like: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$
-
-
-
-=== TEST 3: use ngx.time in set_by_lua
---- config
- location = /time {
- set_by_lua $a 'return ngx.time()';
- echo $a;
- }
---- request
-GET /time
---- response_body_like: ^\d{10,}$
-
-
-
-=== TEST 4: use ngx.time in content_by_lua
---- config
- location = /time {
- content_by_lua 'ngx.say(ngx.time())';
- }
---- request
-GET /time
---- response_body_like: ^\d{10,}$
-
-
-
-=== TEST 5: use ngx.time in content_by_lua
---- config
- location = /time {
- content_by_lua '
- ngx.say(ngx.time())
- ngx.say(ngx.localtime())
- ngx.say(ngx.utctime())
- ngx.say(ngx.cookie_time(ngx.time()))
- ';
- }
---- request
-GET /time
---- response_body_like chomp
-^\d{10,}
-\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}
-\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}
-\w+, .*? GMT$
-
-
-
-=== TEST 6: use ngx.now in set_by_lua
---- config
- location = /time {
- set_by_lua $a 'return ngx.now()';
- echo $a;
- }
---- request
-GET /time
---- response_body_like: ^\d{10,}(\.\d{1,3})?$
-
-
-
-=== TEST 7: use ngx.now in content_by_lua
---- config
- location = /time {
- content_by_lua 'ngx.say(ngx.now())';
- }
---- request
-GET /time
---- response_body_like: ^\d{10,}(\.\d{1,3})?$
-
-
-
-=== TEST 8: use ngx.update_time & ngx.now in content_by_lua
---- config
- location = /time {
- content_by_lua '
- ngx.update_time()
- ngx.say(ngx.now())
- ';
- }
---- request
-GET /time
---- response_body_like: ^\d{10,}(\.\d{1,3})?$
diff --git a/src/deps/src/lua-nginx-module/t/013-base64.t b/src/deps/src/lua-nginx-module/t/013-base64.t
deleted file mode 100644
index d1a8d8b09..000000000
--- a/src/deps/src/lua-nginx-module/t/013-base64.t
+++ /dev/null
@@ -1,245 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 4);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: base64 encode hello
---- config
- location = /encode_base64 {
- content_by_lua 'ngx.say(ngx.encode_base64("hello"))';
- }
---- request
-GET /encode_base64
---- response_body
-aGVsbG8=
-
-
-
-=== TEST 2: nil string to ngx.encode_base64
---- config
- location = /encode_base64 {
- content_by_lua 'ngx.say("left" .. ngx.encode_base64(nil) .. "right")';
- }
---- request
-GET /encode_base64
---- response_body
-leftright
-
-
-
-=== TEST 3: null string to ngx.encode_base64
---- config
- location = /encode_base64 {
- content_by_lua 'ngx.say("left" .. ngx.encode_base64("") .. "right")';
- }
---- request
-GET /encode_base64
---- response_body
-leftright
-
-
-
-=== TEST 4: use ngx.encode_base64 in set_by_lua
---- config
- location = /encode_base64 {
- set_by_lua $a 'return ngx.encode_base64("hello")';
- echo $a;
- }
---- request
-GET /encode_base64
---- response_body
-aGVsbG8=
-
-
-
-=== TEST 5: use ngx.encode_base64 in set_by_lua (nil)
---- config
- location = /encode_base64 {
- set_by_lua $a 'return "left" .. ngx.encode_base64(nil) .. "right"';
- echo $a;
- }
---- request
-GET /encode_base64
---- response_body
-leftright
-
-
-
-=== TEST 6: use ngx.encode_base64 in set_by_lua (null string)
---- config
- location /encode_base64 {
- set_by_lua $a 'return "left" .. ngx.encode_base64("") .. "right"';
- echo $a;
- }
---- request
-GET /encode_base64
---- response_body
-leftright
-
-
-
-=== TEST 7: base64 encode hello
---- config
- location = /decode_base64 {
- content_by_lua 'ngx.say(ngx.decode_base64("aGVsbG8="))';
- }
---- request
-GET /decode_base64
---- response_body
-hello
-
-
-
-=== TEST 8: null string to ngx.decode_base64
---- config
- location = /decode_base64 {
- content_by_lua 'ngx.say("left" .. ngx.decode_base64("") .. "right")';
- }
---- request
-GET /decode_base64
---- response_body
-leftright
-
-
-
-=== TEST 9: use ngx.decode_base64 in set_by_lua
---- config
- location = /decode_base64 {
- set_by_lua $a 'return ngx.decode_base64("aGVsbG8=")';
- echo $a;
- }
---- request
-GET /decode_base64
---- response_body
-hello
-
-
-
-=== TEST 10: use ngx.decode_base64 in set_by_lua (nil)
---- config
- location = /decode_base64 {
- set_by_lua $a 'return "left" .. ngx.decode_base64(nil) .. "right"';
- echo $a;
- }
---- request
-GET /decode_base64
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-string argument only
-
-
-
-=== TEST 11: use ngx.decode_base64 in set_by_lua (null string)
---- config
- location /decode_base64 {
- set_by_lua $a 'return "left" .. ngx.decode_base64("") .. "right"';
- echo $a;
- }
---- request
-GET /decode_base64
---- response_body
-leftright
-
-
-
-=== TEST 12: base64 encode number
---- config
- location = /t {
- content_by_lua 'ngx.say(ngx.encode_base64(32))';
- }
---- request
-GET /t
---- response_body
-MzI=
-
-
-
-=== TEST 13: base64 decode number
---- config
- location = /t {
- content_by_lua 'ngx.say(ngx.decode_base64(32))';
- }
---- request
-GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-string argument only
-
-
-
-=== TEST 14: base64 decode error
---- config
- location = /t {
- content_by_lua 'ngx.say(ngx.decode_base64("^*~"))';
- }
---- request
-GET /t
---- response_body
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 15: base64 encode without padding (explicit true to no_padding)
---- config
- location = /t {
- content_by_lua 'ngx.say(ngx.encode_base64("hello", true))';
- }
---- request
-GET /t
---- response_body
-aGVsbG8
-
-
-
-=== TEST 16: base64 encode short string
---- config
- location = /t {
- content_by_lua 'ngx.say(ngx.encode_base64("w"))';
- }
---- request
-GET /t
---- response_body
-dw==
-
-
-
-=== TEST 17: base64 encode short string with padding (explicit false to no_padding)
---- config
- location = /t {
- content_by_lua 'ngx.say(ngx.encode_base64("w", false))';
- }
---- request
-GET /t
---- response_body
-dw==
-
-
-
-=== TEST 18: base64 encode with wrong 2nd parameter
---- config
- location = /t {
- content_by_lua 'ngx.say(ngx.encode_base64("w", 0))';
- }
---- request
-GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/bad argument \#2 to 'encode_base64' \(boolean expected, got number\)|\[error\] .*? bad no_padding: boolean expected, got number/
diff --git a/src/deps/src/lua-nginx-module/t/014-bugs.t b/src/deps/src/lua-nginx-module/t/014-bugs.t
deleted file mode 100644
index d34f42e23..000000000
--- a/src/deps/src/lua-nginx-module/t/014-bugs.t
+++ /dev/null
@@ -1,1368 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-log_level('debug');
-
-repeat_each(3);
-
-# NB: the shutdown_error_log block is independent from repeat times
-plan tests => repeat_each() * (blocks() * 2 + 33) + 1;
-
-our $HtmlDir = html_dir;
-#warn $html_dir;
-
-$ENV{TEST_NGINX_HTML_DIR} = $HtmlDir;
-$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
-
-#no_diff();
-#no_long_string();
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-#no_shuffle();
-no_long_string();
-
-sub read_file {
- my $infile = shift;
- open my $in, $infile
- or die "cannot open $infile for reading: $!";
- my $cert = do { local $/; <$in> };
- close $in;
- $cert;
-}
-
-our $TestCertificate = read_file("t/cert/test.crt");
-our $TestCertificateKey = read_file("t/cert/test.key");
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /load {
- content_by_lua '
- package.loaded.foo = nil;
- local foo = require "foo";
- foo.hi()
- ';
- }
---- request
-GET /load
---- user_files
->>> foo.lua
-module(..., package.seeall);
-
-function foo ()
- return 1
- return 2
-end
---- error_code: 500
---- response_body_like: 500 Internal Server Error
-
-
-
-=== TEST 2: sanity
---- http_config
-lua_package_cpath '/home/agentz/rpm/BUILD/lua-yajl-1.1/build/?.so;/home/lz/luax/?.so;./?.so';
---- config
- location = '/report/listBidwordPrices4lzExtra.htm' {
- content_by_lua '
- local yajl = require "yajl"
- local w = ngx.var.arg_words
- w = ngx.unescape_uri(w)
- local r = {}
- print("start for")
- for id in string.gmatch(w, "%d+") do
- r[id] = -1
- end
- print("end for, start yajl")
- ngx.print(yajl.to_string(r))
- print("end yajl")
- ';
- }
---- request
-GET /report/listBidwordPrices4lzExtra.htm?words=123,156,2532
---- response_body
---- SKIP
-
-
-
-=== TEST 3: sanity
---- config
- location = /memc {
- #set $memc_value 'hello';
- set $memc_value $arg_v;
- set $memc_cmd $arg_c;
- set $memc_key $arg_k;
- #set $memc_value hello;
-
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- #echo $memc_value;
- }
- location = /echo {
- echo_location '/memc?c=get&k=foo';
- echo_location '/memc?c=set&k=foo&v=hello';
- echo_location '/memc?c=get&k=foo';
- }
- location = /main {
- content_by_lua '
- local res = ngx.location.capture("/memc?c=get&k=foo&v=")
- ngx.say("1: ", res.body)
-
- res = ngx.location.capture("/memc?c=set&k=foo&v=bar");
- ngx.say("2: ", res.body);
-
- res = ngx.location.capture("/memc?c=get&k=foo")
- ngx.say("3: ", res.body);
- ';
- }
---- request
-GET /main
---- response_body_like: 3: bar$
-
-
-
-=== TEST 4: capture works for subrequests with internal redirects
---- config
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/")
- ngx.say(res.status)
- ngx.print(res.body)
- ';
- }
---- request
- GET /lua
---- response_body_like chop
-200
-.*It works
---- SKIP
-
-
-
-=== TEST 5: disk file bufs not working
---- config
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/test.lua")
- ngx.say(res.status)
- ngx.print(res.body)
- ';
- }
---- user_files
->>> test.lua
-print("Hello, world")
---- request
- GET /lua
---- response_body
-200
-print("Hello, world")
-
-
-
-=== TEST 6: print lua empty strings
---- config
- location /lua {
- content_by_lua 'ngx.print("") ngx.flush() ngx.print("Hi")';
- }
---- request
-GET /lua
---- response_body chop
-Hi
-
-
-
-=== TEST 7: say lua empty strings
---- config
- location /lua {
- content_by_lua 'ngx.say("") ngx.flush() ngx.print("Hi")';
- }
---- request
-GET /lua
---- response_body eval
-"
-Hi"
-
-
-
-=== TEST 8: github issue 37: header bug
-https://github.com/chaoslawful/lua-nginx-module/issues/37
-
-https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2
- Just as in HTTP/1.x, header field names are strings of ASCII
- characters that are compared in a case-insensitive fashion. However,
- header field names MUST be converted to lowercase prior to their
- encoding in HTTP/2. A request or response containing uppercase
- header field names MUST be treated as malformed
-
---- config
- location /sub {
- content_by_lua '
- ngx.header["Set-Cookie"] = {"TestCookie1=foo", "TestCookie2=bar"};
- ngx.say("Hello")
- ';
- }
- location /lua {
- content_by_lua '
- -- local yajl = require "yajl"
- ngx.header["Set-Cookie"] = {}
- local res = ngx.location.capture("/sub")
-
- for i,j in pairs(res.header) do
- ngx.header[i] = j
- end
-
- -- ngx.say("set-cookie: ", yajl.to_string(res.header["Set-Cookie"]))
-
- ngx.send_headers()
- ngx.print("body: ", res.body)
- ';
- }
---- request
-GET /lua
---- raw_response_headers_like eval
-my $headers;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $headers = ".*set-cookie: TestCookie1=foo\r
-set-cookie: TestCookie2=bar.*"
-} else {
- $headers = ".*Set-Cookie: TestCookie1=foo\r
-Set-Cookie: TestCookie2=bar.*"
-}
-
-$headers;
-
-
-
-=== TEST 9: memory leak
---- config
- location /foo {
- content_by_lua_file 'html/foo.lua';
- }
---- user_files
->>> foo.lua
-local res = {}
-res = {'good 1', 'good 2', 'good 3'}
-return ngx.redirect("/somedir/" .. ngx.escape_uri(res[math.random(1,#res)]))
---- request
- GET /foo
---- response_body
---- SKIP
-
-
-
-=== TEST 10: capturing locations with internal redirects (no lua redirect)
---- config
- location /bar {
- echo Bar;
- }
- location /foo {
- #content_by_lua '
- #ngx.exec("/bar")
- #';
- echo_exec /bar;
- }
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/foo")
- ngx.print(res.body)
- ';
- }
---- request
- GET /main
---- response_body
-Bar
-
-
-
-=== TEST 11: capturing locations with internal redirects (lua redirect)
---- config
- location /bar {
- content_by_lua 'ngx.say("Bar")';
- }
- location /foo {
- content_by_lua '
- ngx.exec("/bar")
- ';
- }
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/foo")
- ngx.print(res.body)
- ';
- }
---- request
- GET /main
---- response_body
-Bar
-
-
-
-=== TEST 12: capturing locations with internal redirects (simple index)
---- config
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/")
- ngx.print(res.body)
- ';
- }
---- request
- GET /main
---- response_body chop
-
It works!It works!
-
-
-
-=== TEST 13: capturing locations with internal redirects (more lua statements)
---- config
- location /bar {
- content_by_lua '
- ngx.say("hello")
- ngx.say("world")
- ';
- }
- location /foo {
- #content_by_lua '
- #ngx.exec("/bar")
- #';
- echo_exec /bar;
- }
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/foo")
- ngx.print(res.body)
- ';
- }
---- request
- GET /main
---- response_body
-hello
-world
-
-
-
-=== TEST 14: capturing locations with internal redirects (post subrequest with internal redirect)
---- config
- location /bar {
- lua_need_request_body on;
- client_body_in_single_buffer on;
-
- content_by_lua '
- ngx.say(ngx.var.request_body)
- ';
- }
- location /foo {
- #content_by_lua '
- #ngx.exec("/bar")
- #';
- echo_exec /bar;
- }
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/foo", { method = ngx.HTTP_POST, body = "hello" })
- ngx.print(res.body)
- ';
- }
---- request
- GET /main
---- response_body
-hello
-
-
-
-=== TEST 15: nginx rewrite works in subrequests
---- config
- rewrite /foo /foo/ permanent;
- location = /foo/ {
- echo hello;
- }
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/foo")
- ngx.say("status = ", res.status)
- ngx.say("Location: ", res.header["Location"] or "nil")
- ';
- }
---- request
- GET /main
---- response_body
-status = 301
-Location: /foo/
-
-
-
-=== TEST 16: nginx rewrite works in subrequests
---- config
- access_by_lua '
- local res = ngx.location.capture(ngx.var.uri)
- ngx.say("status = ", res.status)
- ngx.say("Location: ", res.header["Location"] or "nil")
- ngx.exit(200)
- ';
---- request
- GET /foo
---- user_files
->>> foo/index.html
-It works!
---- response_body
-status = 301
-Location: /foo/
---- no_check_leak
-
-
-
-=== TEST 17: set content-type header with charset
---- config
- location /lua {
- charset GBK;
- content_by_lua '
- ngx.header.content_type = "text/xml; charset=UTF-8"
- ngx.say("hi")
- ';
- }
---- request
- GET /lua
---- response_body
-hi
---- response_headers
-Content-Type: text/xml; charset=UTF-8
-
-
-
-=== TEST 18: set response header content-type with charset
---- config
- location /lua {
- charset GBK;
- content_by_lua '
- ngx.header.content_type = "text/xml"
- ngx.say("hi")
- ';
- }
---- request
- GET /lua
---- response_body
-hi
---- response_headers
-Content-Type: text/xml; charset=GBK
-
-
-
-=== TEST 19: get by-position capturing variables
---- config
- location ~ '^/lua/(.*)' {
- content_by_lua '
- ngx.say(ngx.var[1] or "nil")
- ';
- }
---- request
- GET /lua/hello
---- response_body
-hello
-
-
-
-=== TEST 20: get by-position capturing variables ($0)
---- config
- location ~ '^/lua/(.*)' {
- content_by_lua '
- ngx.say(ngx.var[0] or "nil")
- ';
- }
---- request
- GET /lua/hello
---- response_body
-nil
-
-
-
-=== TEST 21: get by-position capturing variables (exceeding captures)
---- config
- location ~ '^/lua/(.*)' {
- content_by_lua '
- ngx.say(ngx.var[2] or "nil")
- ';
- }
---- request
- GET /lua/hello
---- response_body
-nil
-
-
-
-=== TEST 22: get by-position capturing variables ($1, $2)
---- config
- location ~ '^/lua/(.*)/(.*)' {
- content_by_lua '
- ngx.say(ngx.var[-1] or "nil")
- ngx.say(ngx.var[0] or "nil")
- ngx.say(ngx.var[1] or "nil")
- ngx.say(ngx.var[2] or "nil")
- ngx.say(ngx.var[3] or "nil")
- ngx.say(ngx.var[4] or "nil")
- ';
- }
---- request
- GET /lua/hello/world
---- response_body
-nil
-nil
-hello
-world
-nil
-nil
-
-
-
-=== TEST 23: set special variables
---- config
- location /main {
- #set_unescape_uri $cookie_a "hello";
- set $http_a "hello";
- content_by_lua '
- ngx.say(ngx.var.http_a)
- ';
- }
---- request
- GET /main
---- response_body
-hello
---- SKIP
-
-
-
-=== TEST 24: set special variables
---- config
- location /main {
- content_by_lua '
- dofile(ngx.var.realpath_root .. "/a.lua")
- ';
- }
- location /echo {
- echo hi;
- }
---- request
- GET /main
---- user_files
->>> a.lua
-ngx.location.capture("/echo")
---- response_body
---- SKIP
-
-
-
-=== TEST 25: set 20+ headers
---- config
- location /test {
- rewrite_by_lua '
- ngx.req.clear_header("Authorization")
- ';
- echo $http_a1;
- echo $http_authorization;
- echo $http_a2;
- echo $http_a3;
- echo $http_a23;
- echo $http_a24;
- echo $http_a25;
- }
---- request
- GET /test
---- more_headers eval
-my $i = 1;
-my $s;
-while ($i <= 25) {
- $s .= "A$i: $i\n";
- if ($i == 22) {
- $s .= "Authorization: blah\n";
- }
- $i++;
-}
-#warn $s;
-$s
---- response_body
-1
-
-2
-3
-23
-24
-25
-
-
-
-=== TEST 26: globals sharing by using _G
---- config
- location /test {
- content_by_lua '
- if _G.t then
- _G.t = _G.t + 1
- else
- _G.t = 0
- end
- ngx.print(t)
- ';
- }
---- pipelined_requests eval
-["GET /test", "GET /test", "GET /test"]
---- response_body_like eval
-[qr/\A[036]\z/, qr/\A[147]\z/, qr/\A[258]\z/]
-
-
-
-=== TEST 27: globals sharing by using _G (set_by_lua*)
---- config
- location /test {
- set_by_lua $a '
- if _G.t then
- _G.t = _G.t + 1
- else
- _G.t = 0
- end
- return t
- ';
- echo -n $a;
- }
---- pipelined_requests eval
-["GET /test", "GET /test", "GET /test"]
---- response_body_like eval
-[qr/\A[036]\z/, qr/\A[147]\z/, qr/\A[258]\z/]
-
-
-
-=== TEST 28: globals sharing by using _G (log_by_lua*)
---- http_config
- lua_shared_dict log_dict 100k;
---- config
- location /test {
- content_by_lua '
- local log_dict = ngx.shared.log_dict
- ngx.print(log_dict:get("cnt") or 0)
- ';
-
- log_by_lua '
- local log_dict = ngx.shared.log_dict
- if _G.t then
- _G.t = _G.t + 1
- else
- _G.t = 1
- end
- log_dict:set("cnt", t)
- ';
- }
---- pipelined_requests eval
-["GET /test", "GET /test", "GET /test"]
---- response_body_like eval
-[qr/\A[036]\z/, qr/\A[147]\z/, qr/\A[258]\z/]
-
-
-
-=== TEST 29: globals sharing by using _G (header_filter_by_lua*)
---- config
- location /test {
- header_filter_by_lua '
- if _G.t then
- _G.t = _G.t + 1
- else
- _G.t = 0
- end
- ngx.ctx.cnt = tostring(t)
- ';
- content_by_lua '
- ngx.send_headers()
- ngx.print(ngx.ctx.cnt or 0)
- ';
- }
---- pipelined_requests eval
-["GET /test", "GET /test", "GET /test"]
---- response_body_like eval
-[qr/\A[036]\z/, qr/\A[147]\z/, qr/\A[258]\z/]
-
-
-
-=== TEST 30: globals sharing by using _G (body_filter_by_lua*)
---- config
- location /test {
- body_filter_by_lua '
- if _G.t then
- _G.t = _G.t + 1
- else
- _G.t = 0
- end
- ngx.ctx.cnt = _G.t
- ';
- content_by_lua '
- ngx.print("a")
- ngx.say(ngx.ctx.cnt or 0)
- ';
- }
---- request
-GET /test
---- response_body_like eval
-qr/\Aa[036]
-\z/
---- no_error_log
-[error]
-
-
-
-=== TEST 31: set content-type header with charset and default_type
---- http_config
---- config
- location /lua {
- default_type application/json;
- charset utf-8;
- charset_types application/json;
- content_by_lua 'ngx.say("hi")';
- }
---- request
- GET /lua
---- response_body
-hi
---- response_headers
-Content-Type: application/json; charset=utf-8
-
-
-
-=== TEST 32: hang on upstream_next (from kindy)
---- no_http2
---- no_check_leak
---- http_config
- upstream xx {
- server 127.0.0.1:$TEST_NGINX_SERVER_PORT max_fails=5;
- server 127.0.0.1:$TEST_NGINX_SERVER_PORT max_fails=5;
- }
-
- server {
- server_name "xx";
- listen $TEST_NGINX_SERVER_PORT;
-
- return 444;
- }
---- config
- location = /t {
- proxy_next_upstream off;
- proxy_pass http://xx;
- }
---- request
- GET /t
---- timeout: 1
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log
-upstream prematurely closed connection while reading response header from upstream
-
-
-
-=== TEST 33: last_in_chain is set properly in subrequests
---- config
- location = /sub {
- echo hello;
- body_filter_by_lua '
- local eof = ngx.arg[2]
- if eof then
- print("eof found in body stream")
- end
- ';
- }
-
- location = /main {
- echo_location /sub;
- }
-
---- request
- GET /main
---- response_body
-hello
---- log_level: notice
---- error_log
-eof found in body stream
-
-
-
-=== TEST 34: testing a segfault when using ngx_poll_module + ngx_resolver
-See more details here: http://mailman.nginx.org/pipermail/nginx-devel/2013-January/003275.html
-
-http3 may cache the dns result.
-so need to skip for http3
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
---- config
- location /t {
- set $myserver nginx.org;
- proxy_pass http://$myserver/;
- resolver 127.0.0.1:6789;
- }
---- request
- GET /t
---- ignore_response
---- abort
---- timeout: 0.3
---- log_level: notice
---- no_error_log
-[alert]
---- error_log eval
-qr/(?:send|recv)\(\) failed \(\d+: Connection refused\) while resolving/
---- curl_error eval
-qr/curl: \(28\) Operation timed out after \d+ milliseconds with 0 bytes received/
-
-
-
-=== TEST 35: github issue #218: ngx.location.capture hangs when querying a remote host that does not exist or is really slow to respond
---- config
- set $myurl "https://not-exist.agentzh.org";
- location /toto {
- content_by_lua '
- local proxyUrl = "/myproxy/entity"
- local res = ngx.location.capture( proxyUrl, { method = ngx.HTTP_GET })
- ngx.say("Hello, ", res.status)
- ';
- }
- location ~ /myproxy {
-
- rewrite ^/myproxy/(.*) /$1 break;
- resolver_timeout 3s;
- #resolver 172.16.0.23; # AWS DNS resolver address is the same in all regions - 172.16.0.23
- resolver $TEST_NGINX_RESOLVER;
- proxy_read_timeout 1s;
- proxy_send_timeout 1s;
- proxy_connect_timeout 1s;
- proxy_pass $myurl:443;
- proxy_pass_request_body off;
- proxy_set_header Content-Length 0;
- proxy_set_header Accept-Encoding "";
- }
-
---- request
-GET /toto
-
---- stap2
-F(ngx_http_lua_post_subrequest) {
- println("lua post subrequest")
- print_ubacktrace()
-}
-
---- response_body
-Hello, 502
-
---- error_log
-not-exist.agentzh.org could not be resolved
---- timeout: 10
-
-
-
-=== TEST 36: line comments in the last line of the inlined Lua code
---- config
- location /lua {
- content_by_lua 'ngx.say("ok") -- blah';
- }
---- request
-GET /lua
---- response_body
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 37: resolving names with a trailing dot
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- set $myhost 'agentzh.org.';
- proxy_pass http://$myhost/misc/.vimrc;
- }
---- request
-GET /t
---- response_body_like: An example for a vimrc file
---- no_error_log
-[error]
---- timeout: 10
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 38: resolving names with a trailing dot
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
- server {
- listen \$TEST_NGINX_RAND_PORT_1;
-
- location = /t {
- echo 'args: \$args';
- }
- }
-"
---- config
- location = /t {
- set $args "foo=1&bar=2";
- proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_1;
- }
-
---- request
-GET /t
---- response_body
-args: foo=1&bar=2
---- no_error_log
-[error]
---- no_check_leak
-
-
-
-=== TEST 39: lua_code_cache off + setkeepalive
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- lua_code_cache off;
- location = /t {
- set $port $TEST_NGINX_REDIS_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port)
- local sock = ngx.socket.tcp()
- local sock2 = ngx.socket.tcp()
-
- sock:settimeout(1000)
- sock2:settimeout(6000000)
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local ok, err = sock2:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local ok, err = sock:setkeepalive(100, 100)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- local ok, err = sock2:setkeepalive(200, 100)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.say("done")
-end
---- request
-GET /t
---- stap2
-F(ngx_close_connection) {
- println("=== close connection")
- print_ubacktrace()
-}
---- stap_out2
---- response_body
-done
---- wait: 0.5
---- no_error_log
-[error]
-
-
-
-=== TEST 40: .lua file of exactly N*1024 bytes (github issue #385)
---- config
- location = /t {
- content_by_lua_file html/a.lua;
- }
-
---- user_files eval
-my $s = "ngx.say('ok')\n";
-">>> a.lua\n" . (" " x (8192 - length($s))) . $s;
-
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 41: https proxy has no timeout protection for ssl handshake
---- http_config
- # to suppress a valgrind false positive in the nginx core:
- proxy_ssl_session_reuse off;
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- location /foo {
- echo foo;
- }
- }
-
- upstream local {
- server unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- }
-
---- config
- location = /t {
- proxy_pass https://local/foo;
- }
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
-
---- request
-GET /t
-
---- stap
-probe process("nginx").function("ngx_http_upstream_ssl_handshake") {
- printf("read timer set: %d\n", $c->read->timer_set)
- printf("write timer set: %d\n", $c->write->timer_set)
-}
---- stap_out
-read timer set: 0
-write timer set: 1
-
---- response_body eval
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 42: tcp: nginx crash when resolve an not exist domain in ngx.thread.spawn
-https://github.com/openresty/lua-nginx-module/issues/1915
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location = /t {
- content_by_lua_block {
- local function tcp(host, port)
- local sock = ngx.socket.tcp()
- local ok,err = sock:connect(host, port)
- if not ok then
- ngx.log(ngx.WARN, "failed: ", err)
- sock:close()
- return false
- end
-
- sock:close()
- return true
- end
-
- local host = "nonexistent.openresty.org"
- local port = 80
-
- local threads = {}
- for i = 1, 3 do
- threads[i] = ngx.thread.spawn(tcp, host, port)
- end
-
- local ok, res = ngx.thread.wait(threads[1],threads[2],threads[3])
- if not ok then
- ngx.say("failed to wait thread")
- return
- end
-
- ngx.say("res: ", res)
-
- for i = 1, 3 do
- ngx.thread.kill(threads[i])
- end
- }
- }
-
---- request
-GET /t
---- response_body
-res: false
---- error_log
-nonexistent.openresty.org could not be resolved
-
-
-
-=== TEST 43: domain exists with tcp socket
-https://github.com/openresty/lua-nginx-module/issues/1915
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location = /t {
- content_by_lua_block {
- local function tcp(host, port)
- local sock = ngx.socket.tcp()
- local ok,err = sock:connect(host, port)
- if not ok then
- ngx.log(ngx.WARN, "failed: ", err)
- sock:close()
- return false
- end
-
- sock:close()
- return true
- end
-
- local host = "www.openresty.org"
- local port = 80
-
- local threads = {}
- for i = 1, 3 do
- threads[i] = ngx.thread.spawn(tcp, host, port)
- end
-
- local ok, res = ngx.thread.wait(threads[1],threads[2],threads[3])
- if not ok then
- ngx.say("failed to wait thread")
- return
- end
-
- ngx.say("res: ", res)
-
- for i = 1, 3 do
- ngx.thread.kill(threads[i])
- end
- }
- }
-
---- request
-GET /t
---- response_body
-res: true
-
-
-
-=== TEST 44: domain exists with udp socket
-https://github.com/openresty/lua-nginx-module/issues/1915
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location = /t {
- content_by_lua_block {
- local function udp(host, port)
- local sock = ngx.socket.udp()
- local ok,err = sock:setpeername(host, port)
- if not ok then
- ngx.log(ngx.WARN, "failed: ", err)
- sock:close()
- return false
- end
-
- sock:close()
- return true
- end
-
- local host = "nonexistent.openresty.org"
- local port = 80
-
- local threads = {}
- for i = 1, 3 do
- threads[i] = ngx.thread.spawn(udp, host, port)
- end
-
- local ok, res = ngx.thread.wait(threads[1],threads[2],threads[3])
- if not ok then
- ngx.say("failed to wait thread")
- return
- end
-
- ngx.say("res: ", res)
-
- for i = 1, 3 do
- ngx.thread.kill(threads[i])
- end
- }
- }
-
---- request
-GET /t
---- response_body
-res: false
---- error_log
-nonexistent.openresty.org could not be resolved
-
-
-
-=== TEST 45: udp: nginx crash when resolve an not exist domain in ngx.thread.spawn
-https://github.com/openresty/lua-nginx-module/issues/1915
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location = /t {
- content_by_lua_block {
- local function udp(host, port)
- local sock = ngx.socket.udp()
- local ok,err = sock:setpeername(host, port)
- if not ok then
- ngx.log(ngx.WARN, "failed: ", err)
- sock:close()
- return false
- end
-
- sock:close()
- return true
- end
-
- local host = "www.openresty.org"
- local port = 80
-
- local threads = {}
- for i = 1, 3 do
- threads[i] = ngx.thread.spawn(udp, host, port)
- end
-
- local ok, res = ngx.thread.wait(threads[1],threads[2],threads[3])
- if not ok then
- ngx.say("failed to wait thread")
- return
- end
-
- ngx.say("res: ", res)
-
- for i = 1, 3 do
- ngx.thread.kill(threads[i])
- end
- }
- }
-
---- request
-GET /t
---- response_body
-res: true
-
-
-
-=== TEST 46: nginx crash when parsing a word or a single configuration item that is too long
-https://github.com/openresty/lua-nginx-module/issues/1938
---- http_config
- init_worker_by_lua '
- err_big_str = 'A NA'
- ';
---- config
- location /t {
- content_by_lua '
- ngx.say("hello world")
- ';
- }
---- request
-GET /t
---- response_body
-res: true
---- no_error_log
-[error]
---- must_die
---- error_log eval
-qr/\[emerg\] \d+#\d+: unexpected "A" in/
-
-
-
-=== TEST 47: cosocket does not exit on worker_shutdown_timeout
---- main_config
-worker_shutdown_timeout 1;
---- config
-location /t {
- content_by_lua_block {
- local function thread_func()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", 65110)
- local bytes, err = sock:send("hello")
- if bytes ~= 5 then
- sock:close()
- return ngx.exit(500)
- end
-
- local data, err = sock:receive(20)
- local line, err, partial = sock:receive()
- if not line then
- ngx.log(ngx.ERR, "failed to read a line: ", err)
- return
- end
-
- ngx.log(ngx.ERR, "successfully read a line: ", line)
- end
-
- local function timer_func()
- ngx.thread.spawn(thread_func)
- end
-
- ngx.timer.at(1, timer_func)
- ngx.say("Hello world")
- }
-}
---- request
- GET /t
---- response_body
-Hello world
---- shutdown_error_log eval
-my $expr;
-
-if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $expr = qr|lua close the global Lua VM|
-} else {
- $expr = qr|failed to read a line: closed|
-}
-
-$expr;
---- timeout: 1.2
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 48: nginx crashes when encountering an illegal http if header
-crash with ngx.send_headers()
---- main_config
---- config
-error_page 412 /my_error_handler_412;
-
-location /t {
- rewrite_by_lua_block {
- ngx.send_headers()
- -- ngx.print() -- this also triggers the bug
- }
-}
-location = /my_error_handler_412 {
- return 412 "hello";
-}
---- request
- GET /t
---- more_headers
-If-Match: 1
---- error_code: 412
---- response_body eval
-qr/\Ahello\z/
-
-
-
-=== TEST 49: nginx crashes when encountering an illegal http if header
-crash with ngx.print()
---- main_config
---- config
-error_page 412 /my_error_handler_412;
-
-location /t {
- rewrite_by_lua_block {
- ngx.print()
- }
-}
-location = /my_error_handler_412 {
- return 412 "hello";
-}
---- request
- GET /t
---- more_headers
-If-Match: 1
---- error_code: 412
---- response_body eval
-qr/\Ahello\z/
diff --git a/src/deps/src/lua-nginx-module/t/015-status.t b/src/deps/src/lua-nginx-module/t/015-status.t
deleted file mode 100644
index aa816c08d..000000000
--- a/src/deps/src/lua-nginx-module/t/015-status.t
+++ /dev/null
@@ -1,295 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-#repeat_each(120);
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 9);
-
-#no_diff();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: no key found
---- config
- location /nil {
- content_by_lua '
- ngx.say(ngx.blah_blah == nil and "nil" or "not nil")
- ';
- }
---- request
-GET /nil
---- response_body
-nil
-
-
-
-=== TEST 2: .status found
---- config
- location /nil {
- content_by_lua '
- ngx.say(ngx.status == nil and "nil" or "not nil")
- ';
- }
---- request
-GET /nil
---- response_body
-not nil
-
-
-
-=== TEST 3: default to 0
---- config
- location /nil {
- content_by_lua '
- ngx.say(ngx.status);
- ';
- }
---- request
-GET /nil
---- response_body
-0
-
-
-
-=== TEST 4: default to 0
---- config
- location /nil {
- content_by_lua '
- ngx.say("blah");
- ngx.say(ngx.status);
- ';
- }
---- request
-GET /nil
---- response_body
-blah
-200
-
-
-
-=== TEST 5: set 201
---- config
- location /201 {
- content_by_lua '
- ngx.status = 201;
- ngx.say("created");
- ';
- }
---- request
-GET /201
---- response_body
-created
---- error_code: 201
-
-
-
-=== TEST 6: set "201"
---- config
- location /201 {
- content_by_lua '
- ngx.status = "201";
- ngx.say("created");
- ';
- }
---- request
-GET /201
---- response_body
-created
---- error_code: 201
-
-
-
-=== TEST 7: set "201.7"
---- config
- location /201 {
- content_by_lua '
- ngx.status = "201.7";
- ngx.say("created");
- ';
- }
---- request
-GET /201
---- response_body
-created
---- error_code: 201
-
-
-
-=== TEST 8: set "abc"
---- config
- location /201 {
- content_by_lua '
- ngx.status = "abc";
- ngx.say("created");
- ';
- }
---- request
-GET /201
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 9: set blah
---- config
- location /201 {
- content_by_lua '
- ngx.blah = 201;
- ngx.say("created");
- ';
- }
---- request
-GET /201
---- response_body
-created
---- no_error_log
-[error]
-
-
-
-=== TEST 10: set ngx.status before headers are sent
---- config
- location /t {
- content_by_lua '
- ngx.say("ok")
- ngx.status = 201
- ';
- }
---- request
- GET /t
---- response_body
-ok
---- error_code: 200
---- error_log eval
-qr/\[error\] .*? attempt to set ngx\.status after sending out response headers/
-
-
-
-=== TEST 11: http 1.0 and ngx.status
---- config
- location /nil {
- content_by_lua '
- ngx.status = ngx.HTTP_UNAUTHORIZED
- ngx.say("invalid request")
- ngx.exit(ngx.HTTP_OK)
- ';
- }
---- request
-GET /nil HTTP/1.0
---- response_body
-invalid request
---- error_code: 401
---- no_error_log
-[error]
-
-
-
-=== TEST 12: github issue #221: cannot modify ngx.status for responses from ngx_proxy
---- config
- location = /t {
- proxy_pass http://127.0.0.1:$server_port/;
- header_filter_by_lua '
- if ngx.status == 206 then
- ngx.status = ngx.HTTP_OK
- end
- ';
- }
-
---- request
-GET /t
-
---- more_headers
-Range: bytes=0-4
-
---- response_body chop
-err_status
---- config
-location = /t {
- return 502;
- header_filter_by_lua_block {
- if ngx.status == 502 then
- ngx.status = 654
- ngx.log(ngx.WARN, "ngx.status: ", ngx.status)
- end
- }
-}
---- request
-GET /t
---- response_body_like: Bad Gateway
---- error_log
-ngx.status: 654
---- no_error_log
-[error]
---- error_code: 654
diff --git a/src/deps/src/lua-nginx-module/t/016-resp-header.t b/src/deps/src/lua-nginx-module/t/016-resp-header.t
deleted file mode 100644
index 6cf699d88..000000000
--- a/src/deps/src/lua-nginx-module/t/016-resp-header.t
+++ /dev/null
@@ -1,2272 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 79);
-
-#no_diff();
-no_long_string();
-
-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-length header
---- config
- location /read {
- content_by_lua '
- ngx.header.content_length = 3
- ngx.say("Hello")
- ';
- }
---- request
-GET /read
---- response_headers
-Content-Length: 3
---- response_body chop
-Hel
---- skip_eval: 3:defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})
-
-
-
-=== TEST 4: set response content-type header
---- config
- location /read {
- content_by_lua '
- ngx.status = 302;
- ngx.header["Location"] = "http://agentzh.org/foo";
- ';
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo
---- 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
-
-
-
-=== TEST 6: set multi response content-type header
---- config
- location /read {
- content_by_lua '
- ngx.header["X-Foo"] = {"a", "bc"}
- ngx.say("Hello")
- ';
- }
---- request
-GET /read
---- raw_response_headers_like eval
-my $headers;
-
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- $headers = qr/x-foo: a\r\n.*?x-foo: bc\r\n/
-} else {
- $headers = qr/X-Foo: a\r\n.*?X-Foo: bc\r\n/
-}
-
-$headers;
---- response_body
-Hello
-
-
-
-=== TEST 7: set response content-type header
---- 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
-
-
-
-=== 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 eval
-my $headers;
-
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- $headers = "x-foo: a\r\n.*?x-foo: abc\r\n"
-} else {
- $headers = "X-Foo: a\r\n.*?X-Foo: abc\r\n"
-}
-
-$headers;
---- response_body
-Hello
-
-
-
-=== 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
-my $headers;
-
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- $headers = ".*foo: a\r
-foo: b.*";
-} else {
- $headers = ".*Foo: a\r
-Foo: b.*";
-}
-
-$headers;
---- 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
-my $headers;
-
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- $headers = ".*foo: a\r
-foo: b.*";
-} else {
- $headers = ".*Foo: a\r
-Foo: b.*";
-}
-
-$headers;
---- response_body
-
-
-
-=== 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
-
-
-
-=== 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
---- response_body chop
-hello
---- error_log
-attempt to set ngx.header.HEADER after sending out response headers
---- no_error_log eval
-["[alert]", "[warn]"]
-
-
-
-=== 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
-
-
-
-=== 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
-
-
-
-=== 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-existent 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-existent 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
-
-
-
-=== 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
-
-
-
-=== 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
---- response_body_like chop
-^Cache-Control: private[;,] no-store$
-
-
-
-=== TEST 32: set single value to Link header
---- config
- location = /t {
- content_by_lua_block {
- ngx.header.link = "; rel=preload"
- ngx.say("Link: ", ngx.var.sent_http_link)
- }
- }
---- request
-GET /t
---- response_headers
-Link: ; rel=preload
---- response_body
-Link: ; rel=preload
-
-
-
-=== TEST 33: set multi values to Link header
---- config
- location = /t {
- content_by_lua_block {
- ngx.header.link = {
- "; rel=preload",
- "; rel=preload; as=style"
- }
-
- ngx.say("Link: ", ngx.var.sent_http_link)
- }
- }
---- request
-GET /t
---- response_headers
-Link: ; rel=preload, ; rel=preload; as=style
---- response_body_like chop
-^Link: ; rel=preload[;,] ; rel=preload; as=style$
---- skip_nginx: 3: < 1.13.9
-
-
-
-=== TEST 34: 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 35: set multi values to Link header and override it with a single value
---- config
- location /lua {
- content_by_lua_block {
- ngx.header.link = {
- "; rel=preload",
- "; rel=preload; as=style"
- }
- ngx.header.link = "; rel=preload"
- ngx.say("Link: ", ngx.var.sent_http_link)
- ngx.say("Link: ", ngx.header.link)
- }
- }
---- request
- GET /lua
---- response_headers
-Link: ; rel=preload
---- response_body
-Link: ; rel=preload
-Link: ; rel=preload
-
-
-
-=== TEST 36: 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)
- ngx.say("Cache-Control: ", table.concat(ngx.header.cache_control, ", "))
- ';
- }
---- request
- GET /lua
---- response_headers
-Cache-Control: no-cache, blah, foo
---- response_body_like chop
-^Cache-Control: no-cache[;,] blah[;,] foo
-Cache-Control: no-cache[;,] blah[;,] foo$
---- no_error_log
-[error]
-
-
-
-=== TEST 37: set multi values to Link header and override it with multiple values
---- config
- location /lua {
- content_by_lua_block {
- ngx.header.link = {
- "; rel=preload",
- "; rel=preload; as=style"
- }
- ngx.header.link = {
- "; rel=preload",
- "; rel=preload",
- "; rel=preload; as=style"
- }
- ngx.say("Link: ", ngx.var.sent_http_link)
- ngx.say("Link: ", table.concat(ngx.header.link, ", "))
- }
- }
---- request
- GET /lua
---- response_headers
-Link: ; rel=preload, ; rel=preload, ; rel=preload; as=style
---- response_body_like chop
-^Link: ; rel=preload[;,] ; rel=preload[;,] ; rel=preload; as=style
-Link: ; rel=preload[;,] ; rel=preload[;,] ; rel=preload; as=style$
---- no_error_log
-[error]
---- skip_nginx: 4: < 1.13.9
-
-
-
-=== TEST 38: 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
-
-
-
-=== TEST 39: set and clear the www-authenticate response header
---- 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
-
-
-
-=== TEST 40: 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" }
- ngx.header.cache_control = {}
- ngx.send_headers()
- ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
- ';
- add_header Cache-Control "blah";
- }
---- request
- GET /lua
---- response_headers
-Cache-Control: blah
---- response_body
-Cache-Control: blah
-
-
-
-=== TEST 41: set last-modified and return 304
---- config
- location /lua {
- content_by_lua '
- ngx.header["Last-Modified"] = ngx.http_time(1290079655)
- ngx.say(ngx.header["Last-Modified"])
- ';
- }
---- 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 42: set last-modified and return 200
---- config
- location /lua {
- content_by_lua '
- ngx.header["Last-Modified"] = ngx.http_time(1290079655)
- ngx.say(ngx.header["Last-Modified"])
- ';
- }
---- 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
-
-
-
-=== TEST 43: 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-Encoding: gzip
---- no_error_log
-[error]
-http gzip filter
---- response_body
-Hello, world, my dear friend!
-
-
-
-=== TEST 44: 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 45: 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
-
-
-
-=== TEST 46: 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.something_else = "hi"
-
- 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])
- end
- ';
- }
---- request
-GET /read
---- response_headers
-Content-Type: text/my-plain
-
---- response_body
-content_type: anything
-something: hello
-something_else: hi
---- no_error_log
-[error]
-
-
-
-=== TEST 47: 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 48: 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]
---- timeout: 10
-
-
-
-=== TEST 49: 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 50: 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 51: 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
-
-
-
-=== TEST 52: 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
---- response_headers_like
-Location: https?://localhost:\d+/t/
---- response_body_like: 301 Moved Permanently
---- error_code: 301
---- no_error_log
-[error]
-
-
-
-=== TEST 53: 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
---- response_headers_like
-Location: https?://localhost:\d+/t/
---- error_code: 301
---- no_error_log
-[error]
-
-
-
-=== TEST 54: 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_like
-Location: https?://localhost:\d+/t/
-Foo: /t/
---- response_body_like: 301 Moved Permanently
---- error_code: 301
---- no_error_log
-[error]
-
-
-
-=== TEST 55: 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_like
-Location: https?://localhost:\d+/t/
-Foo: /t/
---- response_body_like: 301 Moved Permanently
---- error_code: 301
---- no_error_log
-[error]
-
-
-
-=== TEST 56: 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 eval
-my $headers;
-
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- $headers = "cache-control: private"
-} else {
- $headers = "cache-Control: private"
-}
-
-$headers;
---- response_body
-Cache-Control: private
-
-
-
-=== TEST 57: case sensitive Link header
---- config
- location /lua {
- content_by_lua_block {
- ngx.header["link"] = "; rel=preload"
- ngx.say("Link: ", ngx.var.sent_http_link)
- }
- }
---- request
- GET /lua
---- raw_response_headers_like chop
-link: ; rel=preload
---- response_body
-Link: ; rel=preload
-
-
-
-=== TEST 58: 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
-
-
-
-=== TEST 59: clear Link header when there was no Link
---- config
- location /lua {
- content_by_lua_block {
- ngx.header["Link"] = nil
- ngx.say("Link: ", ngx.var.sent_http_link)
- }
- }
---- request
- GET /lua
---- raw_response_headers_unlike eval
-qr/Link/i
---- response_body
-Link: nil
-
-
-
-=== TEST 60: 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]
-
-
-
-=== TEST 61: 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 62: 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]
-
-
-
-=== TEST 63: random access resp headers
---- config
- location /resp-header {
- content_by_lua '
- ngx.header["Foo"] = "bar"
- ngx.header["Bar"] = "baz"
- local headers, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("Foo: ", headers["Foo"] or "nil")
- ngx.say("foo: ", headers["foo"] or "nil")
- ngx.say("Bar: ", headers["Bar"] or "nil")
-
- headers, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("bar: ", headers["bar"] or "nil")
- ';
- }
---- request
-GET /resp-header
---- response_headers
-Foo: bar
-Bar: baz
---- response_body
-Foo: bar
-foo: bar
-Bar: baz
-bar: baz
---- no_error_log
-[error]
-
-
-
-=== TEST 64: iterating through raw resp headers
---- config
- location /resp-header {
- content_by_lua '
- ngx.header["Foo"] = "bar"
- ngx.header["Bar"] = "baz"
-
- local headers, err = ngx.resp.get_headers(nil, true)
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- local h = {}
- for k, v in pairs(headers) 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 65: removed response headers
---- config
- location /resp-header {
- content_by_lua '
- ngx.header["Foo"] = "bar"
- ngx.header["Foo"] = nil
- ngx.header["Bar"] = "baz"
-
- local headers, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("Foo: ", headers["Foo"] or "nil")
- ngx.say("foo: ", headers["foo"] or "nil")
- ngx.say("Bar: ", headers["Bar"] or "nil")
- ngx.say("bar: ", headers["bar"] or "nil")
- ';
- }
---- request
-GET /resp-header
---- response_headers
-!Foo
-Bar: baz
---- response_body
-Foo: nil
-foo: nil
-Bar: baz
-bar: baz
-
-
-
-=== TEST 66: built-in Content-Type header
---- config
- location = /t {
- content_by_lua '
- ngx.say("hi")
- ';
-
- header_filter_by_lua '
- local hs, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- print("my Content-Type: ", hs["Content-Type"])
- print("my content-type: ", hs["content-type"])
- print("my content_type: ", hs["content_type"])
- ';
- }
---- request
- GET /t
---- response_body
-hi
---- no_error_log
-[error]
-[alert]
---- error_log
-my Content-Type: text/plain
-my content-type: text/plain
-my content_type: text/plain
-
-
-
-=== TEST 67: built-in Content-Length header
---- config
- location = /t {
- content_by_lua '
- ngx.say("hi")
- ';
-
- header_filter_by_lua '
- local hs, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- print("my Content-Length: ", hs["Content-Length"])
- print("my content-length: ", hs["content-length"])
- print("my content_length: ", hs.content_length)
- ';
- }
---- request
- GET /t HTTP/1.0
---- response_body
-hi
---- no_error_log
-[error]
-[alert]
---- error_log
-my Content-Length: 3
-my content-length: 3
-my content_length: 3
-
-
-
-=== TEST 68: built-in Connection header
---- config
- location = /t {
- content_by_lua '
- ngx.say("hi")
- ';
-
- header_filter_by_lua '
- local hs, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- print("my Connection: ", hs["Connection"])
- print("my connection: ", hs["connection"])
- ';
- }
---- request
- GET /t HTTP/1.0
---- response_body
-hi
---- no_error_log
-[error]
-[alert]
---- error_log
-my Connection: close
-my connection: close
-
-
-
-=== TEST 69: built-in Transfer-Encoding header (chunked)
---- config
- location = /t {
- content_by_lua '
- ngx.say("hi")
- ';
-
- body_filter_by_lua '
- local hs, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- print("my Transfer-Encoding: ", hs["Transfer-Encoding"])
- print("my transfer-encoding: ", hs["transfer-encoding"])
- print("my transfer_encoding: ", hs.transfer_encoding)
- ';
- }
---- request
- GET /t
---- response_body
-hi
---- no_error_log
-[error]
-[alert]
---- error_log
-my Transfer-Encoding: chunked
-my transfer-encoding: chunked
---- skip_eval: 6:defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})
-
-
-
-=== TEST 70: built-in Transfer-Encoding header (none)
---- config
- location = /t {
- content_by_lua '
- ngx.say("hi")
- ';
-
- body_filter_by_lua '
- local hs, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- print("my Transfer-Encoding: ", hs["Transfer-Encoding"])
- print("my transfer-encoding: ", hs["transfer-encoding"])
- print("my transfer_encoding: ", hs.transfer_encoding)
- ';
- }
---- request
- GET /t HTTP/1.0
---- response_body
-hi
---- no_error_log
-[error]
-[alert]
---- error_log
-my Transfer-Encoding: nil
-my transfer-encoding: nil
-my transfer_encoding: nil
-
-
-
-=== TEST 71: 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 72: 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]
-
-
-
-=== TEST 73: 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 74: 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]
-
-
-
-=== TEST 75: exceeding max header limit (default 100)
---- config
- location /resp-header {
- content_by_lua_block {
- for i = 1, 100 do
- ngx.header["Foo" .. i] = "Foo"
- end
-
- local headers, err = ngx.resp.get_headers()
- if err then
- ngx.say("err: ", err)
- end
-
- local cnt = 0
- for k, v in pairs(headers) do
- cnt = cnt + 1
- end
-
- ngx.say("found ", cnt, " resp headers");
- }
- }
---- request
-GET /resp-header
---- response_body
-err: truncated
-found 100 resp headers
---- no_error_log
-[error]
---- log_level: debug
---- error_log
-lua exceeding response header limit 101 > 100
-
-
-
-=== TEST 76: NOT exceeding max header limit (default 100)
---- config
- location /resp-header {
- content_by_lua_block {
- for i = 1, 99 do
- ngx.header["Foo" .. i] = "Foo"
- end
-
- local headers, err = ngx.resp.get_headers()
- if err then
- ngx.say("err: ", err)
- end
-
- local cnt = 0
- for k, v in pairs(headers) do
- cnt = cnt + 1
- end
-
- ngx.say("found ", cnt, " resp headers");
- }
- }
---- request
-GET /resp-header
---- response_body
-found 100 resp headers
---- no_error_log
-[error]
-lua exceeding response header limit
---- log_level: debug
-
-
-
-=== TEST 77: exceeding max header limit (custom limit, 3)
---- config
- location /resp-header {
- content_by_lua_block {
- for i = 1, 3 do
- ngx.header["Foo" .. i] = "Foo"
- end
-
- local headers, err = ngx.resp.get_headers(3)
- if err then
- ngx.say("err: ", err)
- end
-
- local cnt = 0
- for k, v in pairs(headers) do
- cnt = cnt + 1
- end
-
- ngx.say("found ", cnt, " resp headers");
- }
- }
---- request
-GET /resp-header
---- response_body
-err: truncated
-found 3 resp headers
---- no_error_log
-[error]
---- error_log
-lua exceeding response header limit 4 > 3
---- log_level: debug
-
-
-
-=== TEST 78: NOT exceeding max header limit (custom limit, 3)
---- config
- location /resp-header {
- content_by_lua_block {
- for i = 1, 2 do
- ngx.header["Foo" .. i] = "Foo"
- end
-
- local headers, err = ngx.resp.get_headers(3)
- if err then
- ngx.say("err: ", err)
- end
-
- local cnt = 0
- for k, v in pairs(headers) do
- cnt = cnt + 1
- end
-
- ngx.say("found ", cnt, " resp headers");
- }
- }
---- request
-GET /resp-header
---- response_body
-found 3 resp headers
---- no_error_log
-[error]
-lua exceeding response header limit
-
-
-
-=== TEST 79: return nil if Content-Type is not set yet
---- config
- location /t {
- default_type text/html;
- content_by_lua_block {
- ngx.log(ngx.WARN, "Content-Type: ", ngx.header["content-type"])
- ngx.say("Content-Type: ", ngx.header["content-type"])
- }
- }
---- request
-GET /t
---- response_headers
-Content-Type: text/html
---- response_body
-Content-Type: nil
---- no_error_log
-[error]
---- error_log
-Content-Type: nil
-
-
-
-=== TEST 80: don't generate Content-Type when setting other response header
---- config
- location = /backend {
- content_by_lua_block {
- ngx.say("foo")
- }
- header_filter_by_lua_block {
- ngx.header.content_type = nil
- }
- }
-
- location = /t {
- default_type text/html;
- rewrite_by_lua_block {
- ngx.header.blah = "foo"
- }
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/backend;
- }
---- request
-GET /t
---- response_body
-foo
---- response_headers
-blah: foo
-!Content-Type
---- no_error_log
-[error]
-
-
-
-=== TEST 81: don't generate Content-Type when getting other response header
---- config
- location = /backend {
- content_by_lua_block {
- ngx.say("foo")
- }
- header_filter_by_lua_block {
- ngx.header.content_type = nil
- }
- }
-
- location = /t {
- default_type text/html;
- rewrite_by_lua_block {
- local h = ngx.header.content_length
- }
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/backend;
- }
---- request
-GET /t
---- response_body
-foo
---- response_headers
-!Content-Type
---- no_error_log
-[error]
-
-
-
-=== TEST 82: don't generate Content-Type when getting it
---- config
- location = /backend {
- content_by_lua_block {
- ngx.say("foo")
- }
- header_filter_by_lua_block {
- ngx.header.content_type = nil
- }
- }
-
- location /t {
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/backend;
- header_filter_by_lua_block {
- ngx.log(ngx.WARN, "Content-Type: ", ngx.header["content-type"])
- }
- }
---- request
-GET /t
---- response_body
-foo
---- response_headers
-!Content-Type
---- no_error_log
-[error]
---- error_log
-Content-Type: nil
-
-
-
-=== TEST 83: generate default Content-Type when setting other response header
---- config
- location = /t {
- default_type text/html;
- content_by_lua_block {
- ngx.header.blah = "foo"
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_body
-foo
---- response_headers
-blah: foo
-Content-Type: text/html
---- no_error_log
-[error]
-
-
-
-=== TEST 84: don't generate Content-Type when calling ngx.resp.get_headers()
---- config
- location = /backend {
- content_by_lua_block {
- ngx.say("foo")
- }
- header_filter_by_lua_block {
- ngx.header.content_type = nil
- }
- }
-
- location /t {
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/backend;
- header_filter_by_lua_block {
- local h, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return
- end
-
- ngx.log(ngx.WARN, "Content-Type: ", h["content-type"])
- }
- }
---- request
-GET /t
---- response_body
-foo
---- response_headers
-!Content-Type
---- no_error_log
-[error]
---- error_log
-Content-Type: nil
-
-
-
-=== TEST 85: don't generate default Content-Type when Content-Type is cleared
---- config
- location = /t {
- default_type text/html;
- content_by_lua_block {
- ngx.header["Content-Type"] = nil
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_body
-foo
---- response_headers
-!Content-Type
---- no_error_log
-[error]
-
-
-
-=== TEST 86: don't generate default Content-Type when Content-Type is set
---- config
- location = /t {
- default_type text/html;
- content_by_lua_block {
- ngx.header["Content-Type"] = "application/json"
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_body
-foo
---- response_headers
-Content-Type: application/json
---- no_error_log
-[error]
-
-
-
-=== TEST 87: unsafe header value (with '\r')
---- config
- location = /t {
- content_by_lua_block {
- ngx.header.header = "value\rfoo:bar\nbar:foo"
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_headers
-header: value%0Dfoo:bar%0Abar:foo
-foo:
-bar:
---- no_error_log
-[error]
-
-
-
-=== TEST 88: unsafe header value (with '\n')
---- config
- location = /t {
- content_by_lua_block {
- ngx.header.header = "value\nfoo:bar\rbar:foo"
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_headers
-header: value%0Afoo:bar%0Dbar:foo
-foo:
-bar:
---- no_error_log
-[error]
-
-
-
-=== TEST 89: unsafe header name (with '\r')
---- config
- location = /t {
- content_by_lua_block {
- ngx.header["header: value\rfoo:bar\nbar:foo"] = "xx"
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_headers
-header%3A%20value%0Dfoo%3Abar%0Abar%3Afoo: xx
-header:
-foo:
-bar:
---- no_error_log
-[error]
-
-
-
-=== TEST 90: unsafe header name (with '\n')
---- config
- location = /t {
- content_by_lua_block {
- ngx.header["header: value\nfoo:bar\rbar:foo"] = "xx"
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_headers
-header%3A%20value%0Afoo%3Abar%0Dbar%3Afoo: xx
-header:
-foo:
-bar:
---- no_error_log
-[error]
-
-
-
-=== TEST 91: unsafe header name (with prefix '\r')
---- config
- location = /t {
- content_by_lua_block {
- ngx.header["\rheader: value\rfoo:bar\nbar:foo"] = "xx"
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_headers
-%0Dheader%3A%20value%0Dfoo%3Abar%0Abar%3Afoo: xx
-header:
-foo:
-bar:
---- no_error_log
-[error]
-
-
-
-=== TEST 92: unsafe header name (with prefix '\n')
---- config
- location = /t {
- content_by_lua_block {
- ngx.header["\nheader: value\nfoo:bar\rbar:foo"] = "xx"
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_headers
-%0Aheader%3A%20value%0Afoo%3Abar%0Dbar%3Afoo: xx
-header:
-foo:
-bar:
---- no_error_log
-[error]
-
-
-
-=== TEST 93: multiple unsafe header values (with '\n' and '\r')
---- config
- location = /t {
- content_by_lua_block {
- ngx.header["foo"] = {
- "foo\nxx:bar",
- "bar\rxxx:foo",
- }
- ngx.say("foo")
- }
- }
---- request
-GET /t
---- response_headers
-xx:
-xxx:
---- raw_response_headers_like chomp
-foo: foo%0Axx:bar\r\nfoo: bar%0Dxxx:foo\r\n
---- no_error_log
-[error]
-
-
-
-=== TEST 94: fix negative content-length number(#1791)
---- config
- location = /big-upstream {
- content_by_lua_block {
- ngx.header['Content-Length'] = math.pow(2, 33) - 1
- ngx.say('hi')
- }
- }
-
- location = /t {
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/big-upstream;
- proxy_buffering off;
-
- header_filter_by_lua_block {
- local hs, err = ngx.resp.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- print("my Content-Length: ", hs["Content-Length"])
-
- ngx.header['Content-Length'] = 3
- }
- }
---- request
- GET /t
---- response_body
-hi
---- no_error_log
-[alert]
---- error_log
-my Content-Length: 8589934591
-upstream prematurely closed connection while sending to client
-
-
-
-=== TEST 95: Expose the 'Last-Modified' response header as ngx.header["Last-Modified"]
---- config
- location /a.txt {
- header_filter_by_lua_block {
- local last_modified = ngx.header["Last-Modified"]
- if last_modified == nil then
- ngx.log(ngx.ERR, "can not get lasted modified")
- ngx.exit(500)
- return
- end
-
- local last_mod = ngx.parse_http_time(last_modified)
- local age = ngx.time() - last_mod
- ngx.header["Age"] = age
- }
- }
---- user_files
->>> a.txt
-Foo
---- request
-GET /a.txt
---- raw_response_headers_like eval
-qr/^(a|A)ge: \d\r\n/ms
---- no_error_log
-[error]
-
-
-
-=== TEST 96: 'Last-Modified' from upstream
---- config
- location /test/ {
- proxy_pass http://127.0.0.1:$server_port/;
-
- header_filter_by_lua_block {
- local last_modified = ngx.header["Last-Modified"]
- if last_modified == nil then
- ngx.log(ngx.ERR, "can not get lasted modified")
- ngx.exit(500)
- return
- end
-
- local last_mod = ngx.parse_http_time(last_modified)
- local age = ngx.time() - last_mod
- ngx.header["Age"] = age
- }
- }
-
---- user_files
->>> a.txt
-Foo
---- request
-GET /test/a.txt
---- raw_response_headers_like eval
-qr/^(a|A)ge: \d\r\n/ms
---- no_error_log
-[error]
-
-
-
-=== TEST 97: 'Last-Modified' does not exist
---- config
- location /test {
- header_filter_by_lua_block {
- local last_modified = ngx.header["Last-Modified"]
- if last_modified == nil then
- ngx.log(ngx.INFO, "Last-Modified is nil as expected")
- return
- end
-
- ngx.log(ngx.ERR, "Last-Modified expected to be nil, but got ", last_modified)
- }
-
- content_by_lua_block {
- ngx.say("Hello World")
- }
- }
---- request
-GET /test
---- response_body
-Hello World
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/017-exec.t b/src/deps/src/lua-nginx-module/t/017-exec.t
deleted file mode 100644
index a73e93ee7..000000000
--- a/src/deps/src/lua-nginx-module/t/017-exec.t
+++ /dev/null
@@ -1,596 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 8);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#no_diff();
-#no_shuffle();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /read {
- content_by_lua '
- ngx.exec("/hi");
- ngx.say("Hi");
- ';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body
-Hello
-
-
-
-=== TEST 2: empty uri arg
---- config
- location /read {
- content_by_lua '
- ngx.exec("");
- ngx.say("Hi");
- ';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 3: no arg
---- config
- location /read {
- content_by_lua '
- ngx.exec();
- ngx.say("Hi");
- ';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 4: too many args
---- config
- location /read {
- content_by_lua '
- ngx.exec(1, 2, 3, 4);
- ngx.say("Hi");
- ';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 5: null uri
---- config
- location /read {
- content_by_lua '
- ngx.exec(nil)
- ngx.say("Hi")
- ';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 6: user args
---- config
- location /read {
- content_by_lua '
- ngx.exec("/hi", "Yichun Zhang")
- ngx.say("Hi")
- ';
- }
- location /hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello Yichun Zhang
-
-
-
-=== TEST 7: args in uri
---- config
- location /read {
- content_by_lua '
- ngx.exec("/hi?agentzh")
- ngx.say("Hi")
- ';
- }
- location /hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello agentzh
-
-
-
-=== TEST 8: args in uri and user args
---- config
- location /read {
- content_by_lua '
- ngx.exec("/hi?a=Yichun", "b=Zhang")
- ngx.say("Hi")
- ';
- }
- location /hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello a=Yichun&b=Zhang
-
-
-
-=== TEST 9: args in uri and user args
---- config
- location /read {
- content_by_lua '
- ngx.exec("@hi?a=Yichun", "b=Zhang")
- ngx.say("Hi")
- ';
- }
- location @hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello
-
-
-
-=== TEST 10: exec after location capture (simple echo)
---- config
- location /test {
- content_by_lua_file 'html/test.lua';
- }
-
- location /a {
- echo "hello";
- }
-
- location /b {
- echo "hello";
- }
-
---- user_files
->>> test.lua
-ngx.location.capture('/a')
-
-ngx.exec('/b')
---- request
- GET /test
---- response_body
-hello
-
-
-
-=== TEST 11: exec after location capture (memc)
---- config
- location /test {
- content_by_lua_file 'html/test.lua';
- }
-
- location /a {
- set $memc_key 'hello world';
- set $memc_value 'hello hello hello world world world';
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /b {
- set $memc_key 'hello world';
- set $memc_cmd get;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
---- user_files
->>> test.lua
-ngx.location.capture('/a')
-
-ngx.exec('/b')
---- request
- GET /test
---- response_body: hello hello hello world world world
-
-
-
-=== TEST 12: exec after named location capture (simple echo)
---- config
- location /test {
- content_by_lua_file 'html/test.lua';
- }
-
- location /a {
- echo "hello";
- }
-
- location @b {
- echo "hello";
- }
-
---- user_files
->>> test.lua
-ngx.location.capture('/a')
-
-ngx.exec('@b')
---- request
- GET /test
---- response_body
-hello
-
-
-
-=== TEST 13: exec after named location capture (memc)
---- config
- location /test {
- content_by_lua_file 'html/test.lua';
- }
-
- location /a {
- set $memc_key 'hello world';
- set $memc_value 'hello hello hello world world world';
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location @b {
- set $memc_key 'hello world';
- set $memc_cmd get;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
---- user_files
->>> test.lua
-ngx.location.capture('/a')
-
-ngx.exec('@b')
---- request
- GET /test
---- response_body: hello hello hello world world world
-
-
-
-=== TEST 14: github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location (content)
---- config
- location = /hi {
- echo hello;
- }
- location /sub {
- proxy_pass http://127.0.0.1:$server_port/hi;
- #echo hello;
- }
- location /p{
- #content_by_lua '
- #local res = ngx.location.capture("/sub")
- #ngx.print(res.body)
- #';
- echo_location /sub;
- }
- location /lua {
- content_by_lua '
- ngx.exec("/p")
- ';
- }
---- request
- GET /lua
---- response_body
-hello
-
-
-
-=== TEST 15: github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location (content + named location)
---- config
- location = /hi {
- echo hello;
- }
- location /sub {
- proxy_pass http://127.0.0.1:$server_port/hi;
- #echo hello;
- }
- location @p {
- #content_by_lua '
- #local res = ngx.location.capture("/sub")
- #ngx.print(res.body)
- #';
- echo_location /sub;
- }
- location /lua {
- content_by_lua '
- ngx.exec("@p")
- ';
- }
---- request
- GET /lua
---- response_body
-hello
-
-
-
-=== TEST 16: github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location (content + post subrequest)
---- config
- location = /hi {
- echo hello;
- }
- location /sub {
- proxy_pass http://127.0.0.1:$server_port/hi;
- #echo hello;
- }
- location /p{
- #content_by_lua '
- #local res = ngx.location.capture("/sub")
- #ngx.print(res.body)
- #';
- echo_location /sub;
- }
- location blah {
- echo blah;
- }
- location /lua {
- content_by_lua '
- ngx.location.capture("/blah")
- ngx.exec("/p")
- ';
- }
---- request
- GET /lua
---- response_body
-hello
-
-
-
-=== TEST 17: pcall safe
---- config
- location /lua {
- content_by_lua '
- local function f ()
- ngx.exec("/hi")
- end
-
- pcall(f)
- ngx.say("hello")
- ';
- }
- location /hi {
- echo hi;
- }
---- request
-GET /lua
---- error_code: 200
---- response_body
-hi
-
-
-
-=== TEST 18: lua table as "args" parameter
---- config
- location /lua {
- content_by_lua '
- local args = { foo = 3, bar = 4 }
- ngx.exec("/hi", args)
- ';
- }
- location /hi {
- echo "foo = $arg_foo";
- echo "bar = $arg_bar";
- }
---- request
-GET /lua
---- error_code: 200
---- response_body
-foo = 3
-bar = 4
-
-
-
-=== TEST 19: jump to internal locations requires ctx cleared
---- config
- location @proxy {
- rewrite_by_lua return;
- echo hello;
- }
- location /main {
- content_by_lua '
- ngx.exec("@proxy")
- ';
- }
---- request
- GET /main
---- response_body
-hello
-
-
-
-=== TEST 20: exec + rewrite + named locations
---- config
- location @proxy {
- rewrite_by_lua return;
- echo hello;
- }
- location /main {
- rewrite_by_lua '
- ngx.exec("@proxy")
- ';
- }
---- request
- GET /main
---- response_body
-hello
-
-
-
-=== TEST 21: exec(named location) in subrequests
---- config
- location /entry {
- echo_location /foo;
- echo_location /foo2;
- }
- location /foo {
- content_by_lua '
- ngx.exec("@bar")
- ';
- }
- location /foo2 {
- content_by_lua '
- ngx.exec("@bar")
- ';
- }
-
- location @bar {
- proxy_pass http://127.0.0.1:$server_port/bar;
- }
- location /bar {
- echo hello;
- }
---- request
- GET /entry
---- response_body
-hello
-hello
-
-
-
-=== TEST 22: exec(normal location) in subrequests
---- config
- location /entry {
- echo_location /foo;
- echo_location /foo2;
- }
- location /foo {
- content_by_lua '
- ngx.exec("/baz")
- ';
- }
- location /foo2 {
- content_by_lua '
- ngx.exec("/baz")
- ';
- }
-
- location /baz {
- proxy_pass http://127.0.0.1:$server_port/bar;
- }
- location /bar {
- echo hello;
- }
---- request
- GET /entry
---- response_body
-hello
-hello
-
-
-
-=== TEST 23: content_by_lua + ngx.exec + subrequest capture
---- config
- location /main {
- rewrite_by_lua '
- local res = ngx.location.capture("/test_loc");
- ngx.print("hello, ", res.body)
- ';
- content_by_lua return;
- }
- location /test_loc {
- content_by_lua '
- ngx.exec("@proxy")
- ';
- }
- location @proxy {
- #echo proxy;
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
- location /foo {
- #echo_status 201;
- echo bah;
- }
---- request
- GET /main
---- response_body
-hello, bah
-
-
-
-=== TEST 24: jump to an internal location
---- config
- location /t {
- content_by_lua '
- return ngx.exec("/proxy", ngx.var.args)
- ';
- }
-
- location /proxy {
- internal;
-
- proxy_pass http://127.0.0.1:$server_port/dummy;
- }
-
- location = /dummy {
- echo -n dummy;
- }
---- pipelined_requests eval
-["GET /t", "GET /t?foo"]
---- response_body eval
-["dummy", "dummy"]
---- no_error_log
-[error]
-
-
-
-=== TEST 25: pipelined requests
---- config
- location /t {
- content_by_lua_block {
- ngx.exec("@foo")
- }
- }
-
- location @foo {
- return 200;
- }
---- pipelined_requests eval
-["GET /t", "GET /t"]
---- error_code eval
-[200, 200]
---- response_body eval
-["", ""]
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/018-ndk.t b/src/deps/src/lua-nginx-module/t/018-ndk.t
deleted file mode 100644
index 14293772d..000000000
--- a/src/deps/src/lua-nginx-module/t/018-ndk.t
+++ /dev/null
@@ -1,173 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 4);
-
-#no_diff();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /read {
- content_by_lua '
- local s = ndk.set_var.set_escape_uri(" :")
- local r = ndk.set_var.set_unescape_uri("a%20b")
- ngx.say(s)
- ngx.say(r)
- ';
- }
---- request
-GET /read
---- response_body
-%20%3A
-a b
-
-
-
-=== TEST 2: directive not found
---- config
- location /read {
- content_by_lua '
- local s = ndk.set_var.set_escape_uri_blah_blah(" :")
- ngx.say(s)
- ';
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 3: directive not found
---- config
- location /read {
- content_by_lua '
- local s = ndk.set_var.content_by_lua(" :")
- ngx.say(s)
- ';
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 4: directive not found
---- config
- location /read {
- header_filter_by_lua '
- ngx.header.Foo = ndk.set_var.set_escape_uri(" %")
- ';
- echo hi;
- }
---- request
-GET /read
---- response_headers
-Foo: %20%25
---- response_body
-hi
-
-
-
-=== TEST 5: bug: ndk.set_var not initialize ngx_http_variable_value_t variable properly
---- config
- location /luaset {
- content_by_lua "
-
- local version = '2011.10.13+0000'
- local e_version = ndk.set_var.set_encode_base32(version)
- local s_version= ndk.set_var.set_quote_sql_str(version)
- ngx.say(e_version)
- ngx.say(s_version)
- ";
- }
---- request
-GET /luaset
---- response_body
-68o32c9e64o2sc9j5co30c1g
-'2011.10.13+0000'
-
-
-
-=== TEST 6: set_by_lua
---- config
- location /read {
- set_by_lua $r '
- return ndk.set_var.set_unescape_uri("a%20b")
- ';
- echo $r;
- }
---- request
-GET /read
---- response_body
-a b
-
-
-
-=== TEST 7: header_filter_by_lua
---- config
- location /read {
- set $foo '';
- content_by_lua '
- ngx.send_headers()
- ngx.say(ngx.var.foo)
- ';
- header_filter_by_lua '
- ngx.var.foo = ndk.set_var.set_unescape_uri("a%20b")
- ';
- }
---- request
-GET /read
---- response_body
-a b
-
-
-
-=== TEST 8: log_by_lua
---- config
- location /read {
- echo ok;
- log_by_lua '
- local foo = ndk.set_var.set_unescape_uri("a%20b")
- ngx.log(ngx.WARN, "foo = ", foo)
- ';
- }
---- request
-GET /read
---- response_body
-ok
---- wait: 0.1
---- error_log
-foo = a b
-
-
-
-=== TEST 9: ngx.timer.*
---- config
- location /read {
- echo ok;
- log_by_lua '
- ngx.timer.at(0, function ()
- local foo = ndk.set_var.set_unescape_uri("a%20b")
- ngx.log(ngx.WARN, "foo = ", foo)
- end)
- ';
- }
---- request
-GET /read
---- response_body
-ok
---- wait: 0.1
---- error_log
-foo = a b
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/019-const.t b/src/deps/src/lua-nginx-module/t/019-const.t
deleted file mode 100644
index 4f9c7640c..000000000
--- a/src/deps/src/lua-nginx-module/t/019-const.t
+++ /dev/null
@@ -1,46 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => blocks() * repeat_each() * 2;
-
-#no_diff();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /read {
- content_by_lua '
- ngx.say(ngx.OK)
- ngx.say(ngx.AGAIN)
- ngx.say(ngx.DONE)
- ngx.say(ngx.ERROR)
- ';
- }
---- request
-GET /read
---- response_body
-0
--2
--4
--1
-
-
-
-=== TEST 2: http constants
---- config
- location /read {
- content_by_lua '
- ngx.say(ngx.HTTP_GATEWAY_TIMEOUT)
- ';
- }
---- request
-GET /read
---- response_body
-504
diff --git a/src/deps/src/lua-nginx-module/t/020-subrequest.t b/src/deps/src/lua-nginx-module/t/020-subrequest.t
deleted file mode 100644
index 37914be06..000000000
--- a/src/deps/src/lua-nginx-module/t/020-subrequest.t
+++ /dev/null
@@ -1,3620 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use Test::Nginx::Util 'is_tcp_port_used';
-
-#master_on();
-#workers(1);
-#worker_connections(1014);
-#log_level('warn');
-#master_process_enabled(1);
-
-no_root_location;
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 23);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-
-# NB: tcp_listen_port needs to be greater than 10000,
-# because the test cases expect it to be a 5-digit number
-my $tcp_listen_port = 19113;
-while (++$tcp_listen_port < 65535) {
- if (!is_tcp_port_used $tcp_listen_port) {
- last;
- }
-}
-$ENV{TEST_NGINX_TCP_LISTEN_PORT} = $tcp_listen_port;
-
-#no_diff();
-no_long_string();
-#no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: DELETE
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_DELETE });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-DELETE
---- error_log
-lua http subrequest "/other?"
---- no_error_log
-[error]
-
-
-
-=== TEST 2: DELETE (proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_DELETE });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-DELETE
---- no_error_log
-[error]
-
-
-
-=== TEST 3: POST (nobody, proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /t {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_POST });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /t
---- response_body
-POST
---- no_error_log
-[error]
-
-
-
-=== TEST 4: HEAD
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_HEAD });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
---- no_error_log
-[error]
-
-
-
-=== TEST 5: explicit GET
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_GET });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-GET
---- no_error_log
-[error]
-
-
-
-=== TEST 6: implicit GET
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo")
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-GET
---- no_error_log
-[error]
-
-
-
-=== TEST 7: implicit GET (empty option table)
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo", {})
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-GET
---- no_error_log
-[error]
-
-
-
-=== TEST 8: PUT (with body, proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo_read_request_body;
-
- echo $echo_request_method;
- echo_request_body;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_PUT, body = "hello" });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body chomp
-PUT
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 9: PUT (with body, no proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- #echo_read_request_body;
-
- echo $echo_request_method;
- #echo $echo_request_body;
- echo_request_body;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_PUT, body = "hello" });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body chomp
-PUT
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 10: PUT (no body, no proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- #echo_read_request_body;
-
- echo $echo_request_method;
- #echo $echo_request_body;
- echo_request_body;
- #echo "[$http_content_length]";
- echo;
- }
-
- location /foo {
- echo $echo_request_method;
- echo -n "[$http_content_length]";
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_PUT, body = "hello" });
-
- ngx.print(res.body)
-
- res = ngx.location.capture("/foo")
- ngx.say(res.body)
-
- ';
- }
---- request
-GET /lua
---- response_body
-PUT
-hello
-GET
-[]
---- no_error_log
-[error]
-
-
-
-=== TEST 11: POST (with body, proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo_read_request_body;
-
- echo $echo_request_method;
- echo_request_body;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_POST, body = "hello" });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body chomp
-POST
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 12: POST (with body, memc method)
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc {
- set $memc_key $echo_request_uri;
- set $memc_exptime 600;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /lua {
- content_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- ngx.say("GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- ngx.say("PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- ngx.say("cached: " .. res.body);
-
- ';
- }
---- request
-GET /lua
---- response_body
-GET: 404
-PUT: 201
-cached: hello
---- no_error_log
-[error]
-
-
-
-=== TEST 13: POST (with body, memc method)
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc {
- set $memc_cmd "";
- set $memc_key $echo_request_uri;
- set $memc_exptime 600;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /lua {
- content_by_lua '
- ngx.location.capture("/flush",
- { share_all_vars = true });
-
- local res = ngx.location.capture("/memc",
- { share_all_vars = true });
- ngx.say("GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello", share_all_vars = true });
- ngx.say("PUT: " .. res.status);
-
- res = ngx.location.capture("/memc", { share_all_vars = true });
- ngx.say("cached: " .. res.body);
- ';
- }
---- request
-GET /lua
---- response_body
-GET: 404
-PUT: 201
-cached: hello
---- no_error_log
-[error]
-
-
-
-=== TEST 14: empty args option table
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { args = {} })
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body eval: "\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 15: non-empty args option table (1 pair)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { ["fo="] = "=>" } })
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-fo%3D=%3D%3E
---- no_error_log
-[error]
-
-
-
-=== TEST 16: non-empty args option table (2 pairs)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { ["fo="] = "=>",
- ["="] = ":" } })
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body_like chop
-^(?:fo%3D=%3D%3E\&%3D=%3A|%3D=%3A\&fo%3D=%3D%3E)$
---- no_error_log
-[error]
---- no_error_log
-[error]
-
-
-
-=== TEST 17: non-empty args option table (2 pairs, no special chars)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { foo = 3,
- bar = "hello" } })
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body_like chop
-^(?:bar=hello\&foo=3|foo=3\&bar=hello)$
---- no_error_log
-[error]
-
-
-
-=== TEST 18: non-empty args option table (number key)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { [57] = "hi" } })
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-attempt to use a non-string key in the "args" option table
-
-
-
-=== TEST 19: non-empty args option table (plain arrays)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { "hi" } })
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-attempt to use a non-string key in the "args" option table
-
-
-
-=== TEST 20: more args
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo?a=3",
- { args = { b = 4 } })
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-a=3&b=4
---- no_error_log
-[error]
-
-
-
-=== TEST 21: more args
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo?a=3",
- { args = "b=4" })
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-a=3&b=4
---- no_error_log
-[error]
-
-
-
-=== TEST 22: is_subrequest in main request
---- config
- location /lua {
- content_by_lua '
- if ngx.is_subrequest then
- ngx.say("sub req")
- else
- ngx.say("main req")
- end
- ';
- }
---- request
- GET /lua
---- response_body
-main req
---- no_error_log
-[error]
-
-
-
-=== TEST 23: is_subrequest in sub request
---- config
- location /main {
- echo_location /lua;
- }
-
- location /lua {
- content_by_lua '
- if ngx.is_subrequest then
- ngx.say("sub req")
- else
- ngx.say("main req")
- end
- ';
- }
---- request
- GET /main
---- response_body
-sub req
---- no_error_log
-[error]
-
-
-
-=== TEST 24: is_subrequest in sub request in set_by_lua
---- config
- location /main {
- echo_location /lua;
- }
-
- location /lua {
- set_by_lua $a '
- if ngx.is_subrequest then
- return "sub req"
- else
- return "main req"
- end
- ';
- echo $a;
- }
---- request
- GET /main
---- response_body
-sub req
---- no_error_log
-[error]
-
-
-
-=== TEST 25: header inheritance bug (without body) (github issue 38)
-https://github.com/chaoslawful/lua-nginx-module/issues/38
---- config
- location /other {
- default_type 'foo/bar';
- echo -n $http_foo;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_GET });
- ngx.say("header foo: [", res.body, "]")
- ';
- }
---- request
-GET /lua
---- more_headers
-Foo: bar
---- response_body
-header foo: [bar]
---- no_error_log
-[error]
-
-
-
-=== TEST 26: header inheritance bug (with body) (github issue 38)
-https://github.com/chaoslawful/lua-nginx-module/issues/38
---- config
- location /other {
- default_type 'foo/bar';
- echo -n $http_foo;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { body = "abc" });
- ngx.say("header foo: [", res.body, "]")
- ';
- }
---- request
-GET /lua
---- more_headers
-Foo: bar
---- response_body
-header foo: [bar]
---- no_error_log
-[error]
-
-
-
-=== TEST 27: lua calls lua via subrequests
---- config
- location /a {
- content_by_lua '
- ngx.say("hello, a");
- ';
- }
- location /b {
- content_by_lua '
- ngx.say("hello, b");
- ';
- }
- location /c {
- content_by_lua '
- ngx.say("hello, c");
- ';
- }
- location /main {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi({{"/a"}, {"/b"}})
- local res3 = ngx.location.capture("/c")
- ngx.print(res1.body, res2.body, res3.body)
- ';
- }
---- request
- GET /main
---- response_body
-hello, a
-hello, b
-hello, c
---- error_log
-lua reuse free buf memory
---- no_error_log
-[error]
-
-
-
-=== TEST 28: POST (with body, proxy method, main request is a POST too)
---- config
- location /other {
- default_type 'foo/bar';
- echo_read_request_body;
-
- echo $echo_request_method;
- echo_request_body;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_POST, body = "hello" });
-
- ngx.print(res.body)
- ';
- }
---- request
-POST /lua
-hi
---- response_body chomp
-POST
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 29: Last-Modified response header for static file subrequest
---- config
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo.html")
-
- ngx.say(res.status)
- ngx.say(res.header["Last-Modified"])
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- user_files
->>> foo.html
-hello, static file
---- response_body_like chomp
-^200
-[A-Za-z]+, \d{1,2} [A-Za-z]+ \d{4} \d{2}:\d{2}:\d{2} GMT
-hello, static file$
---- no_error_log
-[error]
-
-
-
-=== TEST 30: custom ctx table for subrequest
---- config
- location /sub {
- content_by_lua '
- ngx.ctx.foo = "bar";
- ';
- }
- location /lua {
- content_by_lua '
- local ctx = {}
- local res = ngx.location.capture("/sub", { ctx = ctx })
-
- ngx.say(ctx.foo);
- ngx.say(ngx.ctx.foo);
- ';
- }
---- request
-GET /lua
---- response_body
-bar
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 31: share the ctx with the parent
---- config
- location /sub {
- content_by_lua '
- ngx.ctx.foo = "bar";
- ';
- }
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/sub", { ctx = ngx.ctx })
- ngx.say(ngx.ctx.foo);
- ';
- }
---- request
-GET /lua
---- response_body
-bar
---- no_error_log
-[error]
-
-
-
-=== TEST 32: test memcached with subrequests
---- http_config
- upstream memc {
- server 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- keepalive 100;
- }
---- config
- location /memc {
- set $memc_key some_key;
- set $memc_exptime 600;
- memc_pass memc;
- }
-
- location /t {
- content_by_lua '
- local res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello 1234" });
- -- ngx.say("PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- ngx.say("some_key: " .. res.body);
- ';
- }
---- request
-GET /t
---- response_body
-some_key: hello 1234
---- error_log
-lua reuse free buf chain, but reallocate memory because
---- no_error_log
-[error]
-
-
-
-=== TEST 33: main POST, sub GET (main does not read the body)
---- config
- location /other {
- default_type 'foo/bar';
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_method)
- ngx.say(ngx.req.get_body_data())
- ';
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- #proxy_pass http://127.0.0.1:8892/other;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_GET });
-
- ngx.print(res.body)
- ';
- }
---- request
-POST /lua
-hello, world
---- response_body
-GET
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 34: main POST, sub GET (main has read the body)
---- config
- location /other {
- default_type 'foo/bar';
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_method)
- ngx.say(ngx.req.get_body_data())
- ';
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- #proxy_pass http://127.0.0.1:8892/other;
- }
-
- location /lua {
- content_by_lua '
- ngx.req.read_body()
-
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_GET });
-
- ngx.print(res.body)
- ';
- }
---- request
-POST /lua
-hello, world
---- response_body
-GET
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 35: main POST, sub POST (inherit bodies directly)
---- config
- location /other {
- default_type 'foo/bar';
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_method)
- ngx.say(ngx.req.get_body_data())
- ';
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- #proxy_pass http://127.0.0.1:8892/other;
- }
-
- location /lua {
- content_by_lua '
- ngx.req.read_body()
-
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_POST });
-
- ngx.print(res.body)
- ';
- }
---- request
-POST /lua
-hello, world
---- response_body
-POST
-hello, world
---- no_error_log
-[error]
-
-
-
-=== TEST 36: main POST, sub PUT (inherit bodies directly)
---- config
- location /other {
- default_type 'foo/bar';
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_method)
- ngx.say(ngx.req.get_body_data())
- ';
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- #proxy_pass http://127.0.0.1:8892/other;
- }
-
- location /lua {
- content_by_lua '
- ngx.req.read_body()
-
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_PUT });
-
- ngx.print(res.body)
- ';
- }
---- request
-POST /lua
-hello, world
---- response_body
-PUT
-hello, world
---- no_error_log
-[error]
-
-
-
-=== TEST 37: recursive calls
---- config
- location /t {
- content_by_lua '
- ngx.location.capture("/t")
- ';
- }
---- request
- GET /t
---- ignore_response
---- error_log
-lua subrequests cycle while processing "/t"
-
-
-
-=== TEST 38: OPTIONS
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_OPTIONS });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-OPTIONS
---- no_error_log
-[error]
-
-
-
-=== TEST 39: OPTIONS with a body
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- echo_request_body;
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_OPTIONS, body = "hello world" });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body chop
-OPTIONS
-hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 40: encode args table with a multi-value arg.
---- config
- location /t {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
- if err then
- ngx.say("err: ", err)
- end
-
- local res = ngx.location.capture("/sub", { args = args })
- ngx.print(res.body)
- ';
- }
-
- location /sub {
- echo $query_string;
- }
---- request
-GET /t?r[]=http%3A%2F%2Fajax.googleapis.com%3A80%2Fajax%2Flibs%2Fjquery%2F1.7.2%2Fjquery.min.js&r[]=http%3A%2F%2Fajax.googleapis.com%3A80%2Fajax%2Flibs%2Fdojo%2F1.7.2%2Fdojo%2Fdojo.js.uncompressed.js
---- response_body
-r%5B%5D=http%3A%2F%2Fajax.googleapis.com%3A80%2Fajax%2Flibs%2Fjquery%2F1.7.2%2Fjquery.min.js&r%5B%5D=http%3A%2F%2Fajax.googleapis.com%3A80%2Fajax%2Flibs%2Fdojo%2F1.7.2%2Fdojo%2Fdojo.js.uncompressed.js
---- no_error_log
-[error]
-
-
-
-=== TEST 41: subrequests finalized with NGX_ERROR
---- config
- location /sub {
- content_by_lua '
- ngx.exit(ngx.ERROR)
- ';
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ';
- }
---- request
-GET /main
---- response_body
-status: 500
-body:
-
-
-
-=== TEST 42: subrequests finalized with 500
---- config
- location /sub {
- return 500;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ';
- }
---- request
-GET /main
---- response_body
-status: 500
-body:
-
-
-
-=== TEST 43: subrequests with an output body filter returning NGX_ERROR
---- config
- location /sub {
- echo hello world;
- body_filter_by_lua '
- return ngx.ERROR
- ';
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ';
- }
---- request
-GET /main
---- stap2
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
---- response_body
---- error_code
---- no_error_log
-[error]
---- curl_error eval
-qr{(\Qcurl: (52) Empty reply from server\E|\Qcurl: (95) HTTP/3 stream 0 reset by server\E)}ms
-
-
-
-=== TEST 44: subrequests truncated in its response body due to premature connection close (nonbuffered)
---- config
- server_tokens off;
- location /memc {
- internal;
-
- set $memc_key 'foo';
- #set $memc_exptime 300;
- memc_pass 127.0.0.1:$TEST_NGINX_RAND_PORT_1; #$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/memc")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_RAND_PORT_1
---- tcp_query_len: 9
---- tcp_reply eval
-"VALUE foo 0 1024\r\nhello world"
-
---- stap2
-F(ngx_http_lua_capture_body_filter) {
- if (pid() == target() && $r != $r->main) {
- printf("lua capture body output: %s\n", ngx_chain_dump($in))
- if ($in->buf->last_in_chain) {
- print_ubacktrace()
- }
- }
-}
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-upstream fin req: error=0 eof=1 rc=502
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello world
-truncated: true
---- error_log
-upstream prematurely closed connection
-
-
-
-=== TEST 45: subrequests truncated in its response body due to upstream read timeout (nonbuffered)
---- config
- memc_read_timeout 100ms;
- location /memc {
- internal;
-
- set $memc_key 'foo';
- #set $memc_exptime 300;
- memc_pass 127.0.0.1:$TEST_NGINX_RAND_PORT_1; #$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/memc")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_RAND_PORT_1
---- tcp_no_close
---- tcp_reply eval
-"VALUE foo 0 1024\r\nhello world"
-
---- stap2
-F(ngx_http_lua_capture_body_filter) {
- if (pid() == target() && $r != $r->main) {
- printf("lua capture body output: %s\n", ngx_chain_dump($in))
- //if ($in->buf->last_in_chain) {
- print_ubacktrace()
- //}
- }
-}
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-conn err: 110: upstream timed out
-upstream fin req: error=0 eof=0 rc=504
-post subreq: rc=0, status=200
-
---- response_body_like chop
-^status: 200
-body: [^\n]*
-truncated: true
-
---- error_log
-upstream timed out
-
-
-
-=== TEST 46: subrequests truncated in its response body due to premature connection close (buffered)
---- config
- server_tokens off;
-
- location /proxy {
- internal;
-
- #proxy_read_timeout 100ms;
- proxy_buffering on;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_query_len: 65
---- tcp_reply eval
-"HTTP/1.0 200 OK\r\nContent-Length: 1024\r\n\r\nhello world"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-upstream fin req: error=0 eof=1 rc=502
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello world
-truncated: true
-
---- error_log
-upstream prematurely closed connection
-
-
-
-=== TEST 47: subrequests truncated in its response body due to read timeout (buffered)
---- config
- location /proxy {
- internal;
-
- proxy_read_timeout 100ms;
- proxy_buffering on;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_no_close
---- tcp_reply eval
-"HTTP/1.0 200 OK\r\nContent-Length: 1024\r\n\r\nhello world"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-conn err: 110: upstream timed out
-upstream fin req: error=0 eof=0 rc=502
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body:
-truncated: true
-
---- error_log
-upstream timed out
-
-
-
-=== TEST 48: subrequests truncated in its response body due to premature connection close (buffered, no content-length)
---- config
- server_tokens off;
- location /proxy {
- internal;
-
- #proxy_read_timeout 100ms;
- proxy_buffering on;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_query_len: 65
---- tcp_reply eval
-"HTTP/1.0 200 OK\r\n\r\nhello world"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-upstream fin req: error=0 eof=1 rc=0
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello world
-truncated: false
-
---- no_error_log
-[error]
-
-
-
-=== TEST 49: subrequests truncated in its response body due to read timeout (buffered, no content-length)
---- config
- location /proxy {
- internal;
-
- proxy_read_timeout 100ms;
- proxy_buffering on;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_no_close
---- tcp_reply eval
-"HTTP/1.0 200 OK\r\n\r\nhello world"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-conn err: 110: upstream timed out
-upstream fin req: error=0 eof=0 rc=502
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body:
-truncated: true
-
---- error_log
-upstream timed out
-
-
-
-=== TEST 50: subrequests truncated in its response body due to premature connection close (nonbuffered, no content-length)
---- config
- server_tokens off;
-
- location /proxy {
- internal;
-
- #proxy_read_timeout 100ms;
- proxy_buffering off;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_query_len: 65
---- tcp_reply eval
-"HTTP/1.0 200 OK\r\n\r\nhello world"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-upstream fin req: error=0 eof=1 rc=0
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello world
-truncated: false
-
---- no_error_log
-[error]
-
-
-
-=== TEST 51: subrequests truncated in its response body due to read timeout (nonbuffered, no content-length)
---- config
- location /proxy {
- internal;
-
- proxy_read_timeout 500ms;
- proxy_buffering off;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_no_close
---- tcp_reply eval
-"HTTP/1.0 200 OK\r\n\r\nhello world"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-conn err: 110: upstream timed out
-upstream fin req: error=0 eof=0 rc=504
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello world
-truncated: true
-
---- error_log
-upstream timed out
-
-
-
-=== TEST 52: forwarding in-memory request bodies to multiple subrequests
---- config
- location /other {
- default_type 'foo/bar';
- proxy_pass http://127.0.0.1:$server_port/back;
- }
-
- location /back {
- echo_read_request_body;
- echo_request_body;
- }
-
- location /lua {
- content_by_lua '
- ngx.req.read_body()
-
- for i = 1, 2 do
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_POST });
-
- ngx.say(res.body)
- end
- ';
- }
-
---- request eval
-"POST /lua
-" . "hello world"
-
---- response_body
-hello world
-hello world
-
---- no_error_log
-[error]
-
-
-
-=== TEST 53: forwarding in-file request bodies to multiple subrequests (client_body_in_file_only)
---- config
- location /other {
- default_type 'foo/bar';
- proxy_pass http://127.0.0.1:$server_port/back;
- }
-
- location /back {
- echo_read_request_body;
- echo_request_body;
- }
-
- client_body_in_file_only on;
-
- location /lua {
- content_by_lua '
- ngx.req.read_body()
-
- for i = 1, 2 do
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_POST });
-
- ngx.say(res.body)
- end
- ';
- }
-
---- request eval
-"POST /lua
-" . "hello world"
-
---- response_body
-hello world
-hello world
-
---- no_error_log
-[error]
-
-
-
-=== TEST 54: forwarding in-file request bodies to multiple subrequests (exceeding client_body_buffer_size)
---- config
- location /other {
- default_type 'foo/bar';
- proxy_pass http://127.0.0.1:$server_port/back;
- }
-
- location /back {
- echo_read_request_body;
- echo_request_body;
- }
-
- location /lua {
- #client_body_in_file_only on;
- client_body_buffer_size 1;
- content_by_lua '
- ngx.req.read_body()
-
- for i = 1, 2 do
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_POST });
-
- ngx.say(res.body)
- end
- ';
- }
---- request eval
-"POST /lua
-" . ("hello world" x 100)
-
---- stap2
-global valid = 0
-global fds
-
-F(ngx_http_handler) { valid = 1 }
-
-probe syscall.open {
- if (valid && pid() == target()) {
- print(name, "(", argstr, ")")
- }
-}
-
-probe syscall.close {
- if (valid && pid() == target() && fds[sprintf("%d", $fd)]) {
- println(name, "(", argstr, ")")
- }
-}
-
-probe syscall.unlink {
- if (valid && pid() == target()) {
- println(name, "(", argstr, ")")
- }
-}
-
-probe syscall.open.return {
- if (valid && pid() == target()) {
- println(" = ", retstr)
- fds[retstr] = 1
- }
-}
-
-F(ngx_http_lua_subrequest) {
- println("lua subrequest")
-}
-
-F(ngx_output_chain) {
- printf("output chain: %s\n", ngx_chain_dump($in))
-}
-
-F(ngx_pool_run_cleanup_file) {
- println("clean up file: ", $fd)
-}
-
---- response_body eval
-("hello world" x 100) . "\n"
-. ("hello world" x 100) . "\n"
-
---- no_error_log
-[error]
---- error_log
-a client request body is buffered to a temporary file
-
-
-
-=== TEST 55: subrequests truncated in its response body due to premature connection close (buffered + chunked)
---- config
- server_tokens off;
-
- location /proxy {
- internal;
-
- #proxy_read_timeout 100ms;
- proxy_http_version 1.1;
- proxy_buffering on;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_query_len: 65
---- tcp_reply eval
-"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\nb\r\nhello world\r"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-upstream fin req: error=0 eof=1 rc=502
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello world
-truncated: true
-
---- error_log
-upstream prematurely closed connection
-
-
-
-=== TEST 56: subrequests truncated in its response body due to premature connection close (nonbuffered + chunked)
---- config
- server_tokens off;
-
- location /proxy {
- internal;
-
- #proxy_read_timeout 100ms;
- proxy_http_version 1.1;
- proxy_buffering off;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_query_len: 65
---- tcp_reply eval
-"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\nb\r\nhello world\r"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-upstream fin req: error=0 eof=1 rc=502
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello world
-truncated: true
-
---- error_log
-upstream prematurely closed connection
-
-
-
-=== TEST 57: subrequests truncated in its response body due to read timeout (buffered + chunked)
---- config
- location /proxy {
- internal;
-
- proxy_read_timeout 100ms;
- proxy_buffering on;
- proxy_http_version 1.1;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_no_close
---- tcp_reply eval
-"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\nb\r\nhello world\r"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-conn err: 110: upstream timed out
-upstream fin req: error=0 eof=0 rc=502
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body:
-truncated: true
-
---- error_log
-upstream timed out
-
-
-
-=== TEST 58: good chunked response (buffered)
---- config
- location /proxy {
- internal;
-
- #proxy_read_timeout 100ms;
- proxy_buffering on;
- proxy_http_version 1.1;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_no_close
---- tcp_reply eval
-"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nhello\r\n0\r\n\r\n"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-upstream fin req: error=0 eof=0 rc=0
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello
-truncated: false
-
-
-
-=== TEST 59: good chunked response (nonbuffered)
---- config
- location /proxy {
- internal;
-
- #proxy_read_timeout 100ms;
- proxy_buffering off;
- proxy_http_version 1.1;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_no_close
---- tcp_reply eval
-"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nhello\r\n0\r\n\r\n"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-upstream fin req: error=0 eof=0 rc=0
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello
-truncated: false
-
-
-
-=== TEST 60: subrequests truncated in its response body due to premature connection close (nonbuffered + proxy)
---- config
- server_tokens off;
-
- location /proxy {
- internal;
-
- #proxy_read_timeout 100ms;
- proxy_buffering off;
- proxy_pass http://127.0.0.1:$TEST_NGINX_TCP_LISTEN_PORT;
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/proxy")
- ngx.say("status: ", res.status)
- ngx.say("body: ", res.body)
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /main
---- tcp_listen: $TEST_NGINX_TCP_LISTEN_PORT
---- tcp_query_len: 65
---- tcp_reply eval
-"HTTP/1.0 200 OK\r\nContent-Length: 1024\r\n\r\nhello world"
-
---- stap
-F(ngx_http_upstream_finalize_request) {
- printf("upstream fin req: error=%d eof=%d rc=%d\n",
- $r->upstream->peer->connection->read->error,
- $r->upstream->peer->connection->read->eof,
- $rc)
- #print_ubacktrace()
-}
-F(ngx_connection_error) {
- printf("conn err: %d: %s\n", $err, user_string($text))
- #print_ubacktrace()
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: rc=%d, status=%d\n", $rc, $r->headers_out->status)
- #print_ubacktrace()
-}
-/*
-F(ngx_http_finalize_request) {
- printf("finalize: %d\n", $rc)
-}
-*/
---- stap_out
-upstream fin req: error=0 eof=1 rc=502
-post subreq: rc=0, status=200
-
---- response_body
-status: 200
-body: hello world
-truncated: true
-
---- error_log
-upstream prematurely closed connection
-
-
-
-=== TEST 61: WebDAV methods
---- config
- location /other {
- echo "method: $echo_request_method";
- }
-
- location /lua {
- content_by_lua '
- local methods = {
- ngx.HTTP_MKCOL,
- ngx.HTTP_COPY,
- ngx.HTTP_MOVE,
- ngx.HTTP_PROPFIND,
- ngx.HTTP_PROPPATCH,
- ngx.HTTP_LOCK,
- ngx.HTTP_UNLOCK,
- ngx.HTTP_PATCH,
- ngx.HTTP_TRACE,
- }
-
- for i, method in ipairs(methods) do
- local res = ngx.location.capture("/other",
- { method = method })
- ngx.print(res.body)
- end
- ';
- }
---- request
-GET /lua
---- response_body
-method: MKCOL
-method: COPY
-method: MOVE
-method: PROPFIND
-method: PROPPATCH
-method: LOCK
-method: UNLOCK
-method: PATCH
-method: TRACE
-
---- no_error_log
-[error]
-
-
-
-=== TEST 62: by default DELETE subrequests don't forward request bodies
---- config
- location /other {
- default_type 'foo/bar';
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_data())
- ';
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_DELETE });
-
- ngx.print(res.body)
- ';
- }
---- request
-DELETE /lua
-hello world
---- response_body
-nil
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 63: DELETE subrequests do forward request bodies when always_forward_body == true
---- config
- location = /other {
- default_type 'foo/bar';
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_data())
- ';
- }
-
- location /lua {
- content_by_lua '
- ngx.req.read_body()
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_DELETE, always_forward_body = true });
-
- ngx.print(res.body)
- ';
- }
---- request
-DELETE /lua
-hello world
---- response_body
-hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 64: DELETE subrequests do forward request bodies when always_forward_body == true (on disk)
---- config
- location = /other {
- default_type 'foo/bar';
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_data())
- ';
- }
-
- location /lua {
- content_by_lua '
- ngx.req.read_body()
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_DELETE, always_forward_body = true });
-
- ngx.print(res.body)
- ';
- }
---- request
-DELETE /lua
-hello world
---- stap2
-global c
-probe process("$LIBLUA_PATH").function("rehashtab") {
- c++
- //print_ubacktrace()
- printf("rehash: %d\n", c)
-}
---- stap_out2
---- response_body
-hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 65: DELETE
---- config
- location = /t {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ';
- }
- location = /sub {
- echo hello;
- echo world;
- }
---- request
-GET /t
---- response_body
-hello
-world
---- stap
-F(ngx_http_lua_capture_header_filter) {
- println("capture header filter")
-}
-
-F(ngx_http_lua_capture_body_filter) {
- println("capture body filter")
-}
-
---- stap_out
-capture header filter
-capture body filter
-capture body filter
-capture body filter
-capture header filter
-capture body filter
-capture body filter
---- no_error_log
-[error]
-
-
-
-=== TEST 66: leafo test case 1 for assertion failures
---- config
- location = /t {
- echo hello;
- }
-
- location /proxy {
- internal;
- rewrite_by_lua "
- local req = ngx.req
- print(ngx.var._url)
-
- for k,v in pairs(req.get_headers()) do
- if k ~= 'content-length' then
- req.clear_header(k)
- end
- end
-
- if ngx.ctx.headers then
- for k,v in pairs(ngx.ctx.headers) do
- req.set_header(k, v)
- end
- end
- ";
-
- proxy_http_version 1.1;
- proxy_pass $_url;
- }
-
- location /first {
- set $_url "";
- content_by_lua '
- local res = ngx.location.capture("/proxy", {
- ctx = {
- headers = {
- ["Content-type"] = "application/x-www-form-urlencoded"
- }
- },
- vars = { _url = "http://127.0.0.1:" .. ngx.var.server_port .. "/t" }
- })
-
- ngx.print(res.body)
-
- local res = ngx.location.capture("/proxy", {
- ctx = {
- headers = {
- ["x-some-date"] = "Sun, 01 Dec 2013 11:47:41 GMT",
- ["x-hello-world-header"] = "123412341234",
- ["Authorization"] = "Hello"
- }
- },
- vars = { _url = "http://127.0.0.1:" .. ngx.var.server_port .. "/t" }
- })
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /first
---- response_body
-hello
-hello
---- no_error_log eval
-[
-"[error]",
-qr/Assertion .*? failed/
-]
-
-
-
-=== TEST 67: leafo test case 2 for assertion failures
---- config
- location = /t {
- echo hello;
- }
-
- location /proxy {
- internal;
- rewrite_by_lua "
- local req = ngx.req
- print(ngx.var._url)
-
- for k,v in pairs(req.get_headers()) do
- if k ~= 'content-length' then
- req.clear_header(k)
- end
- end
-
- if ngx.ctx.headers then
- for k,v in pairs(ngx.ctx.headers) do
- req.set_header(k, v)
- end
- end
- ";
-
- proxy_http_version 1.1;
- proxy_pass $_url;
- }
-
- location /second {
- set $_url "";
- content_by_lua '
- local res = ngx.location.capture("/proxy", {
- method = ngx.HTTP_POST,
- body = ("x"):rep(600),
- ctx = {
- headers = {
- ["Content-type"] = "application/x-www-form-urlencoded"
- }
- },
- vars = { _url = "http://127.0.0.1:" .. ngx.var.server_port .. "/t" }
- })
-
- ngx.print(res.body)
-
- local res = ngx.location.capture("/proxy", {
- ctx = {
- headers = {
- ["x-some-date"] = "Sun, 01 Dec 2013 11:47:41 GMT",
- ["x-hello-world-header"] = "123412341234",
- ["Authorization"] = "Hello"
- }
- },
- vars = { _url = "http://127.0.0.1:" .. ngx.var.server_port .. "/t" }
- })
-
- ngx.print(res.body)
-
- local res = ngx.location.capture("/proxy", {
- vars = { _url = "http://127.0.0.1:" .. ngx.var.server_port .. "/t" }
- })
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /second
---- response_body
-hello
-hello
-hello
---- no_error_log eval
-[
-"[error]",
-qr/Assertion .*? failed/
-]
-
-
-
-=== TEST 68: fetch subrequest's builtin request headers
---- config
- location = /sub {
- echo "sr: User-Agent: $http_user_agent";
- echo "sr: Host: $http_host";
- }
-
- location = /t {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ngx.say("pr: User-Agent: ", ngx.var.http_user_agent)
- ngx.say("pr: Host: ", ngx.var.http_host)
- ';
- }
---- request
- GET /t
---- more_headers
-User-Agent: foo
---- response_body
-sr: User-Agent: foo
-sr: Host: localhost
-pr: User-Agent: foo
-pr: Host: localhost
-
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 69: modify subrequest's builtin request headers
---- config
- location = /sub {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "bar")
- ';
- echo "sr: User-Agent: $http_user_agent";
- echo "sr: Host: $http_host";
- }
-
- location = /t {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ngx.say("pr: User-Agent: ", ngx.var.http_user_agent)
- ngx.say("pr: Host: ", ngx.var.http_host)
- ';
- }
---- request
- GET /t
---- more_headers
-User-Agent: foo
---- response_body
-sr: User-Agent: bar
-sr: Host: localhost
-pr: User-Agent: foo
-pr: Host: localhost
-
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 70: modify subrequest's builtin request headers (main req is POST)
---- config
- location = /sub {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "bar")
- ';
- echo "sr: User-Agent: $http_user_agent";
- echo "sr: Host: $http_host";
- }
-
- location = /t {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ngx.say("pr: User-Agent: ", ngx.var.http_user_agent)
- ngx.say("pr: Host: ", ngx.var.http_host)
- ';
- }
---- request
-POST /t
-hello world
---- more_headers
-User-Agent: foo
---- response_body
-sr: User-Agent: bar
-sr: Host: localhost
-pr: User-Agent: foo
-pr: Host: localhost
-
---- no_error_log
-[error]
-
-
-
-=== TEST 71: duplicate request headers (main req is POST)
---- config
- location = /sub {
- echo "sr: Cookie: $http_cookie";
- }
-
- location = /t {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ngx.say("pr: Cookie: ", ngx.var.http_cookie)
- ';
- }
---- request
-POST /t
-hello world
---- more_headers
-Cookie: foo
-Cookie: bar
---- response_body
-sr: Cookie: foo; bar
-pr: Cookie: foo; bar
-
---- no_error_log
-[error]
-
-
-
-=== TEST 72: duplicate request headers (main req is GET)
---- config
- location = /sub {
- echo "sr: Cookie: $http_cookie";
- }
-
- location = /t {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ngx.say("pr: Cookie: ", ngx.var.http_cookie)
- ';
- }
---- request
-GET /t
---- more_headers
-Cookie: foo
-Cookie: bar
---- response_body
-sr: Cookie: foo; bar
-pr: Cookie: foo; bar
-
---- no_error_log
-[error]
-
-
-
-=== TEST 73: HEAD subrequest (github #347)
---- config
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/index.html",
- { method = ngx.HTTP_HEAD });
- ngx.say("content-length: ", res.header["Content-Length"])
- ngx.say("body: [", res.body, "]")
- ';
- }
---- request
-GET /lua
---- response_body_like chop
-^content-length: \d+
-body: \[\]
-$
---- no_error_log
-[error]
-
-
-
-=== TEST 74: image_filter + ngx.location.capture
-ngx_http_image_filter_module's header filter intercepts
-the header filter chain so the r->header_sent flag won't
-get set right after the header filter chain is first invoked.
-
---- config
-
-location = /back {
- empty_gif;
-}
-
-location = /t {
- image_filter rotate 90;
-
- content_by_lua '
- local res = ngx.location.capture("/back")
- for k, v in pairs(res.header) do
- ngx.header[k] = v
- end
- ngx.status = res.status
- ngx.print(res.body)
- ';
-}
-
---- request
-GET /t
---- response_body_like: .
---- stap
-F(ngx_http_image_header_filter) {
- println("image header filter")
-}
---- stap_out
-image header filter
-
---- no_error_log
-[error]
-
-
-
-=== TEST 75: WebDAV + MOVE
---- config
- location = /t {
- content_by_lua_block {
- local file1 = "/file1.txt"
- local file2 = "/file2.txt"
- ngx.req.set_header( "Destination", file2 )
- local res = ngx.location.capture(
- file1, { method = ngx.HTTP_MOVE }
- )
-
- ngx.say(
- "MOVE ", file1, " -> ", file2,
- ", response status: ", res.status
- )
- }
- }
-
- location / {
- dav_methods MOVE;
- }
-
---- user_files
->>> file1.txt
-hello, world!
-
---- request
-GET /t
-
---- response_body
-MOVE /file1.txt -> /file2.txt, response status: 204
-
---- no_error_log
-[error]
---- error_code: 200
-
-
-
-=== TEST 76: WebDAV + DELETE
---- config
- location = /t {
- content_by_lua_block {
- local file = "/file.txt"
- local res = ngx.location.capture(
- file, { method = ngx.HTTP_DELETE }
- )
-
- ngx.say(
- "DELETE ", file,
- ", response status: ", res.status
- )
- }
- }
-
- location / {
- dav_methods DELETE;
- }
-
---- user_files
->>> file.txt
-hello, world!
-
---- request
-GET /t
-
---- response_body
-DELETE /file.txt, response status: 204
-
---- no_error_log
-[error]
---- error_code: 200
-
-
-
-=== TEST 77: avoid request smuggling 1/4 (default capture + smuggle in header)
---- http_config
- upstream backend {
- server unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- keepalive 32;
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
-
- location / {
- content_by_lua_block {
- ngx.say("method: ", ngx.var.request_method,
- ", uri: ", ngx.var.uri,
- ", X: ", ngx.var.http_x)
- }
- }
- }
---- config
- location /proxy {
- proxy_http_version 1.1;
- proxy_set_header Connection "";
- proxy_pass http://backend/foo;
- }
-
- location /capture {
- server_tokens off;
- more_clear_headers Date;
-
- content_by_lua_block {
- local res = ngx.location.capture("/proxy")
- ngx.print(res.body)
- }
- }
-
- location /t {
- content_by_lua_block {
- local req = [[
-GET /capture HTTP/1.1
-Host: test.com
-Content-Length: 37
-Transfer-Encoding: chunked
-
-0
-
-GET /capture HTTP/1.1
-Host: test.com
-X: GET /bar HTTP/1.0
-
-]]
-
- local sock = ngx.socket.tcp()
- sock:settimeout(1000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send req: ", err)
- return
- end
-
- ngx.say("req bytes: ", bytes)
-
- local n_resp = 0
-
- local reader = sock:receiveuntil("\r\n")
- while true do
- local line, err = reader()
- if line then
- ngx.say(line)
- if line == "0" then
- n_resp = n_resp + 1
- end
-
- if n_resp >= 2 then
- break
- end
-
- else
- ngx.say("err: ", err)
- break
- end
- end
-
- sock:close()
- }
- }
---- request
-GET /t
---- response_body
-req bytes: 146
-HTTP/1.1 200 OK
-Server: nginx
-Content-Type: text/plain
-Transfer-Encoding: chunked
-Connection: keep-alive
-
-1f
-method: GET, uri: /foo, X: nil
-
-0
-
-HTTP/1.1 200 OK
-Server: nginx
-Content-Type: text/plain
-Transfer-Encoding: chunked
-Connection: keep-alive
-
-2d
-method: GET, uri: /foo, X: GET /bar HTTP/1.0
-
-0
---- no_error_log
-[error]
---- skip_nginx
-3: >= 1.21.1
-
-
-
-=== TEST 78: avoid request smuggling 2/4 (POST capture + smuggle in body)
---- http_config
- upstream backend {
- server unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- keepalive 32;
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
-
- location / {
- content_by_lua_block {
- ngx.say("method: ", ngx.var.request_method,
- ", uri: ", ngx.var.uri)
- }
- }
- }
---- config
- location /proxy {
- proxy_http_version 1.1;
- proxy_set_header Connection "";
- proxy_pass http://backend/foo;
- }
-
- location /capture {
- server_tokens off;
- more_clear_headers Date;
-
- content_by_lua_block {
- ngx.req.read_body()
- local res = ngx.location.capture("/proxy", { method = ngx.HTTP_POST })
- ngx.print(res.body)
- }
- }
-
- location /t {
- content_by_lua_block {
- local req = [[
-GET /capture HTTP/1.1
-Host: test.com
-Content-Length: 57
-Transfer-Encoding: chunked
-
-0
-
-POST /capture HTTP/1.1
-Host: test.com
-Content-Length: 60
-
-POST /bar HTTP/1.1
-Host: test.com
-Content-Length: 5
-
-hello
-
-]]
-
- local sock = ngx.socket.tcp()
- sock:settimeout(1000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send req: ", err)
- return
- end
-
- ngx.say("req bytes: ", bytes)
-
- local n_resp = 0
-
- local reader = sock:receiveuntil("\r\n")
- while true do
- local line, err = reader()
- if line then
- ngx.say(line)
- if line == "0" then
- n_resp = n_resp + 1
- end
-
- if n_resp >= 2 then
- break
- end
-
- else
- ngx.say("err: ", err)
- break
- end
- end
-
- sock:close()
- }
- }
---- request
-GET /t
---- response_body
-req bytes: 205
-HTTP/1.1 200 OK
-Server: nginx
-Content-Type: text/plain
-Transfer-Encoding: chunked
-Connection: keep-alive
-
-18
-method: POST, uri: /foo
-
-0
-
-HTTP/1.1 200 OK
-Server: nginx
-Content-Type: text/plain
-Transfer-Encoding: chunked
-Connection: keep-alive
-
-18
-method: POST, uri: /foo
-
-0
---- no_error_log
-[error]
---- skip_nginx
-3: >= 1.21.1
-
-
-
-=== TEST 79: avoid request smuggling 3/4 (POST capture w/ always_forward_body + smuggle in body)
---- http_config
- upstream backend {
- server unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- keepalive 32;
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
-
- location / {
- content_by_lua_block {
- ngx.say("method: ", ngx.var.request_method,
- ", uri: ", ngx.var.uri)
- }
- }
- }
---- config
- location /proxy {
- proxy_http_version 1.1;
- proxy_set_header Connection "";
- proxy_pass http://backend/foo;
- }
-
- location /capture {
- server_tokens off;
- more_clear_headers Date;
-
- content_by_lua_block {
- ngx.req.read_body()
- local res = ngx.location.capture("/proxy", {
- method = ngx.HTTP_POST,
- always_forward_body = true
- })
- ngx.print(res.body)
- }
- }
-
- location /t {
- content_by_lua_block {
- local req = [[
-GET /capture HTTP/1.1
-Host: test.com
-Content-Length: 57
-Transfer-Encoding: chunked
-
-0
-
-POST /capture HTTP/1.1
-Host: test.com
-Content-Length: 60
-
-POST /bar HTTP/1.1
-Host: test.com
-Content-Length: 5
-
-hello
-
-]]
-
- local sock = ngx.socket.tcp()
- sock:settimeout(1000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send req: ", err)
- return
- end
-
- ngx.say("req bytes: ", bytes)
-
- local n_resp = 0
-
- local reader = sock:receiveuntil("\r\n")
- while true do
- local line, err = reader()
- if line then
- ngx.say(line)
- if line == "0" then
- n_resp = n_resp + 1
- end
-
- if n_resp >= 2 then
- break
- end
-
- else
- ngx.say("err: ", err)
- break
- end
- end
-
- sock:close()
- }
- }
---- request
-GET /t
---- response_body
-req bytes: 205
-HTTP/1.1 200 OK
-Server: nginx
-Content-Type: text/plain
-Transfer-Encoding: chunked
-Connection: keep-alive
-
-18
-method: POST, uri: /foo
-
-0
-
-HTTP/1.1 200 OK
-Server: nginx
-Content-Type: text/plain
-Transfer-Encoding: chunked
-Connection: keep-alive
-
-18
-method: POST, uri: /foo
-
-0
---- no_error_log
-[error]
---- skip_nginx
-3: >= 1.21.1
-
-
-
-=== TEST 80: avoid request smuggling 4/4 (POST capture w/ body + smuggle in body)
---- http_config
- upstream backend {
- server unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- keepalive 32;
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
-
- location / {
- content_by_lua_block {
- ngx.say("method: ", ngx.var.request_method,
- ", uri: ", ngx.var.uri)
- }
- }
- }
---- config
- location /proxy {
- proxy_http_version 1.1;
- proxy_set_header Connection "";
- proxy_pass http://backend/foo;
- }
-
- location /capture {
- server_tokens off;
- more_clear_headers Date;
-
- content_by_lua_block {
- ngx.req.read_body()
- local res = ngx.location.capture("/proxy", {
- method = ngx.HTTP_POST,
- always_forward_body = true,
- body = ngx.req.get_body_data()
- })
- ngx.print(res.body)
- }
- }
-
- location /t {
- content_by_lua_block {
- local req = [[
-GET /capture HTTP/1.1
-Host: test.com
-Content-Length: 57
-Transfer-Encoding: chunked
-
-0
-
-POST /capture HTTP/1.1
-Host: test.com
-Content-Length: 60
-
-POST /bar HTTP/1.1
-Host: test.com
-Content-Length: 5
-
-hello
-
-]]
-
- local sock = ngx.socket.tcp()
- sock:settimeout(1000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send req: ", err)
- return
- end
-
- ngx.say("req bytes: ", bytes)
-
- local n_resp = 0
-
- local reader = sock:receiveuntil("\r\n")
- while true do
- local line, err = reader()
- if line then
- ngx.say(line)
- if line == "0" then
- n_resp = n_resp + 1
- end
-
- if n_resp >= 2 then
- break
- end
-
- else
- ngx.say("err: ", err)
- break
- end
- end
-
- sock:close()
- }
- }
---- request
-GET /t
---- response_body
-req bytes: 205
-HTTP/1.1 200 OK
-Server: nginx
-Content-Type: text/plain
-Transfer-Encoding: chunked
-Connection: keep-alive
-
-18
-method: POST, uri: /foo
-
-0
-
-HTTP/1.1 200 OK
-Server: nginx
-Content-Type: text/plain
-Transfer-Encoding: chunked
-Connection: keep-alive
-
-18
-method: POST, uri: /foo
-
-0
---- no_error_log
-[error]
---- skip_nginx
-3: >= 1.21.1
-
-
-
-=== TEST 81: bad HTTP method
---- config
- location /other { }
-
- location /lua {
- content_by_lua_block {
- local res = ngx.location.capture("/other",
- { method = 10240 });
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-unsupported HTTP method: 10240
-
-
-
-=== TEST 82: bad requests with both Content-Length and Transfer-Encoding (nginx >= 1.21.1)
---- http_config
- upstream backend {
- server unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- keepalive 32;
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
-
- location / {
- content_by_lua_block {
- ngx.say("method: ", ngx.var.request_method,
- ", uri: ", ngx.var.uri,
- ", X: ", ngx.var.http_x)
- }
- }
- }
---- config
- location /proxy {
- proxy_http_version 1.1;
- proxy_set_header Connection "";
- proxy_pass http://backend/foo;
- }
-
- location /capture {
- server_tokens off;
- more_clear_headers Date;
-
- content_by_lua_block {
- local res = ngx.location.capture("/proxy")
- ngx.print(res.body)
- }
- }
-
- location /t {
- content_by_lua_block {
- local req = [[
-GET /capture HTTP/1.1
-Host: test.com
-Content-Length: 37
-Transfer-Encoding: chunked
-
-0
-
-GET /capture HTTP/1.1
-Host: test.com
-X: GET /bar HTTP/1.0
-
-]]
-
- local sock = ngx.socket.tcp()
- sock:settimeout(1000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send req: ", err)
- return
- end
-
- ngx.say("req bytes: ", bytes)
-
- local n_resp = 0
-
- local reader = sock:receiveuntil("\r\n")
- while true do
- local line, err = reader()
- if line then
- ngx.say(line)
- if line == "0" then
- n_resp = n_resp + 1
- end
-
- if n_resp >= 2 then
- break
- end
-
- else
- ngx.say("err: ", err)
- break
- end
- end
-
- sock:close()
- }
- }
---- request
-GET /t
---- response_body_like
-req bytes: 146
-HTTP/1.1 400 Bad Request
---- no_error_log
-[error]
---- skip_nginx
-3: < 1.21.1
-
-
-
-=== TEST 83: avoid request smuggling of HEAD req
---- config
- location /capture {
- server_tokens off;
- more_clear_headers Date;
-
- content_by_lua_block {
- ngx.say("Hello")
- }
- }
-
- location /t {
- content_by_lua_block {
- local req = [[
-HEAD /capture HTTP/1.1
-Host: test.com
-Content-Length: 63
-
-GET /capture HTTP/1.1
-Host: test.com
-X: GET /bar HTTP/1.0
-
-]]
-
- local sock = ngx.socket.tcp()
- sock:settimeout(1000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send req: ", err)
- return
- end
-
- ngx.say("req bytes: ", bytes)
-
- local n_resp = 0
-
- local reader = sock:receiveuntil("\r\n")
- while true do
- local line, err = reader()
- if line then
- ngx.say(line)
- if line == "0" then
- n_resp = n_resp + 1
- end
-
- if n_resp >= 2 then
- break
- end
-
- else
- ngx.say("err: ", err)
- break
- end
- end
-
- sock:close()
- }
- }
---- request
-GET /t
---- response_body
-req bytes: 117
-HTTP/1.1 200 OK
-Server: nginx
-Content-Type: text/plain
-Connection: keep-alive
-
-err: timeout
---- error_log
-lua tcp socket read timed out
diff --git a/src/deps/src/lua-nginx-module/t/021-cookie-time.t b/src/deps/src/lua-nginx-module/t/021-cookie-time.t
deleted file mode 100644
index b05e40188..000000000
--- a/src/deps/src/lua-nginx-module/t/021-cookie-time.t
+++ /dev/null
@@ -1,45 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: cookie_time
---- config
- location /lua {
- content_by_lua '
- ngx.say(ngx.cookie_time(1290079655))
- ';
- }
---- request
-GET /lua
---- response_body
-Thu, 18-Nov-10 11:27:35 GMT
-
-
-
-=== TEST 2: cookie_time in set_by_lua
---- config
- location /lua {
- set_by_lua $a '
- return ngx.cookie_time(1290079655)
- ';
- echo $a;
- }
---- request
-GET /lua
---- response_body
-Thu, 18-Nov-10 11:27:35 GMT
diff --git a/src/deps/src/lua-nginx-module/t/022-redirect.t b/src/deps/src/lua-nginx-module/t/022-redirect.t
deleted file mode 100644
index 197c76e1d..000000000
--- a/src/deps/src/lua-nginx-module/t/022-redirect.t
+++ /dev/null
@@ -1,428 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3 + 9);
-
-#no_diff();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: default 302
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo");
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo
---- response_body_like: 302 Found
---- error_code: 302
-
-
-
-=== TEST 2: explicit 302
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo", ngx.HTTP_MOVED_TEMPORARILY);
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo
---- response_body_like: 302 Found
---- error_code: 302
-
-
-
-=== TEST 3: explicit 301
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo", ngx.HTTP_MOVED_PERMANENTLY);
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo
---- response_body_like: 301 Moved Permanently
---- error_code: 301
-
-
-
-=== TEST 4: bad rc
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo", 404);
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_headers
-!Location
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-only ngx.HTTP_MOVED_TEMPORARILY, ngx.HTTP_MOVED_PERMANENTLY, ngx.HTTP_PERMANENT_REDIRECT, ngx.HTTP_SEE_OTHER, and ngx.HTTP_TEMPORARY_REDIRECT are allowed
-
-
-
-=== TEST 5: no args
---- config
- location /read {
- content_by_lua '
- ngx.redirect()
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_headers
-!Location
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 6: relative uri
---- config
- location /echo {
- echo hello, world;
- }
- location /proxy {
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/echo;
- }
- location /read {
- content_by_lua '
- ngx.location.capture("/proxy")
- ngx.redirect("/echo")
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- raw_response_headers_like eval
-my $headers;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $headers = "location: /echo\r\n"
-} else {
- $headers = "Location: /echo\r\n"
-}
-
-$headers;
---- response_body_like: 302 Found
---- error_code: 302
-
-
-
-=== TEST 7: default 302 (with uri args)
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo?bar=3");
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo?bar=3
---- response_body_like: 302 Found
---- error_code: 302
-
-
-
-=== TEST 8: location.capture + ngx.redirect
---- config
- location /echo {
- echo hello, world;
- }
- location /proxy {
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/echo;
- }
- location /read {
- content_by_lua '
- ngx.location.capture("/proxy")
- ngx.location.capture("/proxy")
- ngx.redirect("/echo")
- ngx.exit(403)
- ';
- }
---- pipelined_requests eval
-["GET /read/1", "GET /read/2"]
---- error_code eval
-[302, 302]
---- response_body eval
-[qr/302 Found/, qr/302 Found/]
-
-
-
-=== TEST 9: explicit 307
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo", ngx.HTTP_TEMPORARY_REDIRECT);
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo
---- response_body_like: 307 Temporary Redirect
---- error_code: 307
-
-
-
-=== TEST 10: explicit 307 with args
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo?a=b&c=d", ngx.HTTP_TEMPORARY_REDIRECT);
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo?a=b&c=d
---- response_body_like: 307 Temporary Redirect
---- error_code: 307
-
-
-
-=== TEST 11: explicit 307
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo?a=b&c=d", 307);
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo?a=b&c=d
---- response_body_like: 307 Temporary Redirect
---- error_code: 307
-
-
-
-=== TEST 12: explicit 303
---- config
- location /read {
- content_by_lua_block {
- ngx.redirect("http://agentzh.org/foo", ngx.HTTP_SEE_OTHER);
- ngx.say("hi")
- }
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo
---- response_body_like: 303 See Other
---- error_code: 303
-
-
-
-=== TEST 13: explicit 303 with args
---- config
- location /read {
- content_by_lua_block {
- ngx.redirect("http://agentzh.org/foo?a=b&c=d", ngx.HTTP_SEE_OTHER);
- ngx.say("hi")
- }
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo?a=b&c=d
---- response_body_like: 303 See Other
---- error_code: 303
-
-
-
-=== TEST 14: explicit 303
---- config
- location /read {
- content_by_lua_block {
- ngx.redirect("http://agentzh.org/foo?a=b&c=d", 303);
- ngx.say("hi")
- }
- }
---- request
-GET /read
---- response_headers
-Location: http://agentzh.org/foo?a=b&c=d
---- response_body_like: 303 See Other
---- error_code: 303
-
-
-
-=== TEST 15: explicit 308 with args
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo?a=b&c=d", ngx.HTTP_PERMANENT_REDIRECT);
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_body_like: 308 Permanent Redirect
---- response_headers
-Location: http://agentzh.org/foo?a=b&c=d
---- error_code: 308
-
-
-
-=== TEST 16: explicit 308
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo?a=b&c=d", 308);
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_body_like: 308 Permanent Redirect
---- response_headers
-Location: http://agentzh.org/foo?a=b&c=d
---- error_code: 308
-
-
-
-=== TEST 17: explicit 308 with args
---- config
- location /read {
- content_by_lua '
- ngx.redirect("http://agentzh.org/foo?a=b&c=d", 308);
- ngx.say("hi")
- ';
- }
---- request
-GET /read
---- response_body_like: 308 Permanent Redirect
---- response_headers
-Location: http://agentzh.org/foo?a=b&c=d
---- error_code: 308
-
-
-
-=== TEST 18: unsafe uri (with '\r')
---- config
- location = /t {
- content_by_lua_block {
- ngx.redirect("http://agentzh.org/foo\rfoo:bar\nbar:foo");
- ngx.say("hi")
- }
- }
---- request
-GET /t
---- error_code: 500
---- response_headers
-Location:
-foo:
-bar:
---- error_log
-unsafe byte "0x0d" in redirect uri "http://agentzh.org/foo\x0Dfoo:bar\x0Abar:foo"
-
-
-
-=== TEST 19: unsafe uri (with '\n')
---- config
- location = /t {
- content_by_lua_block {
- ngx.redirect("http://agentzh.org/foo\nfoo:bar\rbar:foo");
- ngx.say("hi")
- }
- }
---- request
-GET /t
---- error_code: 500
---- response_headers
-Location:
-foo:
-bar:
---- error_log
-unsafe byte "0x0a" in redirect uri "http://agentzh.org/foo\x0Afoo:bar\x0Dbar:foo"
-
-
-
-=== TEST 20: unsafe uri (with prefix '\n')
---- config
- location = /t {
- content_by_lua_block {
- ngx.redirect("\nfoo:http://agentzh.org/foo");
- ngx.say("hi")
- }
- }
---- request
-GET /t
---- error_code: 500
---- response_headers
-Location:
-foo:
---- error_log
-unsafe byte "0x0a" in redirect uri "\x0Afoo:http://agentzh.org/foo"
-
-
-
-=== TEST 21: unsafe uri (with prefix '\r')
---- config
- location = /t {
- content_by_lua_block {
- ngx.redirect("\rfoo:http://agentzh.org/foo");
- ngx.say("hi")
- }
- }
---- request
-GET /t
---- error_code: 500
---- response_headers
-Location:
-foo:
---- error_log
-unsafe byte "0x0d" in redirect uri "\x0Dfoo:http://agentzh.org/foo"
-
-
-
-=== TEST 22: unsafe uri logging escapes '"' and '\' characters
---- config
- location = /t {
- content_by_lua_block {
- ngx.redirect("\rhttp\\://\"agentzh.org\"/foo");
- ngx.say("hi")
- }
- }
---- request
-GET /t
---- error_code: 500
---- response_headers
-Location:
-foo:
---- error_log
-unsafe byte "0x0d" in redirect uri "\x0Dhttp\x5C://\x22agentzh.org\x22/foo"
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/client-abort.t b/src/deps/src/lua-nginx-module/t/023-rewrite/client-abort.t
deleted file mode 100644
index 61ada3a1b..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/client-abort.t
+++ /dev/null
@@ -1,856 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = <<_EOC_;
-$t::StapThread::GCScript
-
-F(ngx_http_lua_check_broken_connection) {
- println("lua check broken conn")
-}
-
-F(ngx_http_lua_request_cleanup) {
- println("lua req cleanup")
-}
-_EOC_
-
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- plan(skip_all => "HTTP3 does not support client abort");
-} elsif (defined $ENV{TEST_NGINX_USE_HTTP2}) {
- plan(skip_all => "HTTP2 does not support client abort");
-} else {
- plan tests => repeat_each() * (blocks() * 3 - 1);
-}
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 0.1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 2: sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.sleep(1)
- ';
- log_by_lua '
- ngx.log(ngx.NOTICE, "here in log by lua")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-here in log by lua
-
-
-
-=== TEST 3: sleep + ignore
---- config
- location /t {
- lua_check_client_abort off;
- rewrite_by_lua '
- ngx.sleep(1)
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 4: subrequest + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location /sub {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 5: subrequest + ignore
---- config
- location /t {
- lua_check_client_abort off;
- rewrite_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location /sub {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: fail
-lua req cleanup
-delete thread 1
-
---- wait: 1.1
---- timeout: 0.2
---- abort
---- ignore_response
---- error_log
-bad things happen
-
-
-
-=== TEST 6: subrequest + stop (proxy, ignore client abort)
---- config
- location = /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location = /sub {
- proxy_ignore_client_abort on;
- proxy_pass http://127.0.0.2:12345/;
- }
-
- location = /sleep {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 7: subrequest + stop (proxy, check client abort)
---- config
- location = /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location = /sub {
- proxy_ignore_client_abort off;
- proxy_pass http://127.0.0.2:12345/;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 8: need body on + sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- lua_need_request_body on;
- rewrite_by_lua '
- ngx.sleep(1)
- ';
- log_by_lua '
- ngx.log(ngx.NOTICE, "here in log by lua")
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-here in log by lua
-
-
-
-=== TEST 9: ngx.req.read_body + sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.sleep(1)
- ';
- log_by_lua '
- ngx.log(ngx.NOTICE, "here in log by lua")
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-here in log by lua
-
-
-
-=== TEST 10: ngx.req.socket + receive() + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local sock = ngx.req.socket()
- sock:receive()
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 11: ngx.req.socket + receive(N) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local sock = ngx.req.socket()
- sock:receive(5)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 0.1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 12: ngx.req.socket + receive(n) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local sock = ngx.req.socket()
- sock:receive(2)
- ngx.sleep(1)
- ';
- content_by_lua return;
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like
-^(?:lua check broken conn
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup|lua check broken conn
-lua req cleanup
-delete thread 1)$
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 13: ngx.req.socket + m * receive(n) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local sock = ngx.req.socket()
- sock:receive(2)
- sock:receive(2)
- sock:receive(1)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 14: ngx.req.socket + receiveuntil + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local sock = ngx.req.socket()
- local it = sock:receiveuntil("\\n")
- it()
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 15: ngx.req.socket + receiveuntil + it(n) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local sock = ngx.req.socket()
- local it = sock:receiveuntil("\\n")
- it(2)
- it(3)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 16: cosocket + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.req.discard_body()
-
- local sock, err = ngx.socket.tcp()
- if not sock then
- ngx.log(ngx.ERR, "failed to get socket: ", err)
- return
- end
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("blpop nonexist 2\\r\\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send query: ", err)
- return
- end
-
- -- ngx.log(ngx.ERR, "about to receive")
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive query: ", err)
- return
- end
-
- ngx.log(ngx.ERR, "res: ", res)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 17: ngx.req.socket + receive n < content-length + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local sock = ngx.req.socket()
- local res, err = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err)
- return
- end
- error("bad")
- ';
- content_by_lua return;
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 100\r
-\r
-hello"
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-failed to receive: client aborted
-
-
-
-=== TEST 18: ngx.req.socket + receive n == content-length + stop
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local sock = ngx.req.socket()
- local res, err = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err)
- return
- end
- ngx.sleep(1)
- error("bad")
- ';
- content_by_lua return;
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 5\r
-\r
-hello"
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 19: ngx.req.socket + receive n == content-length + ignore
---- config
- location /t {
- rewrite_by_lua '
- local sock = ngx.req.socket()
- local res, err = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err)
- return
- end
- ngx.say("done")
- ';
- content_by_lua return;
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 5\r
-\r
-hello"
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- shutdown: 1
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 20: ngx.req.read_body + sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.req.read_body()
- ';
- content_by_lua return;
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- shutdown: 1
---- wait: 0.1
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 21: exec to lua + ignore
---- config
- location = /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.exec("/t2")
- ';
- }
-
- location = /t2 {
- lua_check_client_abort off;
- content_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-lua req cleanup
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 22: exec to proxy + ignore
---- config
- location = /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.exec("/t2")
- ';
- }
-
- location = /t2 {
- proxy_ignore_client_abort on;
- proxy_pass http://127.0.0.1:$server_port/sleep;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 23: exec (named location) to proxy + ignore
---- config
- location = /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- ngx.exec("@t2")
- ';
- }
-
- location @t2 {
- proxy_ignore_client_abort on;
- proxy_pass http://127.0.0.1:$server_port/sleep;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/exec.t b/src/deps/src/lua-nginx-module/t/023-rewrite/exec.t
deleted file mode 100644
index 59691cb59..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/exec.t
+++ /dev/null
@@ -1,400 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2 + 4);
-
-#no_diff();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /read {
- rewrite_by_lua '
- ngx.exec("/hi");
- ngx.say("Hi");
- ';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body
-Hello
-
-
-
-=== TEST 2: empty uri arg
---- config
- location /read {
- rewrite_by_lua '
- ngx.exec("");
- ngx.say("Hi");
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 3: no arg
---- config
- location /read {
- rewrite_by_lua '
- ngx.exec();
- ngx.say("Hi");
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 4: too many args
---- config
- location /read {
- rewrite_by_lua '
- ngx.exec(1, 2, 3, 4);
- ngx.say("Hi");
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 5: null uri
---- config
- location /read {
- rewrite_by_lua '
- ngx.exec(nil)
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 6: user args
---- config
- location /read {
- rewrite_by_lua '
- ngx.exec("/hi", "Yichun Zhang")
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello Yichun Zhang
-
-
-
-=== TEST 7: args in uri
---- config
- location /read {
- rewrite_by_lua '
- ngx.exec("/hi?agentzh")
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello agentzh
-
-
-
-=== TEST 8: args in uri and user args
---- config
- location /read {
- rewrite_by_lua '
- ngx.exec("/hi?a=Yichun", "b=Zhang")
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello a=Yichun&b=Zhang
-
-
-
-=== TEST 9: args in uri and user args
---- config
- location /read {
- rewrite_by_lua '
- ngx.exec("@hi?a=Yichun", "b=Zhang")
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location @hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello
-
-
-
-=== TEST 10: exec after location capture
---- config
- location /test {
- rewrite_by_lua_file 'html/test.lua';
- echo world;
- }
-
- location /a {
- echo "hello";
- }
-
- location /b {
- echo "hello";
- }
-
---- user_files
->>> test.lua
-ngx.location.capture('/a')
-
-ngx.exec('/b')
---- request
- GET /test
---- response_body
-hello
-
-
-
-=== TEST 11: exec after (named) location capture
---- config
- location /test {
- rewrite_by_lua_file 'html/test.lua';
- }
-
- location /a {
- echo "hello";
- }
-
- location @b {
- echo "hello";
- }
-
---- user_files
->>> test.lua
-ngx.location.capture('/a')
-
-ngx.exec('@b')
---- request
- GET /test
---- response_body
-hello
-
-
-
-=== TEST 12: github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location (rewrite)
---- config
- location = /hi {
- echo hello;
- }
- location /sub {
- proxy_pass http://127.0.0.1:$server_port/hi;
- }
- location /p{
- #content_by_lua '
- #local res = ngx.location.capture("/sub")
- #ngx.print(res.body)
- #';
- echo_location /sub;
- }
- location /lua {
- rewrite_by_lua '
- ngx.exec("/p")
- ';
- }
---- request
- GET /lua
---- response_body
-hello
-
-
-
-=== TEST 13: github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location (rewrite + named location)
---- config
- location = /hi {
- echo hello;
- }
- location /sub {
- proxy_pass http://127.0.0.1:$server_port/hi;
- }
- location @p{
- #content_by_lua '
- #local res = ngx.location.capture("/sub")
- #ngx.print(res.body)
- #';
- echo_location /sub;
- }
- location /lua {
- rewrite_by_lua '
- ngx.exec("@p")
- ';
- }
---- request
- GET /lua
---- response_body
-hello
-
-
-
-=== TEST 14: github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location (rewrite + post subrequest)
---- config
- location = /hi {
- echo hello;
- }
- location /sub {
- proxy_pass http://127.0.0.1:$server_port/hi;
- }
- location /p{
- #content_by_lua '
- #local res = ngx.location.capture("/sub")
- #ngx.print(res.body)
- #';
- echo_location /sub;
- }
- location /blah {
- echo blah;
- }
- location /lua {
- rewrite_by_lua '
- ngx.location.capture("/blah")
- ngx.exec("/p")
- ';
- }
---- request
- GET /lua
---- response_body
-hello
-
-
-
-=== TEST 15: rewrite_by_lua + ngx.exec + subrequest capture
---- config
- location /main {
- rewrite_by_lua '
- local res = ngx.location.capture("/test_loc");
- ngx.print("hello, ", res.body)
- ';
- content_by_lua return;
- }
- location /test_loc {
- rewrite_by_lua '
- ngx.exec("@proxy")
- ';
- }
- location @proxy {
- #echo proxy;
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
- location /foo {
- echo bah;
- }
---- request
- GET /main
---- response_body
-hello, bah
-
-
-
-=== TEST 16: rewrite_by_lua_file + ngx.exec + subrequest capture
---- config
- location /main {
- rewrite_by_lua '
- local res = ngx.location.capture("/test_loc");
- ngx.print("hello, ", res.body)
- ';
- content_by_lua return;
- }
- location /test_loc {
- rewrite_by_lua_file html/jump.lua;
- }
- location @proxy {
- #echo proxy;
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
- location /foo {
- echo bah;
- }
---- user_files
->>> jump.lua
-ngx.exec("@proxy")
---- request
- GET /main
---- response_body
-hello, bah
-
-
-
-=== TEST 17: pipelined requests
---- config
- location /t {
- rewrite_by_lua_block {
- ngx.exec("@foo")
- }
- }
-
- location @foo {
- return 200;
- }
---- pipelined_requests eval
-["GET /t", "GET /t"]
---- error_code eval
-[200, 200]
---- response_body eval
-["", ""]
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/exit.t b/src/deps/src/lua-nginx-module/t/023-rewrite/exit.t
deleted file mode 100644
index 9add80441..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/exit.t
+++ /dev/null
@@ -1,600 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#repeat_each(20000);
-
-repeat_each(2);
-
-#master_on();
-#workers(1);
-#log_level('debug');
-#log_level('warn');
-#worker_connections(1024);
-
-plan tests => repeat_each() * (blocks() * 2 + 4);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
-
-our $LuaCpath = $ENV{LUA_CPATH} ||
- '/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;';
-
-#$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
-
-no_long_string();
-#no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: throw 403
---- config
- location /lua {
- rewrite_by_lua "ngx.exit(403);ngx.say('hi')";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- error_code: 403
---- response_body_like: 403 Forbidden
-
-
-
-=== TEST 2: throw 404
---- config
- location /lua {
- rewrite_by_lua "ngx.exit(404);ngx.say('hi');";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- error_code: 404
---- response_body_like: 404 Not Found
-
-
-
-=== TEST 3: throw 404 after sending the header and partial body
---- config
- location /lua {
- rewrite_by_lua "ngx.say('hi');ngx.exit(404);ngx.say(', you')";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- error_log
-attempt to set status 404 via ngx.exit after sending out the response status 200
---- response_body
-hi
-
-
-
-=== TEST 4: working with ngx_auth_request (succeeded)
---- config
- location /auth {
- rewrite_by_lua "
- if ngx.var.user == 'agentzh' then
- ngx.eof();
- else
- ngx.exit(403)
- end";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /api {
- set $user $arg_user;
- auth_request /auth;
-
- echo "Logged in";
- }
---- request
-GET /api?user=agentzh
---- error_code: 200
---- response_body
-Logged in
-
-
-
-=== TEST 5: working with ngx_auth_request (failed)
---- config
- location /auth {
- rewrite_by_lua "
- if ngx.var.user == 'agentzh' then
- ngx.eof();
- else
- ngx.exit(403)
- end";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /api {
- set $user $arg_user;
- auth_request /auth;
-
- echo "Logged in";
- }
---- request
-GET /api?user=agentz
---- error_code: 403
---- response_body_like: 403 Forbidden
-
-
-
-=== TEST 6: working with ngx_auth_request (simplest form, w/o ngx_memc)
---- http_config eval
-"
- lua_package_cpath '$::LuaCpath';
- upstream backend {
- drizzle_server 127.0.0.1:\$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-"
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /conv-uid-mysql {
- internal;
-
- set $key "conv-uid-$arg_uid";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- drizzle_query "select new_uid as uid from conv_uid where old_uid=$arg_uid";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /conv-uid {
- internal;
- rewrite_by_lua_file 'html/foo.lua';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /api {
- set $uid $arg_uid;
- auth_request /conv-uid;
-
- echo "Logged in $uid";
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local old_uid = ngx.var.uid
-print('about to run sr')
-local res = ngx.location.capture('/conv-uid-mysql?uid=' .. old_uid)
-print('just have run sr' .. res.body)
-if (res.status ~= ngx.HTTP_OK) then
- -- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].uid or
- not string.match(res[1].uid, '^%d+$')) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.uid = res[1].uid;
--- print('done')
---- request
-GET /api?uid=32
---- response_body
-Logged in 56
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 7: working with ngx_auth_request (simplest form)
---- http_config eval
-"
- lua_package_cpath '$::LuaCpath';
- upstream backend {
- drizzle_server 127.0.0.1:\$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-"
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /conv-uid-mysql {
- internal;
-
- set $key "conv-uid-$arg_uid";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- drizzle_query "select new_uid as uid from conv_uid where old_uid=$arg_uid";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /conv-uid {
- internal;
- rewrite_by_lua_file 'html/foo.lua';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /api {
- set $uid $arg_uid;
- auth_request /conv-uid;
-
- echo "Logged in $uid";
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local old_uid = ngx.var.uid
--- print('about to run sr')
-local res = ngx.location.capture('/conv-uid-mysql?uid=' .. old_uid)
--- print('just have run sr' .. res.body)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].uid or
- not string.match(res[1].uid, '^%d+$')) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.uid = res[1].uid;
--- print('done')
---- request
-GET /api?uid=32
---- response_body
-Logged in 56
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 8: working with ngx_auth_request
---- http_config eval
-"
- lua_package_cpath '$::LuaCpath';
- upstream backend {
- drizzle_server 127.0.0.1:\$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-
- upstream memc_a {
- server 127.0.0.1:\$TEST_NGINX_MEMCACHED_PORT;
- }
-
- upstream memc_b {
- server 127.0.0.1:\$TEST_NGINX_MEMCACHED_PORT;
- }
-
- upstream_list memc_cluster memc_a memc_b;
-"
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- set_hashed_upstream $backend memc_cluster $arg_key;
- memc_pass $backend;
- }
-
- location /conv-uid-mysql {
- internal;
-
- set $key "conv-uid-$arg_uid";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- drizzle_query "select new_uid as uid from conv_uid where old_uid=$arg_uid";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /conv-uid {
- internal;
- rewrite_by_lua_file 'html/foo.lua';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /api {
- set $uid $arg_uid;
- auth_request /conv-uid;
-
- echo "Logged in $uid";
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local old_uid = ngx.var.uid
--- print('about to run sr')
-local res = ngx.location.capture('/conv-uid-mysql?uid=' .. old_uid)
--- print('just have run sr' .. res.body)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].uid or
- not string.match(res[1].uid, '^%d+$')) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.uid = res[1].uid;
--- print('done')
---- request
-GET /api?uid=32
---- response_body
-Logged in 56
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 9: working with ngx_auth_request
---- http_config
- upstream backend {
- drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-
- upstream memc_a {
- server 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- keepalive 300;
- }
-
- #upstream_list memc_cluster memc_a memc_b;
-
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- #set_hashed_upstream $backend memc_cluster $arg_key;
- memc_pass memc_a;
- }
-
- location /conv-mysql {
- internal;
-
- set $key "conv-uri-$query_string";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- set_quote_sql_str $seo_uri $query_string;
- drizzle_query "select url from my_url_map where seo_url=$seo_uri";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /conv-uid {
- internal;
- rewrite_by_lua_file 'html/foo.lua';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
-
- location /baz {
- set $my_uri $uri;
- auth_request /conv-uid;
-
- echo_exec /jump $my_uri;
- }
-
- location /jump {
- internal;
- rewrite ^ $query_string? redirect;
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local seo_uri = ngx.var.my_uri
--- print('about to run sr')
-local res = ngx.location.capture('/conv-mysql?' .. seo_uri)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].url) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.my_uri = res[1].url;
--- print('done')
---- request
-GET /baz
---- response_body_like: 302
---- error_code: 302
---- response_headers
-Location: http://localhost:$ServerPort/foo/bar
---- SKIP
-
-
-
-=== TEST 10: throw 0
---- config
- location /lua {
- rewrite_by_lua "ngx.say('Hi'); ngx.eof(); ngx.exit(0);ngx.say('world')";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- error_code: 200
---- response_body
-Hi
-
-
-
-=== TEST 11: throw ngx.OK does *not* skip other rewrite phase handlers
---- config
- location /lua {
- rewrite_by_lua "ngx.exit(ngx.OK)";
- set $foo hello;
- echo $foo;
- }
---- request
-GET /lua
---- response_body
-hello
-
-
-
-=== TEST 12: throw ngx.HTTP_OK *does* skip other rewrite phase handlers (by inlined code)
---- config
- location /lua {
- rewrite_by_lua "ngx.exit(ngx.HTTP_OK)";
- set $foo hello;
- echo $foo;
- }
---- request
-GET /lua
---- response_body
-
-
-
-=== TEST 13: throw ngx.HTTP_OK *does* skip other rewrite phase handlers (by inlined code + partial output)
---- config
- location /lua {
- rewrite_by_lua "ngx.say('hiya') ngx.exit(ngx.HTTP_OK)";
- set $foo hello;
- echo $foo;
- }
---- request
-GET /lua
---- response_body
-hiya
-
-
-
-=== TEST 14: throw ngx.HTTP_OK *does* skip other rewrite phase handlers (by file)
---- config
- location /lua {
- rewrite_by_lua_file html/foo.lua;
- set $foo hello;
- echo $foo;
- }
---- user_files
->>> foo.lua
-ngx.exit(ngx.HTTP_OK)
---- request
-GET /lua
---- response_body
-
-
-
-=== TEST 15: throw ngx.HTTP_OK *does* skip other rewrite phase handlers (by file + partial output)
---- config
- location /lua {
- rewrite_by_lua_file html/foo.lua;
- set $foo hello;
- echo $foo;
- }
---- user_files
->>> foo.lua
-ngx.say("morning")
-ngx.exit(ngx.HTTP_OK)
---- request
-GET /lua
---- response_body
-morning
-
-
-
-=== TEST 16: error page with custom body
---- config
- error_page 410 @err;
- location @err {
- echo blah blah;
- }
- location /foo {
- rewrite_by_lua '
- ngx.status = ngx.HTTP_GONE
- ngx.say("This is our own content")
- -- to cause quit the whole request rather than the current phase handler
- ngx.exit(ngx.HTTP_OK)
- ';
- echo Hello;
- }
---- request
- GET /foo
---- response_body
-This is our own content
---- error_code: 410
-
-
-
-=== TEST 17: exit with 204 (HTTP 1.1)
---- config
- location = /t {
- rewrite_by_lua '
- ngx.exit(204)
- ';
-
- proxy_pass http://127.0.0.1:$server_port/blah;
- }
-
- location = /blah {
- echo blah;
- }
---- request
-GET /t
---- more_headers2
---- stap2
-F(ngx_http_send_header) {
- printf("send header\n")
- print_ubacktrace()
-}
---- response_body
---- error_code: 204
---- no_error_log
-[error]
-
-
-
-=== TEST 18: exit with 204 (HTTP 1.0)
---- config
- location = /t {
- rewrite_by_lua '
- ngx.exit(204)
- ';
-
- proxy_pass http://127.0.0.1:$server_port/blah;
- }
-
- location = /blah {
- echo blah;
- }
---- request
-GET /t HTTP/1.0
---- more_headers2
---- stap2
-F(ngx_http_send_header) {
- printf("send header\n")
- print_ubacktrace()
-}
---- response_body
---- error_code: 204
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/mixed.t b/src/deps/src/lua-nginx-module/t/023-rewrite/mixed.t
deleted file mode 100644
index 5b38d3f45..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/mixed.t
+++ /dev/null
@@ -1,169 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2 + 3);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: rewrite I/O with content I/O
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc {
- set $memc_key $echo_request_uri;
- set $memc_exptime 600;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /lua {
- rewrite_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- print("rewrite GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- print("rewrite PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- print("rewrite cached: " .. res.body);
- ';
-
- content_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- ngx.say("content GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- ngx.say("content PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- ngx.say("content cached: " .. res.body);
- ';
- }
---- request
-GET /lua
---- response_body
-content GET: 404
-content PUT: 201
-content cached: hello
---- grep_error_log eval: qr/rewrite .+?(?= while )/
---- grep_error_log_out
-rewrite GET: 404
-rewrite PUT: 201
-rewrite cached: hello
-
---- log_level: info
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 2: share data via nginx variables
---- config
- location /foo {
- set $foo '';
- rewrite_by_lua '
- ngx.var.foo = 32
- ';
-
- content_by_lua '
- ngx.say(tonumber(ngx.var.foo) * 2)
- ';
- }
---- request
- GET /foo
---- response_body
-64
-
-
-
-=== TEST 3: share the request body (need request body explicitly off)
---- config
- location /echo_body {
- lua_need_request_body off;
- set $res '';
- rewrite_by_lua '
- ngx.var.res = ngx.var.request_body or "nil"
- ';
- content_by_lua '
- ngx.say(ngx.var.res or "nil")
- ngx.say(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body
-nil
-nil
-
-
-
-=== TEST 4: share the request body (need request body off by default)
---- config
- location /echo_body {
- #lua_need_request_body off;
- set $res '';
- rewrite_by_lua '
- ngx.var.res = ngx.var.request_body or "nil"
- ';
- content_by_lua '
- ngx.say(ngx.var.res or "nil")
- ngx.say(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body
-nil
-nil
-
-
-
-=== TEST 5: share the request body (need request body on)
---- config
- location /echo_body {
- lua_need_request_body on;
- set $res '';
- rewrite_by_lua '
- ngx.var.res = ngx.var.request_body or "nil"
- ';
- content_by_lua '
- ngx.say(ngx.var.res or "nil")
- ngx.say(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff
-hello\x00\x01\x02
-world\x03\x04\xff
-"
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/multi-capture.t b/src/deps/src/lua-nginx-module/t/023-rewrite/multi-capture.t
deleted file mode 100644
index a0a02b7a2..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/multi-capture.t
+++ /dev/null
@@ -1,394 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(10);
-
-plan tests => blocks() * repeat_each() * 2;
-
-#$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
-$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /foo {
- rewrite_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
- location /a {
- echo -n a;
- }
- location /b {
- echo -n b;
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-
-
-
-=== TEST 2: 4 concurrent requests
---- config
- location /foo {
- rewrite_by_lua '
- local res1, res2, res3, res4 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- { "/c" },
- { "/d" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
-
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
-
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
-
- ngx.say("res4.status = " .. res4.status)
- ngx.say("res4.body = " .. res4.body)
- ';
- content_by_lua return;
- }
- location ~ '^/([a-d])$' {
- echo -n $1;
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-res3.status = 200
-res3.body = c
-res4.status = 200
-res4.body = d
-
-
-
-=== TEST 3: capture multi in series
---- config
- location /foo {
- rewrite_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
-
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("2 res1.status = " .. res1.status)
- ngx.say("2 res1.body = " .. res1.body)
- ngx.say("2 res2.status = " .. res2.status)
- ngx.say("2 res2.body = " .. res2.body)
-
- ';
- content_by_lua return;
- }
- location /a {
- echo -n a;
- }
- location /b {
- echo -n b;
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-2 res1.status = 200
-2 res1.body = a
-2 res2.status = 200
-2 res2.body = b
-
-
-
-=== TEST 4: capture multi in subrequest
---- config
- location /foo {
- rewrite_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
-
- local n = ngx.var.arg_n
-
- ngx.say(n .. " res1.status = " .. res1.status)
- ngx.say(n .. " res1.body = " .. res1.body)
- ngx.say(n .. " res2.status = " .. res2.status)
- ngx.say(n .. " res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
-
- location /main {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo?n=1")
- ngx.say("top res.status = " .. res.status)
- ngx.say("top res.body = [" .. res.body .. "]")
- ';
- content_by_lua return;
- }
-
- location /a {
- echo -n a;
- }
-
- location /b {
- echo -n b;
- }
---- request
- GET /main
---- response_body
-top res.status = 200
-top res.body = [1 res1.status = 200
-1 res1.body = a
-1 res2.status = 200
-1 res2.body = b
-]
-
-
-
-=== TEST 5: capture multi in parallel
---- config
- location ~ '^/(foo|bar)$' {
- set $tag $1;
- rewrite_by_lua '
- local res1, res2
- if ngx.var.tag == "foo" then
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- else
- res1, res2 = ngx.location.capture_multi{
- { "/c" },
- { "/d" },
- }
- end
-
- local n = ngx.var.arg_n
-
- ngx.say(n .. " res1.status = " .. res1.status)
- ngx.say(n .. " res1.body = " .. res1.body)
- ngx.say(n .. " res2.status = " .. res2.status)
- ngx.say(n .. " res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
-
- location /main {
- rewrite_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/foo?n=1" },
- { "/bar?n=2" },
- }
-
- ngx.say("top res1.status = " .. res1.status)
- ngx.say("top res1.body = [" .. res1.body .. "]")
- ngx.say("top res2.status = " .. res2.status)
- ngx.say("top res2.body = [" .. res2.body .. "]")
- ';
- content_by_lua return;
- }
-
- location ~ '^/([abcd])$' {
- echo -n $1;
- }
---- request
- GET /main
---- response_body
-top res1.status = 200
-top res1.body = [1 res1.status = 200
-1 res1.body = a
-1 res2.status = 200
-1 res2.body = b
-]
-top res2.status = 200
-top res2.body = [2 res1.status = 200
-2 res1.body = c
-2 res2.status = 200
-2 res2.body = d
-]
-
-
-
-=== TEST 6: memc sanity
---- config
- location /foo {
- rewrite_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
- location ~ '^/[ab]$' {
- set $memc_key $uri;
- set $memc_value hello;
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
- GET /foo
---- response_body eval
-"res1.status = 201
-res1.body = STORED\r
-
-res2.status = 201
-res2.body = STORED\r
-
-"
-
-
-
-=== TEST 7: memc muti + multi
---- config
- location /main {
- rewrite_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/foo?n=1" },
- { "/bar?n=2" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = [" .. res1.body .. "]")
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = [" .. res2.body .. "]")
- ';
- content_by_lua return;
- }
- location ~ '^/(foo|bar)$' {
- set $tag $1;
- rewrite_by_lua '
- local res1, res2
- if ngx.var.tag == "foo" then
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- else
- res1, res2 = ngx.location.capture_multi{
- { "/c" },
- { "/d" },
- }
- end
- print("args: " .. ngx.var.args)
- local n = ngx.var.arg_n
- ngx.say(n .. " res1.status = " .. res1.status)
- ngx.say(n .. " res1.body = " .. res1.body)
- ngx.say(n .. " res2.status = " .. res2.status)
- ngx.say(n .. " res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
- location ~ '^/[abcd]$' {
- set $memc_key $uri;
- set $memc_value hello;
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
- GET /main
---- response_body eval
-"res1.status = 200
-res1.body = [1 res1.status = 201
-1 res1.body = STORED\r
-
-1 res2.status = 201
-1 res2.body = STORED\r
-
-]
-res2.status = 200
-res2.body = [2 res1.status = 201
-2 res1.body = STORED\r
-
-2 res2.status = 201
-2 res2.body = STORED\r
-
-]
-"
-
-
-
-=== TEST 8: memc 4 concurrent requests
---- config
- location /foo {
- rewrite_by_lua '
- local res1, res2, res3, res4 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- { "/c" },
- { "/d" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
-
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
-
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
-
- ngx.say("res4.status = " .. res4.status)
- ngx.say("res4.body = " .. res4.body)
- ';
- content_by_lua return;
- }
- location ~ '^/[a-d]$' {
- set $memc_key $uri;
- set $memc_value hello;
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
- GET /foo
---- response_body eval
-"res1.status = 201
-res1.body = STORED\r
-
-res2.status = 201
-res2.body = STORED\r
-
-res3.status = 201
-res3.body = STORED\r
-
-res4.status = 201
-res4.body = STORED\r
-
-"
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/on-abort.t b/src/deps/src/lua-nginx-module/t/023-rewrite/on-abort.t
deleted file mode 100644
index 0535732a0..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/on-abort.t
+++ /dev/null
@@ -1,662 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = <<_EOC_;
-$t::StapThread::GCScript
-
-F(ngx_http_lua_check_broken_connection) {
- println("lua check broken conn")
-}
-
-F(ngx_http_lua_request_cleanup) {
- println("lua req cleanup")
-}
-_EOC_
-
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- plan(skip_all => "HTTP3 does not support on_abort");
-} elsif (defined $ENV{TEST_NGINX_USE_HTTP2}) {
- plan(skip_all => "HTTP2 does not support on_abort");
-} else {
- plan tests => repeat_each() * (blocks() * 4 + 15);
-}
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: ignore the client abort event in the user callback
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-terminate 3: ok
-delete thread 3
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- wait: 0.7
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 2: abort in the user callback
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(444)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- wait: 0.1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 3: ngx.exit(499) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(499)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ';
- content_by_lua return;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 4: ngx.exit(408) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(408)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ';
- content_by_lua return;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- wait: 0.1
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 5: ngx.exit(-1) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(-1)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ';
- content_by_lua return;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 6: ngx.exit(0) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(0)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ngx.log(ngx.ERR, "main handler done")
- ';
- content_by_lua return;
- }
-
- location = /sleep {
- echo_sleep 0.7;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like eval
-qr/^create 2 in 1
-lua check broken conn
-terminate 2: fail
-(?:lua check broken conn
-)?terminate 1: ok
-delete thread 2
-delete thread 1
-terminate 3: ok
-delete thread 3
-lua req cleanup
-$/
---- timeout: 0.2
---- abort
---- wait: 0.6
---- ignore_response
---- error_log eval
-[
-'client prematurely closed connection',
-'on abort called',
-qr/lua user thread aborted: runtime error: rewrite_by_lua\(nginx\.conf:\d+\):4: attempt to abort with pending subrequests/,
-'main handler done',
-]
-
-
-
-=== TEST 7: accessing cosocket in callback
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to redis: ", err)
- ngx.exit(499)
- end
- local bytes, err = sock:send("flushall\\r\\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send query: ", err)
- ngx.exit(499)
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive: ", err)
- ngx.exit(499)
- end
- ngx.log(ngx.NOTICE, "callback done: ", res)
- ngx.exit(499)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- wait: 0.5
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-callback done: +OK
-
-
-
-=== TEST 8: ignore the client abort event in the user callback (no check)
---- config
- location /t {
- lua_check_client_abort off;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- ngx.say("cannot set on_abort: ", err)
- return
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- response_body
-cannot set on_abort: lua_check_client_abort is off
---- no_error_log
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 9: register on_abort callback but no client abortion
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-lua req cleanup
-delete thread 2
-
---- response_body
-done
---- no_error_log
-[error]
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 10: ignore the client abort event in the user callback (uthread)
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- end)
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-lua check broken conn
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-terminate 4: ok
-delete thread 4
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- wait: 0.7
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 11: abort in the user callback (uthread)
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(444)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- end)
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 3
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 12: register on_abort callback but no client abortion (uthread)
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.1)
- ngx.say("done")
- end)
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-delete thread 3
-lua req cleanup
-delete thread 2
-
---- wait: 0.5
---- response_body
-done
---- no_error_log
-[error]
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 13: register on_abort callback multiple times
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- ngx.say("1: cannot set on_abort: " .. err)
- return
- end
-
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- ngx.say("2: cannot set on_abort: " .. err)
- return
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.1)
- ngx.say("done")
- end)
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-lua req cleanup
-delete thread 2
-
---- response_body
-2: cannot set on_abort: duplicate call
-
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/redirect.t b/src/deps/src/lua-nginx-module/t/023-rewrite/redirect.t
deleted file mode 100644
index 2b3dccb0c..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/redirect.t
+++ /dev/null
@@ -1,173 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => blocks() * repeat_each() * 3;
-
-#no_diff();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: default 302
---- config
- location /read {
- rewrite_by_lua '
- ngx.redirect("http://www.taobao.com/foo");
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-Location: http://www.taobao.com/foo
---- response_body_like: 302 Found
---- error_code: 302
-
-
-
-=== TEST 2: explicit 302
---- config
- location /read {
- rewrite_by_lua '
- ngx.redirect("http://www.taobao.com/foo", ngx.HTTP_MOVED_TEMPORARILY);
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-Location: http://www.taobao.com/foo
---- response_body_like: 302 Found
---- error_code: 302
-
-
-
-=== TEST 3: explicit 301
---- config
- location /read {
- rewrite_by_lua '
- ngx.redirect("http://www.taobao.com/foo", ngx.HTTP_MOVED_PERMANENTLY);
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-Location: http://www.taobao.com/foo
---- response_body_like: 301 Moved Permanently
---- error_code: 301
-
-
-
-=== TEST 4: bad rc
---- config
- location /read {
- rewrite_by_lua '
- ngx.redirect("http://www.taobao.com/foo", 404);
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-!Location
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 5: no args
---- config
- location /read {
- rewrite_by_lua '
- ngx.redirect()
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-!Location
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 6: relative uri
---- config
- location /read {
- rewrite_by_lua '
- ngx.redirect("/foo")
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- raw_response_headers_like eval
-my $headers;
-
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- $headers = "location: /foo\r\n"
-} else {
- $headers = "Location: /foo\r\n"
-}
-
-$headers;
---- response_body_like: 302 Found
---- error_code: 302
-
-
-
-=== TEST 7: internal redirects that do not clear module ctx
---- http_config
- rewrite_by_lua_no_postpone on;
---- config
- rewrite_by_lua_block {
- -- this is empty by intention
- }
-
- location /url1 {
- rewrite ^ /url2;
- }
---- request
-GET /url1
---- response_body_like: 404 Not Found
---- error_log eval
-qr{\[error\] .*?/html/url2".*?No such file or directory}
---- error_code: 404
-
-
-
-=== TEST 8: internal redirects that do not clear module ctx (yield in rewrite handler)
---- http_config
- rewrite_by_lua_no_postpone on;
---- config
- rewrite_by_lua_block {
- ngx.sleep(0.001)
- }
-
- location /url1 {
- rewrite ^ /url2;
- }
---- request
-GET /url1
---- response_body_like: 404 Not Found
---- error_log eval
-qr{\[error\] .*?/html/url2".*?No such file or directory}
---- error_code: 404
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/req-body.t b/src/deps/src/lua-nginx-module/t/023-rewrite/req-body.t
deleted file mode 100644
index 0c1857384..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/req-body.t
+++ /dev/null
@@ -1,224 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 5);
-
-#no_diff();
-#no_long_string();
-#master_on();
-#workers(2);
-run_tests();
-
-__DATA__
-
-=== TEST 1: read buffered body
---- config
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ';
- content_by_lua return;
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
-
-
-
-=== TEST 2: read buffered body (timed out)
---- config
- client_body_timeout 1ms;
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ';
- content_by_lua return;
- }
---- raw_request eval
-"POST /test HTTP/1.1\r
-Host: localhost\r
-Content-Length: 100\r
-Connection: close\r
-\r
-hello, world"
---- response_body:
---- error_code_like: ^(?:500)?$
-
-
-
-=== TEST 3: read buffered body and then subrequest
---- config
- location /foo {
- echo -n foo;
- }
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- local res = ngx.location.capture("/foo");
- ngx.say(ngx.var.request_body)
- ngx.say("sub: ", res.body)
- ';
- content_by_lua return;
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
-sub: foo
-
-
-
-=== TEST 4: first subrequest and then read buffered body
---- config
- location /foo {
- echo -n foo;
- }
- location = /test {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo");
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ngx.say("sub: ", res.body)
- ';
- content_by_lua return;
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
-sub: foo
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 5: failed to write 100 continue
---- config
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ngx.exit(200)
- ';
- }
---- request
-POST /test
-hello, world
---- more_headers
-Expect: 100-Continue
---- ignore_response
---- no_error_log
-[alert]
-[error]
-http finalize request: 500, "/test?" a:1, c:0
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 6: not discard body (exit 200)
---- config
- location = /foo {
- rewrite_by_lua '
- -- ngx.req.discard_body()
- ngx.say("body: ", ngx.var.request_body)
- ngx.exit(200)
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-["body: nil\n",
-"body: hiya, world\n",
-]
---- error_code eval
-[200, 200]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 7: not discard body (exit 201)
---- config
- location = /foo {
- rewrite_by_lua '
- -- ngx.req.discard_body()
- ngx.say("body: ", ngx.var.request_body)
- ngx.exit(201)
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-["body: nil\n",
-"body: hiya, world\n",
-]
---- error_code eval
-[200, 200]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 8: not discard body (exit 302)
---- config
- location = /foo {
- rewrite_by_lua '
- -- ngx.req.discard_body()
- -- ngx.say("body: ", ngx.var.request_body)
- ngx.redirect("/blah")
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-[qr/302 Found/,
-"body: hiya, world\n",
-]
---- error_code eval
-[302, 200]
---- no_error_log
-[error]
-[alert]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/req-socket.t b/src/deps/src/lua-nginx-module/t/023-rewrite/req-socket.t
deleted file mode 100644
index f4dd6f4e1..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/req-socket.t
+++ /dev/null
@@ -1,542 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "http3 does not support ngx.req.socket";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 3);
-
-our $HtmlDir = html_dir;
-
-#$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-no_long_string();
-#no_diff();
-#log_level 'warn';
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /t {
- rewrite_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
-
- for i = 1, 3 do
- local data, err, part = sock:receive(5)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
- end
- ';
-
- content_by_lua return;
- }
---- request
-POST /t
-hello world
---- response_body
-got the request socket
-received: hello
-received: worl
-failed to receive: closed [d]
---- no_error_log
-[error]
-
-
-
-=== TEST 2: multipart rfc sample (just partial streaming)
---- config
- location /t {
- rewrite_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
-
- local boundary
- local header = ngx.var.http_content_type
- local m = ngx.re.match(header, [[; +boundary=(?:"(.*?)"|(\\w+))]], "jo")
- if m then
- boundary = m[1] or m[2]
-
- else
- ngx.say("invalid content-type header")
- return
- end
-
- local read_to_boundary = sock:receiveuntil("\\r\\n--" .. boundary)
- local read_line = sock:receiveuntil("\\r\\n")
-
- local data, err, part = read_to_boundary()
- if data then
- ngx.say("preamble: [" .. data .. "]")
- else
- ngx.say("failed to read the first boundary: ", err)
- return
- end
-
- local i = 1
- while true do
- local line, err = read_line()
-
- if not line then
- ngx.say("failed to read post-boundary line: ", err)
- return
- end
-
- m = ngx.re.match(line, "--$", "jo")
- if m then
- ngx.say("found the end of the stream")
- return
- end
-
- while true do
- local line, err = read_line()
- if not line then
- ngx.say("failed to read part ", i, " header: ", err)
- return
- end
-
- if line == "" then
- -- the header part completes
- break
- end
-
- ngx.say("part ", i, " header: [", line, "]")
- end
-
- local data, err, part = read_to_boundary()
- if data then
- ngx.say("part ", i, " body: [" .. data .. "]")
- else
- ngx.say("failed to read part ", i + 1, " boundary: ", err)
- return
- end
-
- i = i + 1
- end
- ';
-
- content_by_lua return;
- }
---- request eval
-"POST /t
-This is the preamble. It is to be ignored, though it
-is a handy place for mail composers to include an
-explanatory note to non-MIME compliant readers.\r
---simple boundary\r
-\r
-This is implicitly typed plain ASCII text.
-It does NOT end with a linebreak.\r
---simple boundary\r
-Content-type: text/plain; charset=us-ascii\r
-\r
-This is explicitly typed plain ASCII text.
-It DOES end with a linebreak.
-\r
---simple boundary--\r
-This is the epilogue. It is also to be ignored.
-"
---- more_headers
-Content-Type: multipart/mixed; boundary="simple boundary"
---- response_body
-got the request socket
-preamble: [This is the preamble. It is to be ignored, though it
-is a handy place for mail composers to include an
-explanatory note to non-MIME compliant readers.]
-part 1 body: [This is implicitly typed plain ASCII text.
-It does NOT end with a linebreak.]
-part 2 header: [Content-type: text/plain; charset=us-ascii]
-part 2 body: [This is explicitly typed plain ASCII text.
-It DOES end with a linebreak.
-]
-found the end of the stream
---- no_error_log
-[error]
-
-
-
-=== TEST 3: multipart rfc sample (completely streaming)
---- config
- location /t {
- rewrite_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
-
- local boundary
- local header = ngx.var.http_content_type
- local m = ngx.re.match(header, [[; +boundary=(?:"(.*?)"|(\\w+))]], "jo")
- if m then
- boundary = m[1] or m[2]
-
- else
- ngx.say("invalid content-type header")
- return
- end
-
- local read_to_boundary = sock:receiveuntil("\\r\\n--" .. boundary)
- local read_line = sock:receiveuntil("\\r\\n")
-
- local preamble = ""
- while true do
- local data, err, part = read_to_boundary(1)
- if data then
- preamble = preamble .. data
-
- elseif not err then
- break
-
- else
- ngx.say("failed to read the first boundary: ", err)
- return
- end
- end
-
- ngx.say("preamble: [" .. preamble .. "]")
-
- local i = 1
- while true do
- local line, err = read_line(50)
-
- if not line and err then
- ngx.say("1: failed to read post-boundary line: ", err)
- return
- end
-
- if line then
- local dummy
- dummy, err = read_line(1)
- if err then
- ngx.say("2: failed to read post-boundary line: ", err)
- return
- end
-
- if dummy then
- ngx.say("bad post-boundary line: ", dummy)
- return
- end
-
- m = ngx.re.match(line, "--$", "jo")
- if m then
- ngx.say("found the end of the stream")
- return
- end
- end
-
- while true do
- local line, err = read_line(50)
- if not line and err then
- ngx.say("failed to read part ", i, " header: ", err)
- return
- end
-
- if line then
- local line, err = read_line(1)
- if line or err then
- ngx.say("error")
- return
- end
- end
-
- if line == "" then
- -- the header part completes
- break
- end
-
- ngx.say("part ", i, " header: [", line, "]")
- end
-
- local body = ""
-
- while true do
- local data, err, part = read_to_boundary(1)
- if data then
- body = body .. data
-
- elseif err then
- ngx.say("failed to read part ", i + 1, " boundary: ", err)
- return
-
- else
- break
- end
- end
-
- ngx.say("part ", i, " body: [" .. body .. "]")
-
- i = i + 1
- end
- ';
-
- content_by_lua return;
- }
---- request eval
-"POST /t
-This is the preamble. It is to be ignored, though it
-is a handy place for mail composers to include an
-explanatory note to non-MIME compliant readers.\r
---simple boundary\r
-\r
-This is implicitly typed plain ASCII text.
-It does NOT end with a linebreak.\r
---simple boundary\r
-Content-type: text/plain; charset=us-ascii\r
-\r
-This is explicitly typed plain ASCII text.
-It DOES end with a linebreak.
-\r
---simple boundary--\r
-This is the epilogue. It is also to be ignored.
-"
---- more_headers
-Content-Type: multipart/mixed; boundary="simple boundary"
---- response_body
-got the request socket
-preamble: [This is the preamble. It is to be ignored, though it
-is a handy place for mail composers to include an
-explanatory note to non-MIME compliant readers.]
-part 1 body: [This is implicitly typed plain ASCII text.
-It does NOT end with a linebreak.]
-part 2 header: [Content-type: text/plain; charset=us-ascii]
-part 2 body: [This is explicitly typed plain ASCII text.
-It DOES end with a linebreak.
-]
-found the end of the stream
---- no_error_log
-[error]
-
-
-
-=== TEST 4: attempt to use the req socket across request boundary
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- rewrite_by_lua '
- local test = require "test"
- test.go()
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock, err
-
-function go()
- if not sock then
- sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
- else
- for i = 1, 3 do
- local data, err, part = sock:receive(5)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
- end
- end
-end
---- request
-POST /t
-hello world
---- response_body_like
-(?:got the request socket
-|failed to receive: closed [d]
-)?done
---- no_error_log
-[alert]
-
-
-
-=== TEST 5: receive until on request_body - receiveuntil(1) on the last byte of the body
-See https://groups.google.com/group/openresty/browse_thread/thread/43cf01da3c681aba for details
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- rewrite_by_lua '
- local test = require "test"
- test.go()
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go()
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- return
- end
-
- local data, err, part = sock:receive(56)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
-
- local discard_line = sock:receiveuntil('\r\n')
-
- local data, err, part = discard_line(8192)
- if data then
- ngx.say("received len: ", #data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
-
- local data, err, part = discard_line(1)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
-end
---- request
-POST /t
------------------------------820127721219505131303151179################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################$
---- response_body
-got the request socket
-received: -----------------------------820127721219505131303151179
-received len: 8192
-received: $
-done
---- no_error_log
-[error]
---- timeout: 10
-
-
-
-=== TEST 6: pipelined POST requests
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- rewrite_by_lua '
- local test = require "test"
- test.go()
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go()
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- return
- end
-
- while true do
- local data, err, part = sock:receive(4)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- return
- end
- end
-end
---- pipelined_requests eval
-["POST /t
-hello, world",
-"POST /t
-hiya, world"]
---- response_body eval
-["got the request socket
-received: hell
-received: o, w
-received: orld
-failed to receive: closed []
-done
-",
-"got the request socket
-received: hiya
-received: , wo
-failed to receive: closed [rld]
-done
-"]
---- no_error_log
-[error]
-
-
-
-=== TEST 7: Expect & 100 Continue
---- config
- location /t {
- rewrite_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- return
- end
-
- for i = 1, 3 do
- local data, err, part = sock:receive(5)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
- end
- ';
-
- content_by_lua return;
- }
---- request
-POST /t
-hello world
---- more_headers
-Expect: 100-Continue
---- error_code: 100
---- response_body_like chomp
-\breceived: hello\b.*?\breceived: worl\b
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/request_body.t b/src/deps/src/lua-nginx-module/t/023-rewrite/request_body.t
deleted file mode 100644
index b867d3a82..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/request_body.t
+++ /dev/null
@@ -1,172 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('debug'); # to ensure any log-level can be outputted
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: test reading request body
---- config
- location /echo_body {
- lua_need_request_body on;
- rewrite_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff"
-
-
-
-=== TEST 2: test not reading request body
---- config
- location /echo_body {
- lua_need_request_body off;
- rewrite_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 3: test default setting (not reading request body)
---- config
- location /echo_body {
- rewrite_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 4: test main conf
---- http_config
- lua_need_request_body on;
---- config
- location /echo_body {
- rewrite_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff"
-
-
-
-=== TEST 5: test server conf
---- config
- lua_need_request_body on;
-
- location /echo_body {
- rewrite_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff"
-
-
-
-=== TEST 6: test override main conf
---- http_config
- lua_need_request_body on;
---- config
- location /echo_body {
- lua_need_request_body off;
- rewrite_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 7: test override server conf
---- config
- lua_need_request_body on;
-
- location /echo_body {
- lua_need_request_body off;
- rewrite_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 8: Expect: 100-Continue
---- config
- location /echo_body {
- lua_need_request_body on;
- rewrite_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ngx.exit(200)
- ';
- }
---- request
-POST /echo_body
-hello world
---- more_headers
-Expect: 100-Continue
---- ignore_response
---- no_error_log
-[error]
-[alert]
-http finalize request: 500, "/echo_body?" a:1, c:2
-http finalize request: 500, "/echo_body?" a:1, c:0
---- log_level: debug
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/sanity.t b/src/deps/src/lua-nginx-module/t/023-rewrite/sanity.t
deleted file mode 100644
index 73a85dc56..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/sanity.t
+++ /dev/null
@@ -1,801 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#no_nginx_manager();
-#log_level('warn');
-#master_on();
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 12);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: basic print
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- rewrite_by_lua 'ngx.print("Hello, Lua!\\n")';
- content_by_lua return;
- #content_by_lua 'ngx.say("Hi")';
- }
---- request
-GET /lua
---- response_body
-Hello, Lua!
-
-
-
-=== TEST 2: basic say
---- config
- location /say {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- rewrite_by_lua '
- ngx.say("Hello, Lua!")
- ngx.say("Yay! ", 123)';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /say
---- response_body
-Hello, Lua!
-Yay! 123
-
-
-
-=== TEST 3: no ngx.echo
---- config
- location /lua {
- rewrite_by_lua 'ngx.echo("Hello, Lua!\\n")';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 4: variable
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- rewrite_by_lua 'local v = ngx.var["request_uri"] ngx.print("request_uri: ", v, "\\n")';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua?a=1&b=2
---- response_body
-request_uri: /lua?a=1&b=2
-
-
-
-=== TEST 5: variable (file)
---- config
- location /lua {
- rewrite_by_lua_file html/test.lua;
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- user_files
->>> test.lua
-local v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- response_body
-request_uri: /lua?a=1&b=2
-
-
-
-=== TEST 6: calc expression
---- config
- location /lua {
- rewrite_by_lua_file html/calc.lua;
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- user_files
->>> calc.lua
-local function uri_unescape(uri)
- local function convert(hex)
- return string.char(tonumber("0x"..hex))
- end
- local s = string.gsub(uri, "%%([0-9a-fA-F][0-9a-fA-F])", convert)
- return s
-end
-
-local function eval_exp(str)
- return loadstring("return "..str)()
-end
-
-local exp_str = ngx.var["arg_exp"]
--- print("exp: '", exp_str, "'\n")
-local status, res
-status, res = pcall(uri_unescape, exp_str)
-if not status then
- ngx.print("error: ", res, "\n")
- return
-end
-status, res = pcall(eval_exp, res)
-if status then
- ngx.print("result: ", res, "\n")
-else
- ngx.print("error: ", res, "\n")
-end
---- request
-GET /lua?exp=1%2B2*math.sin(3)%2Fmath.exp(4)-math.sqrt(2)
---- response_body
-result: -0.4090441561579
-
-
-
-=== TEST 7: read $arg_xxx
---- config
- location = /lua {
- rewrite_by_lua 'local who = ngx.var.arg_who
- ngx.print("Hello, ", who, "!")';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua?who=agentzh
---- response_body chomp
-Hello, agentzh!
-
-
-
-=== TEST 8: capture location
---- config
- location /other {
- echo "hello, world";
- }
-
- location /lua {
- rewrite_by_lua '
-local res = ngx.location.capture("/other")
-ngx.print("status=", res.status, " ")
-ngx.print("body=", res.body)
-';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-status=200 body=hello, world
-
-
-
-=== TEST 9: capture non-existed location
---- config
- location /lua {
- rewrite_by_lua 'local res = ngx.location.capture("/other"); ngx.print("status=", res.status)';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body: status=404
-
-
-
-=== TEST 10: invalid capture location (not as expected...)
---- config
- location /lua {
- rewrite_by_lua 'local res = ngx.location.capture("*(#*"); ngx.say("res=", res.status)';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-res=404
-
-
-
-=== TEST 11: nil is "nil"
---- config
- location /lua {
- rewrite_by_lua 'ngx.say(nil)';
- content_by_lua return;
- }
---- request
-GET /lua
---- response_body
-nil
-
-
-
-=== TEST 12: write boolean
---- config
- location /lua {
- rewrite_by_lua 'ngx.say(true, " ", false)';
- content_by_lua return;
- }
---- request
-GET /lua
---- response_body
-true false
-
-
-
-=== TEST 13: bad argument type to ngx.location.capture
---- config
- location /lua {
- rewrite_by_lua 'ngx.location.capture(nil)';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 14: capture location (default 0);
---- config
- location /recur {
- rewrite_by_lua '
- local num = tonumber(ngx.var.arg_num) or 0;
- ngx.print("num is: ", num, "\\n");
-
- if (num > 0) then
- res = ngx.location.capture("/recur?num="..tostring(num - 1));
- ngx.print("status=", res.status, " ");
- ngx.print("body=", res.body, "\\n");
- else
- ngx.print("end\\n");
- end
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /recur
---- response_body
-num is: 0
-end
-
-
-
-=== TEST 15: capture location
---- config
- location /recur {
- rewrite_by_lua '
- local num = tonumber(ngx.var.arg_num) or 0;
- ngx.print("num is: ", num, "\\n");
-
- if (num > 0) then
- local res = ngx.location.capture("/recur?num="..tostring(num - 1));
- ngx.print("status=", res.status, " ");
- ngx.print("body=", res.body);
- else
- ngx.print("end\\n");
- end
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /recur?num=3
---- response_body
-num is: 3
-status=200 body=num is: 2
-status=200 body=num is: 1
-status=200 body=num is: 0
-end
-
-
-
-=== TEST 16: setting nginx variables from within Lua
---- config
- location /set {
- set $a "";
- rewrite_by_lua 'ngx.var.a = 32; ngx.say(ngx.var.a)';
- content_by_lua 'ngx.exit(ngx.OK)';
- add_header Foo $a;
- }
---- request
-GET /set
---- response_headers
-Foo: 32
---- response_body
-32
-
-
-
-=== TEST 17: nginx quote sql string 1
---- config
- location /set {
- set $a 'hello\n\r\'"\\'; # this runs after rewrite_by_lua
- rewrite_by_lua 'ngx.say(ngx.quote_sql_str(ngx.var.a))';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /set
---- response_body
-'hello\n\r\'\"\\'
-
-
-
-=== TEST 18: nginx quote sql string 2
---- config
-location /set {
- #set $a "hello\n\r'\"\\";
- rewrite_by_lua 'ngx.say(ngx.quote_sql_str("hello\\n\\r\'\\"\\\\"))';
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /set
---- response_body
-'hello\n\r\'\"\\'
-
-
-
-=== TEST 19: use dollar
---- config
-location /set {
- rewrite_by_lua '
- local s = "hello 112";
- ngx.say(string.find(s, "%d+$"))';
-
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /set
---- response_body
-79
-
-
-
-=== TEST 20: subrequests do not share variables of main requests by default
---- config
-location /sub {
- echo $a;
-}
-location /parent {
- set $a 12;
- rewrite_by_lua 'local res = ngx.location.capture("/sub"); ngx.print(res.body)';
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /parent
---- response_body eval: "\n"
-
-
-
-=== TEST 21: subrequests can share variables of main requests
---- config
-location /sub {
- echo $a;
-}
-location /parent {
- set $a '';
- rewrite_by_lua '
- ngx.var.a = 12;
- local res = ngx.location.capture(
- "/sub",
- { share_all_vars = true }
- );
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /parent
---- response_body
-12
-
-
-
-=== TEST 22: main requests use subrequests' variables
---- config
-location /sub {
- set $a 12;
-}
-location /parent {
- rewrite_by_lua '
- local res = ngx.location.capture("/sub", { share_all_vars = true });
- ngx.say(ngx.var.a)
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /parent
---- response_body
-12
-
-
-
-=== TEST 23: main requests do NOT use subrequests' variables
---- config
-location /sub {
- set $a 12;
- content_by_lua return;
-}
-
-location /parent {
- rewrite_by_lua '
- local res = ngx.location.capture("/sub", { share_all_vars = false });
- ngx.say(ngx.var.a)
- ';
- content_by_lua return;
-}
---- request
-GET /parent
---- response_body_like eval: "\n"
-
-
-
-=== TEST 24: capture location headers
---- config
- location /other {
- default_type 'foo/bar';
- echo "hello, world";
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", res.header["Content-Type"]);
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-type: foo/bar
-
-
-
-=== TEST 25: capture location headers
---- config
- location /other {
- default_type 'foo/bar';
- rewrite_by_lua '
- ngx.header.Bar = "Bah";
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", res.header["Content-Type"]);
- ngx.say("Bar: ", res.header["Bar"]);
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-type: foo/bar
-Bar: Bah
-
-
-
-=== TEST 26: capture location headers
---- config
- location /other {
- default_type 'foo/bar';
- rewrite_by_lua '
- ngx.header.Bar = "Bah";
- ngx.header.Bar = nil;
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", res.header["Content-Type"]);
- ngx.say("Bar: ", res.header["Bar"] or "nil");
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-type: foo/bar
-Bar: nil
-
-
-
-=== TEST 27: rewrite_by_lua runs before ngx_access
---- config
- location /lua {
- deny all;
-
- rewrite_by_lua '
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
- ';
-
- content_by_lua return;
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 28: rewrite_by_lua shouldn't send headers automatically (on simple return)
---- config
- location /lua {
- rewrite_by_lua 'return';
-
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location = /foo {
- default_type 'text/css';
- add_header Bar Baz;
- echo foo;
- }
---- request
-GET /lua
---- response_headers
-Bar: Baz
-Content-Type: text/css
---- response_body
-foo
-
-
-
-=== TEST 29: rewrite_by_lua shouldn't send headers automatically (on simple exit)
---- config
- location /lua {
- rewrite_by_lua 'ngx.exit(ngx.OK)';
-
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location = /foo {
- default_type 'text/css';
- add_header Bar Baz;
- echo foo;
- }
---- request
-GET /lua
---- response_headers
-Bar: Baz
-Content-Type: text/css
---- response_body
-foo
-
-
-
-=== TEST 30: short circuit
---- config
- location /lua {
- rewrite_by_lua '
- ngx.say("Hi")
- ngx.eof()
- ngx.exit(ngx.HTTP_OK)
- ';
-
- content_by_lua '
- print("HERE")
- ngx.print("BAD")
- ';
- }
---- request
-GET /lua
---- response_body
-Hi
-
-
-
-=== TEST 31: nginx vars in script path
---- config
- location ~ /lua/(.+)$ {
- rewrite_by_lua_file html/$1.lua;
-
- content_by_lua '
- print("HERE")
- ngx.print("BAD")
- ';
- }
---- user_files
->>> hi.lua
-ngx.say("Hi")
-ngx.eof()
-ngx.exit(ngx.HTTP_OK)
---- request
-GET /lua/hi
---- response_body
-Hi
-
-
-
-=== TEST 32: phase postponing works for various locations
---- config
- location ~ '^/lua/(.+)' {
- set $path $1;
- rewrite_by_lua 'ngx.say(ngx.var.path)';
- content_by_lua return;
- }
- location ~ '^/lua2/(.+)' {
- set $path $1;
- rewrite_by_lua 'ngx.say(ngx.var.path)';
- content_by_lua return;
- }
- location /main {
- echo_location /lua/foo;
- echo_location /lua/bar;
- echo_location /lua2/baz;
- echo_location /lua2/bah;
- }
---- request
-GET /main
---- response_body
-foo
-bar
-baz
-bah
-
-
-
-=== TEST 33: server rewrite_by_lua
---- config
- rewrite_by_lua 'ngx.header["X-Foo"] = "bar" -- ngx.send_headers()';
---- request
-GET /
---- response_body chop
-It works!It works!
---- response_headers
-X-Foo: bar
---- no_error_log
-[error]
-
-
-
-=== TEST 34: server rewrite_by_lua_file
---- config
- rewrite_by_lua_file html/foo.lua;
---- user_files
->>> foo.lua
-ngx.header["X-Foo"] = "bar" -- ngx.send_headers()
---- request
-GET /
---- response_body chop
-It works!It works!
---- response_headers
-X-Foo: bar
-
-
-
-=== TEST 35: rewrite last before rewrite_by_lua
---- config
- location /main {
- rewrite ^/main/xyz\.html$ /abc.html last;
- rewrite_by_lua 'ngx.exit(503)';
- }
- location ~ /abc.html {
- echo abc;
- }
---- request
- GET /main/xyz.html
---- response_body
-abc
-
-
-
-=== TEST 36: rewrite last before rewrite_by_lua_file
---- config
- location /main {
- rewrite ^/main/xyz\.html$ /abc.html last;
- rewrite_by_lua_file html/exit.lua;
- }
- location ~ /abc.html {
- echo abc;
- }
---- user_files
->>> exit.lua
-ngx.exit(503)
---- request
- GET /main/xyz.html
---- response_body
-abc
-
-
-
-=== TEST 37: rewrite before rewrite_by_lua
---- config
- location /main {
- rewrite ^/main/xyz\.html$ /abc.html;
- rewrite_by_lua 'ngx.exit(503)';
- }
- location ~ /abc.html {
- echo abc;
- }
---- request
- GET /main/xyz.html
---- response_body
-abc
-
-
-
-=== TEST 38: rewrite break before rewrite_by_lua
---- config
- location /main {
- rewrite ^/main/xyz\.html$ /abc.html break;
- rewrite_by_lua 'ngx.exit(503)';
- }
- location ~ /abc.html {
- echo abc;
- }
---- request
- GET /main/xyz.html
---- response_body_like: 503 Service Temporarily Unavailable
---- error_code: 503
-
-
-
-=== TEST 39: Lua file does not exist
---- config
- location /lua {
- rewrite_by_lua_file html/test2.lua;
- }
---- user_files
->>> test.lua
-v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- response_body_like: 404 Not Found
---- error_code: 404
---- error_log eval
-qr/failed to load external Lua file ".*?\btest2\.lua": cannot open .*? No such file or directory/
-
-
-
-=== TEST 40: use of ngx.say() in rewrite_by_lua without exiting with 200+.
---- config
- location /t {
- rewrite_by_lua "ngx.say('test')";
- echo_exec /t2;
- }
---- request
- GET /t
---- response_body
-test
---- no_error_log
-[alert]
-
-
-
-=== TEST 41: use of ngx.say() in rewrite_by_lua without exiting with 200+. (with explicit ngx.eof())
---- config
- location /t {
- rewrite_by_lua "ngx.say('test') ngx.eof()";
- echo_exec /t2;
- }
---- request
- GET /t
---- response_body
-test
---- no_error_log
-[alert]
-
-
-
-=== TEST 42: use of ngx.say() in rewrite_by_lua without exiting with 200+. (with IO)
---- config
- location /t {
- rewrite_by_lua "ngx.say('test') ngx.sleep(0.001)";
- echo_exec /t2;
- }
---- request
- GET /t
---- response_body
-test
---- no_error_log
-[alert]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/sleep.t b/src/deps/src/lua-nginx-module/t/023-rewrite/sleep.t
deleted file mode 100644
index 0135d5e44..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/sleep.t
+++ /dev/null
@@ -1,224 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * 33;
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sleep 0.5
---- config
- location /test {
- rewrite_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.sleep(0.5)
- local now = ngx.now()
- ngx.say(now - before)
- ngx.exit(200)
- ';
- }
---- request
-GET /test
---- response_body_like chop
-^0\.(?:4[5-9]\d*|5[0-9]\d*|5)$
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
-
-
-
-=== TEST 2: sleep ag
---- config
- location /test {
- rewrite_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.sleep("a")
- local now = ngx.now()
- ngx.say(now - before)
- ngx.exit(200)
- ';
- }
---- request
-GET /test
---- error_code: 500
---- response_body_like: 500 Internal Server Error
---- error_log
-bad argument #1 to 'sleep'
-
-
-
-=== TEST 3: sleep 0.5 in subrequest
---- config
- location /test {
- rewrite_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.location.capture("/sleep")
- local now = ngx.now()
- local delay = now - before
- ngx.say(delay)
- ngx.exit(200)
- ';
- }
- location /sleep {
- rewrite_by_lua 'ngx.sleep(0.5) ngx.exit(200)';
- }
---- request
-GET /test
---- response_body_like chop
-^0\.(?:4[5-9]\d*|5[0-9]\d*|5)$
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/sleep?"
---- no_error_log
-[error]
-
-
-
-=== TEST 4: sleep a in subrequest with bad argument
---- config
- location /test {
- rewrite_by_lua '
- local res = ngx.location.capture("/sleep");
- ngx.say(res.status)
- ngx.exit(200)
- ';
- }
- location /sleep {
- rewrite_by_lua 'ngx.sleep("a") ngx.exit(200)';
- }
---- request
-GET /test
---- response_body
-500
---- error_log
-bad argument #1 to 'sleep'
-
-
-
-=== TEST 5: sleep 0.5 - multi-times
---- quic_max_idle_timeout: 1.0
---- config
- location /test {
- rewrite_by_lua '
- ngx.update_time()
- local start = ngx.now()
- ngx.sleep(0.3)
- ngx.sleep(0.3)
- ngx.sleep(0.3)
- ngx.say(ngx.now() - start)
- ngx.exit(200)
- ';
- }
---- request
-GET /test
---- response_body_like chop
-^0\.(?:8[5-9]\d*|9[0-9]\d*|9)$
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 6: sleep 0.5 - interleaved by ngx.say() - ended by ngx.sleep
---- quic_max_idle_timeout: 2.05
---- config
- location /test {
- rewrite_by_lua '
- ngx.send_headers()
- -- ngx.location.capture("/sleep")
- ngx.sleep(1)
- ngx.say("blah")
- ngx.sleep(1)
- -- ngx.location.capture("/sleep")
- ngx.exit(200)
- ';
- }
- location = /sleep {
- echo_sleep 0.1;
- }
---- request
-GET /test
---- response_body
-blah
---- error_log
-lua ready to sleep
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 7: sleep 0.5 - interleaved by ngx.say() - not ended by ngx.sleep
---- quic_max_idle_timeout: 0.85
---- config
- location /test {
- rewrite_by_lua '
- ngx.send_headers()
- -- ngx.location.capture("/sleep")
- ngx.sleep(0.3)
- ngx.say("blah")
- ngx.sleep(0.5)
- -- ngx.location.capture("/sleep")
- ngx.say("hiya")
- ngx.exit(200)
- ';
- }
- location = /sleep {
- echo_sleep 0.1;
- }
---- request
-GET /test
---- response_body
-blah
-hiya
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 8: ngx.location.capture before and after ngx.sleep
---- config
- location /test {
- rewrite_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
-
- ngx.sleep(0.1)
-
- res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ngx.exit(200)
- ';
- }
- location = /hello {
- echo hello world;
- }
- location = /sub {
- proxy_pass http://127.0.0.1:$server_port/hello;
- }
---- request
-GET /test
---- response_body
-hello world
-hello world
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/socket-keepalive.t b/src/deps/src/lua-nginx-module/t/023-rewrite/socket-keepalive.t
deleted file mode 100644
index 9ce8d5e29..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/socket-keepalive.t
+++ /dev/null
@@ -1,1017 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 5 + 4);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_HTML_DIR} = $HtmlDir;
-#$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
-
-$ENV{LUA_PATH} ||=
- '/usr/local/openresty-debug/lualib/?.lua;/usr/local/openresty/lualib/?.lua;;';
-
-no_long_string();
-#no_diff();
-#log_level 'warn';
-
-no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- rewrite_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port)
- test.go(port)
- ';
-
- content_by_lua return;
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body_like
-^connected: 1, reused: \d+
-request sent: 11
-received: OK
-connected: 1, reused: [1-9]\d*
-request sent: 11
-received: OK
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for "]
---- grep_error_log eval
-qr/lua tcp socket get keepalive peer: using connection|lua tcp socket keepalive create connection pool for key "[^"]+"/
-
---- grep_error_log_out eval
-[
-qq{lua tcp socket keepalive create connection pool for key "127.0.0.1:$ENV{TEST_NGINX_MEMCACHED_PORT}"
-lua tcp socket get keepalive peer: using connection
-},
-"lua tcp socket get keepalive peer: using connection
-lua tcp socket get keepalive peer: using connection
-"]
-
-
-
-=== TEST 2: free up the whole connection pool if no active connections
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- rewrite_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port, true)
- test.go(port, false)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port, keepalive)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- if keepalive then
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- else
- sock:close()
- end
-end
---- response_body_like
-^connected: 1, reused: \d+
-request sent: 11
-received: OK
-connected: 1, reused: [1-9]\d*
-request sent: 11
-received: OK
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket get keepalive peer: using connection",
-"lua tcp socket keepalive: free connection pool for "]
-
-
-
-=== TEST 3: upstream sockets close prematurely
---- no_http3
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- keepalive_timeout 100ms;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- rewrite_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for "]
---- timeout: 3
-
-
-
-=== TEST 4: http keepalive
---- no_http3
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
-
- set $port $TEST_NGINX_SERVER_PORT;
- rewrite_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive close handler: fd:",
-"lua tcp socket keepalive: free connection pool for "]
---- timeout: 4
-
-
-
-=== TEST 5: lua_socket_keepalive_timeout
---- quic_max_idle_timeout: 1.1
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 100ms;
-
- set $port $TEST_NGINX_SERVER_PORT;
- rewrite_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive timeout: 100 ms",
-qr/lua tcp socket connection pool size: 30\b/]
---- timeout: 4
-
-
-
-=== TEST 6: lua_socket_pool_size
---- quic_max_idle_timeout: 1.1
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 100ms;
- lua_socket_pool_size 1;
-
- set $port $TEST_NGINX_SERVER_PORT;
- rewrite_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive timeout: 100 ms",
-qr/lua tcp socket connection pool size: 1\b/]
---- timeout: 4
-
-
-
-=== TEST 7: "lua_socket_keepalive_timeout 0" means unlimited
---- quic_max_idle_timeout: 1.2
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 0;
-
- set $port $TEST_NGINX_SERVER_PORT;
- rewrite_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- grep_error_log eval
-qr/lua tcp socket keepalive timeout: unlimited|lua tcp socket connection pool size: \d+/
---- grep_error_log_out eval
-["lua tcp socket connection pool size: 30
-lua tcp socket keepalive timeout: unlimited
-",
-"lua tcp socket keepalive timeout: unlimited
-"]
---- timeout: 4
-
-
-
-=== TEST 8: setkeepalive(timeout) overrides lua_socket_keepalive_timeout
---- quic_max_idle_timeout: 1.1
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 60s;
-
- set $port $TEST_NGINX_SERVER_PORT;
- rewrite_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive(123)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive timeout: 123 ms",
-qr/lua tcp socket connection pool size: 30\b/]
---- timeout: 4
-
-
-
-=== TEST 9: sock:setkeepalive(timeout, size) overrides lua_socket_pool_size
---- quic_max_idle_timeout: 1.1
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 100ms;
- lua_socket_pool_size 100;
-
- set $port $TEST_NGINX_SERVER_PORT;
- rewrite_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive(101, 25)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive timeout: 101 ms",
-qr/lua tcp socket connection pool size: 25\b/]
---- timeout: 4
-
-
-
-=== TEST 10: sock:keepalive_timeout(0) means unlimited
---- quic_max_idle_timeout: 1.1
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 1000ms;
-
- set $port $TEST_NGINX_SERVER_PORT;
- rewrite_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive(0)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- grep_error_log eval
-qr/lua tcp socket keepalive timeout: unlimited|lua tcp socket connection pool size: \d+/
---- grep_error_log_out eval
-["lua tcp socket connection pool size: 30
-lua tcp socket keepalive timeout: unlimited
-",
-"lua tcp socket keepalive timeout: unlimited
-"
-]
---- timeout: 4
-
-
-
-=== TEST 11: sanity (uds)
---- http_config eval
-"
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
- server {
- listen unix:$::HtmlDir/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
- }
-"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- rewrite_by_lua '
- local test = require "test"
- local path = "$TEST_NGINX_HTML_DIR/nginx.sock";
- local port = ngx.var.port
- test.go(path, port)
- test.go(path, port)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(path, port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:" .. path)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keepalive\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\r\n0\r\n\r\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- response_body_like
-^connected: 1, reused: \d+
-request sent: 61
-received response of 119 bytes
-connected: 1, reused: [1-9]\d*
-request sent: 61
-received response of 119 bytes
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for "]
---- grep_error_log eval
-qr/lua tcp socket get keepalive peer: using connection|lua tcp socket keepalive create connection pool for key "unix:/
---- grep_error_log_out eval
-[qq{lua tcp socket keepalive create connection pool for key "unix:
-lua tcp socket get keepalive peer: using connection
-},
-"lua tcp socket get keepalive peer: using connection
-lua tcp socket get keepalive peer: using connection
-"
-]
-
-
-
-=== TEST 12: github issue #108: ngx.location.capture + redis.set_keepalive
---- http_config eval
- qq{
- lua_package_path "$::HtmlDir/?.lua;;";
- }
---- config
- location /t {
- default_type text/html;
- set $port $TEST_NGINX_MEMCACHED_PORT;
- #lua_code_cache off;
- lua_need_request_body on;
- rewrite_by_lua_file html/t.lua;
- content_by_lua return;
- }
-
- location /anyurl {
- internal;
- proxy_pass http://127.0.0.1:$server_port/dummy;
- }
-
- location = /dummy {
- echo dummy;
- }
---- user_files
->>> t.lua
-local sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port)
-if not sock then ngx.say(err) return end
-sock:send("flush_all\r\n")
-sock:receive()
-sock:setkeepalive()
-
-sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port)
-if not sock then ngx.say(err) return end
-local res = ngx.location.capture("/anyurl") --3
-
-ngx.say("ok")
---- request
- GET /t
---- response_body
-ok
---- error_log
-lua tcp socket get keepalive peer: using connection
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 13: github issue #110: ngx.exit with HTTP_NOT_FOUND causes worker process to exit
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- error_page 404 /404.html;
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- access_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port)
- ngx.exit(404)
- ';
- echo hello;
- }
---- user_files
->>> 404.html
-Not found, dear...
->>> test.lua
-module("test", package.seeall)
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.log(ngx.ERR, "failed to send request: ", err)
- return
- end
-
- local line, err, part = sock:receive()
- if not line then
- ngx.log(ngx.ERR, "failed to receive a line: ", err, " [", part, "]")
- return
- end
-
- -- local ok, err = sock:setkeepalive()
- -- if not ok then
- -- ngx.log(ngx.ERR, "failed to set reusable: ", err)
- -- return
- -- end
-end
---- request
-GET /t
---- response_body
-Not found, dear...
---- error_code: 404
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/subrequest.t b/src/deps/src/lua-nginx-module/t/023-rewrite/subrequest.t
deleted file mode 100644
index cb8523c46..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/subrequest.t
+++ /dev/null
@@ -1,641 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: DELETE
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_DELETE });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-DELETE
-
-
-
-=== TEST 2: DELETE (proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_DELETE });
-
- ngx.print(res.body)
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-DELETE
-
-
-
-=== TEST 3: POST (nobody, proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_POST });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-POST
-
-
-
-=== TEST 4: HEAD
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_HEAD });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-
-
-
-=== TEST 5: explicit GET
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_GET });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET
-
-
-
-=== TEST 6: implicit GET
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo")
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET
-
-
-
-=== TEST 7: implicit GET (empty option table)
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo", {})
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET
-
-
-
-=== TEST 8: PUT (nobody, proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo_read_request_body;
-
- echo $echo_request_method;
- echo_request_body;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_PUT, body = "hello" });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body chomp
-PUT
-hello
-
-
-
-=== TEST 9: PUT (nobody, no proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- #echo_read_request_body;
-
- echo $echo_request_method;
- #echo $echo_request_body;
- echo_request_body;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_PUT, body = "hello" });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body chomp
-PUT
-hello
-
-
-
-=== TEST 10: PUT (nobody, no proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- #echo_read_request_body;
-
- echo $echo_request_method;
- #echo $echo_request_body;
- echo_request_body;
- #echo "[$http_content_length]";
- echo;
- }
-
- location /foo {
- echo $echo_request_method;
- echo -n "[$http_content_length]";
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_PUT, body = "hello" });
-
- ngx.print(res.body)
-
- res = ngx.location.capture("/foo")
- ngx.say(res.body)
-
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-PUT
-hello
-GET
-[]
-
-
-
-=== TEST 11: POST (with body, proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo_read_request_body;
-
- echo $echo_request_method;
- echo_request_body;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_POST, body = "hello" });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body chomp
-POST
-hello
-
-
-
-=== TEST 12: POST (with body, memc method)
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc {
- set $memc_key $echo_request_uri;
- set $memc_exptime 600;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /lua {
- rewrite_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- ngx.say("GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- ngx.say("PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- ngx.say("cached: " .. res.body);
-
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET: 404
-PUT: 201
-cached: hello
-
-
-
-=== TEST 13: POST (with body, memc method)
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc {
- set $memc_cmd "";
- set $memc_key $echo_request_uri;
- set $memc_exptime 600;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /lua {
- rewrite_by_lua '
- ngx.location.capture("/flush",
- { share_all_vars = true });
-
- local res = ngx.location.capture("/memc",
- { share_all_vars = true });
- ngx.say("GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello", share_all_vars = true });
- ngx.say("PUT: " .. res.status);
-
- res = ngx.location.capture("/memc", { share_all_vars = true });
- ngx.say("cached: " .. res.body);
-
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET: 404
-PUT: 201
-cached: hello
-
-
-
-=== TEST 14: empty args option table
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { args = {} })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body eval: "\n"
-
-
-
-=== TEST 15: non-empty args option table (1 pair)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { ["fo="] = "=>" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-fo%3D=%3D%3E
-
-
-
-=== TEST 16: non-empty args option table (2 pairs)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { ["fo="] = "=>",
- ["="] = ":" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like chop
-^(?:fo%3D=%3D%3E\&%3D=%3A|%3D=%3A\&fo%3D=%3D%3E)$
-
-
-
-=== TEST 17: non-empty args option table (2 pairs, no special chars)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { foo = 3,
- bar = "hello" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like chop
-^(?:bar=hello\&foo=3|foo=3\&bar=hello)$
-
-
-
-=== TEST 18: non-empty args option table (number key)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { [57] = "hi" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 19: non-empty args option table (plain arrays)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { "hi" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 20: more args
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo?a=3",
- { args = { b = 4 } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-a=3&b=4
-
-
-
-=== TEST 21: more args
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- rewrite_by_lua '
- local res = ngx.location.capture("/foo?a=3",
- { args = "b=4" })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-a=3&b=4
-
-
-
-=== TEST 22: more args
---- config
- location /memc {
- set $memc_cmd get;
- set $memc_key $arg_key;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc_set {
- #set $memc_cmd set;
- #set $memc_key $arg_key;
- #memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- echo OK;
- }
-
- location /lua {
- rewrite_by_lua '
- print("HELLO")
- local memc_key = "hello"
- local res = ngx.location.capture("/memc?key=" .. memc_key )
- ngx.say("copass: res " .. res.status)
-
- if res.status == 404 then
- ngx.say("copas: capture /memc_set")
- res = ngx.location.capture("/memc_set?key=" .. memc_key)
- ngx.say("copss: status " .. res.status);
- end
- ';
- content_by_lua 'return';
- #echo Hi;
- }
---- request
- GET /lua
---- response_body
-copass: res 404
-copas: capture /memc_set
-copss: status 200
-
-
-
-=== TEST 23: I/O in named location
-the nginx core requires the patch https://github.com/agentzh/ngx_openresty/blob/master/patches/nginx-1.0.15-reset_wev_handler_in_named_locations.patch
---- config
- location /t {
- echo_exec @named;
- }
-
- location @named {
- rewrite_by_lua '
- ngx.location.capture("/hello")
- ';
- echo done;
- }
-
- location /hello {
- echo hello;
- }
---- request
- GET /t
---- response_body
-done
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/tcp-socket-timeout.t b/src/deps/src/lua-nginx-module/t/023-rewrite/tcp-socket-timeout.t
deleted file mode 100644
index 9be808132..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/tcp-socket-timeout.t
+++ /dev/null
@@ -1,607 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-BEGIN {
- if (!defined $ENV{LD_PRELOAD}) {
- $ENV{LD_PRELOAD} = '';
- }
-
- if ($ENV{LD_PRELOAD} !~ /\bmockeagain\.so\b/) {
- $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}";
- }
-
- if ($ENV{MOCKEAGAIN} eq 'r') {
- $ENV{MOCKEAGAIN} = 'rw';
-
- } else {
- $ENV{MOCKEAGAIN} = 'w';
- }
-
- delete($ENV{TEST_NGINX_USE_HTTP2});
- $ENV{TEST_NGINX_EVENT_TYPE} = 'poll';
- $ENV{MOCKEAGAIN_WRITE_TIMEOUT_PATTERN} = 'get helloworld';
-}
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 8);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-no_long_string();
-no_diff();
-run_tests();
-
-__DATA__
-
-=== TEST 1: lua_socket_connect_timeout only
---- config
- server_tokens off;
- lua_socket_connect_timeout 100ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t1 {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t1
---- response_body
-failed to connect: timeout
---- error_log
-lua tcp socket connect timeout: 100
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
---- timeout: 10
-
-
-
-=== TEST 2: sock:settimeout() overrides lua_socket_connect_timeout
---- config
- server_tokens off;
- lua_socket_connect_timeout 60s;
- lua_socket_log_errors off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t2 {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(150)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t2
---- response_body
-failed to connect: timeout
---- error_log
-lua tcp socket connect timeout: 150
---- no_error_log
-[error]
-[alert]
---- timeout: 10
-
-
-
-=== TEST 3: sock:settimeout(nil) does not override lua_socket_connect_timeout
---- config
- server_tokens off;
- lua_socket_log_errors off;
- lua_socket_connect_timeout 102ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- #resolver_timeout 3s;
- location /t3 {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(nil)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t3
---- response_body
-failed to connect: timeout
---- error_log
-lua tcp socket connect timeout: 102
---- no_error_log
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 4: sock:settimeout(0) does not override lua_socket_connect_timeout
---- config
- server_tokens off;
- lua_socket_connect_timeout 102ms;
- lua_socket_log_errors off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t4 {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(0)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t4
---- response_body
-failed to connect: timeout
---- error_log
-lua tcp socket connect timeout: 102
---- timeout: 5
---- no_error_log
-[error]
-[alert]
---- timeout: 10
-
-
-
-=== TEST 5: -1 is bad timeout value
---- config
- server_tokens off;
- lua_socket_connect_timeout 102ms;
- lua_socket_log_errors off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t5 {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(-1)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t5
---- response_body_like chomp
-500 Internal Server Error
---- error_log
-bad timeout value
---- timeout: 10
---- error_code: 500
-
-
-
-=== TEST 6: lua_socket_read_timeout only
---- config
- server_tokens off;
- lua_socket_read_timeout 100ms;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua tcp socket read timeout: 100
-lua tcp socket connect timeout: 60000
-lua tcp socket read timed out
-
-
-
-=== TEST 7: sock:settimeout() overrides lua_socket_read_timeout
---- config
- server_tokens off;
- lua_socket_read_timeout 60s;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(150)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket read timeout: 150
-lua tcp socket read timed out
-
-
-
-=== TEST 8: sock:settimeout(nil) does not override lua_socket_read_timeout
---- config
- server_tokens off;
- lua_socket_read_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(nil)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket read timeout: 102
-lua tcp socket read timed out
-
-
-
-=== TEST 9: sock:settimeout(0) does not override lua_socket_read_timeout
---- config
- server_tokens off;
- lua_socket_read_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(0)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
-
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket read timeout: 102
-lua tcp socket read timed out
-
-
-
-=== TEST 10: -1 is bad timeout value
---- config
- server_tokens off;
- lua_socket_read_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- sock:settimeout(-1)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body_like chomp
-500 Internal Server Error
---- error_log
-bad timeout value
---- timeout: 10
---- error_code: 500
-
-
-
-=== TEST 11: lua_socket_send_timeout only
---- config
- server_tokens off;
- lua_socket_send_timeout 100ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to send: timeout
---- error_log
-lua tcp socket send timeout: 100
-lua tcp socket connect timeout: 60000
-lua tcp socket write timed out
-
-
-
-=== TEST 12: sock:settimeout() overrides lua_socket_send_timeout
---- config
- server_tokens off;
- lua_socket_send_timeout 60s;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(150)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to send: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket send timeout: 150
-lua tcp socket write timed out
-
-
-
-=== TEST 13: sock:settimeout(nil) does not override lua_socket_send_timeout
---- config
- server_tokens off;
- lua_socket_send_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(nil)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to send: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket send timeout: 102
-lua tcp socket write timed out
-
-
-
-=== TEST 14: sock:settimeout(0) does not override lua_socket_send_timeout
---- config
- server_tokens off;
- lua_socket_send_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(0)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to send: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket send timeout: 102
-lua tcp socket write timed out
-
-
-
-=== TEST 15: -1 is bad timeout value
---- config
- server_tokens off;
- lua_socket_send_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- sock:settimeout(-1)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body_like chomp
-500 Internal Server Error
---- error_log
-bad timeout value
---- timeout: 10
---- error_code: 500
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/tcp-socket.t b/src/deps/src/lua-nginx-module/t/023-rewrite/tcp-socket.t
deleted file mode 100644
index 966365f90..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/tcp-socket.t
+++ /dev/null
@@ -1,2420 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * 107;
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-#log_level 'warn';
-
-#no_long_string();
-#no_diff();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 2: no trailing newline
---- config
- server_tokens off;
- location /t {
- #set $port 1234;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- sock:close()
- ngx.say("closed")
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.print("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 3
-received: Connection: close
-received:
-failed to receive a line: closed [foo]
-closed
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 3: no resolver defined
---- config
- server_tokens off;
- location /t {
- #set $port 1234;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("agentzh.org", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body
-failed to connect: no resolver defined to resolve "agentzh.org"
-connected: nil
-failed to send request: closed
---- error_log
-attempt to send data on a closed socket:
---- no_http2
-
-
-
-=== TEST 4: with resolver
---- timeout: 10
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = 80
- local ok, err = sock:connect("agentzh.org", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET / HTTP/1.0\\r\\nHost: agentzh.org\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local line, err = sock:receive()
- if line then
- ngx.say("first line received: ", line)
-
- else
- ngx.say("failed to receive the first line: ", err)
- end
-
- line, err = sock:receive()
- if line then
- ngx.say("second line received: ", line)
-
- else
- ngx.say("failed to receive the second line: ", err)
- end
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body_like
-connected: 1
-request sent: 56
-first line received: HTTP\/1\.1 200 OK
-second line received: (?:Date|Server): .*?
---- no_error_log
-[error]
-
-
-
-=== TEST 5: connection refused (tcp)
---- config
- location /test {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", 16787)
- ngx.say("connect: ", ok, " ", err)
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
---- request
- GET /test
---- response_body
-connect: nil connection refused
-send: nil closed
-receive: nil closed
-close: nil closed
---- error_log eval
-qr/connect\(\) failed \(\d+: Connection refused\)/
-
-
-
-=== TEST 6: connection timeout (tcp)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_socket_connect_timeout 100ms;
- lua_socket_send_timeout 100ms;
- lua_socket_read_timeout 100ms;
- resolver_timeout 3s;
- location /test {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.2", 12345)
- ngx.say("connect: ", ok, " ", err)
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
---- request
- GET /test
---- response_body
-connect: nil timeout
-send: nil closed
-receive: nil closed
-close: nil closed
---- error_log
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
---- timeout: 10
-
-
-
-=== TEST 7: not closed manually
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 8: resolver error (host not found)
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = 80
- local ok, err = sock:connect("blah-blah-not-found.agentzh.org", port)
- print("connected: ", ok, " ", err, " ", not ok)
- if not ok then
- ngx.say("failed to connect: ", err)
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET / HTTP/1.0\\r\\nHost: agentzh.org\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body_like
-^failed to connect: blah-blah-not-found\.agentzh\.org could not be resolved(?: \(3: Host not found\))?
-connected: nil
-failed to send request: closed$
---- error_log
-attempt to send data on a closed socket
---- timeout: 10
-
-
-
-=== TEST 9: resolver error (timeout)
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 1ms;
- location /t {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = 80
- local ok, err = sock:connect("blah-blah-not-found.agentzh.org", port)
- print("connected: ", ok, " ", err, " ", not ok)
- if not ok then
- ngx.say("failed to connect: ", err)
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET / HTTP/1.0\\r\\nHost: agentzh.org\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
- ';
-
- content_by_lua return;
- }
---- request
-GET /t
---- response_body_like
-^failed to connect: blah-blah-not-found\.agentzh\.org could not be resolved(?: \(\d+: (?:Operation timed out|Host not found)\))?
-connected: nil
-failed to send request: closed$
---- error_log
-attempt to send data on a closed socket
-
-
-
-=== TEST 10: explicit *l pattern for receive
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err = sock:receive("*l")
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err)
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed
-close: 1 nil
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 11: *a pattern for receive
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local data, err = sock:receive("*a")
- if data then
- ngx.say("receive: ", data)
- ngx.say("err: ", err)
-
- else
- ngx.say("failed to receive: ", err)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-receive: HTTP/1.1 200 OK\r
-Server: nginx\r
-Content-Type: text/plain\r
-Content-Length: 4\r
-Connection: close\r
-\r
-foo
-
-err: nil
-close: 1 nil
-"
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 12: mixing *a and *l patterns for receive
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local line, err = sock:receive("*l")
- if line then
- ngx.say("receive: ", line)
- ngx.say("err: ", err)
-
- else
- ngx.say("failed to receive: ", err)
- end
-
- local data
- data, err = sock:receive("*a")
- if data then
- ngx.say("receive: ", data)
- ngx.say("err: ", err)
-
- else
- ngx.say("failed to receive: ", err)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-receive: HTTP/1.1 200 OK
-err: nil
-receive: Server: nginx\r
-Content-Type: text/plain\r
-Content-Length: 4\r
-Connection: close\r
-\r
-foo
-
-err: nil
-close: 1 nil
-"
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 13: receive by chunks
---- timeout: 5
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local data, err, partial = sock:receive(10)
- if data then
- local len = string.len(data)
- if len == 10 then
- ngx.print("[", data, "]")
- else
- ngx.say("ERROR: returned invalid length of data: ", len)
- end
-
- else
- ngx.say("failed to receive a line: ", err, " [", partial, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-[HTTP/1.1 2][00 OK\r
-Ser][ver: nginx][\r
-Content-][Type: text][/plain\r
-Co][ntent-Leng][th: 4\r
-Con][nection: c][lose\r
-\r
-fo]failed to receive a line: closed [o
-]
-close: 1 nil
-"
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 14: receive by chunks (very small buffer)
---- timeout: 5
---- config
- server_tokens off;
- lua_socket_buffer_size 1;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local data, err, partial = sock:receive(10)
- if data then
- local len = string.len(data)
- if len == 10 then
- ngx.print("[", data, "]")
- else
- ngx.say("ERROR: returned invalid length of data: ", len)
- end
-
- else
- ngx.say("failed to receive a line: ", err, " [", partial, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-[HTTP/1.1 2][00 OK\r
-Ser][ver: nginx][\r
-Content-][Type: text][/plain\r
-Co][ntent-Leng][th: 4\r
-Con][nection: c][lose\r
-\r
-fo]failed to receive a line: closed [o
-]
-close: 1 nil
-"
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 15: line reading (very small buffer)
---- config
- server_tokens off;
- lua_socket_buffer_size 1;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 16: ngx.socket.connect (working)
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local port = ngx.var.port
- local sock, err = ngx.socket.connect("127.0.0.1", port)
- if not sock then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected.")
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected.
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 17: ngx.socket.connect() shortcut (connection refused)
---- config
- location /test {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local sock, err = sock:connect("127.0.0.1", 16787)
- if not sock then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
---- request
- GET /test
---- response_body
-failed to connect: connection refused
---- error_log eval
-qr/connect\(\) failed \(\d+: Connection refused\)/
-
-
-
-=== TEST 18: receive by chunks (stringified size)
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local data, err, partial = sock:receive("10")
- if data then
- local len = string.len(data)
- if len == 10 then
- ngx.print("[", data, "]")
- else
- ngx.say("ERROR: returned invalid length of data: ", len)
- end
-
- else
- ngx.say("failed to receive a line: ", err, " [", partial, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-[HTTP/1.1 2][00 OK\r
-Ser][ver: nginx][\r
-Content-][Type: text][/plain\r
-Co][ntent-Leng][th: 4\r
-Con][nection: c][lose\r
-\r
-fo]failed to receive a line: closed [o
-]
-close: 1 nil
-"
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 19: cannot survive across request boundary (send)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- rewrite_by_lua '
- local test = require "test"
- test.go(ngx.var.port)
- ';
-
- content_by_lua return;
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function go(port)
- if not sock then
- sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-end
---- request
-GET /t
---- response_body_like eval
-"^(?:connected: 1
-request sent: 11
-received: OK|failed to send request: closed)\$"
-
-
-
-=== TEST 20: cannot survive across request boundary (receive)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- rewrite_by_lua '
- local test = require "test"
- test.go(ngx.var.port)
- ';
-
- content_by_lua return;
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function go(port)
- if not sock then
- sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- else
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
- return
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-end
---- request
-GET /t
---- response_body_like eval
-qr/^(?:connected: 1
-request sent: 11
-received: OK|failed to receive a line: closed \[nil\])$/
-
-
-
-=== TEST 21: cannot survive across request boundary (close)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- rewrite_by_lua '
- local test = require "test"
- test.go(ngx.var.port)
- ';
-
- content_by_lua return;
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function go(port)
- if not sock then
- sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- else
- local ok, err = sock:close()
- if ok then
- ngx.say("successfully closed")
-
- else
- ngx.say("failed to close: ", err)
- end
- return
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-end
---- request
-GET /t
---- response_body_like eval
-qr/^(?:connected: 1
-request sent: 11
-received: OK|failed to close: closed)$/
-
-
-
-=== TEST 22: cannot survive across request boundary (connect)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- rewrite_by_lua '
- local test = require "test"
- test.go(ngx.var.port)
- test.go(ngx.var.port)
- ';
-
- content_by_lua return;
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function go(port)
- if not sock then
- sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- else
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect again: ", err)
- return
- end
-
- ngx.say("connected again: ", ok)
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-end
---- request
-GET /t
---- response_body_like eval
-qr/^(?:connected(?: again)?: 1
-request sent: 11
-received: OK
-){2}$/
---- error_log
-lua reuse socket upstream ctx
---- no_error_log
-[error]
---- SKIP
-
-
-
-=== TEST 23: connect again immediately
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected again: ", ok)
-
- local req = "flush_all\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-connected again: 1
-request sent: 11
-received: OK
-close: 1 nil
---- no_error_log
-[error]
---- error_log eval
-["lua reuse socket upstream", "lua tcp socket reconnect without shutting down"]
-
-
-
-=== TEST 24: two sockets mix together
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port1 $TEST_NGINX_MEMCACHED_PORT;
- set $port2 $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock1 = ngx.socket.tcp()
- local sock2 = ngx.socket.tcp()
-
- local port1 = ngx.var.port1
- local port2 = ngx.var.port2
-
- local ok, err = sock1:connect("127.0.0.1", port1)
- if not ok then
- ngx.say("1: failed to connect: ", err)
- return
- end
-
- ngx.say("1: connected: ", ok)
-
- ok, err = sock2:connect("127.0.0.1", port2)
- if not ok then
- ngx.say("2: failed to connect: ", err)
- return
- end
-
- ngx.say("2: connected: ", ok)
-
- local req1 = "flush_all\\r\\n"
- local bytes, err = sock1:send(req1)
- if not bytes then
- ngx.say("1: failed to send request: ", err)
- return
- end
- ngx.say("1: request sent: ", bytes)
-
- local req2 = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock2:send(req2)
- if not bytes then
- ngx.say("2: failed to send request: ", err)
- return
- end
- ngx.say("2: request sent: ", bytes)
-
- local line, err, part = sock1:receive()
- if line then
- ngx.say("1: received: ", line)
-
- else
- ngx.say("1: failed to receive a line: ", err, " [", part, "]")
- end
-
- line, err, part = sock2:receive()
- if line then
- ngx.say("2: received: ", line)
-
- else
- ngx.say("2: failed to receive a line: ", err, " [", part, "]")
- end
-
- ok, err = sock1:close()
- ngx.say("1: close: ", ok, " ", err)
-
- ok, err = sock2:close()
- ngx.say("2: close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-1: connected: 1
-2: connected: 1
-1: request sent: 11
-2: request sent: 57
-1: received: OK
-2: received: HTTP/1.1 200 OK
-1: close: 1 nil
-2: close: 1 nil
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 25: send tables of string fragments
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", 1, ".", 0, "\\r\\n",
- "Host: localhost\\r\\n", "Connection: close\\r\\n",
- "\\r\\n"}
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 26: send tables of string fragments (bad type "nil")
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", nil, 1, ".", 0, "\\r\\n",
- "Host: localhost\\r\\n", "Connection: close\\r\\n",
- "\\r\\n"}
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- ignore_response
---- error_log
-bad argument #1 to 'send' (bad data type nil found)
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
---- no_http2
-
-
-
-=== TEST 27: send tables of string fragments (bad type "boolean")
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", true, 1, ".", 0, "\\r\\n",
- "Host: localhost\\r\\n", "Connection: close\\r\\n",
- "\\r\\n"}
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- ignore_response
---- error_log
-bad argument #1 to 'send' (bad data type boolean found)
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
---- no_http2
-
-
-
-=== TEST 28: send tables of string fragments (bad type ngx.null)
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", ngx.null, 1, ".", 0, "\\r\\n",
- "Host: localhost\\r\\n", "Connection: close\\r\\n",
- "\\r\\n"}
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- ignore_response
---- error_log
-bad argument #1 to 'send' (bad data type userdata found)
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
---- no_http2
-
-
-
-=== TEST 29: cosocket before location capture (tcpsock:send did not clear u->waiting)
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
-
- local resp = ngx.location.capture("/memc")
- if type(resp) ~= "table" then
- ngx.say("bad resp: type ", type(resp), ": ", resp)
- return
- end
-
- ngx.print("subrequest: ", resp.status, ", ", resp.body)
- ';
-
- content_by_lua return;
- }
-
- location /memc {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 11
-received: OK
-close: 1 nil
-subrequest: 200, OK\r
-"
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 30: CR in a line
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo\\r\\rbar\\rbaz")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 13
-received: Connection: close
-received:
-received: foobarbaz
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
---- SKIP
---- no_http2
-
-
-
-=== TEST 31: receive(0)
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local data, err, part = sock:receive(0)
- if not data then
- ngx.say("failed to receive(0): ", err)
- return
- end
-
- ngx.say("receive(0): [", data, "]")
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-receive(0): []
-close: 1 nil
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 32: send("")
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local bytes, err = sock:send("")
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("send(\\"\\"): ", bytes)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-send(""): 0
-close: 1 nil
---- no_error_log
-[error]
---- no_http2
-
-
-
-=== TEST 33: bad request tries to connect
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location = /main {
- echo_location /t?reset=1;
- echo_location /t;
- }
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- rewrite_by_lua '
- local test = require "test"
- if ngx.var.arg_reset then
- test.new_sock()
- end
- local sock = test.get_sock()
- local ok, err = sock:connect("127.0.0.1", ngx.var.port)
- if not ok then
- ngx.say("failed to connect: ", err)
- else
- ngx.say("connected")
- end
- ';
-
- content_by_lua return;
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
- repeat_each() * (2 * blocks() + 1);
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-
-no_long_string();
-#no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: connection refused (unix domain socket)
---- config
- location /test {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:/tmp/nosuchfile.sock")
- ngx.say("connect: ", ok, " ", err)
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
---- request
- GET /test
---- response_body
-connect: nil no such file or directory
-send: nil closed
-receive: nil closed
-close: nil closed
---- error_log eval
-qr{\[crit\] .*? connect\(\) to unix:/tmp/nosuchfile\.sock failed}
-
-
-
-=== TEST 2: invalid host argument
---- http_server
- server {
- listen /tmp/test-nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
- }
---- config
- location /test {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("/tmp/test-nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
-
- content_by_lua return;
- }
---- request
- GET /test
---- response_body
-failed to connect: missing the port number
-
-
-
-=== TEST 3: sanity
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
- }
---- config
- location /test {
- rewrite_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- print("calling receive")
- local line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err)
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
-
- content_by_lua return;
- }
---- request
- GET /test
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed
-close: 1 nil
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-exec.t b/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-exec.t
deleted file mode 100644
index 9428bd67b..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-exec.t
+++ /dev/null
@@ -1,345 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: exec in user thread (entry still pending)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ngx.say("hello")
- ';
- content_by_lua return;
- }
-
- location /foo {
- echo i am foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-delete thread 1
-
---- response_body
-i am foo
---- no_error_log
-[error]
-
-
-
-=== TEST 2: exec in user thread (entry already quits)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
- ';
- content_by_lua return;
- }
-
- location /foo {
- echo i am foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-i am foo
---- no_error_log
-[error]
-
-
-
-=== TEST 3: exec in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ';
- content_by_lua return;
- }
-
- location = /foo {
- echo hello foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- response_body
-hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 4: exec in a user thread (another user thread is still pending on ngx.sleep)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- local function g()
- ngx.sleep(1)
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ';
- content_by_lua return;
- }
-
- location = /foo {
- echo hello foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-create 3 in 1
-spawn user thread 3 in 1
-add timer 1000
-terminate 1: ok
-delete thread 1
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 3
-free request
-
---- response_body
-hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 5: exec in user thread (entry thread is still pending on ngx.location.capture), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture("/sleep")
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
-
- location = /foo {
- echo hello world;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-exit.t b/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-exit.t
deleted file mode 100644
index 87f850ce8..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-exit.t
+++ /dev/null
@@ -1,1333 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 1);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: exit in user thread (entry thread is still pending to run)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ngx.sleep(1)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-M(timer-add) {
- if ($arg2 == 1000) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before
-hello in thread
---- no_error_log
-[error]
-
-
-
-=== TEST 2: exit in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ngx.sleep(1)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 3: exit in a user thread (another user thread is still pending on ngx.sleep)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("f")
- ngx.exit(0)
- end
-
- local function g()
- ngx.sleep(1)
- ngx.say("g")
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-create 3 in 1
-spawn user thread 3 in 1
-add timer 1000
-terminate 1: ok
-delete thread 1
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 3
-free request
-
---- response_body
-end
-f
---- no_error_log
-[error]
-
-
-
-=== TEST 4: exit in user thread (entry already quits)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("exiting the user thread")
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- wait: 0.1
---- response_body
-before
-after
-exiting the user thread
---- no_error_log
-[error]
-
-
-
-=== TEST 5: exit in user thread (entry thread is still pending on the DNS resolver for ngx.socket.tcp)
---- config
- location /lua {
- resolver 127.0.0.2:12345;
- resolver_timeout 12s;
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.001)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_resolve_start) {
- println("resolver started")
-}
-
-F(ngx_http_lua_socket_resolve_handler) {
- println("resolver done")
-}
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-F(ngx_resolve_name) {
- printf("resolving %s\n", user_string_n($ctx->name->data, $ctx->name->len))
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 1) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 12000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_tcp_resolve_cleanup) {
- println("lua tcp resolve cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 1
-resolver started
-resolving agentzh.org
-add timer 12000
-expire timer 1
-terminate 2: ok
-delete thread 2
-lua tcp resolve cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 6: exit in user thread (entry thread is still pending on the DNS resolver for ngx.socket.udp)
---- config
- location /lua {
- resolver 127.0.0.2:12345;
- #resolver 127.0.0.1;
- resolver_timeout 12s;
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.001)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername("agentzh.org", 80)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_resolve_start) {
- println("resolver started")
-}
-
-F(ngx_http_lua_socket_resolve_handler) {
- println("resolver done")
-}
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-F(ngx_resolve_name) {
- printf("resolving %s\n", user_string_n($ctx->name->data, $ctx->name->len))
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 1) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 12000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_udp_resolve_cleanup) {
- println("lua udp resolve cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 1
-resolver started
-resolving agentzh.org
-add timer 12000
-expire timer 1
-terminate 2: ok
-delete thread 2
-lua udp resolve cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 7: exit in user thread (entry thread is still pending on tcpsock:connect)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
- sock:settimeout(12000)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 12000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 8: exit in user thread (entry thread is still pending on tcpsock:receive)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, ok = sock:send("blpop not_exists 2\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local data, err = sock:receive()
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 9: exit in user thread (entry thread is still pending on tcpsock:receiveuntil's iterator)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, ok = sock:send("blpop not_exists 2\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- local it, err = sock:receiveuntil("\\r\\n")
- if not it then
- ngx.say("failed to receive until: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local data, err = it()
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 10: exit in user thread (entry thread is still pending on udpsock:receive)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.udp()
-
- local ok, err = sock:setpeername("8.8.8.8", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local data, err = sock:receive()
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_udp_socket_cleanup) {
- println("lua udp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua udp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 11: exit in user thread (entry thread is still pending on reqsock:receive)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.req.socket()
-
- sock:settimeout(12000)
-
- local data, err = sock:receive(1024)
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-POST /lua
-
---- more_headers
-Content-Length: 1024
-
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 12: exit in user thread (entry thread is still pending on ngx.req.read_body)
---- config
- location /lua {
- client_body_timeout 12000ms;
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.req.read_body()
-
- ngx.say("end")
- ';
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_req_body_cleanup) {
- println("lua req body cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua req body cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 13: exit in user thread (entry thread is still pending on ngx.location.capture), with pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.location.capture("/sleep")
-
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 14: exit in user thread (entry thread is still pending on ngx.location.capture), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture("/sleep")
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 15: exit in user thread (entry thread is still pending on ngx.location.capture_multi), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture_multi{
- {"/echo"},
- {"/sleep"}
- }
- ngx.say("end")
- ';
- }
-
- location = /echo {
- echo hello;
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-post subreq /echo
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-redirect.t b/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-redirect.t
deleted file mode 100644
index 0e636f7bb..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-redirect.t
+++ /dev/null
@@ -1,188 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: ngx.redirect() in user thread (entry thread is still pending on ngx.location.capture_multi), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.redirect(301)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture_multi{
- {"/echo"},
- {"/sleep"}
- }
- ngx.say("end")
- ';
- }
-
- location = /echo {
- echo hello;
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-post subreq /echo
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 2: redirect in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.redirect(301)
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ngx.say("end")
- ';
- content_by_lua return;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- response_body_like: 302 Found
---- error_code: 302
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-spawn.t b/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-spawn.t
deleted file mode 100644
index 62d837cff..000000000
--- a/src/deps/src/lua-nginx-module/t/023-rewrite/uthread-spawn.t
+++ /dev/null
@@ -1,1456 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 1);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple user thread without I/O
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval
-<<'_EOC_' . $::StapScript;
-
-F(ngx_http_lua_send_chain_link) {
- printf("send link %p\n", $in)
-}
-
-F(ngx_http_core_content_phase) {
- println("core content phase")
-}
-
-_EOC_
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 2: two simple user threads without I/O
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("in thread 1")
- end
-
- local function g()
- ngx.say("in thread 2")
- end
-
- ngx.say("before 1")
- ngx.thread.spawn(f)
- ngx.say("after 1")
-
- ngx.say("before 2")
- ngx.thread.spawn(g)
- ngx.say("after 2")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: ok
-terminate 1: ok
-delete thread 2
-delete thread 3
-delete thread 1
-
---- response_body
-before 1
-in thread 1
-after 1
-before 2
-in thread 2
-after 2
---- no_error_log
-[error]
-
-
-
-=== TEST 3: simple user thread with sleep
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("before sleep")
- ngx.sleep(0.1)
- ngx.say("after sleep")
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before thread create
-before sleep
-after thread create
-after sleep
---- no_error_log
-[error]
-
-
-
-=== TEST 4: two simple user threads with sleep
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("1: before sleep")
- ngx.sleep(0.2)
- ngx.say("1: after sleep")
- end
-
- local function g()
- ngx.say("2: before sleep")
- ngx.sleep(0.1)
- ngx.say("2: after sleep")
- end
-
- ngx.say("1: before thread create")
- ngx.thread.spawn(f)
- ngx.say("1: after thread create")
-
- ngx.say("2: before thread create")
- ngx.thread.spawn(g)
- ngx.say("2: after thread create")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2
-
---- wait: 0.1
---- response_body
-1: before thread create
-1: before sleep
-1: after thread create
-2: before thread create
-2: before sleep
-2: after thread create
-2: after sleep
-1: after sleep
---- no_error_log
-[error]
-
-
-
-=== TEST 5: error in user thread
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.blah()
- end
-
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: fail
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-after
---- error_log eval
-qr/lua user thread aborted: runtime error: rewrite_by_lua\(nginx\.conf:\d+\):3: attempt to call field 'blah' \(a nil value\)/
-
-
-
-=== TEST 6: simple user threads doing a single subrequest (entry quits early)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("before capture")
- local res = ngx.location.capture("/proxy")
- ngx.say("after capture: ", res.body)
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello world;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before thread create
-before capture
-after thread create
-after capture: hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 7: simple user threads doing a single subrequest (entry also does a subrequest and quits early)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("before capture")
- local res = ngx.location.capture("/proxy?foo")
- ngx.say("after capture: ", res.body)
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- local res = ngx.location.capture("/proxy?bar")
- ngx.say("capture: ", res.body)
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/$args;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello foo;
- }
-
- location /bar {
- echo -n hello bar;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before thread create
-before capture
-after thread create
-capture: hello bar
-after capture: hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 8: simple user threads doing a single subrequest (entry also does a subrequest and quits late)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("before capture")
- local res = ngx.location.capture("/proxy?foo")
- ngx.say("after capture: ", res.body)
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- local res = ngx.location.capture("/proxy?bar")
- ngx.say("capture: ", res.body)
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/$args;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello foo;
- }
-
- location /bar {
- echo_sleep 0.2;
- echo -n hello bar;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before thread create
-before capture
-after thread create
-after capture: hello foo
-capture: hello bar
---- no_error_log
-[error]
-
-
-
-=== TEST 9: two simple user threads doing single subrequests (entry also does a subrequest and quits between)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("f: before capture")
- local res = ngx.location.capture("/proxy?foo")
- ngx.say("f: after capture: ", res.body)
- end
-
- local function g()
- ngx.say("g: before capture")
- local res = ngx.location.capture("/proxy?bah")
- ngx.say("g: after capture: ", res.body)
- end
-
- ngx.say("before thread 1 create")
- ngx.thread.spawn(f)
- ngx.say("after thread 1 create")
-
- ngx.say("before thread 2 create")
- ngx.thread.spawn(g)
- ngx.say("after thread 2 create")
-
- local res = ngx.location.capture("/proxy?bar")
- ngx.say("capture: ", res.body)
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/$args;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello foo;
- }
-
- location /bar {
- echo_sleep 0.2;
- echo -n hello bar;
- }
-
- location /bah {
- echo_sleep 0.3;
- echo -n hello bah;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-terminate 3: ok
-delete thread 3
-
---- response_body
-before thread 1 create
-f: before capture
-after thread 1 create
-before thread 2 create
-g: before capture
-after thread 2 create
-f: after capture: hello foo
-capture: hello bar
-g: after capture: hello bah
---- no_error_log
-[error]
-
-
-
-=== TEST 10: nested user threads
---- config
- location /lua {
- rewrite_by_lua '
- local g
- local function f()
- ngx.say("before g")
- ngx.thread.spawn(g)
- ngx.say("after g")
- end
-
- function g()
- ngx.say("hello in g()")
- end
-
- ngx.say("before f")
- ngx.thread.spawn(f)
- ngx.say("after f")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 3
-delete thread 2
-
---- response_body
-before f
-before g
-hello in g()
-after f
-after g
---- no_error_log
-[error]
-
-
-
-=== TEST 11: nested user threads (with I/O)
---- config
- location /lua {
- rewrite_by_lua '
- local g
- local function f()
- ngx.say("before g")
- ngx.thread.spawn(g)
- ngx.say("after g")
- end
-
- function g()
- ngx.sleep(0.1)
- ngx.say("hello in g()")
- end
-
- ngx.say("before f")
- ngx.thread.spawn(f)
- ngx.say("after f")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-before f
-before g
-after f
-after g
-hello in g()
---- no_error_log
-[error]
-
-
-
-=== TEST 12: coroutine status of a running user thread
---- config
- location /lua {
- rewrite_by_lua '
- local co
- local function f()
- co = coroutine.running()
- ngx.sleep(0.1)
- end
-
- ngx.thread.spawn(f)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-status: running
---- no_error_log
-[error]
-
-
-
-=== TEST 13: coroutine status of a dead user thread
---- config
- location /lua {
- rewrite_by_lua '
- local co
- local function f()
- co = coroutine.running()
- end
-
- ngx.thread.spawn(f)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-status: zombie
---- no_error_log
-[error]
-
-
-
-=== TEST 14: coroutine status of a "normal" user thread
---- config
- location /lua {
- rewrite_by_lua '
- local co
- local g
- local function f()
- co = coroutine.running()
- local co2 = coroutine.create(g)
- coroutine.resume(co2)
- end
-
- function g()
- ngx.sleep(0.1)
- end
-
- ngx.thread.spawn(f)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 2
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-terminate 2: ok
-delete thread 2
-
---- response_body
-status: normal
---- no_error_log
-[error]
-
-
-
-=== TEST 15: creating user threads in a user coroutine
---- config
- location /lua {
- rewrite_by_lua '
- local g
- local function f()
- ngx.say("before g")
- ngx.thread.spawn(g)
- ngx.say("after g")
- end
-
- function g()
- ngx.say("hello in g()")
- end
-
- ngx.say("before f")
- local co = coroutine.create(f)
- coroutine.resume(co)
- ngx.say("after f")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-terminate 2: ok
-delete thread 3
-terminate 1: ok
-delete thread 1
-
---- response_body
-before f
-before g
-hello in g()
-after g
-after f
---- no_error_log
-[error]
-
-
-
-=== TEST 16: manual time slicing between a user thread and the entry thread
---- config
- location /lua {
- rewrite_by_lua '
- local yield = coroutine.yield
-
- local function f()
- local self = coroutine.running()
- ngx.say("f 1")
- yield(self)
- ngx.say("f 2")
- yield(self)
- ngx.say("f 3")
- end
-
- local self = coroutine.running()
- ngx.say("0")
- yield(self)
- ngx.say("1")
- ngx.thread.spawn(f)
- ngx.say("2")
- yield(self)
- ngx.say("3")
- yield(self)
- ngx.say("4")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-0
-1
-f 1
-2
-f 2
-3
-f 3
-4
---- no_error_log
-[error]
-
-
-
-=== TEST 17: manual time slicing between two user threads
---- config
- location /lua {
- rewrite_by_lua '
- local yield = coroutine.yield
-
- local function f()
- local self = coroutine.running()
- ngx.say("f 1")
- yield(self)
- ngx.say("f 2")
- yield(self)
- ngx.say("f 3")
- end
-
- local function g()
- local self = coroutine.running()
- ngx.say("g 1")
- yield(self)
- ngx.say("g 2")
- yield(self)
- ngx.say("g 3")
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ngx.say("done")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-f 1
-g 1
-f 2
-done
-g 2
-f 3
-g 3
---- no_error_log
-[error]
-
-
-
-=== TEST 18: entry thread and a user thread flushing at the same time
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello in thread")
- coroutine.yield(coroutine.running)
- ngx.flush(true)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ngx.flush(true)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 19: two user threads flushing at the same time
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.say("hello from f")
- ngx.flush(true)
- end
-
- local function g()
- ngx.say("hello from g")
- ngx.flush(true)
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like
-^(?:create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3|create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: ok
-terminate 1: ok
-delete thread 2
-delete thread 3
-delete thread 1)$
-
---- response_body
-hello from f
-hello from g
---- no_error_log
-[error]
-
-
-
-=== TEST 20: user threads + ngx.socket.tcp
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- local bytes, err = sock:send("flush_all\\r\\n")
- if not bytes then
- ngx.say("failed to send query: ", err)
- return
- end
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("received: ", line)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before
-after
-received: OK
---- no_error_log
-[error]
-
-
-
-=== TEST 21: user threads + ngx.socket.udp
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername("127.0.0.1", 12345)
- local bytes, err = sock:send("blah")
- if not bytes then
- ngx.say("failed to send query: ", err)
- return
- end
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("received: ", line)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^(?:create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-|create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1)$
-
---- udp_listen: 12345
---- udp_query: blah
---- udp_reply: hello udp
---- response_body_like chop
-^(?:before
-after
-received: hello udp
-|before
-received: hello udp
-after)$
-
---- no_error_log
-[error]
-
-
-
-=== TEST 22: simple user thread with ngx.req.read_body()
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.req.read_body()
- local body = ngx.req.get_body_data()
- ngx.say("body: ", body)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- content_by_lua return;
- }
---- request
-POST /lua
-hello world
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^(?:create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1|create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2)$
-
---- response_body_like chop
-^(?:before
-body: hello world
-after|before
-after
-body: hello world)$
-
---- no_error_log
-[error]
-
-
-
-=== TEST 23: simple user thread with ngx.req.socket()
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- local sock = ngx.req.socket()
- local body, err = sock:receive(11)
- if not body then
- ngx.say("failed to read body: ", err)
- return
- end
-
- ngx.say("body: ", body)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-POST /lua
-hello world
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^(?:create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1|create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2)$
-
---- response_body_like chop
-^(?:before
-body: hello world
-after|before
-after
-body: hello world)$
-
---- no_error_log
-[error]
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 24: multiple user threads + subrequests returning 404 immediately
---- config
- location /t {
- rewrite_by_lua '
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- ngx.say("status: ", res.status)
- end
-
- local threads = {}
- for i = 1, 2 do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- return 404;
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap eval
-"$::GCScript"
-.
-'
-F(ngx_http_finalize_request) {
- printf("finalize request %s: rc:%d c:%d a:%d\n", ngx_http_req_uri($r), $rc, $r->main->count, $r == $r->main);
- #if ($rc == -1) {
- #print_ubacktrace()
- #}
-}
-
-M(http-subrequest-done) {
- printf("subrequest %s done\n", ngx_http_req_uri($r))
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: %s rc=%d, status=%d a=%d\n", ngx_http_req_uri($r), $rc,
- $r->headers_out->status, $r == $r->main)
- #print_ubacktrace()
-}
-'
---- stap_out_like chop
-^create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-finalize request /proxy/1: rc:404 c:3 a:0
-post subreq: /proxy/1 rc=404, status=0 a=0
-subrequest /proxy/1 done
-terminate 2: ok
-delete thread 2
-finalize request /proxy/2: rc:404 c:2 a:0
-post subreq: /proxy/2 rc=404, status=0 a=0
-subrequest /proxy/2 done
-terminate 3: ok
-delete thread 3
-finalize request /t: rc:200 c:1 a:1
-(?:finalize request /t: rc:0 c:1 a:1)?$
-
---- response_body
-ok
-status: 404
-status: 404
---- no_error_log
-[error]
---- timeout: 3
-
-
-
-=== TEST 25: multiple user threads + subrequests returning 404 remotely (no wait)
---- config
- location /t {
- rewrite_by_lua '
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- ngx.say("status: ", res.status)
- end
-
- local threads = {}
- for i = 1, 5 do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- proxy_pass http://127.0.0.1:$server_port/d/$1;
- }
-
- location /d {
- return 404;
- #echo $uri;
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-create 4 in 1
-spawn user thread 4 in 1
-create 5 in 1
-spawn user thread 5 in 1
-create 6 in 1
-spawn user thread 6 in 1
-terminate 1: ok
-delete thread 1
-(?:terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-terminate 4: ok
-delete thread 4
-terminate 5: ok
-delete thread 5
-terminate 6: ok
-delete thread 6|terminate 6: ok
-delete thread 6
-terminate 5: ok
-delete thread 5
-terminate 4: ok
-delete thread 4
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2)$
-
---- response_body
-ok
-status: 404
-status: 404
-status: 404
-status: 404
-status: 404
---- no_error_log
-[error]
---- timeout: 6
-
-
-
-=== TEST 26: multiple user threads + subrequests returning 201 immediately
---- config
- location /t {
- rewrite_by_lua '
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- ngx.say("status: ", res.status)
- end
-
- local threads = {}
- for i = 1, 2 do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- content_by_lua 'ngx.exit(201)';
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap3
-F(ngx_http_send_header) {
- printf("send header main_req=%d, r=%p\n", $r == $r->main, $r)
- print_ubacktrace()
- printf("========================================")
-}
---- stap_out3
---- stap eval
-"$::GCScript"
-.
-'
-F(ngx_http_finalize_request) {
- printf("finalize request %s: rc:%d c:%d a:%d\n", ngx_http_req_uri($r), $rc, $r->main->count, $r == $r->main);
- #if ($rc == -1) {
- #print_ubacktrace()
- #}
-}
-
-M(http-subrequest-done) {
- printf("subrequest %s done\n", ngx_http_req_uri($r))
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: %s rc=%d, status=%d a=%d\n", ngx_http_req_uri($r), $rc,
- $r->headers_out->status, $r == $r->main)
- #print_ubacktrace()
-}
-'
---- stap_out_like chop
-^create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 4: ok
-delete thread 4
-finalize request /proxy/1: rc:0 c:3 a:0
-post subreq: /proxy/1 rc=0, status=201 a=0
-subrequest /proxy/1 done
-terminate 2: ok
-delete thread 2
-terminate 5: ok
-delete thread 5
-finalize request /proxy/2: rc:0 c:2 a:0
-post subreq: /proxy/2 rc=0, status=201 a=0
-subrequest /proxy/2 done
-terminate 3: ok
-delete thread 3
-finalize request /t: rc:200 c:1 a:1
-(?:finalize request /t: rc:0 c:1 a:1)?$
-
---- response_body
-ok
-status: 201
-status: 201
---- no_error_log
-[error]
---- timeout: 3
-
-
-
-=== TEST 27: multiple user threads + subrequests returning 204 immediately
---- config
- location /t {
- rewrite_by_lua '
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- ngx.say("status: ", res.status)
- end
-
- local threads = {}
- for i = 1, 2 do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- content_by_lua 'ngx.exit(204)';
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap eval
-"$::GCScript"
-.
-'
-F(ngx_http_finalize_request) {
- printf("finalize request %s: rc:%d c:%d a:%d\n", ngx_http_req_uri($r), $rc, $r->main->count, $r == $r->main);
- #if ($rc == -1) {
- #print_ubacktrace()
- #}
-}
-
-M(http-subrequest-done) {
- printf("subrequest %s done\n", ngx_http_req_uri($r))
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: %s rc=%d, status=%d a=%d\n", ngx_http_req_uri($r), $rc,
- $r->headers_out->status, $r == $r->main)
- #print_ubacktrace()
-}
-'
-
---- stap_out_like chop
-^create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 4: ok
-delete thread 4
-finalize request /proxy/1: rc:204 c:3 a:0
-post subreq: /proxy/1 rc=204, status=204 a=0
-subrequest /proxy/1 done
-terminate 2: ok
-delete thread 2
-terminate 5: ok
-delete thread 5
-finalize request /proxy/2: rc:204 c:2 a:0
-post subreq: /proxy/2 rc=204, status=204 a=0
-subrequest /proxy/2 done
-terminate 3: ok
-delete thread 3
-finalize request /t: rc:200 c:1 a:1
-(?:finalize request /t: rc:0 c:1 a:1)?$
-
---- response_body
-ok
-status: 204
-status: 204
---- no_error_log
-[error]
---- timeout: 3
diff --git a/src/deps/src/lua-nginx-module/t/024-access/auth.t b/src/deps/src/lua-nginx-module/t/024-access/auth.t
deleted file mode 100644
index 56e986262..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/auth.t
+++ /dev/null
@@ -1,109 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-#no_nginx_manager();
-
-#repeat_each(1);
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 1);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: basic test passing
---- config
- location /lua {
- lua_need_request_body on;
- client_max_body_size 100k;
- client_body_buffer_size 100k;
-
- access_by_lua '
- -- check the client IP addr is in our black list
- if ngx.var.remote_addr == "132.5.72.3" then
- ngx.exit(ngx.HTTP_FORBIDDEN)
- end
-
- -- check if the request body contains bad words
- if ngx.var.request_body and string.match(ngx.var.request_body, "fuck") then
- return ngx.redirect("/terms_of_use.html")
- end
-
- -- tests passed
- ';
-
- echo Logged in;
- }
---- request
-GET /lua
---- response_body
-Logged in
-
-
-
-=== TEST 2: bad words in request body
---- config
- location /lua {
- lua_need_request_body on;
- client_max_body_size 100k;
- client_body_buffer_size 100k;
-
- access_by_lua '
- -- check the client IP addr is in our black list
- if ngx.var.remote_addr == "132.5.72.3" then
- ngx.exit(ngx.HTTP_FORBIDDEN)
- end
-
- -- check if the request body contains bad words
- if ngx.var.request_body and string.match(ngx.var.request_body, "fuck") then
- return ngx.redirect("/terms_of_use.html")
- end
-
- -- tests passed
- ';
-
- echo Logged in;
- }
---- request
-POST /lua
-He fucks himself!
---- response_body_like: 302 Found
---- response_headers_like
-Location: /terms_of_use\.html
---- error_code: 302
-
-
-
-=== TEST 3: client IP
---- config
- location /lua {
- lua_need_request_body on;
- client_max_body_size 100k;
- client_body_buffer_size 100k;
-
- access_by_lua '
- -- check the client IP addr is in our black list
- if ngx.var.remote_addr == "127.0.0.1" then
- ngx.exit(ngx.HTTP_FORBIDDEN)
- end
-
- -- check if the request body contains bad words
- if ngx.var.request_body and string.match(ngx.var.request_body, "fuck") then
- return ngx.redirect("/terms_of_use.html")
- end
-
- -- tests passed
- ';
-
- echo Logged in;
- }
---- request
-GET /lua
---- response_body_like: 403 Forbidden
---- error_code: 403
diff --git a/src/deps/src/lua-nginx-module/t/024-access/client-abort.t b/src/deps/src/lua-nginx-module/t/024-access/client-abort.t
deleted file mode 100644
index e4abb4ebd..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/client-abort.t
+++ /dev/null
@@ -1,862 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "http3 does not support ngx.req.socket and lua_check_client_abort";
- } elsif ($ENV{TEST_NGINX_USE_HTTP2}) {
- $SkipReason = "http2 does not support ngx.req.socket and lua_check_client_abort";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-use t::StapThread;
-
-our $GCScript = <<_EOC_;
-$t::StapThread::GCScript
-
-F(ngx_http_lua_check_broken_connection) {
- println("lua check broken conn")
-}
-
-F(ngx_http_lua_request_cleanup) {
- println("lua req cleanup")
-}
-_EOC_
-
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 - 1);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 0.1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 2: sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.sleep(1)
- ';
- log_by_lua '
- ngx.log(ngx.NOTICE, "here in log by lua")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- wait: 0.1
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-here in log by lua
-
-
-
-=== TEST 3: sleep + ignore
---- config
- location /t {
- lua_check_client_abort off;
- access_by_lua '
- ngx.sleep(1)
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 4: subrequest + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location /sub {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 5: subrequest + ignore
---- config
- location /t {
- lua_check_client_abort off;
- access_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location /sub {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: fail
-lua req cleanup
-delete thread 1
-
---- wait: 1.1
---- timeout: 0.2
---- abort
---- ignore_response
---- error_log
-bad things happen
-
-
-
-=== TEST 6: subrequest + stop (proxy, ignore client abort)
---- config
- location = /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location = /sub {
- proxy_ignore_client_abort on;
- proxy_pass http://127.0.0.2:12345/;
- }
-
- location = /sleep {
- lua_check_client_abort on;
- access_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 7: subrequest + stop (proxy, check client abort)
---- config
- location = /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location = /sub {
- proxy_ignore_client_abort off;
- proxy_pass http://127.0.0.2:12345/;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 8: need body on + sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- lua_need_request_body on;
- access_by_lua '
- ngx.sleep(1)
- ';
- log_by_lua '
- ngx.log(ngx.NOTICE, "here in log by lua")
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-here in log by lua
-
-
-
-=== TEST 9: ngx.req.read_body + sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.req.read_body()
- ngx.sleep(1)
- ';
- log_by_lua '
- ngx.log(ngx.NOTICE, "here in log by lua")
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-here in log by lua
-
-
-
-=== TEST 10: ngx.req.socket + receive() + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local sock = ngx.req.socket()
- sock:receive()
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 11: ngx.req.socket + receive(N) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local sock = ngx.req.socket()
- sock:receive(5)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 0.1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 12: ngx.req.socket + receive(n) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local sock = ngx.req.socket()
- sock:receive(2)
- ngx.sleep(1)
- ';
- content_by_lua return;
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like
-^(?:lua check broken conn
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup|lua check broken conn
-lua req cleanup
-delete thread 1)$
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 13: ngx.req.socket + m * receive(n) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local sock = ngx.req.socket()
- sock:receive(2)
- sock:receive(2)
- sock:receive(1)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 14: ngx.req.socket + receiveuntil + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local sock = ngx.req.socket()
- local it = sock:receiveuntil("\\n")
- it()
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 15: ngx.req.socket + receiveuntil + it(n) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local sock = ngx.req.socket()
- local it = sock:receiveuntil("\\n")
- it(2)
- it(3)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 16: cosocket + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.req.discard_body()
-
- local sock, err = ngx.socket.tcp()
- if not sock then
- ngx.log(ngx.ERR, "failed to get socket: ", err)
- return
- end
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("blpop nonexist 2\\r\\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send query: ", err)
- return
- end
-
- -- ngx.log(ngx.ERR, "about to receive")
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive query: ", err)
- return
- end
-
- ngx.log(ngx.ERR, "res: ", res)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 17: ngx.req.socket + receive n < content-length + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local sock = ngx.req.socket()
- local res, err = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err)
- return
- end
- error("bad")
- ';
- content_by_lua return;
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 100\r
-\r
-hello"
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-failed to receive: client aborted
-
-
-
-=== TEST 18: ngx.req.socket + receive n == content-length + stop
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local sock = ngx.req.socket()
- local res, err = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err)
- return
- end
- ngx.sleep(1)
- error("bad")
- ';
-
- content_by_lua return;
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 5\r
-\r
-hello"
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 19: ngx.req.socket + receive n == content-length + ignore
---- config
- location /t {
- access_by_lua '
- local sock = ngx.req.socket()
- local res, err = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err)
- return
- end
- ngx.say("done")
- ';
- content_by_lua return;
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 5\r
-\r
-hello"
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- shutdown: 1
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 20: ngx.req.read_body + sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.req.read_body()
- ';
- content_by_lua return;
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- shutdown: 1
---- wait: 0.1
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 21: exec to lua + ignore
---- config
- location = /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.exec("/t2")
- ';
- }
-
- location = /t2 {
- lua_check_client_abort off;
- content_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-lua req cleanup
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 22: exec to proxy + ignore
---- config
- location = /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.exec("/t2")
- ';
- }
-
- location = /t2 {
- proxy_ignore_client_abort on;
- proxy_pass http://127.0.0.1:$server_port/sleep;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 23: exec (named location) to proxy + ignore
---- config
- location = /t {
- lua_check_client_abort on;
- access_by_lua '
- ngx.exec("@t2")
- ';
- }
-
- location @t2 {
- proxy_ignore_client_abort on;
- proxy_pass http://127.0.0.1:$server_port/sleep;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
diff --git a/src/deps/src/lua-nginx-module/t/024-access/exec.t b/src/deps/src/lua-nginx-module/t/024-access/exec.t
deleted file mode 100644
index d168a47d8..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/exec.t
+++ /dev/null
@@ -1,393 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 6);
-
-#no_diff();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /read {
- access_by_lua '
- ngx.exec("/hi");
- ngx.say("Hi");
- ';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body
-Hello
-
-
-
-=== TEST 2: empty uri arg
---- config
- location /read {
- access_by_lua '
- ngx.exec("");
- ngx.say("Hi");
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 3: no arg
---- config
- location /read {
- access_by_lua '
- ngx.exec();
- ngx.say("Hi");
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 4: too many args
---- config
- location /read {
- access_by_lua '
- ngx.exec(1, 2, 3, 4);
- ngx.say("Hi");
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 5: null uri
---- config
- location /read {
- access_by_lua '
- ngx.exec(nil)
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 6: user args
---- config
- location /read {
- access_by_lua '
- ngx.exec("/hi", "Yichun Zhang")
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello Yichun Zhang
-
-
-
-=== TEST 7: args in uri
---- config
- location /read {
- access_by_lua '
- ngx.exec("/hi?agentzh")
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello agentzh
-
-
-
-=== TEST 8: args in uri and user args
---- config
- location /read {
- access_by_lua '
- ngx.exec("/hi?a=Yichun", "b=Zhang")
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello a=Yichun&b=Zhang
-
-
-
-=== TEST 9: args in uri and user args
---- config
- location /read {
- access_by_lua '
- ngx.exec("@hi?a=Yichun", "b=Zhang")
- ngx.say("Hi")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location @hi {
- echo Hello $query_string;
- }
---- request
-GET /read
---- response_body
-Hello
-
-
-
-=== TEST 10: exec after location capture
---- config
- location /test {
- access_by_lua_file 'html/test.lua';
- echo world;
- }
-
- location /a {
- echo "hello";
- }
-
- location /b {
- echo "hello";
- }
-
---- user_files
->>> test.lua
-ngx.location.capture('/a')
-
-ngx.exec('/b')
---- request
- GET /test
---- response_body
-hello
-
-
-
-=== TEST 11: exec after (named) location capture
---- config
- location /test {
- access_by_lua_file 'html/test.lua';
- }
-
- location /a {
- echo "hello";
- }
-
- location @b {
- echo "hello";
- }
-
---- user_files
->>> test.lua
-ngx.location.capture('/a')
-
-ngx.exec('@b')
---- request
- GET /test
---- response_body
-hello
-
-
-
-=== TEST 12: github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location
---- config
- location = /hi {
- echo hello;
- }
- location /sub {
- proxy_pass http://127.0.0.1:$server_port/hi;
- }
- location /p{
- #content_by_lua '
- #local res = ngx.location.capture("/sub")
- #ngx.print(res.body)
- #';
- echo_location /sub;
- }
- location /lua {
- access_by_lua '
- ngx.exec("/p")
- ';
- }
---- request
- GET /lua
---- response_body
-hello
---- timeout: 3
-
-
-
-=== TEST 13: github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location (named location)
---- config
- location = /hi {
- echo hello;
- }
- location /sub {
- proxy_pass http://127.0.0.1:$server_port/hi;
- }
- location @p {
- #content_by_lua '
- #local res = ngx.location.capture("/sub")
- #ngx.print(res.body)
- #';
- echo_location /sub;
- }
- location /lua {
- access_by_lua '
- ngx.exec("@p")
- ';
- }
---- request
- GET /lua
---- response_body
-hello
-
-
-
-=== TEST 14: github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location (post subrequest)
---- config
- location = /hi {
- echo hello;
- }
- location /sub {
- proxy_pass http://127.0.0.1:$server_port/hi;
- }
- location /p{
- #content_by_lua '
- #local res = ngx.location.capture("/sub")
- #ngx.print(res.body)
- #';
- echo_location /sub;
- }
- location /blah {
- echo blah;
- }
- location /lua {
- access_by_lua '
- ngx.location.capture("/blah")
- ngx.exec("/p")
- ';
- }
---- request
- GET /lua
---- response_body
-hello
-
-
-
-=== TEST 15: access_by_lua + ngx.exec + subrequest capture
---- config
- location /main {
- access_by_lua '
- local res = ngx.location.capture("/test_loc");
- ngx.print("hello, ", res.body)
- ';
- content_by_lua return;
- }
- location /test_loc {
- rewrite_by_lua '
- ngx.exec("@proxy")
- ';
- }
- location @proxy {
- #echo proxy;
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
- location /foo {
- echo bah;
- }
---- request
- GET /main
---- response_body
-hello, bah
-
-
-
-=== TEST 16: github issue #905: unsafe uri
---- config
- location /read {
- access_by_lua_block {
- ngx.exec("/hi/../");
- }
- }
- location /hi {
- echo "Hello";
- }
---- request
-GET /read
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-[
-'unsafe URI "/hi/../" was detected',
-qr/runtime error: access_by_lua\(nginx.conf:\d+\):2: unsafe uri/,
-]
-
-
-
-=== TEST 17: pipelined requests
---- config
- location /t {
- access_by_lua_block {
- ngx.exec("@foo")
- }
- }
-
- location @foo {
- return 200;
- }
---- pipelined_requests eval
-["GET /t", "GET /t"]
---- error_code eval
-[200, 200]
---- response_body eval
-["", ""]
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/024-access/exit.t b/src/deps/src/lua-nginx-module/t/024-access/exit.t
deleted file mode 100644
index b77778213..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/exit.t
+++ /dev/null
@@ -1,550 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#repeat_each(20000);
-repeat_each(2);
-
-#master_on();
-#workers(1);
-#log_level('debug');
-#log_level('warn');
-#worker_connections(1024);
-
-plan tests => repeat_each() * (blocks() * 2 + 2);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
-
-our $LuaCpath = $ENV{LUA_CPATH} ||
- '/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;';
-
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: throw 403
---- config
- location /lua {
- access_by_lua "ngx.exit(403);ngx.say('hi')";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- error_code: 403
---- response_body_like: 403 Forbidden
-
-
-
-=== TEST 2: throw 404
---- config
- location /lua {
- access_by_lua "ngx.exit(404);ngx.say('hi');";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- error_code: 404
---- response_body_like: 404 Not Found
-
-
-
-=== TEST 3: throw 404 after sending the header and partial body
---- config
- location /lua {
- access_by_lua "ngx.say('hi');ngx.exit(404);ngx.say(', you')";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-hi
---- no_error_log
-[alert]
---- error_log
-attempt to set status 404 via ngx.exit after sending out the response status 200
-
-
-
-=== TEST 4: working with ngx_auth_request (succeeded)
---- config
- location /auth {
- access_by_lua "
- if ngx.var.user == 'agentzh' then
- ngx.eof();
- else
- ngx.exit(403)
- end";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
- location /api {
- set $user $arg_user;
- auth_request /auth;
-
- echo "Logged in";
- }
---- request
-GET /api?user=agentzh
---- error_code: 200
---- response_body
-Logged in
-
-
-
-=== TEST 5: working with ngx_auth_request (failed)
---- config
- location /api {
- set $user $arg_user;
- access_by_lua "
- if ngx.var.user == 'agentzh' then
- ngx.eof();
- else
- ngx.exit(403)
- end";
-
- echo "Logged in";
- }
---- request
-GET /api?user=agentz
---- error_code: 403
---- response_body_like: 403 Forbidden
-
-
-
-=== TEST 6: working with ngx_auth_request (simplest form, w/o ngx_memc)
---- http_config eval
-"
- lua_package_cpath '$::LuaCpath';
- upstream backend {
- drizzle_server 127.0.0.1:\$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-"
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /conv-uid-mysql {
- internal;
-
- set $key "conv-uid-$arg_uid";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- drizzle_query "select new_uid as uid from conv_uid where old_uid=$arg_uid";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /api {
- set $uid $arg_uid;
- access_by_lua_file 'html/foo.lua';
-
- echo "Logged in $uid";
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local old_uid = ngx.var.uid
-print('about to run sr')
-local res = ngx.location.capture('/conv-uid-mysql?uid=' .. old_uid)
-print('just have run sr' .. res.body)
-if (res.status ~= ngx.HTTP_OK) then
- -- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].uid or
- not string.match(res[1].uid, '^%d+$')) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.uid = res[1].uid;
--- print('done')
---- request
-GET /api?uid=32
---- response_body
-Logged in 56
---- timeout: 3
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 7: working with ngx_auth_request (simplest form)
---- http_config eval
-"
- lua_package_cpath '$::LuaCpath';
- upstream backend {
- drizzle_server 127.0.0.1:\$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-"
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /conv-uid-mysql {
- internal;
-
- set $key "conv-uid-$arg_uid";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- drizzle_query "select new_uid as uid from conv_uid where old_uid=$arg_uid";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /api {
- set $uid $arg_uid;
- access_by_lua_file html/foo.lua;
-
- echo "Logged in $uid";
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local old_uid = ngx.var.uid
--- print('about to run sr')
-local res = ngx.location.capture('/conv-uid-mysql?uid=' .. old_uid)
--- print('just have run sr' .. res.body)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].uid or
- not string.match(res[1].uid, '^%d+$')) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.uid = res[1].uid;
--- print('done')
---- request
-GET /api?uid=32
---- response_body
-Logged in 56
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 8: working with ngx_auth_request
---- http_config eval
-"
- lua_package_cpath '$::LuaCpath';
- upstream backend {
- drizzle_server 127.0.0.1:\$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-
- upstream memc_a {
- server 127.0.0.1:\$TEST_NGINX_MEMCACHED_PORT;
- }
-
- upstream memc_b {
- server 127.0.0.1:\$TEST_NGINX_MEMCACHED_PORT;
- }
-
- upstream_list memc_cluster memc_a memc_b;
-"
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- set_hashed_upstream $backend memc_cluster $arg_key;
- memc_pass $backend;
- }
-
- location /conv-uid-mysql {
- internal;
-
- set $key "conv-uid-$arg_uid";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- drizzle_query "select new_uid as uid from conv_uid where old_uid=$arg_uid";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /api {
- set $uid $arg_uid;
- access_by_lua_file html/foo.lua;
-
- echo "Logged in $uid";
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local old_uid = ngx.var.uid
--- print('about to run sr')
-local res = ngx.location.capture('/conv-uid-mysql?uid=' .. old_uid)
--- print('just have run sr' .. res.body)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].uid or
- not string.match(res[1].uid, '^%d+$')) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.uid = res[1].uid;
--- print('done')
---- request
-GET /api?uid=32
---- response_body
-Logged in 56
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 9: working with ngx_auth_request
---- http_config
- upstream backend {
- drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
-
- upstream memc_a {
- server 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- keepalive 300;
- }
-
- #upstream_list memc_cluster memc_a memc_b;
-
---- config
- location /memc {
- internal;
-
- set $memc_key $arg_key;
- set $memc_exptime $arg_exptime;
-
- #set_hashed_upstream $backend memc_cluster $arg_key;
- memc_pass memc_a;
- }
-
- location /conv-mysql {
- internal;
-
- set $key "conv-uri-$query_string";
-
- #srcache_fetch GET /memc key=$key;
- #srcache_store PUT /memc key=$key;
-
- default_type 'application/json';
-
- set_quote_sql_str $seo_uri $query_string;
- drizzle_query "select url from my_url_map where seo_url=$seo_uri";
- drizzle_pass backend;
-
- rds_json on;
- }
-
- location /conv-uid {
- internal;
- access_by_lua_file 'html/foo.lua';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
-
- location /baz {
- set $my_uri $uri;
- auth_request /conv-uid;
-
- echo_exec /jump $my_uri;
- }
-
- location /jump {
- internal;
- rewrite ^ $query_string? redirect;
- }
---- user_files
->>> foo.lua
-local cjson = require('cjson');
-local seo_uri = ngx.var.my_uri
--- print('about to run sr')
-local res = ngx.location.capture('/conv-mysql?' .. seo_uri)
-if (res.status ~= ngx.HTTP_OK) then
- ngx.exit(res.status)
-end
-res = cjson.decode(res.body)
-if (not res or not res[1] or not res[1].url) then
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
-end
-ngx.var.my_uri = res[1].url;
--- print('done')
---- request
-GET /baz
---- response_body_like: 302
---- error_code: 302
---- response_headers
-Location: http://localhost:$ServerPort/foo/bar
---- SKIP
-
-
-
-=== TEST 10: throw 0
---- config
- location /lua {
- access_by_lua "ngx.say('Hi'); ngx.eof(); ngx.exit(0);ngx.say('world')";
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- error_code: 200
---- response_body
-Hi
-
-
-
-=== TEST 11: throw ngx.OK does *not* skip other later phase handlers
---- config
- location /lua {
- access_by_lua "ngx.exit(ngx.OK)";
- set $foo hello;
- echo $foo;
- }
---- request
-GET /lua
---- response_body
-hello
-
-
-
-=== TEST 12: throw ngx.HTTP_OK *does* skip other later phase handlers (by inlined code)
---- config
- location /lua {
- access_by_lua "ngx.exit(ngx.HTTP_OK)";
- set $foo hello;
- echo $foo;
- }
---- request
-GET /lua
---- response_body
-
-
-
-=== TEST 13: throw ngx.HTTP_OK *does* skip other rewrite phase handlers (by inlined code + partial output)
---- config
- location /lua {
- rewrite_by_lua "ngx.say('hiya') ngx.exit(ngx.HTTP_OK)";
- set $foo hello;
- echo $foo;
- }
---- request
-GET /lua
---- response_body
-hiya
-
-
-
-=== TEST 14: throw ngx.HTTP_OK *does* skip other later phase handlers (by file)
---- config
- location /lua {
- access_by_lua_file html/foo.lua;
- set $foo hello;
- echo $foo;
- }
---- user_files
->>> foo.lua
-ngx.exit(ngx.HTTP_OK)
---- request
-GET /lua
---- response_body
-
-
-
-=== TEST 15: throw ngx.HTTP_OK *does* skip other rewrite phase handlers (by file + partial output)
---- config
- location /lua {
- rewrite_by_lua_file html/foo.lua;
- set $foo hello;
- echo $foo;
- }
---- user_files
->>> foo.lua
-ngx.say("morning")
-ngx.exit(ngx.HTTP_OK)
---- request
-GET /lua
---- response_body
-morning
-
-
-
-=== TEST 16: error page with custom body
---- config
- error_page 410 @err;
- location @err {
- echo blah blah;
- }
- location /foo {
- access_by_lua '
- ngx.status = ngx.HTTP_GONE
- ngx.say("This is our own content")
- -- to cause quit the whole request rather than the current phase handler
- ngx.exit(ngx.HTTP_OK)
- ';
- echo Hello;
- }
---- request
- GET /foo
---- response_body
-This is our own content
---- error_code: 410
-
-
-
-=== TEST 17: exit(404) after I/O
---- config
- error_page 400 /400.html;
- error_page 404 /404.html;
- location /foo {
- access_by_lua '
- ngx.location.capture("/sleep")
- ngx.exit(ngx.HTTP_NOT_FOUND)
- ';
- echo Hello;
- }
-
- location /sleep {
- echo_sleep 0.002;
- }
---- user_files
->>> 400.html
-Bad request, dear...
->>> 404.html
-Not found, dear...
---- request
- GET /bah
---- response_body
-Not found, dear...
---- error_code: 404
diff --git a/src/deps/src/lua-nginx-module/t/024-access/mixed.t b/src/deps/src/lua-nginx-module/t/024-access/mixed.t
deleted file mode 100644
index 22f003791..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/mixed.t
+++ /dev/null
@@ -1,261 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2 + 4);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: access I/O with content I/O
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc {
- set $memc_key $echo_request_uri;
- set $memc_exptime 600;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /lua {
- access_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- print("access GET: ", res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- print("access PUT: ", res.status);
-
- res = ngx.location.capture("/memc");
- print("access cached: ", res.body);
- ';
-
- content_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- ngx.say("content GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- ngx.say("content PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- ngx.say("content cached: " .. res.body);
- ';
- }
---- request
-GET /lua
---- response_body
-content GET: 404
-content PUT: 201
-content cached: hello
---- grep_error_log eval: qr/access .+?(?= while )/
---- grep_error_log_out
-access GET: 404
-access PUT: 201
-access cached: hello
-
---- log_level: info
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 2: share data via nginx variables
---- config
- location /foo {
- set $foo '';
- access_by_lua '
- ngx.var.foo = 32
- ';
-
- content_by_lua '
- ngx.say(tonumber(ngx.var.foo) * 2)
- ';
- }
---- request
- GET /foo
---- response_body
-64
-
-
-
-=== TEST 3: share the request body (need request body explicitly off)
---- config
- location /echo_body {
- lua_need_request_body off;
- set $res '';
- access_by_lua '
- ngx.var.res = ngx.var.request_body or "nil"
- ';
- content_by_lua '
- ngx.say(ngx.var.res or "nil")
- ngx.say(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body
-nil
-nil
-
-
-
-=== TEST 4: share the request body (need request body off by default)
---- config
- location /echo_body {
- #lua_need_request_body off;
- set $res '';
- access_by_lua '
- ngx.var.res = ngx.var.request_body or "nil"
- ';
- content_by_lua '
- ngx.say(ngx.var.res or "nil")
- ngx.say(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body
-nil
-nil
-
-
-
-=== TEST 5: share the request body (need request body on)
---- config
- location /echo_body {
- lua_need_request_body on;
- set $res '';
- access_by_lua '
- ngx.var.res = ngx.var.request_body or "nil"
- ';
- content_by_lua '
- ngx.say(ngx.var.res or "nil")
- ngx.say(ngx.var.request_body or "nil")
- ';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff
-hello\x00\x01\x02
-world\x03\x04\xff
-"
-
-
-
-=== TEST 6: rewrite I/O with access I/O with content I/O
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc {
- set $memc_key $echo_request_uri;
- set $memc_exptime 600;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /lua {
- rewrite_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- print("rewrite GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- print("rewrite PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- print("rewrite cached: " .. res.body);
- ';
-
- access_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- print("access GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- print("access PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- print("access cached: " .. res.body);
- ';
-
- content_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- ngx.say("content GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- ngx.say("content PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- ngx.say("content cached: " .. res.body);
-
- ';
- }
---- request
-GET /lua
---- response_body
-content GET: 404
-content PUT: 201
-content cached: hello
-
---- grep_error_log eval: qr/(?:rewrite|access) .+?(?= while )/
---- grep_error_log_out
-rewrite GET: 404
-rewrite PUT: 201
-rewrite cached: hello
-access GET: 404
-access PUT: 201
-access cached: hello
-
---- log_level: info
-
-
-
-=== TEST 7: I/O in access shortcuts content automatically
---- config
- location = /t {
- access_by_lua_block {
- ngx.print("")
- }
-
- echo ok;
- }
---- request
- GET /t
---- response_body
diff --git a/src/deps/src/lua-nginx-module/t/024-access/multi-capture.t b/src/deps/src/lua-nginx-module/t/024-access/multi-capture.t
deleted file mode 100644
index b1757dd12..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/multi-capture.t
+++ /dev/null
@@ -1,394 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(10);
-
-plan tests => blocks() * repeat_each() * 2;
-
-#$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
-$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /foo {
- access_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
- location /a {
- echo -n a;
- }
- location /b {
- echo -n b;
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-
-
-
-=== TEST 2: 4 concurrent requests
---- config
- location /foo {
- access_by_lua '
- local res1, res2, res3, res4 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- { "/c" },
- { "/d" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
-
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
-
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
-
- ngx.say("res4.status = " .. res4.status)
- ngx.say("res4.body = " .. res4.body)
- ';
- content_by_lua return;
- }
- location ~ '^/([a-d])$' {
- echo -n $1;
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-res3.status = 200
-res3.body = c
-res4.status = 200
-res4.body = d
-
-
-
-=== TEST 3: capture multi in series
---- config
- location /foo {
- access_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
-
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("2 res1.status = " .. res1.status)
- ngx.say("2 res1.body = " .. res1.body)
- ngx.say("2 res2.status = " .. res2.status)
- ngx.say("2 res2.body = " .. res2.body)
-
- ';
- content_by_lua return;
- }
- location /a {
- echo -n a;
- }
- location /b {
- echo -n b;
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-2 res1.status = 200
-2 res1.body = a
-2 res2.status = 200
-2 res2.body = b
-
-
-
-=== TEST 4: capture multi in subrequest
---- config
- location /foo {
- rewrite_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
-
- local n = ngx.var.arg_n
-
- ngx.say(n .. " res1.status = " .. res1.status)
- ngx.say(n .. " res1.body = " .. res1.body)
- ngx.say(n .. " res2.status = " .. res2.status)
- ngx.say(n .. " res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
-
- location /main {
- access_by_lua '
- local res = ngx.location.capture("/foo?n=1")
- ngx.say("top res.status = " .. res.status)
- ngx.say("top res.body = [" .. res.body .. "]")
- ';
- content_by_lua return;
- }
-
- location /a {
- echo -n a;
- }
-
- location /b {
- echo -n b;
- }
---- request
- GET /main
---- response_body
-top res.status = 200
-top res.body = [1 res1.status = 200
-1 res1.body = a
-1 res2.status = 200
-1 res2.body = b
-]
-
-
-
-=== TEST 5: capture multi in parallel
---- config
- location ~ '^/(foo|bar)$' {
- set $tag $1;
- rewrite_by_lua '
- local res1, res2
- if ngx.var.tag == "foo" then
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- else
- res1, res2 = ngx.location.capture_multi{
- { "/c" },
- { "/d" },
- }
- end
-
- local n = ngx.var.arg_n
-
- ngx.say(n .. " res1.status = " .. res1.status)
- ngx.say(n .. " res1.body = " .. res1.body)
- ngx.say(n .. " res2.status = " .. res2.status)
- ngx.say(n .. " res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
-
- location /main {
- access_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/foo?n=1" },
- { "/bar?n=2" },
- }
-
- ngx.say("top res1.status = " .. res1.status)
- ngx.say("top res1.body = [" .. res1.body .. "]")
- ngx.say("top res2.status = " .. res2.status)
- ngx.say("top res2.body = [" .. res2.body .. "]")
- ';
- content_by_lua return;
- }
-
- location ~ '^/([abcd])$' {
- echo -n $1;
- }
---- request
- GET /main
---- response_body
-top res1.status = 200
-top res1.body = [1 res1.status = 200
-1 res1.body = a
-1 res2.status = 200
-1 res2.body = b
-]
-top res2.status = 200
-top res2.body = [2 res1.status = 200
-2 res1.body = c
-2 res2.status = 200
-2 res2.body = d
-]
-
-
-
-=== TEST 6: memc sanity
---- config
- location /foo {
- access_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
- location ~ '^/[ab]$' {
- set $memc_key $uri;
- set $memc_value hello;
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
- GET /foo
---- response_body eval
-"res1.status = 201
-res1.body = STORED\r
-
-res2.status = 201
-res2.body = STORED\r
-
-"
-
-
-
-=== TEST 7: memc muti + multi
---- config
- location /main {
- access_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/foo?n=1" },
- { "/bar?n=2" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = [" .. res1.body .. "]")
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = [" .. res2.body .. "]")
- ';
- content_by_lua return;
- }
- location ~ '^/(foo|bar)$' {
- set $tag $1;
- rewrite_by_lua '
- local res1, res2
- if ngx.var.tag == "foo" then
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- else
- res1, res2 = ngx.location.capture_multi{
- { "/c" },
- { "/d" },
- }
- end
- print("args: " .. ngx.var.args)
- local n = ngx.var.arg_n
- ngx.say(n .. " res1.status = " .. res1.status)
- ngx.say(n .. " res1.body = " .. res1.body)
- ngx.say(n .. " res2.status = " .. res2.status)
- ngx.say(n .. " res2.body = " .. res2.body)
- ';
- content_by_lua return;
- }
- location ~ '^/[abcd]$' {
- set $memc_key $uri;
- set $memc_value hello;
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
- GET /main
---- response_body eval
-"res1.status = 200
-res1.body = [1 res1.status = 201
-1 res1.body = STORED\r
-
-1 res2.status = 201
-1 res2.body = STORED\r
-
-]
-res2.status = 200
-res2.body = [2 res1.status = 201
-2 res1.body = STORED\r
-
-2 res2.status = 201
-2 res2.body = STORED\r
-
-]
-"
-
-
-
-=== TEST 8: memc 4 concurrent requests
---- config
- location /foo {
- access_by_lua '
- local res1, res2, res3, res4 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- { "/c" },
- { "/d" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
-
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
-
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
-
- ngx.say("res4.status = " .. res4.status)
- ngx.say("res4.body = " .. res4.body)
- ';
- content_by_lua return;
- }
- location ~ '^/[a-d]$' {
- set $memc_key $uri;
- set $memc_value hello;
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
- GET /foo
---- response_body eval
-"res1.status = 201
-res1.body = STORED\r
-
-res2.status = 201
-res2.body = STORED\r
-
-res3.status = 201
-res3.body = STORED\r
-
-res4.status = 201
-res4.body = STORED\r
-
-"
diff --git a/src/deps/src/lua-nginx-module/t/024-access/on-abort.t b/src/deps/src/lua-nginx-module/t/024-access/on-abort.t
deleted file mode 100644
index 70637ba86..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/on-abort.t
+++ /dev/null
@@ -1,657 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = <<_EOC_;
-$t::StapThread::GCScript
-
-F(ngx_http_lua_check_broken_connection) {
- println("lua check broken conn")
-}
-
-F(ngx_http_lua_request_cleanup) {
- println("lua req cleanup")
-}
-_EOC_
-
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- plan(skip_all => "HTTP3 does not support on_abort");
-} elsif (defined $ENV{TEST_NGINX_USE_HTTP2}) {
- plan(skip_all => "HTTP2 does not support on_abort");
-} else {
- plan tests => repeat_each() * (blocks() * 4 + 15);
-}
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: ignore the client abort event in the user callback
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-terminate 3: ok
-delete thread 3
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- wait: 0.7
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 2: abort in the user callback
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(444)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 3: ngx.exit(499) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(499)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ';
- content_by_lua return;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 4: ngx.exit(408) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(408)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ';
- content_by_lua return;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- wait: 0.1
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 5: ngx.exit(-1) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(-1)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ';
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 6: ngx.exit(0) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(0)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ngx.log(ngx.ERR, "main handler done")
- ';
- content_by_lua return;
- }
-
- location = /sleep {
- echo_sleep 0.7;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: fail
-terminate 1: ok
-delete thread 2
-delete thread 1
-terminate 3: ok
-delete thread 3
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- wait: 0.6
---- ignore_response
---- error_log eval
-[
-'client prematurely closed connection',
-'on abort called',
-qr/lua user thread aborted: runtime error: access_by_lua\(nginx\.conf:\d+\):4: attempt to abort with pending subrequests/,
-'main handler done',
-]
-
-
-
-=== TEST 7: accessing cosocket in callback
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to redis: ", err)
- ngx.exit(499)
- end
- local bytes, err = sock:send("flushall\\r\\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send query: ", err)
- ngx.exit(499)
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive: ", err)
- ngx.exit(499)
- end
- ngx.log(ngx.NOTICE, "callback done: ", res)
- ngx.exit(499)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^create 2 in 1
-lua check broken conn
-(?:lua check broken conn
-)?terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-$
---- timeout: 0.2
---- abort
---- wait: 0.2
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-callback done: +OK
-
-
-
-=== TEST 8: ignore the client abort event in the user callback (no check)
---- config
- location /t {
- lua_check_client_abort off;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- ngx.say("cannot set on_abort: ", err)
- return
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- response_body
-cannot set on_abort: lua_check_client_abort is off
---- no_error_log
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 9: register on_abort callback but no client abortion
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-lua req cleanup
-delete thread 2
-
---- response_body
-done
---- no_error_log
-[error]
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 10: ignore the client abort event in the user callback (uthread)
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- end)
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-lua check broken conn
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-terminate 4: ok
-delete thread 4
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- wait: 0.7
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 11: abort in the user callback (uthread)
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(444)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- end)
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 3
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 12: register on_abort callback but no client abortion (uthread)
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.1)
- ngx.say("done")
- end)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-delete thread 3
-lua req cleanup
-delete thread 2
-
---- response_body
-done
---- no_error_log
-[error]
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 13: register on_abort callback multiple times
---- config
- location /t {
- lua_check_client_abort on;
- access_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- ngx.say("1: cannot set on_abort: " .. err)
- return
- end
-
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- ngx.say("2: cannot set on_abort: " .. err)
- return
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.1)
- ngx.say("done")
- end)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-lua req cleanup
-delete thread 2
-
---- response_body
-2: cannot set on_abort: duplicate call
-
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/024-access/redirect.t b/src/deps/src/lua-nginx-module/t/024-access/redirect.t
deleted file mode 100644
index e8609af06..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/redirect.t
+++ /dev/null
@@ -1,133 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => blocks() * repeat_each() * 3;
-
-#no_diff();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: default 302
---- config
- location /read {
- access_by_lua '
- ngx.redirect("http://www.taobao.com/foo");
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-Location: http://www.taobao.com/foo
---- response_body_like: 302 Found
---- error_code: 302
-
-
-
-=== TEST 2: explicit 302
---- config
- location /read {
- access_by_lua '
- ngx.redirect("http://www.taobao.com/foo", ngx.HTTP_MOVED_TEMPORARILY);
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-Location: http://www.taobao.com/foo
---- response_body_like: 302 Found
---- error_code: 302
-
-
-
-=== TEST 3: explicit 301
---- config
- location /read {
- access_by_lua '
- ngx.redirect("http://www.taobao.com/foo", ngx.HTTP_MOVED_PERMANENTLY);
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-Location: http://www.taobao.com/foo
---- response_body_like: 301 Moved Permanently
---- error_code: 301
-
-
-
-=== TEST 4: bad rc
---- config
- location /read {
- access_by_lua '
- ngx.redirect("http://www.taobao.com/foo", 404);
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-!Location
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 5: no args
---- config
- location /read {
- access_by_lua '
- ngx.redirect()
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- response_headers
-!Location
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 6: relative uri
---- config
- location /read {
- access_by_lua '
- ngx.redirect("/foo")
- ngx.say("hi")
- ';
- content_by_lua 'return';
- }
---- request
-GET /read
---- raw_response_headers_like eval
-my $headers;
-
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- $headers = "location: /foo\r\n"
-} else {
- $headers = "Location: /foo\r\n"
-}
-
-$headers;
---- response_body_like: 302 Found
---- error_code: 302
diff --git a/src/deps/src/lua-nginx-module/t/024-access/req-body.t b/src/deps/src/lua-nginx-module/t/024-access/req-body.t
deleted file mode 100644
index 48caeb900..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/req-body.t
+++ /dev/null
@@ -1,221 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 19);
-
-#no_diff();
-#no_long_string();
-#master_on();
-#workers(2);
-run_tests();
-
-__DATA__
-
-=== TEST 1: read buffered body
---- config
- location = /test {
- access_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ';
- content_by_lua return;
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
-
-
-
-=== TEST 2: read buffered body (timed out)
---- config
- client_body_timeout 1ms;
- location = /test {
- access_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ';
- content_by_lua return;
- }
---- raw_request eval
-"POST /test HTTP/1.1\r
-Host: localhost\r
-Content-Length: 100\r
-Connection: close\r
-\r
-hello, world"
---- response_body:
---- error_code_like: ^(?:500)?$
-
-
-
-=== TEST 3: read buffered body and then subrequest
---- config
- location /foo {
- echo -n foo;
- }
- location = /test {
- access_by_lua '
- ngx.req.read_body()
- local res = ngx.location.capture("/foo");
- ngx.say(ngx.var.request_body)
- ngx.say("sub: ", res.body)
- ';
- content_by_lua return;
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
-sub: foo
-
-
-
-=== TEST 4: first subrequest and then read buffered body
---- config
- location /foo {
- echo -n foo;
- }
- location = /test {
- access_by_lua '
- local res = ngx.location.capture("/foo");
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ngx.say("sub: ", res.body)
- ';
- content_by_lua return;
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
-sub: foo
-
-
-
-=== TEST 5: failed to write 100 continue
---- config
- location = /test {
- access_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ngx.exit(200)
- ';
- }
---- request
-POST /test
-hello, world
---- more_headers
-Expect: 100-Continue
---- ignore_response
---- no_error_log
-[alert]
-[error]
-http finalize request: 500, "/test?" a:1, c:0
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 6: not discard body (exit 200)
---- config
- location = /foo {
- access_by_lua '
- -- ngx.req.discard_body()
- ngx.say("body: ", ngx.var.request_body)
- ngx.exit(200)
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-["body: nil\n",
-"body: hiya, world\n",
-]
---- error_code eval
-[200, 200]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 7: not discard body (exit 201)
---- config
- location = /foo {
- access_by_lua '
- -- ngx.req.discard_body()
- ngx.say("body: ", ngx.var.request_body)
- ngx.exit(201)
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-["body: nil\n",
-"body: hiya, world\n",
-]
---- error_code eval
-[200, 200]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 8: not discard body (exit 302)
---- config
- location = /foo {
- access_by_lua '
- -- ngx.req.discard_body()
- -- ngx.say("body: ", ngx.var.request_body)
- ngx.redirect("/blah")
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-[qr/302 Found/,
-"body: hiya, world\n",
-]
---- error_code eval
-[302, 200]
---- no_error_log
-[error]
-[alert]
diff --git a/src/deps/src/lua-nginx-module/t/024-access/request_body.t b/src/deps/src/lua-nginx-module/t/024-access/request_body.t
deleted file mode 100644
index fa0319527..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/request_body.t
+++ /dev/null
@@ -1,172 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('debug'); # to ensure any log-level can be outputted
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: test reading request body
---- config
- location /echo_body {
- lua_need_request_body on;
- access_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff"
-
-
-
-=== TEST 2: test not reading request body
---- config
- location /echo_body {
- lua_need_request_body off;
- access_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 3: test default setting (not reading request body)
---- config
- location /echo_body {
- access_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 4: test main conf
---- http_config
- lua_need_request_body on;
---- config
- location /echo_body {
- access_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff"
-
-
-
-=== TEST 5: test server conf
---- config
- lua_need_request_body on;
-
- location /echo_body {
- access_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"hello\x00\x01\x02
-world\x03\x04\xff"
-
-
-
-=== TEST 6: test override main conf
---- http_config
- lua_need_request_body on;
---- config
- location /echo_body {
- lua_need_request_body off;
- access_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 7: test override server conf
---- config
- lua_need_request_body on;
-
- location /echo_body {
- lua_need_request_body off;
- access_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request eval
-"POST /echo_body
-hello\x00\x01\x02
-world\x03\x04\xff"
---- response_body eval
-"nil"
-
-
-
-=== TEST 8: Expect: 100-Continue
---- config
- location /echo_body {
- lua_need_request_body on;
- access_by_lua '
- ngx.print(ngx.var.request_body or "nil")
- ngx.exit(200)
- ';
- }
---- request
-POST /echo_body
-hello world
---- more_headers
-Expect: 100-Continue
---- ignore_response
---- no_error_log
-[error]
-[alert]
-http finalize request: 500, "/echo_body?" a:1, c:2
-http finalize request: 500, "/echo_body?" a:1, c:0
---- log_level: debug
diff --git a/src/deps/src/lua-nginx-module/t/024-access/sanity.t b/src/deps/src/lua-nginx-module/t/024-access/sanity.t
deleted file mode 100644
index e5612a8b8..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/sanity.t
+++ /dev/null
@@ -1,743 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#log_level('warn');
-#no_nginx_manager();
-#master_on();
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 11);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: basic print
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- access_by_lua 'ngx.print("Hello, Lua!\\n")';
- content_by_lua return;
- #content_by_lua 'ngx.say("Hi")';
- }
---- request
-GET /lua
---- response_body
-Hello, Lua!
-
-
-
-=== TEST 2: basic say
---- config
- location /say {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- access_by_lua '
- ngx.say("Hello, Lua!")
- ngx.say("Yay! ", 123)';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /say
---- response_body
-Hello, Lua!
-Yay! 123
-
-
-
-=== TEST 3: no ngx.echo
---- config
- location /lua {
- access_by_lua 'ngx.echo("Hello, Lua!\\n")';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 4: variable
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- access_by_lua 'local v = ngx.var["request_uri"] ngx.print("request_uri: ", v, "\\n")';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua?a=1&b=2
---- response_body
-request_uri: /lua?a=1&b=2
-
-
-
-=== TEST 5: variable (file)
---- config
- location /lua {
- access_by_lua_file html/test.lua;
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- user_files
->>> test.lua
-local v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- response_body
-request_uri: /lua?a=1&b=2
-
-
-
-=== TEST 6: calc expression
---- config
- location /lua {
- access_by_lua_file html/calc.lua;
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- user_files
->>> calc.lua
-local function uri_unescape(uri)
- local function convert(hex)
- return string.char(tonumber("0x"..hex))
- end
- local s = string.gsub(uri, "%%([0-9a-fA-F][0-9a-fA-F])", convert)
- return s
-end
-
-local function eval_exp(str)
- return loadstring("return "..str)()
-end
-
-local exp_str = ngx.var["arg_exp"]
--- print("exp: '", exp_str, "'\n")
-local status, res
-status, res = pcall(uri_unescape, exp_str)
-if not status then
- ngx.print("error: ", res, "\n")
- return
-end
-status, res = pcall(eval_exp, res)
-if status then
- ngx.print("result: ", res, "\n")
-else
- ngx.print("error: ", res, "\n")
-end
---- request
-GET /lua?exp=1%2B2*math.sin(3)%2Fmath.exp(4)-math.sqrt(2)
---- response_body
-result: -0.4090441561579
-
-
-
-=== TEST 7: read $arg_xxx
---- config
- location = /lua {
- access_by_lua 'local who = ngx.var.arg_who
- ngx.print("Hello, ", who, "!")';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua?who=agentzh
---- response_body chomp
-Hello, agentzh!
-
-
-
-=== TEST 8: capture location
---- config
- location /other {
- echo "hello, world";
- }
-
- location /lua {
- access_by_lua '
-local res = ngx.location.capture("/other")
-ngx.print("status=", res.status, " ")
-ngx.print("body=", res.body)
-';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-status=200 body=hello, world
-
-
-
-=== TEST 9: capture non-existed location
---- config
- location /lua {
- access_by_lua 'local res = ngx.location.capture("/other"); ngx.print("status=", res.status)';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body: status=404
-
-
-
-=== TEST 10: invalid capture location (not as expected...)
---- config
- location /lua {
- access_by_lua 'local res = ngx.location.capture("*(#*"); ngx.say("res=", res.status)';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-res=404
-
-
-
-=== TEST 11: nil is "nil"
---- config
- location /lua {
- access_by_lua 'ngx.say(nil)';
- content_by_lua return;
- }
---- request
-GET /lua
---- response_body
-nil
-
-
-
-=== TEST 12: write boolean
---- config
- location /lua {
- access_by_lua 'ngx.say(true, " ", false)';
- content_by_lua return;
- }
---- request
-GET /lua
---- response_body
-true false
-
-
-
-=== TEST 13: bad argument type to ngx.location.capture
---- config
- location /lua {
- access_by_lua 'ngx.location.capture(nil)';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 14: capture location (default 0);
---- config
- location /recur {
- access_by_lua '
- local num = tonumber(ngx.var.arg_num) or 0;
- ngx.print("num is: ", num, "\\n");
-
- if (num > 0) then
- local res = ngx.location.capture("/recur?num="..tostring(num - 1));
- ngx.print("status=", res.status, " ");
- ngx.print("body=", res.body, "\\n");
- else
- ngx.print("end\\n");
- end
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /recur
---- response_body
-num is: 0
-end
-
-
-
-=== TEST 15: capture location
-access phase not running in subrequests
---- config
- location /recur {
- access_by_lua '
- local num = tonumber(ngx.var.arg_num) or 0;
- ngx.print("num is: ", num, "\\n");
-
- if (num > 0) then
- local res = ngx.location.capture("/recur?num="..tostring(num - 1));
- ngx.print("status=", res.status, " ");
- ngx.print("body=", res.body);
- else
- ngx.print("end\\n");
- end
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /recur?num=3
---- response_body chomp
-num is: 3
-status=200 body=
-
-
-
-=== TEST 16: setting nginx variables from within Lua
---- config
- location /set {
- set $a "";
- access_by_lua 'ngx.var.a = 32; ngx.say(ngx.var.a)';
- content_by_lua 'ngx.exit(ngx.OK)';
- add_header Foo $a;
- }
---- request
-GET /set
---- response_headers
-Foo: 32
---- response_body
-32
-
-
-
-=== TEST 17: nginx quote sql string 1
---- config
- location /set {
- set $a 'hello\n\r\'"\\'; # this runs after access_by_lua
- access_by_lua 'ngx.say(ngx.quote_sql_str(ngx.var.a))';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /set
---- response_body
-'hello\n\r\'\"\\'
-
-
-
-=== TEST 18: nginx quote sql string 2
---- config
-location /set {
- #set $a "hello\n\r'\"\\";
- access_by_lua 'ngx.say(ngx.quote_sql_str("hello\\n\\r\'\\"\\\\"))';
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /set
---- response_body
-'hello\n\r\'\"\\'
-
-
-
-=== TEST 19: use dollar
---- config
-location /set {
- access_by_lua '
- local s = "hello 112";
- ngx.say(string.find(s, "%d+$"))';
-
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /set
---- response_body
-79
-
-
-
-=== TEST 20: subrequests do not share variables of main requests by default
---- config
-location /sub {
- echo $a;
-}
-location /parent {
- set $a 12;
- access_by_lua 'local res = ngx.location.capture("/sub"); ngx.print(res.body)';
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /parent
---- response_body eval: "\n"
-
-
-
-=== TEST 21: subrequests can share variables of main requests
---- config
-location /sub {
- echo $a;
-}
-location /parent {
- set $a '';
- access_by_lua '
- ngx.var.a = 12;
- local res = ngx.location.capture(
- "/sub",
- { share_all_vars = true }
- );
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /parent
---- response_body
-12
-
-
-
-=== TEST 22: main requests use subrequests' variables
---- config
-location /sub {
- set $a 12;
-}
-location /parent {
- access_by_lua '
- local res = ngx.location.capture("/sub", { share_all_vars = true });
- ngx.say(ngx.var.a)
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
-}
---- request
-GET /parent
---- response_body
-12
-
-
-
-=== TEST 23: main requests do NOT use subrequests' variables
---- config
-location /sub {
- set $a 12;
- content_by_lua return;
-}
-
-location /parent {
- access_by_lua '
- local res = ngx.location.capture("/sub", { share_all_vars = false });
- ngx.say(ngx.var.a)
- ';
- content_by_lua return;
-}
---- request
-GET /parent
---- response_body_like eval: "\n"
-
-
-
-=== TEST 24: capture location headers
---- config
- location /other {
- default_type 'foo/bar';
- echo "hello, world";
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", res.header["Content-Type"]);
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-type: foo/bar
-
-
-
-=== TEST 25: capture location headers
---- config
- location /other {
- default_type 'foo/bar';
- rewrite_by_lua '
- ngx.header.Bar = "Bah";
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", res.header["Content-Type"]);
- ngx.say("Bar: ", res.header["Bar"]);
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-type: foo/bar
-Bar: Bah
-
-
-
-=== TEST 26: capture location headers
---- config
- location /other {
- default_type 'foo/bar';
- access_by_lua '
- ngx.header.Bar = "Bah";
- ngx.header.Bar = nil;
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/other");
- ngx.say("type: ", res.header["Content-Type"]);
- ngx.say("Bar: ", res.header["Bar"] or "nil");
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-type: foo/bar
-Bar: nil
-
-
-
-=== TEST 27: access_by_lua runs after ngx_access
---- config
- location /lua {
- deny all;
-
- access_by_lua '
- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
- ';
-
- content_by_lua return;
- }
---- request
-GET /lua
---- response_body_like: 403 Forbidden
---- error_code: 403
-
-
-
-=== TEST 28: auth_request runs before ngx_access
---- config
- location /lua {
- deny all;
-
- auth_request /auth;
-
- content_by_lua return;
- }
---- request
-GET /lua
---- response_body_like: 403 Forbidden
---- error_code: 403
---- SKIP
-
-
-
-=== TEST 29: access_by_lua shouldn't send headers automatically (on simple return)
---- config
- location /lua {
- access_by_lua 'return';
-
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location = /foo {
- default_type 'text/css';
- add_header Bar Baz;
- echo foo;
- }
---- request
-GET /lua
---- response_headers
-Bar: Baz
-Content-Type: text/css
---- response_body
-foo
-
-
-
-=== TEST 30: access_by_lua shouldn't send headers automatically (on simple exit)
---- config
- location /lua {
- access_by_lua 'ngx.exit(ngx.OK)';
-
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location = /foo {
- default_type 'text/css';
- add_header Bar Baz;
- echo foo;
- }
---- request
-GET /lua
---- response_headers
-Bar: Baz
-Content-Type: text/css
---- response_body
-foo
-
-
-
-=== TEST 31: short circuit
---- config
- location /lua {
- access_by_lua '
- ngx.say("Hi")
- ngx.eof()
- ngx.exit(ngx.HTTP_OK)
- ';
-
- content_by_lua '
- print("HERE")
- ngx.print("BAD")
- ';
- }
---- request
-GET /lua
---- response_body
-Hi
-
-
-
-=== TEST 32: nginx vars in script path
---- config
- location ~ ^/lua/(.+)$ {
- access_by_lua_file html/$1.lua;
-
- content_by_lua '
- print("HERE")
- ngx.print("BAD")
- ';
- }
---- user_files
->>> hi.lua
-ngx.say("Hi")
-ngx.eof()
-ngx.exit(ngx.HTTP_OK)
---- request
-GET /lua/hi
---- response_body
-Hi
-
-
-
-=== TEST 33: phase postponing works for various locations (access phase not running in subrequest)
---- config
- location ~ '^/lua/(.+)' {
- set $path $1;
- access_by_lua 'ngx.say(ngx.var.path)';
- content_by_lua return;
- }
- location ~ '^/lua2/(.+)' {
- set $path $1;
- access_by_lua 'ngx.say(ngx.var.path)';
- content_by_lua return;
- }
- location /main {
- echo_location /lua/foo;
- echo_location /lua/bar;
- echo_location /lua2/baz;
- echo_location /lua2/bah;
- }
---- request
-GET /main
---- response_body
-
-
-
-=== TEST 34: server access_by_lua
---- config
- access_by_lua 'ngx.header["X-Foo"] = "bar" -- ngx.send_headers()';
---- request
-GET /
---- response_body chop
-It works!It works!
---- response_headers
-X-Foo: bar
-
-
-
-=== TEST 35: server access_by_lua_file
---- config
- access_by_lua_file html/foo.lua;
---- user_files
->>> foo.lua
-ngx.header["X-Foo"] = "bar" -- ngx.send_headers()
---- request
-GET /
---- response_body chop
-It works!It works!
---- response_headers
-X-Foo: bar
-
-
-
-=== TEST 36: Lua file does not exist
---- config
- location /lua {
- access_by_lua_file html/test2.lua;
- }
---- user_files
->>> test.lua
-v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- response_body_like: 404 Not Found
---- error_code: 404
---- error_log eval
-qr/failed to load external Lua file ".*?test2\.lua": cannot open .*? No such file or directory/
-
-
-
-=== TEST 37: use of ngx.say() in access_by_lua without exiting with 200+.
---- config
- location /t {
- access_by_lua "ngx.say('test')";
- echo_exec /t2;
- }
---- request
- GET /t
---- response_body
-test
---- no_error_log
-[alert]
-
-
-
-=== TEST 38: use of ngx.say() in access_by_lua without exiting with 200+. (with explicit ngx.eof())
---- config
- location /t {
- access_by_lua "ngx.say('test') ngx.eof()";
- echo_exec /t2;
- }
---- request
- GET /t
---- response_body
-test
---- no_error_log
-[alert]
-
-
-
-=== TEST 39: use of ngx.say() in access_by_lua without exiting with 200+. (with IO)
---- config
- location /t {
- access_by_lua "ngx.say('test') ngx.sleep(0.001)";
- echo_exec /t2;
- }
---- request
- GET /t
---- response_body
-test
---- no_error_log
-[alert]
diff --git a/src/deps/src/lua-nginx-module/t/024-access/satisfy.t b/src/deps/src/lua-nginx-module/t/024-access/satisfy.t
deleted file mode 100644
index 7902f4938..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/satisfy.t
+++ /dev/null
@@ -1,211 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-worker_connections(1014);
-#master_on();
-#workers(4);
-#log_level('warn');
-no_root_location();
-
-#repeat_each(2);
-#repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: satisfy any
---- config
- location /test {
- satisfy any;
- allow all;
- access_by_lua 'ngx.exit(403)';
-
- echo something important;
- }
---- request
- GET /test
---- more_headers
---- response_body
-something important
---- no_error_log
-[error]
-
-
-
-=== TEST 2: satisfy any
---- config
- location /test {
- satisfy any;
- deny all;
- access_by_lua 'ngx.exit(403)';
-
- echo something important;
- }
---- request
- GET /test
---- more_headers
---- response_body_like: 403 Forbidden
---- error_code: 403
---- error_log
-access forbidden by rule
-
-
-
-=== TEST 3: satisfy any (explicit ngx.exit(0))
---- config
- location /test {
- satisfy any;
- deny all;
- access_by_lua 'ngx.exit(0)';
-
- echo something important;
- }
---- request
- GET /test
---- more_headers
---- response_body
-something important
---- error_code: 200
---- no_error_log
-[error]
-
-
-
-=== TEST 4: satisfy any (simple return)
---- config
- location /test {
- satisfy any;
- deny all;
- access_by_lua return;
-
- echo something important;
- }
---- request
- GET /test
---- more_headers
---- response_body
-something important
---- error_code: 200
---- no_error_log
-[error]
-
-
-
-=== TEST 5: satisfy any (declined)
---- config
- location /test {
- satisfy any;
- deny all;
- access_by_lua 'ngx.exit(ngx.DECLINED)';
-
- echo something important;
- }
---- request
- GET /test
---- more_headers
---- response_body_like: 403 Forbidden
---- error_code: 403
---- error_log
-access forbidden by rule
-
-
-
-=== TEST 6: satisfy any (declined, with I/O)
---- config
- location /test {
- satisfy any;
- deny all;
- access_by_lua 'ngx.location.capture("/echo") ngx.exit(ngx.DECLINED)';
-
- echo something important;
- }
-
- location /echo {
- echo hi;
- #echo_sleep 0.01;
- }
---- request
- GET /test
---- more_headers
---- response_body_like: 403 Forbidden
---- error_code: 403
---- error_log
-access forbidden by rule
-
-
-
-=== TEST 7: satisfy any (simple return, with I/O)
---- config
- location /test {
- satisfy any;
- deny all;
- access_by_lua 'ngx.location.capture("/echo") return';
-
- echo something important;
- }
-
- location /echo {
- echo hi;
- }
---- request
- GET /test
---- more_headers
---- response_body
-something important
---- error_code: 200
---- no_error_log
-[error]
-
-
-
-=== TEST 8: satisfy any - with I/O
---- config
- location /test {
- satisfy any;
- deny all;
- access_by_lua 'ngx.location.capture("/echo") ngx.exit(403)';
-
- echo something important;
- }
-
- location /echo {
- echo hi;
- }
---- request
- GET /test
---- more_headers
---- response_body_like: 403 Forbidden
---- error_code: 403
---- error_log
-access forbidden by rule
-
-
-
-=== TEST 9: satisfy any (explicit ngx.exit(0), with I/O)
---- config
- location /test {
- satisfy any;
- deny all;
- access_by_lua 'ngx.location.capture("/echo") ngx.exit(0)';
-
- echo something important;
- }
-
- location /echo {
- echo hi;
- }
---- request
- GET /test
---- more_headers
---- response_body
-something important
---- error_code: 200
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/024-access/sleep.t b/src/deps/src/lua-nginx-module/t/024-access/sleep.t
deleted file mode 100644
index c7aa0b65a..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/sleep.t
+++ /dev/null
@@ -1,224 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * 33;
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sleep 0.5
---- config
- location /test {
- access_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.sleep(0.5)
- local now = ngx.now()
- ngx.say(now - before)
- ngx.exit(200)
- ';
- }
---- request
-GET /test
---- response_body_like chop
-^0\.(?:4[5-9]\d*|5[0-5]\d*|5)$
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
-
-
-
-=== TEST 2: sleep ag
---- config
- location /test {
- access_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.sleep("a")
- local now = ngx.now()
- ngx.say(now - before)
- ngx.exit(200)
- ';
- }
---- request
-GET /test
---- error_code: 500
---- response_body_like: 500 Internal Server Error
---- error_log
-bad argument #1 to 'sleep'
-
-
-
-=== TEST 3: sleep 0.5 in subrequest
---- config
- location /test {
- access_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.location.capture("/sleep")
- local now = ngx.now()
- local delay = now - before
- ngx.say(delay)
- ngx.exit(200)
- ';
- }
- location /sleep {
- content_by_lua 'ngx.sleep(0.5)';
- }
---- request
-GET /test
---- response_body_like chop
-^0\.(?:4[5-9]\d*|5[0-9]\d*|5)$
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/sleep?"
---- no_error_log
-[error]
-
-
-
-=== TEST 4: sleep a in subrequest with bad argument
---- config
- location /test {
- access_by_lua '
- local res = ngx.location.capture("/sleep");
- ngx.say(res.status)
- ngx.exit(200)
- ';
- }
- location /sleep {
- content_by_lua 'ngx.sleep("a")';
- }
---- request
-GET /test
---- response_body
-500
---- error_log
-bad argument #1 to 'sleep'
-
-
-
-=== TEST 5: sleep 0.5 - multi-times
---- quic_max_idle_timeout: 1.0
---- config
- location /test {
- access_by_lua '
- ngx.update_time()
- local start = ngx.now()
- ngx.sleep(0.3)
- ngx.sleep(0.3)
- ngx.sleep(0.3)
- ngx.say(ngx.now() - start)
- ngx.exit(200)
- ';
- }
---- request
-GET /test
---- response_body_like chop
-^0\.(?:8[5-9]\d*|9[0-9]\d*|9)$
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 6: sleep 0.5 - interleaved by ngx.say() - ended by ngx.sleep
---- quic_max_idle_timeout: 2.2
---- config
- location /test {
- access_by_lua '
- ngx.send_headers()
- -- ngx.location.capture("/sleep")
- ngx.sleep(1)
- ngx.say("blah")
- ngx.sleep(1)
- -- ngx.location.capture("/sleep")
- ngx.exit(200)
- ';
- }
- location = /sleep {
- echo_sleep 0.1;
- }
---- request
-GET /test
---- response_body
-blah
---- error_log
-lua ready to sleep
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 7: sleep 0.5 - interleaved by ngx.say() - not ended by ngx.sleep
---- quic_max_idle_timeout: 0.85
---- config
- location /test {
- access_by_lua '
- ngx.send_headers()
- -- ngx.location.capture("/sleep")
- ngx.sleep(0.3)
- ngx.say("blah")
- ngx.sleep(0.5)
- -- ngx.location.capture("/sleep")
- ngx.say("hiya")
- ngx.exit(200)
- ';
- }
- location = /sleep {
- echo_sleep 0.1;
- }
---- request
-GET /test
---- response_body
-blah
-hiya
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 8: ngx.location.capture before and after ngx.sleep
---- config
- location /test {
- access_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
-
- ngx.sleep(0.1)
-
- res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ngx.exit(200)
- ';
- }
- location = /hello {
- echo hello world;
- }
- location = /sub {
- proxy_pass http://127.0.0.1:$server_port/hello;
- }
---- request
-GET /test
---- response_body
-hello world
-hello world
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/024-access/subrequest.t b/src/deps/src/lua-nginx-module/t/024-access/subrequest.t
deleted file mode 100644
index 665780a6d..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/subrequest.t
+++ /dev/null
@@ -1,601 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: DELETE
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_DELETE });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-DELETE
-
-
-
-=== TEST 2: DELETE (proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_DELETE });
-
- ngx.print(res.body)
- ';
-
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-DELETE
-
-
-
-=== TEST 3: POST (nobody, proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_POST });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-POST
-
-
-
-=== TEST 4: HEAD
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_HEAD });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-
-
-
-=== TEST 5: explicit GET
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_GET });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET
-
-
-
-=== TEST 6: implicit GET
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo")
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET
-
-
-
-=== TEST 7: implicit GET (empty option table)
---- config
- location /other {
- default_type 'foo/bar';
- echo $echo_request_method;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo", {})
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET
-
-
-
-=== TEST 8: PUT (nobody, proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo_read_request_body;
-
- echo $echo_request_method;
- echo_request_body;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_PUT, body = "hello" });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body chomp
-PUT
-hello
-
-
-
-=== TEST 9: PUT (nobody, no proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- #echo_read_request_body;
-
- echo $echo_request_method;
- #echo $echo_request_body;
- echo_request_body;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_PUT, body = "hello" });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body chomp
-PUT
-hello
-
-
-
-=== TEST 10: PUT (nobody, no proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- #echo_read_request_body;
-
- echo $echo_request_method;
- #echo $echo_request_body;
- echo_request_body;
- #echo "[$http_content_length]";
- echo;
- }
-
- location /foo {
- echo $echo_request_method;
- echo -n "[$http_content_length]";
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/other",
- { method = ngx.HTTP_PUT, body = "hello" });
-
- ngx.print(res.body)
-
- res = ngx.location.capture("/foo")
- ngx.say(res.body)
-
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-PUT
-hello
-GET
-[]
-
-
-
-=== TEST 11: POST (with body, proxy method)
---- config
- location /other {
- default_type 'foo/bar';
- echo_read_request_body;
-
- echo $echo_request_method;
- echo_request_body;
- }
-
- location /foo {
- proxy_pass http://127.0.0.1:$server_port/other;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { method = ngx.HTTP_POST, body = "hello" });
-
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body chomp
-POST
-hello
-
-
-
-=== TEST 12: POST (with body, memc method)
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc {
- set $memc_key $echo_request_uri;
- set $memc_exptime 600;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /lua {
- access_by_lua '
- ngx.location.capture("/flush");
-
- local res = ngx.location.capture("/memc");
- ngx.say("GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello" });
- ngx.say("PUT: " .. res.status);
-
- res = ngx.location.capture("/memc");
- ngx.say("cached: " .. res.body);
-
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET: 404
-PUT: 201
-cached: hello
-
-
-
-=== TEST 13: POST (with body, memc method)
---- config
- location /flush {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /memc {
- set $memc_cmd "";
- set $memc_key $echo_request_uri;
- set $memc_exptime 600;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location /lua {
- access_by_lua '
- ngx.location.capture("/flush",
- { share_all_vars = true });
-
- local res = ngx.location.capture("/memc",
- { share_all_vars = true });
- ngx.say("GET: " .. res.status);
-
- res = ngx.location.capture("/memc",
- { method = ngx.HTTP_PUT, body = "hello", share_all_vars = true });
- ngx.say("PUT: " .. res.status);
-
- res = ngx.location.capture("/memc", { share_all_vars = true });
- ngx.say("cached: " .. res.body);
-
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-GET: 404
-PUT: 201
-cached: hello
-
-
-
-=== TEST 14: empty args option table
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { args = {} })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body eval: "\n"
-
-
-
-=== TEST 15: non-empty args option table (1 pair)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { ["fo="] = "=>" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-fo%3D=%3D%3E
-
-
-
-=== TEST 16: non-empty args option table (2 pairs)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { ["fo="] = "=>",
- ["="] = ":" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like chop
-^(?:fo%3D=%3D%3E\&%3D=%3A|%3D=%3A\&fo%3D=%3D%3E)$
-
-
-
-=== TEST 17: non-empty args option table (2 pairs, no special chars)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { foo = 3,
- bar = "hello" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like chop
-^(?:bar=hello\&foo=3|foo=3\&bar=hello)$
-
-
-
-=== TEST 18: non-empty args option table (number key)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { [57] = "hi" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 19: non-empty args option table (plain arrays)
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo",
- { args = { "hi" } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 20: more args
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo?a=3",
- { args = { b = 4 } })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-a=3&b=4
-
-
-
-=== TEST 21: more args
---- config
- location /foo {
- echo $query_string;
- }
-
- location /lua {
- access_by_lua '
- local res = ngx.location.capture("/foo?a=3",
- { args = "b=4" })
- ngx.print(res.body)
- ';
- content_by_lua 'ngx.exit(ngx.OK)';
- }
---- request
-GET /lua
---- response_body
-a=3&b=4
-
-
-
-=== TEST 22: I/O in named location
-the nginx core requires the patch https://github.com/agentzh/ngx_openresty/blob/master/patches/nginx-1.0.15-reset_wev_handler_in_named_locations.patch
---- config
- location /t {
- echo_exec @named;
- }
-
- location @named {
- access_by_lua '
- ngx.location.capture("/hello")
- ';
- echo done;
- }
-
- location /hello {
- echo hello;
- }
---- request
- GET /t
---- response_body
-done
diff --git a/src/deps/src/lua-nginx-module/t/024-access/uthread-exec.t b/src/deps/src/lua-nginx-module/t/024-access/uthread-exec.t
deleted file mode 100644
index 9c88eb33e..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/uthread-exec.t
+++ /dev/null
@@ -1,346 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: exec in user thread (entry still pending)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ngx.say("hello")
- ';
- content_by_lua return;
- }
-
- location /foo {
- echo i am foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-delete thread 1
-
---- response_body
-i am foo
---- no_error_log
-[error]
-
-
-
-=== TEST 2: exec in user thread (entry already quits)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
- ';
- content_by_lua return;
- }
-
- location /foo {
- echo i am foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-i am foo
---- no_error_log
-[error]
-
-
-
-=== TEST 3: exec in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ';
- content_by_lua return;
- }
-
- location = /foo {
- echo hello foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 4: exec in a user thread (another user thread is still pending on ngx.sleep)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- local function g()
- ngx.sleep(1)
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ';
- content_by_lua return;
- }
-
- location = /foo {
- echo hello foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-create 3 in 1
-spawn user thread 3 in 1
-add timer 1000
-terminate 1: ok
-delete thread 1
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 3
-free request
-
---- response_body
-hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 5: exec in user thread (entry thread is still pending on ngx.location.capture), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture("/sleep")
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
-
- location = /foo {
- echo hello world;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
diff --git a/src/deps/src/lua-nginx-module/t/024-access/uthread-exit.t b/src/deps/src/lua-nginx-module/t/024-access/uthread-exit.t
deleted file mode 100644
index bd165ae70..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/uthread-exit.t
+++ /dev/null
@@ -1,1315 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: exit in user thread (entry thread is still pending to run)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ngx.sleep(1)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-M(timer-add) {
- if ($arg2 == 1000) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before
-hello in thread
---- no_error_log
-[error]
-
-
-
-=== TEST 2: exit in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ngx.sleep(1)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 3: exit in a user thread (another user thread is still pending on ngx.sleep)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("f")
- ngx.exit(0)
- end
-
- local function g()
- ngx.sleep(1)
- ngx.say("g")
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-create 3 in 1
-spawn user thread 3 in 1
-add timer 1000
-terminate 1: ok
-delete thread 1
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 3
-free request
-
---- response_body
-end
-f
---- no_error_log
-[error]
-
-
-
-=== TEST 4: exit in user thread (entry already quits)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("exiting the user thread")
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- wait: 0.1
---- response_body
-before
-after
-exiting the user thread
---- no_error_log
-[error]
-
-
-
-=== TEST 5: exit in user thread (entry thread is still pending on the DNS resolver for ngx.socket.tcp)
---- config
- location /lua {
- resolver 127.0.0.2:12345;
- resolver_timeout 12s;
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.001)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("agentzh.org", 80)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-F(ngx_resolve_name) {
- printf("resolving %s\n", user_string_n($ctx->name->data, $ctx->name->len))
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 1) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 12000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_tcp_resolve_cleanup) {
- println("lua tcp resolve cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 1
-resolving agentzh.org
-add timer 12000
-expire timer 1
-terminate 2: ok
-delete thread 2
-lua tcp resolve cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 6: exit in user thread (entry thread is still pending on the DNS resolver for ngx.socket.udp)
---- config
- location /lua {
- resolver 127.0.0.2:12345;
- resolver_timeout 12s;
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.001)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername("agentzh.org", 80)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-F(ngx_resolve_name) {
- printf("resolving %s\n", user_string_n($ctx->name->data, $ctx->name->len))
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 1) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 12000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_udp_resolve_cleanup) {
- println("lua udp resolve cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 1
-resolving agentzh.org
-add timer 12000
-expire timer 1
-terminate 2: ok
-delete thread 2
-lua udp resolve cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 7: exit in user thread (entry thread is still pending on tcpsock:connect)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
- sock:settimeout(12000)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 12000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 8: exit in user thread (entry thread is still pending on tcpsock:receive)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, ok = sock:send("blpop not_exists 2\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local data, err = sock:receive()
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 9: exit in user thread (entry thread is still pending on tcpsock:receiveuntil's iterator)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, ok = sock:send("blpop not_exists 2\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- local it, err = sock:receiveuntil("\\r\\n")
- if not it then
- ngx.say("failed to receive until: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local data, err = it()
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 10: exit in user thread (entry thread is still pending on udpsock:receive)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.udp()
-
- local ok, err = sock:setpeername("8.8.8.8", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local data, err = sock:receive()
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_udp_socket_cleanup) {
- println("lua udp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua udp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 11: exit in user thread (entry thread is still pending on reqsock:receive)
---- skip_eval: 5:$ENV{TEST_NGINX_USE_HTTP3}
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.req.socket()
-
- sock:settimeout(12000)
-
- local data, err = sock:receive(1024)
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-POST /lua
-
---- more_headers
-Content-Length: 1024
-
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 12: exit in user thread (entry thread is still pending on ngx.req.read_body)
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
---- config
- location /lua {
- client_body_timeout 12000ms;
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.req.read_body()
-
- ngx.say("end")
- ';
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_req_body_cleanup) {
- println("lua req body cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua req body cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 13: exit in user thread (entry thread is still pending on ngx.location.capture), with pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.location.capture("/sleep")
-
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 14: exit in user thread (entry thread is still pending on ngx.location.capture), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture("/sleep")
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 15: exit in user thread (entry thread is still pending on ngx.location.capture_multi), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture_multi{
- {"/echo"},
- {"/sleep"}
- }
- ngx.say("end")
- ';
- }
-
- location = /echo {
- echo hello;
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-post subreq /echo
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
diff --git a/src/deps/src/lua-nginx-module/t/024-access/uthread-redirect.t b/src/deps/src/lua-nginx-module/t/024-access/uthread-redirect.t
deleted file mode 100644
index cb99a3512..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/uthread-redirect.t
+++ /dev/null
@@ -1,189 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: ngx.redirect() in user thread (entry thread is still pending on ngx.location.capture_multi), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.redirect(301)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture_multi{
- {"/echo"},
- {"/sleep"}
- }
- ngx.say("end")
- ';
- }
-
- location = /echo {
- echo hello;
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-post subreq /echo
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 2: redirect in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.redirect(301)
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ngx.say("end")
- ';
- content_by_lua return;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body_like: 302 Found
---- error_code: 302
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/024-access/uthread-spawn.t b/src/deps/src/lua-nginx-module/t/024-access/uthread-spawn.t
deleted file mode 100644
index b31edbcb1..000000000
--- a/src/deps/src/lua-nginx-module/t/024-access/uthread-spawn.t
+++ /dev/null
@@ -1,1123 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 1);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple user thread without I/O
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval
-<<'_EOC_' . $::StapScript;
-
-F(ngx_http_lua_send_chain_link) {
- printf("send link %p\n", $in)
-}
-
-F(ngx_http_core_content_phase) {
- println("core content phase")
-}
-
-_EOC_
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 2: two simple user threads without I/O
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("in thread 1")
- end
-
- local function g()
- ngx.say("in thread 2")
- end
-
- ngx.say("before 1")
- ngx.thread.spawn(f)
- ngx.say("after 1")
-
- ngx.say("before 2")
- ngx.thread.spawn(g)
- ngx.say("after 2")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: ok
-terminate 1: ok
-delete thread 2
-delete thread 3
-delete thread 1
-
---- response_body
-before 1
-in thread 1
-after 1
-before 2
-in thread 2
-after 2
---- no_error_log
-[error]
-
-
-
-=== TEST 3: simple user thread with sleep
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("before sleep")
- ngx.sleep(0.1)
- ngx.say("after sleep")
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before thread create
-before sleep
-after thread create
-after sleep
---- no_error_log
-[error]
-
-
-
-=== TEST 4: two simple user threads with sleep
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("1: before sleep")
- ngx.sleep(0.2)
- ngx.say("1: after sleep")
- end
-
- local function g()
- ngx.say("2: before sleep")
- ngx.sleep(0.1)
- ngx.say("2: after sleep")
- end
-
- ngx.say("1: before thread create")
- ngx.thread.spawn(f)
- ngx.say("1: after thread create")
-
- ngx.say("2: before thread create")
- ngx.thread.spawn(g)
- ngx.say("2: after thread create")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2
-
---- wait: 0.1
---- response_body
-1: before thread create
-1: before sleep
-1: after thread create
-2: before thread create
-2: before sleep
-2: after thread create
-2: after sleep
-1: after sleep
---- no_error_log
-[error]
-
-
-
-=== TEST 5: error in user thread
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.blah()
- end
-
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: fail
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-after
---- error_log eval
-qr/lua user thread aborted: runtime error: access_by_lua\(nginx\.conf:\d+\):3: attempt to call field 'blah' \(a nil value\)/
-
-
-
-=== TEST 6: simple user threads doing a single subrequest (entry quits early)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("before capture")
- local res = ngx.location.capture("/proxy")
- ngx.say("after capture: ", res.body)
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello world;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before thread create
-before capture
-after thread create
-after capture: hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 7: simple user threads doing a single subrequest (entry also does a subrequest and quits early)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("before capture")
- local res = ngx.location.capture("/proxy?foo")
- ngx.say("after capture: ", res.body)
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- local res = ngx.location.capture("/proxy?bar")
- ngx.say("capture: ", res.body)
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/$args;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello foo;
- }
-
- location /bar {
- echo -n hello bar;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before thread create
-before capture
-after thread create
-capture: hello bar
-after capture: hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 8: simple user threads doing a single subrequest (entry also does a subrequest and quits late)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("before capture")
- local res = ngx.location.capture("/proxy?foo")
- ngx.say("after capture: ", res.body)
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- local res = ngx.location.capture("/proxy?bar")
- ngx.say("capture: ", res.body)
- ';
- content_by_lua return;
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/$args;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello foo;
- }
-
- location /bar {
- echo_sleep 0.2;
- echo -n hello bar;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before thread create
-before capture
-after thread create
-after capture: hello foo
-capture: hello bar
---- no_error_log
-[error]
-
-
-
-=== TEST 9: two simple user threads doing single subrequests (entry also does a subrequest and quits between)
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("f: before capture")
- local res = ngx.location.capture("/proxy?foo")
- ngx.say("f: after capture: ", res.body)
- end
-
- local function g()
- ngx.say("g: before capture")
- local res = ngx.location.capture("/proxy?bah")
- ngx.say("g: after capture: ", res.body)
- end
-
- ngx.say("before thread 1 create")
- ngx.thread.spawn(f)
- ngx.say("after thread 1 create")
-
- ngx.say("before thread 2 create")
- ngx.thread.spawn(g)
- ngx.say("after thread 2 create")
-
- local res = ngx.location.capture("/proxy?bar")
- ngx.say("capture: ", res.body)
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/$args;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello foo;
- }
-
- location /bar {
- echo_sleep 0.2;
- echo -n hello bar;
- }
-
- location /bah {
- echo_sleep 0.3;
- echo -n hello bah;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-terminate 3: ok
-delete thread 3
-
---- response_body
-before thread 1 create
-f: before capture
-after thread 1 create
-before thread 2 create
-g: before capture
-after thread 2 create
-f: after capture: hello foo
-capture: hello bar
-g: after capture: hello bah
---- no_error_log
-[error]
-
-
-
-=== TEST 10: nested user threads
---- config
- location /lua {
- access_by_lua '
- local g
- local function f()
- ngx.say("before g")
- ngx.thread.spawn(g)
- ngx.say("after g")
- end
-
- function g()
- ngx.say("hello in g()")
- end
-
- ngx.say("before f")
- ngx.thread.spawn(f)
- ngx.say("after f")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 3
-delete thread 2
-
---- response_body
-before f
-before g
-hello in g()
-after f
-after g
---- no_error_log
-[error]
-
-
-
-=== TEST 11: nested user threads (with I/O)
---- config
- location /lua {
- access_by_lua '
- local g
- local function f()
- ngx.say("before g")
- ngx.thread.spawn(g)
- ngx.say("after g")
- end
-
- function g()
- ngx.sleep(0.1)
- ngx.say("hello in g()")
- end
-
- ngx.say("before f")
- ngx.thread.spawn(f)
- ngx.say("after f")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-before f
-before g
-after f
-after g
-hello in g()
---- no_error_log
-[error]
-
-
-
-=== TEST 12: coroutine status of a running user thread
---- config
- location /lua {
- access_by_lua '
- local co
- local function f()
- co = coroutine.running()
- ngx.sleep(0.1)
- end
-
- ngx.thread.spawn(f)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-status: running
---- no_error_log
-[error]
-
-
-
-=== TEST 13: coroutine status of a dead user thread
---- config
- location /lua {
- access_by_lua '
- local co
- local function f()
- co = coroutine.running()
- end
-
- ngx.thread.spawn(f)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-status: zombie
---- no_error_log
-[error]
-
-
-
-=== TEST 14: coroutine status of a "normal" user thread
---- config
- location /lua {
- access_by_lua '
- local co
- local g
- local function f()
- co = coroutine.running()
- local co2 = coroutine.create(g)
- coroutine.resume(co2)
- end
-
- function g()
- ngx.sleep(0.1)
- end
-
- ngx.thread.spawn(f)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 2
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-terminate 2: ok
-delete thread 2
-
---- response_body
-status: normal
---- no_error_log
-[error]
-
-
-
-=== TEST 15: creating user threads in a user coroutine
---- config
- location /lua {
- access_by_lua '
- local g
- local function f()
- ngx.say("before g")
- ngx.thread.spawn(g)
- ngx.say("after g")
- end
-
- function g()
- ngx.say("hello in g()")
- end
-
- ngx.say("before f")
- local co = coroutine.create(f)
- coroutine.resume(co)
- ngx.say("after f")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-terminate 2: ok
-delete thread 3
-terminate 1: ok
-delete thread 1
-
---- response_body
-before f
-before g
-hello in g()
-after g
-after f
---- no_error_log
-[error]
-
-
-
-=== TEST 16: manual time slicing between a user thread and the entry thread
---- config
- location /lua {
- access_by_lua '
- local yield = coroutine.yield
-
- local function f()
- local self = coroutine.running()
- ngx.say("f 1")
- yield(self)
- ngx.say("f 2")
- yield(self)
- ngx.say("f 3")
- end
-
- local self = coroutine.running()
- ngx.say("0")
- yield(self)
- ngx.say("1")
- ngx.thread.spawn(f)
- ngx.say("2")
- yield(self)
- ngx.say("3")
- yield(self)
- ngx.say("4")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-0
-1
-f 1
-2
-f 2
-3
-f 3
-4
---- no_error_log
-[error]
-
-
-
-=== TEST 17: manual time slicing between two user threads
---- config
- location /lua {
- access_by_lua '
- local yield = coroutine.yield
-
- local function f()
- local self = coroutine.running()
- ngx.say("f 1")
- yield(self)
- ngx.say("f 2")
- yield(self)
- ngx.say("f 3")
- end
-
- local function g()
- local self = coroutine.running()
- ngx.say("g 1")
- yield(self)
- ngx.say("g 2")
- yield(self)
- ngx.say("g 3")
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ngx.say("done")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-f 1
-g 1
-f 2
-done
-g 2
-f 3
-g 3
---- no_error_log
-[error]
-
-
-
-=== TEST 18: entry thread and a user thread flushing at the same time
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello in thread")
- coroutine.yield(coroutine.running)
- ngx.flush(true)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ngx.flush(true)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 19: two user threads flushing at the same time
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.say("hello from f")
- ngx.flush(true)
- end
-
- local function g()
- ngx.say("hello from g")
- ngx.flush(true)
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like
-^(?:create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3|create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: ok
-terminate 1: ok
-delete thread 2
-delete thread 3
-delete thread 1)$
-
---- response_body
-hello from f
-hello from g
---- no_error_log
-[error]
-
-
-
-=== TEST 20: user threads + ngx.socket.tcp
---- config
- location /lua {
- access_by_lua '
- local function f()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- local bytes, err = sock:send("flush_all\\r\\n")
- if not bytes then
- ngx.say("failed to send query: ", err)
- return
- end
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("received: ", line)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before
-after
-received: OK
---- no_error_log
-[error]
-
-
-
-=== TEST 21: user threads + ngx.socket.udp
---- config
- location /lua {
- access_by_lua '
- local function f()
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername("127.0.0.1", 12345)
- local bytes, err = sock:send("blah")
- if not bytes then
- ngx.say("failed to send query: ", err)
- return
- end
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("received: ", line)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^(?:create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-|create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1)$
-
---- udp_listen: 12345
---- udp_query: blah
---- udp_reply: hello udp
---- response_body_like chop
-^(?:before
-after
-received: hello udp
-|before
-received: hello udp
-after)$
-
---- no_error_log
-[error]
-
-
-
-=== TEST 22: simple user thread with ngx.req.read_body()
---- config
- location /lua {
- access_by_lua '
- local function f()
- ngx.req.read_body()
- local body = ngx.req.get_body_data()
- ngx.say("body: ", body)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-POST /lua
-hello world
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^(?:create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1|create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2)$
-
---- response_body_like chop
-^(?:before
-body: hello world
-after|before
-after
-body: hello world)$
-
---- no_error_log
-[error]
-
-
-
-=== TEST 23: simple user thread with ngx.req.socket()
---- config
- location /lua {
- access_by_lua '
- local function f()
- local sock = ngx.req.socket()
- local body, err = sock:receive(11)
- if not body then
- ngx.say("failed to read body: ", err)
- return
- end
-
- ngx.say("body: ", body)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-POST /lua
-hello world
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^(?:create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1|create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2)$
-
---- response_body_like chop
-^(?:before
-body: hello world
-after|before
-after
-body: hello world)$
-
---- no_error_log
-[error]
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
diff --git a/src/deps/src/lua-nginx-module/t/025-codecache.t b/src/deps/src/lua-nginx-module/t/025-codecache.t
deleted file mode 100644
index cd56cf57a..000000000
--- a/src/deps/src/lua-nginx-module/t/025-codecache.t
+++ /dev/null
@@ -1,1884 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use Cwd qw(abs_path realpath);
-use File::Basename;
-
-repeat_each(2);
-
-plan tests => repeat_each() * 198;
-
-#$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-$ENV{TEST_NGINX_CERT_DIR} ||= dirname(realpath(abs_path(__FILE__)));
-
-no_long_string();
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-check_accum_error_log();
-run_tests();
-
-__DATA__
-
-=== TEST 1: code cache on by default
---- config
- location /lua {
- content_by_lua_file html/test.lua;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/test.lua", "w"))
- f:write("ngx.say(101)")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-ngx.say(32)
---- request
-GET /main
---- response_body
-32
-updated
-32
---- no_error_log
-[alert]
-
-
-
-=== TEST 2: code cache explicitly on
---- config
- location /lua {
- lua_code_cache on;
- content_by_lua_file html/test.lua;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/test.lua", "w"))
- f:write("ngx.say(101)")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-ngx.say(32)
---- request
-GET /main
---- response_body
-32
-updated
-32
---- no_error_log
-[alert]
-
-
-
-=== TEST 3: code cache explicitly off
---- config
- location /lua {
- lua_code_cache off;
- content_by_lua_file html/test.lua;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/test.lua", "w"))
- f:write("ngx.say(101)")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-ngx.say(32)
---- request
-GET /main
---- response_body
-32
-updated
-101
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 4: code cache explicitly off (server level)
---- config
- lua_code_cache off;
-
- location /lua {
- content_by_lua_file html/test.lua;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/test.lua", "w"))
- f:write("ngx.say(101)")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-ngx.say(32)
---- request
-GET /main
---- response_body
-32
-updated
-101
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 5: code cache explicitly off (server level) but be overridden in the location
---- config
- lua_code_cache off;
-
- location /lua {
- lua_code_cache on;
- content_by_lua_file html/test.lua;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/test.lua", "w"))
- f:write("ngx.say(101)")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-ngx.say(32)
---- request
-GET /main
---- response_body
-32
-updated
-32
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 6: code cache explicitly off (affects require) + content_by_lua
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /lua {
- lua_code_cache off;
- content_by_lua '
- local foo = require "foo";
- ';
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/foo.lua", "w"))
- f:write("module(..., package.seeall); ngx.say(102);")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> foo.lua
-module(..., package.seeall); ngx.say(32);
---- request
-GET /main
---- response_body
-32
-updated
-102
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 7: code cache explicitly off (affects require) + content_by_lua_file
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /lua {
- lua_code_cache off;
- content_by_lua_file html/test.lua;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/foo.lua", "w"))
- f:write("module(..., package.seeall); ngx.say(102);")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-local foo = require "foo";
->>> foo.lua
-module(..., package.seeall); ngx.say(32);
---- request
-GET /main
---- response_body
-32
-updated
-102
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 8: code cache explicitly off (affects require) + set_by_lua_file
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /lua {
- lua_code_cache off;
- set_by_lua_file $a html/test.lua;
- echo $a;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/foo.lua", "w"))
- f:write("module(..., package.seeall); return 102;")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-return require "foo"
->>> foo.lua
-module(..., package.seeall); return 32;
---- request
-GET /main
---- response_body
-32
-updated
-102
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 9: code cache explicitly on (affects require) + set_by_lua_file
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /lua {
- lua_code_cache on;
- set_by_lua_file $a html/test.lua;
- echo $a;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/foo.lua", "w"))
- f:write("module(..., package.seeall); return 102;")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-return require "foo"
->>> foo.lua
-module(..., package.seeall); return 32;
---- request
-GET /main
---- response_body
-32
-updated
-32
---- no_error_log
-[alert]
-
-
-
-=== TEST 10: code cache explicitly off + set_by_lua_file
---- config
- location /lua {
- lua_code_cache off;
- set_by_lua_file $a html/test.lua;
- echo $a;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/test.lua", "w"))
- f:write("return 101")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-return 32
---- request
-GET /main
---- response_body
-32
-updated
-101
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 11: code cache explicitly on + set_by_lua_file
---- config
- location /lua {
- lua_code_cache on;
- set_by_lua_file $a html/test.lua;
- echo $a;
- }
- location /update {
- content_by_lua '
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/test.lua", "w"))
- f:write("return 101")
- f:close()
- ngx.say("updated")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /update;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-return 32
---- request
-GET /main
---- response_body
-32
-updated
-32
---- no_error_log
-[alert]
-
-
-
-=== TEST 12: no clear builtin lib "string"
---- config
- location /lua {
- lua_code_cache off;
- content_by_lua_file html/test.lua;
- }
- location /main {
- echo_location /lua;
- echo_location /lua;
- }
---- user_files
->>> test.lua
-ngx.say(string.len("hello"))
-ngx.say(table.concat({1,2,3}, ", "))
---- request
- GET /main
---- response_body
-5
-1, 2, 3
-5
-1, 2, 3
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 13: no clear builtin lib "string"
---- config
- location /lua {
- lua_code_cache off;
- content_by_lua '
- ngx.say(string.len("hello"))
- ngx.say(table.concat({1,2,3}, ", "))
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /lua;
- }
---- request
- GET /main
---- response_body
-5
-1, 2, 3
-5
-1, 2, 3
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 14: no clear builtin lib "string"
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- lua_code_cache off;
- location /lua {
- content_by_lua '
- local test = require("test")
- ';
- }
- location /main {
- echo_location /lua;
- echo_location /lua;
- }
---- request
- GET /main
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-string = require("string")
-math = require("math")
-io = require("io")
-os = require("os")
-table = require("table")
-coroutine = require("coroutine")
-package = require("package")
-ngx.say("OK")
---- response_body
-OK
-OK
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 15: do not skip luarocks
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
- lua_code_cache off;"
---- config
- location /main {
- echo_location /load;
- echo_location /check;
- echo_location /check;
- }
-
- location /load {
- content_by_lua '
- package.loaded.luarocks = nil;
- local foo = require "luarocks";
- foo.hi()
- ';
- }
-
- location /check {
- content_by_lua '
- local foo = package.loaded.luarocks
- if foo then
- ngx.say("found")
- else
- ngx.say("not found")
- end
- ';
- }
---- request
-GET /main
---- user_files
->>> luarocks.lua
-module(..., package.seeall);
-
-ngx.say("loading");
-
-function hi ()
- ngx.say("hello, foo")
-end;
---- response_body
-loading
-hello, foo
-not found
-not found
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 16: do not skip luarocks*
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
- lua_code_cache off;"
---- config
- location /main {
- echo_location /load;
- echo_location /check;
- echo_location /check;
- }
-
- location /load {
- content_by_lua '
- package.loaded.luarocks2 = nil;
- local foo = require "luarocks2";
- foo.hi()
- ';
- }
-
- location /check {
- content_by_lua '
- local foo = package.loaded.luarocks2
- if foo then
- ngx.say("found")
- else
- ngx.say("not found")
- end
- ';
- }
---- request
-GET /main
---- user_files
->>> luarocks2.lua
-module(..., package.seeall);
-
-ngx.say("loading");
-
-function hi ()
- ngx.say("hello, foo")
-end;
---- response_body
-loading
-hello, foo
-not found
-not found
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 17: clear _G table
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- lua_code_cache off;
- location /t {
- content_by_lua '
- if not _G.foo then
- _G.foo = 1
- else
- _G.foo = _G.foo + 1
- end
- ngx.say("_G.foo: ", _G.foo)
- ';
- }
---- request
- GET /t
---- response_body
-_G.foo: 1
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 18: github #257: globals cleared when code cache off
---- http_config
- lua_code_cache off;
- init_by_lua '
- test = setfenv(
- function()
- ngx.say(tostring(table))
- end,
- setmetatable({},
- {
- __index = function(self, key)
- return rawget(self, key) or _G[key]
- end
- }))';
---- config
- location = /t {
- content_by_lua 'test()';
- }
---- request
-GET /t
---- response_body_like chop
-^table: 0x\d*?[1-9a-fA-F]
---- no_error_log
-[error]
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 19: lua_code_cache off + FFI-based Lua modules
---- http_config
- lua_code_cache off;
- lua_package_path "$prefix/html/?.lua;;";
-
---- config
- location = /t {
- content_by_lua '
- if not jit then
- ngx.say("skipped for non-LuaJIT")
- else
- local test = require("test")
- ngx.say("test module loaded: ", test and true or false)
- collectgarbage()
- end
- ';
- }
---- user_files
->>> test.lua
-local ffi = require "ffi"
-
-ffi.cdef[[
- int my_test_function_here(void *p);
- int my_test_function_here2(void *p);
- int my_test_function_here3(void *p);
-]]
-
-return {
-}
---- request
-GET /t
---- response_body_like chop
-^(?:skipped for non-LuaJIT|test module loaded: true)$
---- no_error_log
-[error]
---- error_log eval
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-
-
-
-=== TEST 20: ngx.timer.* + ndk
---- config
- lua_code_cache off;
- location /read {
- echo ok;
- log_by_lua '
- ngx.timer.at(0, function ()
- local foo = ndk.set_var.set_unescape_uri("a%20b")
- ngx.log(ngx.WARN, "foo = ", foo)
- end)
- ';
- }
---- request
-GET /read
---- response_body
-ok
---- wait: 0.1
---- no_error_log
-[error]
---- error_log eval
-["foo = a b",
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
-]
-
-
-
-=== TEST 21: set ngx.ctx before internal redirects performed by other nginx modules (with log_by_lua)
---- config
- lua_code_cache off;
- location = /t {
- rewrite_by_lua '
- ngx.ctx.foo = "hello world";
- ';
- echo_exec /foo;
- }
-
- location = /foo {
- echo hello;
- log_by_lua return;
- }
---- request
-GET /t
---- response_body
-hello
---- no_error_log
-[error]
---- log_level: debug
---- error_log eval
-["lua release ngx.ctx at ref",
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"lua close the global Lua VM",
-]
-
-
-
-=== TEST 22: set by lua file
---- config
- lua_code_cache off;
- location /lua {
- set_by_lua_file $res html/a.lua $arg_a $arg_b;
- echo $res;
- }
---- user_files
->>> a.lua
-return ngx.arg[1] + ngx.arg[2]
---- request
-GET /lua?a=5&b=2
---- response_body
-7
---- no_error_log
-[error]
---- error_log eval
-[qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"lua close the global Lua VM",
-]
-
-
-
-=== TEST 23: simple set by lua
---- config
- lua_code_cache off;
- location /lua {
- set_by_lua $res "return 1+1";
- echo $res;
- }
---- request
-GET /lua
---- response_body
-2
---- no_error_log
-[error]
---- error_log eval
-[
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"lua close the global Lua VM",
-]
-
-
-
-=== TEST 24: lua_max_pending_timers - chained timers (non-zero delay) - not exceeding
---- http_config
- lua_max_pending_timers 1;
- lua_code_cache off;
-
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- local ok, err = ngx.timer.at(0.01, g)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-decrementing the reference count for Lua VM: 3
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"trace: [m][f][g]",
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"lua close the global Lua VM",
-"decrementing the reference count for Lua VM: 2",
-"decrementing the reference count for Lua VM: 1",
-]
-
-
-
-=== TEST 25: lua variable sharing via upvalue
---- http_config
- lua_code_cache off;
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local foo
- local function f()
- foo = 3
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.06)
- ngx.say("foo = ", foo)
- ';
- }
---- request
-GET /t
---- response_body
-registered timer
-foo = 3
-
---- wait: 0.1
---- no_error_log
-[error]
-decrementing the reference count for Lua VM: 3
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"lua close the global Lua VM",
-"decrementing the reference count for Lua VM: 2",
-"decrementing the reference count for Lua VM: 1",
-]
-
-
-
-=== TEST 26: lua_max_running_timers (just not enough)
---- http_config
- lua_max_running_timers 1;
---- config
- lua_code_cache off;
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local f, g
-
- g = function ()
- ngx.sleep(0.01)
- collectgarbage()
- end
-
- f = function ()
- ngx.sleep(0.01)
- collectgarbage()
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer f: ", err)
- return
- end
- local ok, err = ngx.timer.at(0, g)
- if not ok then
- ngx.say("failed to set timer g: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-
---- error_log eval
-[
-"1 lua_max_running_timers are not enough",
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"decrementing the reference count for Lua VM: 3",
-"decrementing the reference count for Lua VM: 2",
-"decrementing the reference count for Lua VM: 1",
-"lua close the global Lua VM",
-]
-
-
-
-=== TEST 27: GC issue with the on_abort thread object
-curl: (52) Empty reply from server
---- config
- lua_code_cache off;
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.on_abort(function () end)
- collectgarbage()
- ngx.sleep(1)
- ';
- }
---- request
- GET /t
---- abort
---- timeout: 0.2
---- wait: 1
---- ignore_response
---- no_error_log
-[error]
-decrementing the reference count for Lua VM: 2
-decrementing the reference count for Lua VM: 3
---- error_log eval
-["decrementing the reference count for Lua VM: 1",
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"lua close the global Lua VM",
-]
---- curl_error eval
-qr/curl: \(\d+\) Empty reply from server|curl: \(28\) Operation timed out after \d+ milliseconds with 0 bytes received/
-
-
-
-=== TEST 28: multiple parallel timers
---- config
- lua_code_cache off;
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- local ok, err = ngx.timer.at(0.01, g)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-decrementing the reference count for Lua VM: 4
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"trace: [m][f][g]",
-"decrementing the reference count for Lua VM: 3",
-"decrementing the reference count for Lua VM: 2",
-"decrementing the reference count for Lua VM: 1",
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"lua close the global Lua VM",
-]
-
-
-
-=== TEST 29: cosocket connection pool timeout (after Lua VM destroys)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- lua_code_cache off;
- location = /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive(10)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-request sent: 11
-received: OK
---- no_error_log
-[error]
-lua tcp socket keepalive max idle timeout
-
---- error_log eval
-[
-qq{lua tcp socket keepalive create connection pool for key "127.0.0.1:$ENV{TEST_NGINX_MEMCACHED_PORT}"},
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-qr/\blua tcp socket keepalive: free connection pool [0-9A-F]+ for "127.0.0.1:/,
-]
-
-
-
-=== TEST 30: cosocket connection pool timeout (before Lua VM destroys)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- lua_code_cache off;
- location = /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive(1)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
- ngx.sleep(0.01)
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-request sent: 11
-received: OK
---- no_error_log
-[error]
---- error_log eval
-[
-qq{lua tcp socket keepalive create connection pool for key "127.0.0.1:$ENV{TEST_NGINX_MEMCACHED_PORT}"},
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive max idle timeout",
-]
-
-
-
-=== TEST 31: lua_max_running_timers (just not enough, also low lua_max_pending_timers)
---- http_config
- lua_max_running_timers 1;
- lua_max_pending_timers 10;
---- config
- lua_code_cache off;
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local f, g
-
- g = function ()
- ngx.sleep(0.01)
- collectgarbage()
- end
-
- f = function ()
- ngx.sleep(0.01)
- collectgarbage()
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer f: ", err)
- return
- end
- local ok, err = ngx.timer.at(0, g)
- if not ok then
- ngx.say("failed to set timer g: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-
---- error_log eval
-[
-"1 lua_max_running_timers are not enough",
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
-"decrementing the reference count for Lua VM: 3",
-"decrementing the reference count for Lua VM: 2",
-"decrementing the reference count for Lua VM: 1",
-"lua close the global Lua VM",
-]
-
-
-
-=== TEST 32: make sure inline code keys are correct
-GitHub issue #1428
---- config
-include ../html/a/proxy.conf;
-include ../html/b/proxy.conf;
-include ../html/c/proxy.conf;
-
-location /t {
- echo_location /a/;
- echo_location /b/;
- echo_location /a/;
- echo_location /c/;
-}
-
---- user_files
->>> a/proxy.conf
-location /a/ {
- content_by_lua_block { ngx.say("/a/ is called") }
-}
-
->>> b/proxy.conf
-location /b/ {
- content_by_lua_block { ngx.say("/b/ is called") }
-}
-
->>> c/proxy.conf
-location /c/ {
- content_by_lua_block { ngx.say("/b/ is called") }
-}
-
---- request
-GET /t
---- response_body
-/a/ is called
-/b/ is called
-/a/ is called
-/b/ is called
---- grep_error_log eval: qr/code cache .*/
---- grep_error_log_out eval
-[
-"code cache lookup (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=-1)
-code cache miss (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=-1)
-code cache lookup (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=-1)
-code cache miss (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=-1)
-code cache lookup (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=1)
-code cache hit (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=1)
-code cache lookup (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=-1)
-code cache setting ref (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=2)
-code cache hit (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=2)
-",
-"code cache lookup (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=-1)
-code cache miss (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=-1)
-code cache lookup (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=-1)
-code cache miss (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=-1)
-code cache lookup (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=1)
-code cache hit (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=1)
-code cache lookup (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=-1)
-code cache setting ref (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=2)
-code cache hit (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=2)
-code cache lookup (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=1)
-code cache hit (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=1)
-code cache lookup (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=2)
-code cache hit (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=2)
-code cache lookup (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=1)
-code cache hit (key='content_by_lua_nhli_3c7137b8371d10bc148c8f8bb3042ee6', ref=1)
-code cache lookup (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=2)
-code cache hit (key='content_by_lua_nhli_1dfe09105792ef65c8d576cc486d5e04', ref=2)
-"]
---- log_level: debug
---- no_error_log
-[error]
-
-
-
-=== TEST 33: make sure Lua code file keys are correct
-GitHub issue #1428
---- config
-include ../html/a/proxy.conf;
-include ../html/b/proxy.conf;
-include ../html/c/proxy.conf;
-
-location /t {
- echo_location /a/;
- echo_location /b/;
- echo_location /a/;
- echo_location /c/;
-}
-
---- user_files
->>> a.lua
-ngx.say("/a/ is called")
-
->>> b.lua
-ngx.say("/b/ is called")
-
->>> c.lua
-ngx.say("/b/ is called")
-
->>> a/proxy.conf
-location /a/ {
- content_by_lua_file html/a.lua;
-}
-
->>> b/proxy.conf
-location /b/ {
- content_by_lua_file html/b.lua;
-}
-
->>> c/proxy.conf
-location /c/ {
- content_by_lua_file html/c.lua;
-}
-
---- request
-GET /t
---- response_body
-/a/ is called
-/b/ is called
-/a/ is called
-/b/ is called
---- grep_error_log eval: qr/code cache .*/
---- grep_error_log_out eval
-[
-"code cache lookup (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=-1)
-code cache miss (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=-1)
-code cache lookup (key='nhlf_68f5f4e946c3efd1cc206452b807e8b6', ref=-1)
-code cache miss (key='nhlf_68f5f4e946c3efd1cc206452b807e8b6', ref=-1)
-code cache lookup (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=1)
-code cache hit (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=1)
-code cache lookup (key='nhlf_042c9b3a136fbacbbd0e4b9ad10896b7', ref=-1)
-code cache miss (key='nhlf_042c9b3a136fbacbbd0e4b9ad10896b7', ref=-1)
-",
-"code cache lookup (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=-1)
-code cache miss (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=-1)
-code cache lookup (key='nhlf_68f5f4e946c3efd1cc206452b807e8b6', ref=-1)
-code cache miss (key='nhlf_68f5f4e946c3efd1cc206452b807e8b6', ref=-1)
-code cache lookup (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=1)
-code cache hit (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=1)
-code cache lookup (key='nhlf_042c9b3a136fbacbbd0e4b9ad10896b7', ref=-1)
-code cache miss (key='nhlf_042c9b3a136fbacbbd0e4b9ad10896b7', ref=-1)
-code cache lookup (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=1)
-code cache hit (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=1)
-code cache lookup (key='nhlf_68f5f4e946c3efd1cc206452b807e8b6', ref=2)
-code cache hit (key='nhlf_68f5f4e946c3efd1cc206452b807e8b6', ref=2)
-code cache lookup (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=1)
-code cache hit (key='nhlf_48a9a7def61143c003a7de1644e026e4', ref=1)
-code cache lookup (key='nhlf_042c9b3a136fbacbbd0e4b9ad10896b7', ref=3)
-code cache hit (key='nhlf_042c9b3a136fbacbbd0e4b9ad10896b7', ref=3)
-"
-]
---- log_level: debug
---- no_error_log
-[error]
-
-
-
-=== TEST 34: variables in set_by_lua_file's file path
---- config
- location ~ ^/lua/(.+)$ {
- set_by_lua_file $res html/$1.lua;
- echo $res;
- }
-
- location /main {
- echo_location /lua/a;
- echo_location /lua/b;
- echo_location /lua/a;
- echo_location /lua/a;
- echo_location /lua/b;
- }
---- user_files
->>> a.lua
-return "a"
->>> b.lua
-return "b"
---- request
-GET /main
---- response_body
-a
-b
-a
-a
-b
---- no_error_log
-[error]
-
-
-
-=== TEST 35: variables in rewrite_by_lua_file's file path
---- config
- location ~ ^/lua/(.+)$ {
- rewrite_by_lua_file html/$1.lua;
- }
-
- location /main {
- echo_location /lua/a;
- echo_location /lua/b;
- echo_location /lua/a;
- echo_location /lua/a;
- echo_location /lua/b;
- }
---- user_files
->>> a.lua
-ngx.say("a")
->>> b.lua
-ngx.say("b")
---- request
-GET /main
---- response_body
-a
-b
-a
-a
-b
---- no_error_log
-[error]
-
-
-
-=== TEST 36: variables in access_by_lua_file's file path
---- config
- location ~ ^/lua/(.+)$ {
- access_by_lua_file html/$1.lua;
-
- content_by_lua_block {
- return
- }
- }
-
- location ~ ^/proxy/(.+)$ {
- proxy_pass http://127.0.0.1:$server_port/lua/$1;
- }
-
- location /main {
- content_by_lua_block {
- local res1, res2, res3, res4, res5 = ngx.location.capture_multi{
- { "/proxy/a" },
- { "/proxy/b" },
- { "/proxy/a" },
- { "/proxy/a" },
- { "/proxy/b" },
- }
-
- ngx.say(res1.body)
- ngx.say(res2.body)
- ngx.say(res3.body)
- ngx.say(res4.body)
- ngx.say(res5.body)
- }
- }
---- user_files
->>> a.lua
-ngx.print("a")
->>> b.lua
-ngx.print("b")
---- request
-GET /main
---- response_body
-a
-b
-a
-a
-b
---- no_error_log
-[error]
-
-
-
-=== TEST 37: variables in content_by_lua_file's file path
---- config
- location ~ ^/lua/(.+)$ {
- content_by_lua_file html/$1.lua;
- }
-
- location /main {
- echo_location /lua/a;
- echo_location /lua/b;
- echo_location /lua/a;
- echo_location /lua/a;
- echo_location /lua/b;
- }
---- user_files
->>> a.lua
-ngx.say("a")
->>> b.lua
-ngx.say("b")
---- request
-GET /main
---- response_body
-a
-b
-a
-a
-b
---- no_error_log
-[error]
-
-
-
-=== TEST 38: variables in header_filter_by_lua_file's file path
---- config
- location ~ ^/lua/(.+)$ {
- return 200;
-
- header_filter_by_lua_file html/$1.lua;
- }
-
- location ~ ^/proxy/(.+)$ {
- proxy_pass http://127.0.0.1:$server_port/lua/$1;
- }
-
- location /main {
- content_by_lua_block {
- local res1, res2, res3, res4, res5 = ngx.location.capture_multi{
- { "/proxy/a" },
- { "/proxy/b" },
- { "/proxy/a" },
- { "/proxy/a" },
- { "/proxy/b" },
- }
-
- ngx.say(res1.header.match)
- ngx.say(res2.header.match)
- ngx.say(res3.header.match)
- ngx.say(res4.header.match)
- ngx.say(res5.header.match)
- }
- }
---- user_files
->>> a.lua
-ngx.header.match = "a"
->>> b.lua
-ngx.header.match = "b"
---- request
-GET /main
---- response_body
-a
-b
-a
-a
-b
---- no_error_log
-[error]
-
-
-
-=== TEST 39: variables in body_filter_by_lua_file's file path
---- config
- location ~ ^/lua/(.+)$ {
- echo hello;
-
- body_filter_by_lua_file html/$1.lua;
- }
-
- location /main {
- echo_location /lua/a;
- echo_location /lua/b;
- echo_location /lua/a;
- echo_location /lua/a;
- echo_location /lua/b;
- }
---- user_files
->>> a.lua
-ngx.arg[1] = "a\n"
-ngx.arg[2] = true
->>> b.lua
-ngx.arg[1] = "b\n"
-ngx.arg[2] = true
---- request
-GET /main
---- response_body
-a
-b
-a
-a
-b
---- no_error_log
-[error]
-
-
-
-=== TEST 40: variables in log_by_lua_file's file path
---- config
- log_subrequest on;
-
- location ~ ^/lua/(.+)$ {
- echo hello;
-
- log_by_lua_file html/$1.lua;
- }
-
- location /main {
- echo_location /lua/a;
- echo_location /lua/b;
- echo_location /lua/a;
- echo_location /lua/a;
- echo_location /lua/b;
- }
---- user_files
->>> a.lua
-ngx.log(ngx.NOTICE, "grep me: a")
->>> b.lua
-ngx.log(ngx.NOTICE, "grep me: b")
---- request
-GET /main
---- ignore_response_body
---- grep_error_log eval: qr/grep me: ([ab])/
---- grep_error_log_out eval
-[
-"grep me: a
-grep me: b
-grep me: a
-grep me: a
-grep me: b
-",
-"grep me: a
-grep me: b
-grep me: a
-grep me: a
-grep me: b
-grep me: a
-grep me: b
-grep me: a
-grep me: a
-grep me: b
-"]
---- no_error_log
-[error]
-
-
-
-=== TEST 41: same chunk from different directives produces different closures
---- http_config
- ssl_session_fetch_by_lua_block { ngx.log(ngx.INFO, "hello") }
-
- ssl_session_store_by_lua_block { ngx.log(ngx.INFO, "hello") }
-
- upstream backend {
- server unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- balancer_by_lua_block { ngx.log(ngx.INFO, "hello") }
- }
-
- server {
- server_name test.com;
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- ssl_certificate_by_lua_block { ngx.log(ngx.INFO, "hello") }
-
- location /lua {
- set_by_lua_block $res { ngx.log(ngx.INFO, "hello") }
-
- rewrite_by_lua_block { ngx.log(ngx.INFO, "hello") }
-
- access_by_lua_block { ngx.log(ngx.INFO, "hello") }
-
- content_by_lua_block { ngx.log(ngx.INFO, "hello") }
-
- header_filter_by_lua_block { ngx.log(ngx.INFO, "hello") }
-
- body_filter_by_lua_block { ngx.log(ngx.INFO, "hello") }
-
- log_by_lua_block { ngx.log(ngx.INFO, "hello") }
- }
- }
---- config
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location = /proxy {
- proxy_pass http://backend;
- }
-
- location = /t {
- set $html_dir $TEST_NGINX_HTML_DIR;
-
- content_by_lua_block {
- ngx.location.capture("/proxy")
-
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:" .. ngx.var.html_dir .. "/nginx.sock")
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.log(ngx.ERR, "failed to do SSL handshake: ", err)
- return
- end
- package.loaded.session = sess
- sock:close()
-
- local ok, err = sock:connect("unix:" .. ngx.var.html_dir .. "/nginx.sock")
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.log(ngx.ERR, "failed to do SSL handshake: ", err)
- return
- end
-
- local req = "GET /lua HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.log(ngx.ERR, "failed to send http request: ", err)
- return
- end
- }
- }
---- request
-GET /t
---- ignore_response_body
---- grep_error_log eval: qr/code cache .*/
---- grep_error_log_out eval
-[
-"code cache lookup (key='content_by_lua_nhli_56ca4388611109b6ecfdeada050c8024', ref=-1)
-code cache miss (key='content_by_lua_nhli_56ca4388611109b6ecfdeada050c8024', ref=-1)
-code cache lookup (key='balancer_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='balancer_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='ssl_session_fetch_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='ssl_session_fetch_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3)
-code cache hit (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3)
-code cache lookup (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4)
-code cache hit (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4)
-code cache lookup (key='set_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='set_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='rewrite_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='rewrite_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='access_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='access_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='content_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='content_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='header_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='header_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='body_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='body_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='log_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='log_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-",
-"code cache lookup (key='content_by_lua_nhli_56ca4388611109b6ecfdeada050c8024', ref=-1)
-code cache miss (key='content_by_lua_nhli_56ca4388611109b6ecfdeada050c8024', ref=-1)
-code cache lookup (key='balancer_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='balancer_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='ssl_session_fetch_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='ssl_session_fetch_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3)
-code cache hit (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3)
-code cache lookup (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4)
-code cache hit (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4)
-code cache lookup (key='set_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='set_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='rewrite_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='rewrite_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='access_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='access_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='content_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='content_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='header_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='header_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='body_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='body_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='log_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache miss (key='log_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1)
-code cache lookup (key='content_by_lua_nhli_56ca4388611109b6ecfdeada050c8024', ref=1)
-code cache hit (key='content_by_lua_nhli_56ca4388611109b6ecfdeada050c8024', ref=1)
-code cache lookup (key='balancer_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=2)
-code cache hit (key='balancer_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=2)
-code cache lookup (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3)
-code cache hit (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3)
-code cache lookup (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4)
-code cache hit (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4)
-code cache lookup (key='ssl_session_fetch_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=5)
-code cache hit (key='ssl_session_fetch_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=5)
-code cache lookup (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3)
-code cache hit (key='ssl_certificate_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3)
-code cache lookup (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4)
-code cache hit (key='ssl_session_store_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4)
-code cache lookup (key='set_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=6)
-code cache hit (key='set_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=6)
-code cache lookup (key='rewrite_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=7)
-code cache hit (key='rewrite_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=7)
-code cache lookup (key='access_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=8)
-code cache hit (key='access_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=8)
-code cache lookup (key='content_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=9)
-code cache hit (key='content_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=9)
-code cache lookup (key='header_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=10)
-code cache hit (key='header_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=10)
-code cache lookup (key='body_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=11)
-code cache hit (key='body_filter_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=11)
-code cache lookup (key='log_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=12)
-code cache hit (key='log_by_lua_nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=12)
-"]
---- error_log eval
-[
-qr/balancer_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/ssl_session_fetch_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/ssl_certificate_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/ssl_session_store_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/set_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/rewrite_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/access_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/content_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/header_filter_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/body_filter_by_lua\(nginx\.conf:\d+\):\d+: hello/,
-qr/log_by_lua\(nginx.conf:\d+\):\d+: hello/,
-]
---- log_level: debug
---- no_error_log
-[error]
---- skip_eval: 14:$ENV{TEST_NGINX_USE_HTTP3}
diff --git a/src/deps/src/lua-nginx-module/t/026-mysql.t b/src/deps/src/lua-nginx-module/t/026-mysql.t
deleted file mode 100644
index 02e14b938..000000000
--- a/src/deps/src/lua-nginx-module/t/026-mysql.t
+++ /dev/null
@@ -1,131 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => blocks() * repeat_each() * 3;
-
-#$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
-$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
-
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: when mysql query timed out, kill that query by Lua
---- http_config
- upstream backend {
- drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
---- config
- location = /mysql {
- #internal;
- drizzle_send_query_timeout 100ms;
- #drizzle_send_query_timeout 1s;
- drizzle_query $echo_request_body;
- drizzle_pass backend;
-
- #error_page 504 /ret/504;
- rds_json on;
- more_set_headers -s 504 "X-Mysql-Tid: $drizzle_thread_id";
- }
-
- location /lua {
- content_by_lua '
- local sql = "select sleep(5)"
- local res = ngx.location.capture("/mysql",
- { method = ngx.HTTP_POST, body = sql })
-
- ngx.say("status = " .. res.status)
-
- local tid = res.header["X-Mysql-Tid"]
- if tid == nil then
- ngx.say("thread id = nil")
- return
- end
-
- tid = tonumber(tid)
- ngx.say("thread id = " .. tid)
-
- res = ngx.location.capture("/mysql",
- { method = ngx.HTTP_POST,
- body = "kill query " .. tid })
-
- ngx.say("kill status = " .. res.status)
- ngx.say("kill body = " .. res.body)
- ';
- }
---- request
- GET /lua
---- response_body_like
-^status = 504
-thread id = \d+
-kill status = 200
-kill body = \{"errcode":0\}$
---- error_log eval
-qr{upstream timed out \(\d+: Connection timed out\) while sending query to drizzle upstream}
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 2: no error pages
---- http_config
- upstream backend {
- drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
- dbname=ngx_test user=ngx_test password=ngx_test;
- drizzle_keepalive max=300 mode=single overflow=ignore;
- }
---- config
- location @err { echo Hi; }
- error_page 504 = @err;
- location = /mysql {
- #internal;
- drizzle_send_query_timeout 100ms;
- #drizzle_send_query_timeout 1s;
- drizzle_query $echo_request_body;
- drizzle_pass backend;
-
- no_error_pages;
-
- rds_json on;
- more_set_headers -s 504 "X-Mysql-Tid: $drizzle_thread_id";
- }
-
- location /lua {
- content_by_lua '
- local sql = "select sleep(3)"
- local res = ngx.location.capture("/mysql",
- { method = ngx.HTTP_POST, body = sql })
-
- ngx.say("status = " .. res.status)
-
- local tid = res.header["X-Mysql-Tid"]
- if tid == nil then
- ngx.say("thread id = nil")
- return
- end
-
- tid = tonumber(tid)
- ngx.say("thread id = " .. tid)
-
- res = ngx.location.capture("/mysql",
- { method = ngx.HTTP_POST,
- body = "kill query " .. tid })
-
- ngx.say("kill status = " .. res.status)
- ngx.say("kill body = " .. res.body)
- ';
- }
---- request
- GET /lua
---- response_body_like
-^status = 504
-thread id = \d+
-kill status = 200
-kill body = \{"errcode":0\}$
---- SKIP
diff --git a/src/deps/src/lua-nginx-module/t/027-multi-capture.t b/src/deps/src/lua-nginx-module/t/027-multi-capture.t
deleted file mode 100644
index b3cdbaff0..000000000
--- a/src/deps/src/lua-nginx-module/t/027-multi-capture.t
+++ /dev/null
@@ -1,826 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(10);
-
-plan tests => repeat_each() * (blocks() * 2 + 4);
-
-#$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
-$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#log_level 'warn';
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /foo {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ';
- }
- location /a {
- echo -n a;
- }
- location /b {
- echo -n b;
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-
-
-
-=== TEST 2: 4 concurrent requests
---- config
- location /foo {
- content_by_lua '
- local res1, res2, res3, res4 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- { "/c" },
- { "/d" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
-
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
-
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
-
- ngx.say("res4.status = " .. res4.status)
- ngx.say("res4.body = " .. res4.body)
- ';
- }
- location ~ '^/([a-d])$' {
- echo -n $1;
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-res3.status = 200
-res3.body = c
-res4.status = 200
-res4.body = d
-
-
-
-=== TEST 3: capture multi in series
---- config
- location /foo {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
-
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("2 res1.status = " .. res1.status)
- ngx.say("2 res1.body = " .. res1.body)
- ngx.say("2 res2.status = " .. res2.status)
- ngx.say("2 res2.body = " .. res2.body)
-
- ';
- }
- location /a {
- echo -n a;
- }
- location /b {
- echo -n b;
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-2 res1.status = 200
-2 res1.body = a
-2 res2.status = 200
-2 res2.body = b
-
-
-
-=== TEST 4: capture multi in subrequest
---- config
- location /foo {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
-
- local n = ngx.var.arg_n
-
- ngx.say(n .. " res1.status = " .. res1.status)
- ngx.say(n .. " res1.body = " .. res1.body)
- ngx.say(n .. " res2.status = " .. res2.status)
- ngx.say(n .. " res2.body = " .. res2.body)
- ';
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/foo?n=1")
- ngx.say("top res.status = " .. res.status)
- ngx.say("top res.body = [" .. res.body .. "]")
- ';
- }
-
- location /a {
- echo -n a;
- }
-
- location /b {
- echo -n b;
- }
---- request
- GET /main
---- response_body
-top res.status = 200
-top res.body = [1 res1.status = 200
-1 res1.body = a
-1 res2.status = 200
-1 res2.body = b
-]
-
-
-
-=== TEST 5: capture multi in parallel
---- config
- location ~ '^/(foo|bar)$' {
- set $tag $1;
- content_by_lua '
- local res1, res2
- if ngx.var.tag == "foo" then
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- else
- res1, res2 = ngx.location.capture_multi{
- { "/c" },
- { "/d" },
- }
- end
-
- local n = ngx.var.arg_n
-
- ngx.say(n .. " res1.status = " .. res1.status)
- ngx.say(n .. " res1.body = " .. res1.body)
- ngx.say(n .. " res2.status = " .. res2.status)
- ngx.say(n .. " res2.body = " .. res2.body)
- ';
- }
-
- location /main {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/foo?n=1" },
- { "/bar?n=2" },
- }
-
- ngx.say("top res1.status = " .. res1.status)
- ngx.say("top res1.body = [" .. res1.body .. "]")
- ngx.say("top res2.status = " .. res2.status)
- ngx.say("top res2.body = [" .. res2.body .. "]")
- ';
- }
-
- location ~ '^/([abcd])$' {
- echo -n $1;
- }
---- request
- GET /main
---- response_body
-top res1.status = 200
-top res1.body = [1 res1.status = 200
-1 res1.body = a
-1 res2.status = 200
-1 res2.body = b
-]
-top res2.status = 200
-top res2.body = [2 res1.status = 200
-2 res1.body = c
-2 res2.status = 200
-2 res2.body = d
-]
-
-
-
-=== TEST 6: memc sanity
---- config
- location /foo {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ';
- }
- location ~ '^/[ab]$' {
- set $memc_key $uri;
- set $memc_value hello;
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
- GET /foo
---- response_body eval
-"res1.status = 201
-res1.body = STORED\r
-
-res2.status = 201
-res2.body = STORED\r
-
-"
-
-
-
-=== TEST 7: memc muti + multi
---- config
- location /main {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/foo?n=1" },
- { "/bar?n=2" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = [" .. res1.body .. "]")
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = [" .. res2.body .. "]")
- ';
- }
- location ~ '^/(foo|bar)$' {
- set $tag $1;
- content_by_lua '
- local res1, res2
- if ngx.var.tag == "foo" then
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- else
- res1, res2 = ngx.location.capture_multi{
- { "/c" },
- { "/d" },
- }
- end
- print("args: " .. ngx.var.args)
- local n = ngx.var.arg_n
- ngx.say(n .. " res1.status = " .. res1.status)
- ngx.say(n .. " res1.body = " .. res1.body)
- ngx.say(n .. " res2.status = " .. res2.status)
- ngx.say(n .. " res2.body = " .. res2.body)
- ';
- }
- location ~ '^/[abcd]$' {
- set $memc_key $uri;
- set $memc_value hello;
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
- GET /main
---- response_body eval
-"res1.status = 200
-res1.body = [1 res1.status = 201
-1 res1.body = STORED\r
-
-1 res2.status = 201
-1 res2.body = STORED\r
-
-]
-res2.status = 200
-res2.body = [2 res1.status = 201
-2 res1.body = STORED\r
-
-2 res2.status = 201
-2 res2.body = STORED\r
-
-]
-"
-
-
-
-=== TEST 8: memc 4 concurrent requests
---- config
- location /foo {
- content_by_lua '
- local res1, res2, res3, res4 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- { "/c" },
- { "/d" },
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
-
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
-
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
-
- ngx.say("res4.status = " .. res4.status)
- ngx.say("res4.body = " .. res4.body)
- ';
- }
- location ~ '^/[a-d]$' {
- set $memc_key $uri;
- set $memc_value hello;
- set $memc_cmd set;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
- GET /foo
---- response_body eval
-"res1.status = 201
-res1.body = STORED\r
-
-res2.status = 201
-res2.body = STORED\r
-
-res3.status = 201
-res3.body = STORED\r
-
-res4.status = 201
-res4.body = STORED\r
-
-"
-
-
-
-=== TEST 9: capture multi in series (more complex)
---- config
- location /foo {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- local res3, res4 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- res3, res4 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
-
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
- ngx.say("res4.status = " .. res4.status)
- ngx.say("res4.body = " .. res4.body)
-
- ';
- }
- location /a {
- echo -n a;
- }
- location /b {
- echo -n b;
- }
- location /main {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/foo" },
- { "/foo" },
- }
- local res3, res4 = ngx.location.capture_multi{
- { "/foo" },
- { "/foo" },
- }
- ngx.print(res1.body)
- ngx.print(res2.body)
- ngx.print(res3.body)
- ngx.print(res4.body)
- ';
- }
---- request
- GET /main
---- response_body eval
-"res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-res3.status = 200
-res3.body = a
-res4.status = 200
-res4.body = b
-" x 4
-
-
-
-=== TEST 10: capture multi in series (more complex, using memc)
---- config
- location /foo {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- res1, res2 = ngx.location.capture_multi{
- { "/a" },
- { "/b" },
- }
- local res3, res4 = ngx.location.capture_multi{
- { "/c" },
- { "/d" },
- }
- res3, res4 = ngx.location.capture_multi{
- { "/e" },
- { "/f" },
- }
-
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
- ngx.say("res4.status = " .. res4.status)
- ngx.say("res4.body = " .. res4.body)
- ';
- }
-
- location /memc {
- set $memc_key $arg_val;
- set $memc_value $arg_val;
- set $memc_cmd $arg_cmd;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location ~ '^/([a-f])$' {
- set $tag $1;
- content_by_lua '
- ngx.location.capture("/memc?cmd=set&val=" .. ngx.var.tag)
- local res = ngx.location.capture("/memc?cmd=get&val=" .. ngx.var.tag)
- ngx.print(res.body)
- ';
- }
-
- location /main {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/foo" },
- { "/foo" },
- }
- local res3, res4 = ngx.location.capture_multi{
- { "/foo" },
- { "/foo" },
- }
- ngx.print(res1.body)
- ngx.print(res2.body)
- ngx.print(res3.body)
- ngx.print(res4.body)
- ';
- }
---- request
- GET /main
---- response_body2
---- response_body eval
-"res1.status = 200
-res1.body = a
-res2.status = 200
-res2.body = b
-res3.status = 200
-res3.body = e
-res4.status = 200
-res4.body = f
-" x 4
---- no_error_log eval
-["[error]", "[alert]"]
---- timeout: 10
-
-
-
-=== TEST 11: a mixture of rewrite, access, content phases
---- config
- location /main {
- rewrite_by_lua '
- local res = ngx.location.capture("/a")
- print("rewrite a: " .. res.body)
-
- res = ngx.location.capture("/b")
- print("rewrite b: " .. res.body)
-
- res = ngx.location.capture("/c")
- print("rewrite c: " .. res.body)
- ';
-
- access_by_lua '
- local res = ngx.location.capture("/A")
- print("access A: " .. res.body)
-
- res = ngx.location.capture("/B")
- print("access B: " .. res.body)
- ';
-
- content_by_lua '
- local res = ngx.location.capture("/d")
- ngx.say("content d: " .. res.body)
-
- res = ngx.location.capture("/e")
- ngx.say("content e: " .. res.body)
-
- res = ngx.location.capture("/f")
- ngx.say("content f: " .. res.body)
- ';
- }
-
- location /memc {
- set $memc_key $arg_val;
- set $memc_value $arg_val;
- set $memc_cmd $arg_cmd;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location ~ '^/([A-F])$' {
- echo -n $1;
- }
-
- location ~ '^/([a-f])$' {
- set $tag $1;
- content_by_lua '
- ngx.location.capture("/memc?cmd=set&val=" .. ngx.var.tag)
- local res = ngx.location.capture("/memc?cmd=get&val=" .. ngx.var.tag)
- ngx.print(res.body)
- ';
- }
---- request
- GET /main
---- response_body
-content d: d
-content e: e
-content f: f
-
---- log_level: info
---- grep_error_log eval: qr/rewrite .+?(?= while )|access .+?(?=,)/
---- grep_error_log_out
-rewrite a: a
-rewrite b: b
-rewrite c: c
-access A: A
-access B: B
-
-
-
-=== TEST 12: a mixture of rewrite, access, content phases
---- config
- location /main {
- rewrite_by_lua '
- local a, b, c = ngx.location.capture_multi{
- {"/a"}, {"/b"}, {"/c"},
- }
- print("rewrite a: " .. a.body)
- print("rewrite b: " .. b.body)
- print("rewrite c: " .. c.body)
- ';
-
- access_by_lua '
- local A, B = ngx.location.capture_multi{
- {"/A"}, {"/B"},
- }
- print("access A: " .. A.body)
- print("access B: " .. B.body)
- ';
-
- content_by_lua '
- local d, e, f = ngx.location.capture_multi{
- {"/d"}, {"/e"}, {"/f"},
- }
- ngx.say("content d: " .. d.body)
- ngx.say("content e: " .. e.body)
- ngx.say("content f: " .. f.body)
- ';
- }
-
- location /memc {
- set $memc_key $arg_val;
- set $memc_value $arg_val;
- set $memc_cmd $arg_cmd;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
-
- location ~ '^/([A-F])$' {
- echo -n $1;
- }
-
- location ~ '^/([a-f])$' {
- set $tag $1;
- content_by_lua '
- ngx.location.capture("/memc?cmd=set&val=" .. ngx.var.tag)
- local res = ngx.location.capture("/memc?cmd=get&val=" .. ngx.var.tag)
- ngx.print(res.body)
- ';
- }
---- request
- GET /main
---- stap2
-global delta = " "
-
-M(http-subrequest-start) {
- r = $arg1
- n = ngx_http_subreq_depth(r)
- pr = ngx_http_req_parent(r)
- printf("%sbegin %s -> %s (%d)\n", ngx_indent(n, delta),
- ngx_http_req_uri(pr),
- ngx_http_req_uri(r),
- n)
-}
-
-F(ngx_http_lua_run_thread) {
- r = $r
- uri = ngx_http_req_uri(r)
- if (uri == "/main") {
- printf("run thread %s: %d\n", uri, $nret)
- #print_ubacktrace()
- }
-}
-
-M(http-lua-info) {
- uri = ngx_http_req_uri($r)
- #if (uri == "/main") {
- printf("XXX info: %s: %s", uri, user_string($arg1))
- #}
-}
-
-F(ngx_http_lua_post_subrequest) {
- r = $r
- n = ngx_http_subreq_depth(r)
- pr = ngx_http_req_parent(r)
-
- printf("%send %s -> %s (%d)\n", ngx_indent(n, delta),
- ngx_http_req_uri(r),
- ngx_http_req_uri(pr),
- n)
-}
-
-F(ngx_http_lua_handle_subreq_responses) {
- r = $r
- n = ngx_http_subreq_depth(r)
- printf("%shandle res %s (%d)\n", ngx_indent(n, delta), ngx_http_req_uri(r), n)
-}
-
---- response_body
-content d: d
-content e: e
-content f: f
---- log_level: info
---- grep_error_log eval: qr/rewrite .+?(?= while )|access .+?(?=,)/
---- grep_error_log_out
-rewrite a: a
-rewrite b: b
-rewrite c: c
-access A: A
-access B: B
-
-
-
-=== TEST 13: proxy_cache_lock in subrequests
---- http_config
-proxy_cache_lock on;
-proxy_cache_lock_timeout 100ms;
-proxy_connect_timeout 300ms;
-
-proxy_cache_path conf/cache levels=1:2 keys_zone=STATIC:10m inactive=10m max_size=1m;
-
---- config
- location /foo {
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- { "/proxy" },
- { "/proxy" },
- { "/proxy" },
- { "/proxy" },
- }
- ngx.say("ok")
- ';
- }
-
- location = /proxy {
- proxy_cache STATIC;
- proxy_pass http://127.0.0.2:12345;
- proxy_cache_key $proxy_host$uri$args;
- proxy_cache_valid any 1s;
- #proxy_http_version 1.1;
- }
---- request
- GET /foo
---- response_body
-ok
-
-
-
-=== TEST 14: capture multi with headers
---- config
- location /foo {
- content_by_lua_block {
- local res1, res2, res3 = ngx.location.capture_multi{
- {"/test", { headers = { ["X-Test-Header"] = "aa"} } },
- {"/test", { headers = { ["X-Test-Header"] = "bb"} } },
- {"/test"},
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
- }
- }
-
- location = /test {
- content_by_lua_block {
- ngx.print(ngx.var.http_x_test_header)
- }
- }
---- request
- GET /foo
---- response_body
-res1.status = 200
-res1.body = aa
-res2.status = 200
-res2.body = bb
-res3.status = 200
-res3.body = nil
-
-
-
-=== TEST 15: capture multi with headers override
---- config
- location /foo {
- content_by_lua_block {
- local res1, res2, res3 = ngx.location.capture_multi{
- {"/test", { headers = { ["X-Test-Header"] = "aa"} } },
- {"/test", { headers = { ["X-Test-Header"] = "bb"} } },
- {"/test"},
- }
- ngx.say("res1.status = " .. res1.status)
- ngx.say("res1.body = " .. res1.body)
- ngx.say("res2.status = " .. res2.status)
- ngx.say("res2.body = " .. res2.body)
- ngx.say("res3.status = " .. res3.status)
- ngx.say("res3.body = " .. res3.body)
- }
- }
-
- location = /test {
- content_by_lua_block {
- ngx.print(ngx.var.http_x_test_header)
- }
- }
---- request
- GET /foo
---- more_headers
-X-Test-Header: cc
---- response_body
-res1.status = 200
-res1.body = aa
-res2.status = 200
-res2.body = bb
-res3.status = 200
-res3.body = cc
diff --git a/src/deps/src/lua-nginx-module/t/028-req-header.t b/src/deps/src/lua-nginx-module/t/028-req-header.t
deleted file mode 100644
index 21da3fc1a..000000000
--- a/src/deps/src/lua-nginx-module/t/028-req-header.t
+++ /dev/null
@@ -1,2415 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (2 * blocks() + 48);
-
-#no_diff();
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: random access req headers
---- config
- location /req-header {
- content_by_lua '
- local headers, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("Foo: ", headers["Foo"] or "nil")
- ngx.say("Bar: ", headers["Bar"] or "nil")
- ';
- }
---- request
-GET /req-header
---- more_headers
-Foo: bar
-Bar: baz
---- response_body
-Foo: bar
-Bar: baz
---- log_level: debug
---- no_error_log
-lua exceeding request header limit
-
-
-
-=== TEST 2: iterating through headers
---- config
- location /req-header {
- content_by_lua '
- local headers, err = ngx.req.get_headers(nil, true)
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- local h = {}
- for k, v in pairs(headers) do
- h[k] = v
- end
- if (ngx.req.http_version() == 3 or ngx.req.http_version() == 2) then
- ngx.say("Foo: ", h["foo"] or "nil")
- ngx.say("Bar: ", h["bar"] or "nil")
- else
- ngx.say("Foo: ", h["Foo"] or "nil")
- ngx.say("Bar: ", h["Bar"] or "nil")
- end
- ';
- }
---- request
-GET /req-header
---- more_headers
-Foo: bar
-Bar: baz
---- response_body
-Foo: bar
-Bar: baz
-
-
-
-=== TEST 3: set input header
---- config
- location /req-header {
- rewrite_by_lua '
- ngx.req.set_header("Foo", "new value");
- ';
-
- echo "Foo: $http_foo";
- }
---- request
-GET /req-header
---- more_headers
-Foo: bar
-Bar: baz
---- response_body
-Foo: new value
-
-
-
-=== TEST 4: clear input header
---- config
- location /req-header {
- rewrite_by_lua '
- ngx.req.set_header("Foo", nil);
- ';
-
- echo "Foo: $http_foo";
- }
---- request
-GET /req-header
---- more_headers
-Foo: bar
-Bar: baz
---- response_body
-Foo:
-
-
-
-=== TEST 5: rewrite content length
---- config
- location /bar {
- rewrite_by_lua '
- ngx.req.set_header("Content-Length", 2048)
- ';
- echo_read_request_body;
- echo_request_body;
- }
---- request eval
-"POST /bar\n" .
-"a" x 4096
---- response_body eval
-"a" x 2048
---- timeout: 15
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
---- no_http2
-
-
-
-=== TEST 6: rewrite content length (normalized form)
---- config
- location /bar {
- rewrite_by_lua '
- ngx.req.set_header("content-length", 2048)
- ';
- echo_read_request_body;
- echo_request_body;
- }
---- request eval
-"POST /bar\n" .
-"a" x 4096
---- response_body eval
-"a" x 2048
---- timeout: 15
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
---- no_http2
-
-
-
-=== TEST 7: rewrite host and user-agent
---- config
- location /bar {
- rewrite_by_lua '
- ngx.req.set_header("Host", "foo")
- ngx.req.set_header("User-Agent", "blah")
- ';
- echo "Host: $host";
- echo "User-Agent: $http_user_agent";
- }
---- request
-GET /bar
---- response_body
-Host: foo
-User-Agent: blah
-
-
-
-=== TEST 8: clear host and user-agent
-$host always has a default value and cannot be really cleared.
---- config
- location /bar {
- rewrite_by_lua '
- ngx.req.set_header("Host", nil)
- ngx.req.set_header("User-Agent", nil)
- ';
- echo "Host: $host";
- echo "Host (2): $http_host";
- echo "User-Agent: $http_user_agent";
- }
---- request
-GET /bar
---- response_body
-Host: localhost
-Host (2):
-User-Agent:
-
-
-
-=== TEST 9: clear host and user-agent (the other way)
---- config
- location /bar {
- rewrite_by_lua '
- ngx.req.clear_header("Host")
- ngx.req.clear_header("User-Agent")
- ngx.req.clear_header("X-Foo")
- ';
- echo "Host: $host";
- echo "User-Agent: $http_user_agent";
- echo "X-Foo: $http_x_foo";
- }
---- request
-GET /bar
---- more_headers
-X-Foo: bar
---- response_body
-Host: localhost
-User-Agent:
-X-Foo:
-
-
-
-=== TEST 10: clear content-length
---- config
- location /bar {
- access_by_lua '
- ngx.req.clear_header("Content-Length")
- ';
- echo "Content-Length: $http_content_length";
- }
---- request
-POST /bar
-hello
---- more_headers
---- response_body
-Content-Length:
-
-
-
-=== TEST 11: rewrite type
---- config
- location /bar {
- access_by_lua '
- ngx.req.set_header("Content-Type", "text/css")
- ';
- echo "Content-Type: $content_type";
- }
---- request
-POST /bar
-hello
---- more_headers
-Content-Type: text/plain
---- response_body
-Content-Type: text/css
-
-
-
-=== TEST 12: clear type
---- config
- location /bar {
- access_by_lua '
- ngx.req.clear_header("Content-Type")
- ';
- echo "Content-Type: $content_type";
- }
---- request
-POST /bar
-hello
---- more_headers
-Content-Type: text/plain
---- response_body
-Content-Type:
-
-
-
-=== TEST 13: add multiple request headers
---- config
- location /bar {
- access_by_lua '
- ngx.req.set_header("Foo", {"a", "b"})
- ';
- echo "Foo: $http_foo";
- }
---- request
-GET /bar
---- response_body eval
-# Since nginx version 1.23.0, nginx combines same $http_* variable together
-$Test::Nginx::Util::NginxVersion >= 1.023000 ?
-
-"Foo: a, b\n"
-:
-"Foo: a\n"
-
-
-
-=== TEST 14: add multiple request headers
---- config
- location /bar {
- access_by_lua '
- ngx.req.set_header("Foo", {"a", "abc"})
- ';
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location = /foo {
- echo $echo_client_request_headers;
- }
---- request
-GET /bar
---- response_body_like chomp
-\bFoo: a\r\n.*?\bFoo: abc\b
-
-
-
-=== TEST 15: set_header and clear_header should refresh ngx.req.get_headers() automatically
---- config
- location /foo {
- content_by_lua '
- local headers, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("Foo: ", headers["Foo"] or "nil")
-
- ngx.req.set_header("Foo", 32)
-
- headers, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("Foo 1: ", headers["Foo"] or "nil")
-
- ngx.req.set_header("Foo", "abc")
-
- headers, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("Foo 2: ", headers["Foo"] or "nil")
-
- ngx.req.clear_header("Foo")
-
- headers, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("Foo 3: ", headers["Foo"] or "nil")
- ';
- }
---- more_headers
-Foo: foo
-
---- request
- GET /foo
---- response_body
-Foo: foo
-Foo 1: 32
-Foo 2: abc
-Foo 3: nil
-
-
-
-=== TEST 16: duplicate req headers
---- config
- location /foo {
- content_by_lua '
- collectgarbage()
- local headers, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- local vals = headers["Foo"]
- ngx.say("value is of type ", type(vals), ".")
- if type(vals) == "table" then
- ngx.say("Foo takes ", #vals or "nil", " values.")
- ngx.say("They are ", table.concat(vals, ", "), ".")
- end
- ';
- }
---- more_headers
-Foo: foo
-Foo: bar
-Foo: baz
---- request
- GET /foo
---- response_body
-value is of type table.
-Foo takes 3 values.
-They are foo, bar, baz.
-
-
-
-=== TEST 17: Accept-Encoding (scalar)
---- config
- location /bar {
- default_type 'text/plain';
- rewrite_by_lua '
- ngx.req.set_header("Accept-Encoding", "gzip")
- ';
- gzip on;
- gzip_min_length 1;
- gzip_buffers 4 8k;
- gzip_types text/plain;
- }
---- user_files
-">>> bar
-" . ("hello" x 512)
---- request
-GET /bar
---- response_headers
-Content-Encoding: gzip
---- response_body_like: .{20}
-
-
-
-=== TEST 18: Accept-Encoding (table)
---- config
- location /bar {
- default_type 'text/plain';
- rewrite_by_lua '
- ngx.req.set_header("Accept-Encoding", {"gzip"})
- ';
- gzip on;
- gzip_min_length 1;
- gzip_buffers 4 8k;
- gzip_types text/plain;
- }
---- user_files
-">>> bar
-" . ("hello" x 512)
---- request
-GET /bar
---- response_headers
-Content-Encoding: gzip
---- response_body_like: .{20}
-
-
-
-=== TEST 19: exceeding default max 100 header limit
---- config
- location /lua {
- content_by_lua '
- local headers, err = ngx.req.get_headers()
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(headers) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, ": ", headers[key])
- end
- ';
- }
---- request
-GET /lua
---- more_headers eval
-my $i = 1;
-my $s;
-while ($i <= 99) {
- $s .= "X-$i:$i\n";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-my $i = 1;
-while ($i <= 98) {
- push @k, "x-$i";
- $i++;
-}
-push @k, "connection: close\n";
-push @k, "host: localhost\n";
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= ": $&\n";
- }
-}
-"err: truncated\n" . CORE::join("", @k);
---- timeout: 4
---- error_log
-lua exceeding request header limit 101 > 100
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
---- no_http2
-
-
-
-=== TEST 20: NOT exceeding default max 100 header limit
---- config
- location /lua {
- content_by_lua '
- local headers, err = ngx.req.get_headers()
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(headers) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- local cnt = 0
- for i, key in ipairs(keys) do
- ngx.say(key, ": ", headers[key])
- cnt = cnt + 1
- end
- ngx.say("found ", cnt, " headers")
- ';
- }
---- request
-GET /lua
---- more_headers eval
-my $i = 1;
-my $s;
-while ($i <= 98) {
- $s .= "X-$i:$i\n";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- push @k, "host: localhost\n";
-}
-my $i = 1;
-while ($i <= 98) {
- push @k, "x-$i";
- $i++;
-}
-
-my $found_headers = "found 99 headers\n";
-if (!defined($ENV{TEST_NGINX_USE_HTTP3}) && !defined($ENV{TEST_NGINX_USE_HTTP2})) {
- push @k, "connection: close\n";
- push @k, "host: localhost\n";
- $found_headers = "found 100 headers\n";
-}
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= ": $&\n";
- }
-}
-
-CORE::join("", @k) . $found_headers;
---- timeout: 4
---- no_error_log
-[error]
-lua exceeding request header limit
-
-
-
-=== TEST 21: exceeding custom max 102 header limit
---- config
- location /lua {
- content_by_lua '
- local headers, err = ngx.req.get_headers(102)
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(headers) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, ": ", headers[key])
- end
- ';
- }
---- request
-GET /lua
---- more_headers eval
-my $i = 1;
-my $s;
-while ($i <= 101) {
- $s .= "X-$i:$i\n";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- push @k, "host: localhost\n";
-}
-my $i = 1;
-while ($i <= 100) {
- push @k, "x-$i";
- $i++;
-}
-push @k, "connection: close\n";
-push @k, "host: localhost\n";
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= ": $&\n";
- }
-}
-"err: truncated\n" . CORE::join("", @k);
---- timeout: 4
---- error_log
-lua exceeding request header limit 103 > 102
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
---- no_http2
-
-
-
-=== TEST 22: NOT exceeding custom max 102 header limit
---- config
- location /lua {
- content_by_lua '
- local headers, err = ngx.req.get_headers(102)
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(headers) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, ": ", headers[key])
- end
- ';
- }
---- request
-GET /lua
---- more_headers eval
-my $i = 1;
-my $s;
-while ($i <= 100) {
- $s .= "X-$i:$i\n";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- push @k, "host: localhost\n";
-}
-my $i = 1;
-while ($i <= 100) {
- push @k, "x-$i";
- $i++;
-}
-
-if (!defined($ENV{TEST_NGINX_USE_HTTP3}) && !defined($ENV{TEST_NGINX_USE_HTTP2})) {
- push @k, "connection: close\n";
- push @k, "host: localhost\n";
-}
-
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= ": $&\n";
- }
-}
-CORE::join("", @k);
---- timeout: 4
---- no_error_log
-[error]
-lua exceeding request header limit
-
-
-
-=== TEST 23: custom unlimited headers
---- config
- location /lua {
- content_by_lua '
- local headers, err = ngx.req.get_headers(0)
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(headers) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, ": ", headers[key])
- end
- ';
- }
---- request
-GET /lua
---- more_headers eval
-my $s;
-my $i = 1;
-while ($i <= 105) {
- $s .= "X-$i:$i\n";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-if (defined($ENV{TEST_NGINX_USE_HTTP3}) || defined($ENV{TEST_NGINX_USE_HTTP2})) {
- push @k, "host: localhost\n";
-}
-my $i = 1;
-while ($i <= 105) {
- push @k, "x-$i";
- $i++;
-}
-if (!defined($ENV{TEST_NGINX_USE_HTTP3}) && !defined($ENV{TEST_NGINX_USE_HTTP2})) {
- push @k, "connection: close\n";
- push @k, "host: localhost\n";
-}
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= ": $&\n";
- }
-}
-CORE::join("", @k);
---- timeout: 4
-
-
-
-=== TEST 24: modify subrequest req headers should not affect the parent
---- config
- location = /main {
- rewrite_by_lua '
- local res = ngx.location.capture("/sub")
- print("subrequest: ", res.status)
- ';
-
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
-
- location /sub {
- content_by_lua '
- ngx.req.set_header("foo121", 121)
- ngx.req.set_header("foo122", 122)
- ngx.say("ok")
- ';
- }
-
- location = /echo {
- #echo $echo_client_request_headers;
- echo "foo121: [$http_foo121]";
- echo "foo122: [$http_foo122]";
- }
---- request
-GET /main
---- more_headers
-Foo: foo
-Bar: bar
-Foo1: foo1
-Foo2: foo2
-Foo3: foo3
-Foo4: foo4
-Foo5: foo5
-Foo6: foo6
-Foo7: foo7
-Foo8: foo8
-Foo9: foo9
-Foo10: foo10
-Foo11: foo11
-Foo12: foo12
-Foo13: foo13
-Foo14: foo14
-Foo15: foo15
-Foo16: foo16
-Foo17: foo17
-Foo18: foo18
-Foo19: foo19
-Foo20: foo20
---- response_body
-Foo: []
-Bar: []
---- SKIP
-
-
-
-=== TEST 25: clear_header should clear all the instances of the user custom header
---- config
- location = /t {
- rewrite_by_lua '
- ngx.req.clear_header("Foo")
- ';
-
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
-
- location = /echo {
- echo "Foo: [$http_foo]";
- echo "Test-Header: [$http_test_header]";
- }
---- request
-GET /t
---- more_headers
-Foo: foo
-Foo: bah
-Test-Header: 1
---- response_body
-Foo: []
-Test-Header: [1]
-
-
-
-=== TEST 26: clear_header should clear all the instances of the builtin header
---- config
- location = /t {
- rewrite_by_lua '
- ngx.req.clear_header("Content-Type")
- ';
-
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
-
- location = /echo {
- echo "Content-Type: [$http_content_type]";
- echo "Test-Header: [$http_test_header]";
- #echo $echo_client_request_headers;
- }
---- request
-GET /t
---- more_headers
-Content-Type: foo
-Content-Type: bah
-Test-Header: 1
---- response_body
-Content-Type: []
-Test-Header: [1]
-
-
-
-=== TEST 27: Converting POST to GET - clearing headers (bug found by Matthieu Tourne, 411 error page)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.clear_header("Content-Type")
- ngx.req.clear_header("Content-Length")
- ';
-
- #proxy_pass http://127.0.0.1:8888;
- proxy_pass http://127.0.0.1:$server_port/back;
- }
-
- location /back {
- echo -n $echo_client_request_headers;
- }
---- request
-POST /t
-hello world
---- more_headers
-Content-Type: application/ocsp-request
-Test-Header: 1
---- response_body_like eval
-my $body;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $body = qr/Connection: close\r
-test-header: 1\r
-\r
-$/;
-} else {
- $body = qr/Connection: close\r
-Test-Header: 1\r
-\r
-$/;
-}
-
-$body;
---- no_error_log
-[error]
-
-
-
-=== TEST 28: clear_header() does not duplicate subsequent headers (old bug)
---- config
- location = /t {
- rewrite_by_lua '
- ngx.req.clear_header("Foo")
- ';
-
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
-
- location = /echo {
- echo $echo_client_request_headers;
- }
---- request
-GET /t
---- more_headers
-Bah: bah
-Foo: foo
-Test-Header: 1
-Foo1: foo1
-Foo2: foo2
-Foo3: foo3
-Foo4: foo4
-Foo5: foo5
-Foo6: foo6
-Foo7: foo7
-Foo8: foo8
-Foo9: foo9
-Foo10: foo10
-Foo11: foo11
-Foo12: foo12
-Foo13: foo13
-Foo14: foo14
-Foo15: foo15
-Foo16: foo16
-Foo17: foo17
-Foo18: foo18
-Foo19: foo19
-Foo20: foo20
-Foo21: foo21
-Foo22: foo22
---- response_body_like eval
-my $headers;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $headers = qr/bah: bah\r
-test-header: 1\r
-foo1: foo1\r
-foo2: foo2\r
-foo3: foo3\r
-foo4: foo4\r
-foo5: foo5\r
-foo6: foo6\r
-foo7: foo7\r
-foo8: foo8\r
-foo9: foo9\r
-foo10: foo10\r
-foo11: foo11\r
-foo12: foo12\r
-foo13: foo13\r
-foo14: foo14\r
-foo15: foo15\r
-foo16: foo16\r
-foo17: foo17\r
-foo18: foo18\r
-foo19: foo19\r
-foo20: foo20\r
-foo21: foo21\r
-foo22: foo22\r
-/;
-} else {
- $headers = qr/Bah: bah\r
-Test-Header: 1\r
-Foo1: foo1\r
-Foo2: foo2\r
-Foo3: foo3\r
-Foo4: foo4\r
-Foo5: foo5\r
-Foo6: foo6\r
-Foo7: foo7\r
-Foo8: foo8\r
-Foo9: foo9\r
-Foo10: foo10\r
-Foo11: foo11\r
-Foo12: foo12\r
-Foo13: foo13\r
-Foo14: foo14\r
-Foo15: foo15\r
-Foo16: foo16\r
-Foo17: foo17\r
-Foo18: foo18\r
-Foo19: foo19\r
-Foo20: foo20\r
-Foo21: foo21\r
-Foo22: foo22\r
-/;
-}
-
-$headers;
-
-
-
-=== TEST 29: iterating through headers (raw form)
---- config
- location /t {
- content_by_lua '
- local h = {}
- local arr = {}
- local headers, err = ngx.req.get_headers(nil, true)
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- for k, v in pairs(headers) do
- h[k] = v
- table.insert(arr, k)
- end
- table.sort(arr)
- for i, k in ipairs(arr) do
- ngx.say(k, ": ", h[k])
- end
- ';
- }
---- request
-GET /t
---- more_headers
-My-Foo: bar
-Bar: baz
---- response_body eval
-my $body;
-if ($ENV{TEST_NGINX_USE_HTTP3} || $ENV{TEST_NGINX_USE_HTTP2}) {
- $body = "bar: baz
-host: localhost
-my-foo: bar
-";
-} else {
- $body = "Bar: baz
-Connection: close
-Host: localhost
-My-Foo: bar
-";
-}
-$body;
-
-
-
-=== TEST 30: __index metamethod not working for "raw" mode
---- config
- location /t {
- content_by_lua '
- local h, err = ngx.req.get_headers(nil, true)
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("My-Foo-Header: ", h.my_foo_header)
- ';
- }
---- request
-GET /t
---- more_headers
-My-Foo-Header: Hello World
---- response_body
-My-Foo-Header: nil
-
-
-
-=== TEST 31: __index metamethod not working for the default mode
---- config
- location /t {
- content_by_lua '
- local h, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("My-Foo-Header: ", h.my_foo_header)
- ';
- }
---- request
-GET /t
---- more_headers
-My-Foo-Header: Hello World
---- response_body
-My-Foo-Header: Hello World
-
-
-
-=== TEST 32: clear input header (just more than 20 headers)
---- config
- location = /t {
- rewrite_by_lua 'ngx.req.clear_header("R")';
- proxy_pass http://127.0.0.1:$server_port/back;
- proxy_set_header Host foo;
- #proxy_pass http://127.0.0.1:1234/back;
- }
-
- location = /back {
- echo -n $echo_client_request_headers;
- }
---- request
-GET /t
---- more_headers eval
-my $s = "User-Agent: curl\n";
-
-for my $i ('a' .. 'r') {
- $s .= uc($i) . ": " . "$i\n"
-}
-$s
---- response_body eval
-my $s = "GET /back HTTP/1.0\r
-Host: foo\r
-Connection: close\r\n";
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $s .= "user-agent: curl\r\n";
- for my $i ('a' .. 'q') {
- $s .= $i . ": " . "$i\r\n"
- }
-} else {
- $s .= "User-Agent: curl\r\n";
- for my $i ('a' .. 'q') {
- $s .= uc($i) . ": " . "$i\r\n"
- }
-}
-
-$s . "\r\n";
-
-
-
-=== TEST 33: clear input header (just more than 20 headers, and add more)
---- config
- location = /t {
- rewrite_by_lua '
- ngx.req.clear_header("R")
- for i = 1, 21 do
- ngx.req.set_header("foo-" .. i, i)
- end
- ';
- proxy_pass http://127.0.0.1:$server_port/back;
- proxy_set_header Host foo;
- #proxy_pass http://127.0.0.1:1234/back;
- }
-
- location = /back {
- echo -n $echo_client_request_headers;
- }
---- request
-GET /t
---- more_headers eval
-my $s = "User-Agent: curl\n";
-
-for my $i ('a' .. 'r') {
- $s .= uc($i) . ": " . "$i\n"
-}
-$s
---- response_body eval
-my $body;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $body = "GET /back HTTP/1.0\r
-Host: foo\r
-Connection: close\r
-user-agent: curl\r
-a: a\r
-b: b\r
-c: c\r
-d: d\r
-e: e\r
-f: f\r
-g: g\r
-h: h\r
-i: i\r
-j: j\r
-k: k\r
-l: l\r
-m: m\r
-n: n\r
-o: o\r
-p: p\r
-q: q\r
-foo-1: 1\r
-foo-2: 2\r
-foo-3: 3\r
-foo-4: 4\r
-foo-5: 5\r
-foo-6: 6\r
-foo-7: 7\r
-foo-8: 8\r
-foo-9: 9\r
-foo-10: 10\r
-foo-11: 11\r
-foo-12: 12\r
-foo-13: 13\r
-foo-14: 14\r
-foo-15: 15\r
-foo-16: 16\r
-foo-17: 17\r
-foo-18: 18\r
-foo-19: 19\r
-foo-20: 20\r
-foo-21: 21\r
-\r
-";
-} else {
- $body = "GET /back HTTP/1.0\r
-Host: foo\r
-Connection: close\r
-User-Agent: curl\r
-A: a\r
-B: b\r
-C: c\r
-D: d\r
-E: e\r
-F: f\r
-G: g\r
-H: h\r
-I: i\r
-J: j\r
-K: k\r
-L: l\r
-M: m\r
-N: n\r
-O: o\r
-P: p\r
-Q: q\r
-foo-1: 1\r
-foo-2: 2\r
-foo-3: 3\r
-foo-4: 4\r
-foo-5: 5\r
-foo-6: 6\r
-foo-7: 7\r
-foo-8: 8\r
-foo-9: 9\r
-foo-10: 10\r
-foo-11: 11\r
-foo-12: 12\r
-foo-13: 13\r
-foo-14: 14\r
-foo-15: 15\r
-foo-16: 16\r
-foo-17: 17\r
-foo-18: 18\r
-foo-19: 19\r
-foo-20: 20\r
-foo-21: 21\r
-\r
-";
-}
-
-$body;
-
-
-
-=== TEST 34: clear input header (just more than 21 headers)
---- config
- location = /t {
- rewrite_by_lua '
- ngx.req.clear_header("R")
- ngx.req.clear_header("Q")
- ';
- proxy_pass http://127.0.0.1:$server_port/back;
- proxy_set_header Host foo;
- #proxy_pass http://127.0.0.1:1234/back;
- }
-
- location = /back {
- echo -n $echo_client_request_headers;
- }
---- request
-GET /t
---- more_headers eval
-my $s = "User-Agent: curl\nBah: bah\n";
-
-for my $i ('a' .. 'r') {
- $s .= uc($i) . ": " . "$i\n"
-}
-$s
---- response_body eval
-my $body;
-
-if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $body = "GET /back HTTP/1.0\r
-Host: foo\r
-Connection: close\r
-user-agent: curl\r
-bah: bah\r
-a: a\r
-b: b\r
-c: c\r
-d: d\r
-e: e\r
-f: f\r
-g: g\r
-h: h\r
-i: i\r
-j: j\r
-k: k\r
-l: l\r
-m: m\r
-n: n\r
-o: o\r
-p: p\r
-\r
-"
-} else {
-$body = "GET /back HTTP/1.0\r
-Host: foo\r
-Connection: close\r
-User-Agent: curl\r
-Bah: bah\r
-A: a\r
-B: b\r
-C: c\r
-D: d\r
-E: e\r
-F: f\r
-G: g\r
-H: h\r
-I: i\r
-J: j\r
-K: k\r
-L: l\r
-M: m\r
-N: n\r
-O: o\r
-P: p\r
-\r
-"
-}
-
-$body;
-
-
-
-=== TEST 35: clear input header (just more than 21 headers)
---- config
- location = /t {
- rewrite_by_lua '
- ngx.req.clear_header("R")
- ngx.req.clear_header("Q")
- for i = 1, 21 do
- ngx.req.set_header("foo-" .. i, i)
- end
- ';
- proxy_pass http://127.0.0.1:$server_port/back;
- proxy_set_header Host foo;
- #proxy_pass http://127.0.0.1:1234/back;
- }
-
- location = /back {
- echo -n $echo_client_request_headers;
- }
---- request
-GET /t
---- more_headers eval
-my $s = "User-Agent: curl\nBah: bah\n";
-
-for my $i ('a' .. 'r') {
- $s .= uc($i) . ": " . "$i\n"
-}
-$s
---- response_body eval
-my $body;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $body = "GET /back HTTP/1.0\r
-Host: foo\r
-Connection: close\r
-user-agent: curl\r
-bah: bah\r
-a: a\r
-b: b\r
-c: c\r
-d: d\r
-e: e\r
-f: f\r
-g: g\r
-h: h\r
-i: i\r
-j: j\r
-k: k\r
-l: l\r
-m: m\r
-n: n\r
-o: o\r
-p: p\r
-foo-1: 1\r
-foo-2: 2\r
-foo-3: 3\r
-foo-4: 4\r
-foo-5: 5\r
-foo-6: 6\r
-foo-7: 7\r
-foo-8: 8\r
-foo-9: 9\r
-foo-10: 10\r
-foo-11: 11\r
-foo-12: 12\r
-foo-13: 13\r
-foo-14: 14\r
-foo-15: 15\r
-foo-16: 16\r
-foo-17: 17\r
-foo-18: 18\r
-foo-19: 19\r
-foo-20: 20\r
-foo-21: 21\r
-\r
-";
-} else {
- $body = "GET /back HTTP/1.0\r
-Host: foo\r
-Connection: close\r
-User-Agent: curl\r
-Bah: bah\r
-A: a\r
-B: b\r
-C: c\r
-D: d\r
-E: e\r
-F: f\r
-G: g\r
-H: h\r
-I: i\r
-J: j\r
-K: k\r
-L: l\r
-M: m\r
-N: n\r
-O: o\r
-P: p\r
-foo-1: 1\r
-foo-2: 2\r
-foo-3: 3\r
-foo-4: 4\r
-foo-5: 5\r
-foo-6: 6\r
-foo-7: 7\r
-foo-8: 8\r
-foo-9: 9\r
-foo-10: 10\r
-foo-11: 11\r
-foo-12: 12\r
-foo-13: 13\r
-foo-14: 14\r
-foo-15: 15\r
-foo-16: 16\r
-foo-17: 17\r
-foo-18: 18\r
-foo-19: 19\r
-foo-20: 20\r
-foo-21: 21\r
-\r
-"
-}
-
-$body;
-
-
-
-=== TEST 36: raw form
---- config
- location /t {
- content_by_lua '
- local headers, err = ngx.req.get_headers(0, true)
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- -- get ALL the raw headers (0 == no limit, not recommended)
- local h = {}
- local arr = {}
- for k, v in pairs(headers) do
- h[k] = v
- table.insert(arr, k)
- end
- table.sort(arr)
- for i, k in ipairs(arr) do
- ngx.say(k, ": ", h[k])
- end
- ';
- }
---- request
-GET /t
---- more_headers
-My-Foo: bar
-Bar: baz
---- response_body eval
-my $body;
-
-if (defined($ENV{TEST_NGINX_USE_HTTP3})|| defined($ENV{TEST_NGINX_USE_HTTP2})) {
- $body="bar: baz
-host: localhost
-my-foo: bar
-";
-} else {
- $body="Bar: baz
-Connection: close
-Host: localhost
-My-Foo: bar
-";
-}
-
-$body;
---- no_error_log
-[error]
-
-
-
-=== TEST 37: clear X-Real-IP
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("X-Real-IP", nil)
- ';
- echo "X-Real-IP: $http_x_real_ip";
- }
---- request
-GET /t
---- more_headers
-X-Real-IP: 8.8.8.8
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
- printf("rewrite: x-real-ip: %s\n",
- user_string_n($r->headers_in->x_real_ip->value->data,
- $r->headers_in->x_real_ip->value->len))
- } else {
- println("rewrite: no x-real-ip")
- }
-}
-
-F(ngx_http_core_content_phase) {
- if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
- printf("content: x-real-ip: %s\n",
- user_string_n($r->headers_in->x_real_ip->value->data,
- $r->headers_in->x_real_ip->value->len))
- } else {
- println("content: no x-real-ip")
- }
-}
-
---- stap_out
-rewrite: x-real-ip: 8.8.8.8
-content: no x-real-ip
-
---- response_body
-X-Real-IP:
-
---- no_error_log
-[error]
-
-
-
-=== TEST 38: set custom X-Real-IP
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("X-Real-IP", "8.8.4.4")
- ';
- echo "X-Real-IP: $http_x_real_ip";
- }
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
- printf("rewrite: x-real-ip: %s\n",
- user_string_n($r->headers_in->x_real_ip->value->data,
- $r->headers_in->x_real_ip->value->len))
- } else {
- println("rewrite: no x-real-ip")
- }
-
-}
-
-F(ngx_http_core_content_phase) {
- if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
- printf("content: x-real-ip: %s\n",
- user_string_n($r->headers_in->x_real_ip->value->data,
- $r->headers_in->x_real_ip->value->len))
- } else {
- println("content: no x-real-ip")
- }
-}
-
---- stap_out
-rewrite: no x-real-ip
-content: x-real-ip: 8.8.4.4
-
---- response_body
-X-Real-IP: 8.8.4.4
-
---- no_error_log
-[error]
-
-
-
-=== TEST 39: clear Via
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("Via", nil)
- ';
- echo "Via: $http_via";
- }
---- request
-GET /t
---- more_headers
-Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- if (@defined($r->headers_in->via) && $r->headers_in->via) {
- printf("rewrite: via: %s\n",
- user_string_n($r->headers_in->via->value->data,
- $r->headers_in->via->value->len))
- } else {
- println("rewrite: no via")
- }
-}
-
-F(ngx_http_core_content_phase) {
- if (@defined($r->headers_in->via) && $r->headers_in->via) {
- printf("content: via: %s\n",
- user_string_n($r->headers_in->via->value->data,
- $r->headers_in->via->value->len))
- } else {
- println("content: no via")
- }
-}
-
---- stap_out
-rewrite: via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
-content: no via
-
---- response_body
-Via:
-
---- no_error_log
-[error]
-
-
-
-=== TEST 40: set custom Via
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("Via", "1.0 fred, 1.1 nowhere.com (Apache/1.1)")
- ';
- echo "Via: $http_via";
- }
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- if (@defined($r->headers_in->via) && $r->headers_in->via) {
- printf("rewrite: via: %s\n",
- user_string_n($r->headers_in->via->value->data,
- $r->headers_in->via->value->len))
- } else {
- println("rewrite: no via")
- }
-
-}
-
-F(ngx_http_core_content_phase) {
- if (@defined($r->headers_in->via) && $r->headers_in->via) {
- printf("content: via: %s\n",
- user_string_n($r->headers_in->via->value->data,
- $r->headers_in->via->value->len))
- } else {
- println("content: no via")
- }
-}
-
---- stap_out
-rewrite: no via
-content: via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
-
---- response_body
-Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
-
---- no_error_log
-[error]
-
-
-
-=== TEST 41: set input header (with underscores in the header name)
---- config
- location /req-header {
- rewrite_by_lua '
- ngx.req.set_header("foo_bar", "some value");
- ';
- proxy_pass http://127.0.0.1:$server_port/back;
- }
- location = /back {
- echo -n $echo_client_request_headers;
- }
---- request
-GET /req-header
---- response_body_like eval
-qr{^GET /back HTTP/1.0\r
-Host: 127.0.0.1:\d+\r
-Connection: close\r
-foo_bar: some value\r
-\r
-$}
-
-
-
-=== TEST 42: HTTP 0.9 (set & get)
---- config
- location /foo {
- content_by_lua '
- ngx.req.set_header("X-Foo", "howdy");
- local headers, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("X-Foo: ", headers["X-Foo"])
- ';
- }
---- raw_request eval
-"GET /foo\r\n"
---- response_headers
-! X-Foo
---- response_body
-X-Foo: nil
---- http09
---- no_error_log
-[error]
-
-
-
-=== TEST 43: HTTP 0.9 (clear)
---- config
- location /foo {
- content_by_lua '
- ngx.req.set_header("X-Foo", "howdy");
- local headers, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("X-Foo: ", headers["X-Foo"])
- ';
- }
---- raw_request eval
-"GET /foo\r\n"
---- response_headers
-! X-Foo
---- response_body
-X-Foo: nil
---- http09
---- no_error_log
-[error]
-
-
-
-=== TEST 44: Host header with port and $host (github issue #292)
---- config
- location /bar {
- rewrite_by_lua '
- ngx.req.set_header("Host", "agentzh.org:1984")
- ';
- echo "host var: $host";
- echo "http_host var: $http_host";
- }
---- request
-GET /bar
---- response_body
-host var: agentzh.org
-http_host var: agentzh.org:1984
-
-
-
-=== TEST 45: Host header with upper case letters and $host (github issue #292)
---- config
- location /bar {
- rewrite_by_lua '
- ngx.req.set_header("Host", "agentZH.org:1984")
- ';
- echo "host var: $host";
- echo "http_host var: $http_host";
- }
---- request
-GET /bar
---- response_body
-host var: agentzh.org
-http_host var: agentZH.org:1984
-
-
-
-=== TEST 46: clear all and re-insert
---- config
- location = /t {
- content_by_lua '
- local headers, err = ngx.req.get_headers(100, true)
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- local n = 0
- for header, _ in pairs(headers) do
- n = n + 1
- ngx.req.clear_header(header)
- end
- ngx.say("got ", n, " headers")
- local i = 0
- for header, value in pairs(headers) do
- i = i + 1
- print("1: reinsert header ", header, ": ", i)
- ngx.req.set_header(header, value)
- end
-
- headers, err = ngx.req.get_headers(100, true)
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- n = 0
- for header, _ in pairs(headers) do
- n = n + 1
- ngx.req.clear_header(header)
- end
- ngx.say("got ", n, " headers")
- -- do return end
- local i = 0
- for header, value in pairs(headers) do
- i = i + 1
- if i > 8 then
- break
- end
- print("2: reinsert header ", header, ": ", i)
- ngx.req.set_header(header, value)
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-Cache-Control: max-age=0\r
-Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r
-User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36\r
-Accept-Encoding: gzip,deflate,sdch\r
-Accept-Language: en-US,en;q=0.8\r
-Cookie: test=cookie;\r
-\r
-"
---- response_body
-got 8 headers
-got 8 headers
---- no_error_log
-[error]
-
-
-
-=== TEST 47: github issue #314: ngx.req.set_header does not override request headers with multiple values
---- config
- #lua_code_cache off;
- location = /t {
- content_by_lua '
- ngx.req.set_header("AAA", "111")
- local headers, err = ngx.req.get_headers()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- ngx.say(headers["AAA"])
- ';
- }
---- request
-GET /t
---- more_headers
-AAA: 123
-AAA: 456
-AAA: 678
-
---- response_body
-111
---- no_error_log
-[error]
-
-
-
-=== TEST 48: clear If-Match req header
---- config
- location /t {
- content_by_lua '
- ngx.req.clear_header("if-match")
- if not ngx.send_headers() then
- return
- end
- ngx.say("test")
- ';
- }
---- request
-GET /t
---- more_headers
-If-Match: abc
---- response_body
-test
---- no_error_log
-[error]
-
-
-
-=== TEST 49: clear If-Unmodified-Since req header
---- config
- location /t {
- content_by_lua '
- ngx.req.clear_header("if-unmodified-since")
- ngx.header["Last-Modified"] = "Tue, 30 Jun 2011 12:16:36 GMT"
- if not ngx.send_headers() then
- return
- end
- ngx.say("test")
- ';
- }
---- request
-GET /t
---- more_headers
-If-Unmodified-Since: Tue, 28 Jun 2011 12:16:36 GMT
---- response_body
-test
---- no_error_log
-[error]
-
-
-
-=== TEST 50: clear If-None-Match req header
---- config
- location /t {
- content_by_lua '
- ngx.req.clear_header("if-none-match")
- -- ngx.header["etags"] = "abc"
- if not ngx.send_headers() then
- return
- end
- ngx.say("test")
- ';
- }
---- request
-GET /t
---- more_headers
-If-None-Match: *
---- response_body
-test
---- no_error_log
-[error]
-
-
-
-=== TEST 51: set the Destination request header for WebDav
---- config
- location = /a.txt {
- rewrite_by_lua_block {
- ngx.req.set_header("Destination", "/b.txt")
- }
- dav_methods MOVE;
- dav_access all:rw;
- root html;
- }
-
---- user_files
->>> a.txt
-hello, world!
-
---- request
-MOVE /a.txt
-
---- response_body
---- no_error_log
-client sent no "Destination" header
-[error]
---- error_code: 204
-
-
-
-=== TEST 52: X-Forwarded-For
---- config
- location = /t {
- access_by_lua_block {
- ngx.req.set_header("X-Forwarded-For", "8.8.8.8")
- }
- proxy_pass http://127.0.0.1:$server_port/back;
- proxy_set_header Foo $proxy_add_x_forwarded_for;
- }
-
- location = /back {
- echo "Foo: $http_foo";
- }
-
---- request
-GET /t
-
---- response_body
-Foo: 8.8.8.8, 127.0.0.1
---- no_error_log
-[error]
-
-
-
-=== TEST 53: X-Forwarded-For
---- config
- location = /t {
- access_by_lua_block {
- ngx.req.clear_header("X-Forwarded-For")
- }
- proxy_pass http://127.0.0.1:$server_port/back;
- proxy_set_header Foo $proxy_add_x_forwarded_for;
- }
-
- location = /back {
- echo "Foo: $http_foo";
- }
-
---- request
-GET /t
-
---- more_headers
-X-Forwarded-For: 8.8.8.8
---- response_body
-Foo: 127.0.0.1
---- no_error_log
-[error]
-
-
-
-=== TEST 54: for bad requests (bad request method letter case)
---- config
- error_page 400 = /err;
-
- location = /err {
- content_by_lua_block {
- ngx.req.set_header("Foo", "bar")
- ngx.say("ok")
- }
- }
---- raw_request
-GeT / HTTP/1.1
---- response_body
-ok
---- no_error_log
-[error]
---- no_check_leak
-
-
-
-=== TEST 55: for bad requests (bad request method names)
---- config
- error_page 400 = /err;
-
- location = /err {
- content_by_lua_block {
- ngx.req.set_header("Foo", "bar")
- ngx.say("ok")
- }
- }
---- raw_request
-GET x HTTP/1.1
---- response_body
-ok
---- no_error_log
-[error]
---- no_check_leak
-
-
-
-=== TEST 56: for bad requests causing segfaults when setting & getting multi-value headers
---- config
- error_page 400 = /err;
-
- location = /err {
- content_by_lua_block {
- ngx.req.set_header("Cookie", "foo=bar")
- local test = ngx.var.cookie_bar
-
- ngx.say("ok")
- }
- }
---- raw_request
-GeT / HTTP/1.1
---- response_body
-ok
---- no_error_log
-[error]
---- no_check_leak
-
-
-
-=== TEST 57: exceeding custom 3 header limit
---- config
- location /lua {
- content_by_lua '
- local headers, err = ngx.req.get_headers(3)
- if err then
- ngx.say("err: ", err)
- end
-
- local cnt = 0
- for key, val in pairs(headers) do
- cnt = cnt + 1
- end
-
- ngx.say("found ", cnt, " headers.");
- ';
- }
---- request
-GET /lua
---- more_headers eval
-my $i = 1;
-my $s;
-while ($i <= 2) {
- $s .= "X-$i:$i\n";
- $i++;
-}
-$s
---- response_body
-err: truncated
-found 3 headers.
---- timeout: 4
---- error_log
-lua exceeding request header limit 4 > 3
---- no_error_log
-[error]
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
---- no_http2
-
-
-
-=== TEST 58: NOT exceeding custom 3 header limit
---- config
- location /lua {
- content_by_lua '
- local headers, err = ngx.req.get_headers(3)
- if err then
- ngx.say("err: ", err)
- end
-
- local cnt = 0
- for key, val in pairs(headers) do
- cnt = cnt + 1
- end
-
- ngx.say("found ", cnt, " headers.");
- ';
- }
---- request
-GET /lua
---- more_headers eval
-my $i = 1;
-my $s;
-while ($i <= 1) {
- $s .= "X-$i:$i\n";
- $i++;
-}
-$s
---- response_body
-found 3 headers.
---- timeout: 4
---- no_error_log
-lua exceeding request header limit
-[error]
---- skip_eval: 4: $ENV{TEST_NGINX_USE_HTTP3}
---- no_http2
-
-
-
-=== TEST 59: exceeding custom 3 header limit (raw)
---- config
- location /lua {
- content_by_lua '
- local headers, err = ngx.req.get_headers(3, true)
- if err then
- ngx.say("err: ", err)
- end
-
- local cnt = 0
- for key, val in pairs(headers) do
- cnt = cnt + 1
- end
-
- ngx.say("found ", cnt, " headers.");
- ';
- }
---- request
-GET /lua
---- more_headers eval
-my $i = 1;
-my $s;
-while ($i <= 2) {
- $s .= "X-$i:$i\n";
- $i++;
-}
-$s
---- response_body
-err: truncated
-found 3 headers.
---- timeout: 4
---- error_log
-lua exceeding request header limit 4 > 3
---- no_error_log
-[error]
---- skip_eval: 4: $ENV{TEST_NGINX_USE_HTTP3}
---- no_http2
-
-
-
-=== TEST 60: NOT exceeding custom 3 header limit (raw)
---- config
- location /lua {
- content_by_lua '
- local headers, err = ngx.req.get_headers(3, true)
- if err then
- ngx.say("err: ", err)
- end
-
- local cnt = 0
- for key, val in pairs(headers) do
- cnt = cnt + 1
- end
-
- ngx.say("found ", cnt, " headers.");
- ';
- }
---- request
-GET /lua
---- more_headers eval
-my $i = 1;
-my $s;
-while ($i <= 1) {
- $s .= "X-$i:$i\n";
- $i++;
-}
-$s
---- response_body eval
-my $body;
-if (!defined $ENV{TEST_NGINX_USE_HTTP2}) {
- $body = "found 3 headers.
-";
-} else {
- $body = "found 2 headers.
-";
-}
-
-$body;
---- timeout: 4
---- no_error_log
-lua exceeding request header limit
-[error]
---- skip_eval: 4: $ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 61: setting Host header clears cached $host variable
---- config
- location /req-header {
- # this makes $host indexed and cacheable
- set $foo $host;
-
- content_by_lua_block {
- ngx.say(ngx.var.host)
- ngx.req.set_header("Host", "new");
- ngx.say(ngx.var.host)
- }
- }
---- request
-GET /req-header
---- response_body
-localhost
-new
---- no_error_log
-[error]
-
-
-
-=== TEST 62: unsafe header name (with '\r')
---- config
- location /req-header {
- rewrite_by_lua_block {
- ngx.req.set_header("Foo\rfoo", "new value");
- }
-
- echo "Foo: $http_foo";
- }
---- request
-GET /req-header
---- response_body
-Foo:
---- no_error_log
-[error]
-
-
-
-=== TEST 63: unsafe header value (with '\n')
---- config
- location /req-header {
- rewrite_by_lua_block {
- ngx.req.set_header("Foo", "new\nvalue");
- }
-
- echo "Foo: $http_foo";
- }
---- request
-GET /req-header
---- response_body
-Foo: new%0Avalue
---- no_error_log
-[error]
-
-
-
-=== TEST 64: multiple unsafe header values (with '\n' and '\t')
---- config
- location /req-header {
- rewrite_by_lua_block {
- ngx.req.set_header("Foo", { "new\nvalue", "foo\tbar" } );
- }
-
- content_by_lua_block {
- ngx.say(table.concat(ngx.req.get_headers()["foo"], ", "), ".")
- }
- }
---- request
-GET /req-header
---- response_body
-new%0Avalue, foo bar.
---- no_error_log
-[error]
-
-
-
-=== TEST 65: unsafe names/values logging escapes '"' and '\' characters
---- config
- location /req-header {
- rewrite_by_lua_block {
- ngx.req.set_header("Foo", "\"new\nvalue\\\"");
- }
-
- content_by_lua_block {
- ngx.say(ngx.req.get_headers()["foo"])
- }
- }
---- request
-GET /req-header
---- response_body
-"new%0Avalue\"
---- no_error_log
-[error]
-
-
-
-=== TEST 66: add request headers with '\r\n'
---- config
- location /bar {
- access_by_lua_block {
- ngx.req.set_header("Foo\r", "123\r\n")
- }
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location = /foo {
- echo $echo_client_request_headers;
- }
---- request
-GET /bar
---- response_body_like chomp
-\bFoo%0D: 123%0D%0A\b
-
-
-
-=== TEST 67: add request headers with '\0'
---- config
- location /bar {
- access_by_lua_block {
- ngx.req.set_header("Foo", "\0")
- }
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location = /foo {
- echo $echo_client_request_headers;
- }
---- request
-GET /bar
---- response_body_like chomp
-\bFoo: %00\b
-
-
-
-=== TEST 68: add request headers with '䏿–‡'
---- config
- location /bar {
- access_by_lua_block {
- ngx.req.set_header("Foo䏿–‡", "ab䏿–‡a")
- }
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location = /foo {
- echo $echo_client_request_headers;
- }
---- request
-GET /bar
---- response_body_like chomp
-\bFoo%E4%B8%AD%E6%96%87: ab䏿–‡a\r\n
diff --git a/src/deps/src/lua-nginx-module/t/029-http-time.t b/src/deps/src/lua-nginx-module/t/029-http-time.t
deleted file mode 100644
index ecef4921a..000000000
--- a/src/deps/src/lua-nginx-module/t/029-http-time.t
+++ /dev/null
@@ -1,87 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: http_time in content_by_lua
---- config
- location /lua {
- content_by_lua '
- ngx.say(ngx.http_time(1290079655))
- ';
- }
---- request
-GET /lua
---- response_body
-Thu, 18 Nov 2010 11:27:35 GMT
-
-
-
-=== TEST 2: http_time in set_by_lua
---- config
- location /lua {
- set_by_lua $a '
- return ngx.http_time(1290079655)
- ';
- echo $a;
- }
---- request
-GET /lua
---- response_body
-Thu, 18 Nov 2010 11:27:35 GMT
-
-
-
-=== TEST 3: parse_http_time in set_by_lua
---- config
- location /lua {
- set_by_lua $a '
- return ngx.parse_http_time("Thu, 18 Nov 2010 11:27:35 GMT")
- ';
- echo $a;
- }
---- request
-GET /lua
---- response_body
-1290079655
-
-
-
-=== TEST 4: parse_http_time in content_by_lua
---- config
- location /lua {
- content_by_lua '
- ngx.say(ngx.parse_http_time("Thu, 18 Nov 2010 11:27:35 GMT"))
- ';
- }
---- request
-GET /lua
---- response_body
-1290079655
-
-
-
-=== TEST 5: bad arg for parse_http_time in content_by_lua
---- config
- location /lua {
- content_by_lua '
- ngx.say(ngx.parse_http_time("abc") or "nil")
- ';
- }
---- request
-GET /lua
---- response_body
-nil
diff --git a/src/deps/src/lua-nginx-module/t/030-uri-args-with-ctrl.t b/src/deps/src/lua-nginx-module/t/030-uri-args-with-ctrl.t
deleted file mode 100644
index e74da38ee..000000000
--- a/src/deps/src/lua-nginx-module/t/030-uri-args-with-ctrl.t
+++ /dev/null
@@ -1,137 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 3);
-
-no_root_location();
-
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: rewrite args (string with \r)
---- config
- location /foo {
- rewrite_by_lua_block {
- ngx.req.set_uri_args("a\rb")
- }
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/echo;
- }
- location /echo {
- content_by_lua_block {
- ngx.say(ngx.var.request_uri);
- }
- }
---- request
-GET /foo?world
---- error_code: 200
---- response_body
-/echo?a%0Db
-
-
-
-=== TEST 2: rewrite args (string with \n)
---- config
- location /foo {
- rewrite_by_lua_block {
- ngx.req.set_uri_args("a\nb")
- }
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/echo;
- }
- location /echo {
- content_by_lua_block {
- ngx.say(ngx.var.request_uri);
- }
- }
---- request
-GET /foo?world
---- response_body
-/echo?a%0Ab
-
-
-
-=== TEST 3: rewrite args (string with \0)
---- config
- location /foo {
- rewrite_by_lua_block {
- ngx.req.set_uri_args("a\0b")
- }
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/echo;
- }
- location /echo {
- content_by_lua_block {
- ngx.say(ngx.var.request_uri);
- }
- }
---- request
-GET /foo?world
---- response_body
-/echo?a%00b
-
-
-
-=== TEST 4: rewrite args (string arg with 'lang=䏿–‡')
-ngx.req.set_uri_args with string argument should be carefully encoded.
-For backward compatibility, we are allowed to pass such parameters.
---- config
- location /foo {
- rewrite_by_lua_block {
- ngx.req.set_uri_args("lang=䏿–‡")
- }
- content_by_lua_block {
- ngx.say(ngx.var.arg_lang)
- }
- }
---- request
-GET /foo?world
---- response_body
-䏿–‡
---- no_error_log
-[error]
-
-
-
-=== TEST 5: rewrite args (string arg with 'è¯è¨€=chinese')
-ngx.req.set_uri_args with string argument should be carefully encoded.
-For backward compatibility, we are allowed to pass such parameters.
---- config
- location /foo {
- rewrite_by_lua_block {
- ngx.req.set_uri_args("è¯è¨€=chinese")
- }
- content_by_lua_block {
- ngx.say(ngx.var.arg_è¯è¨€)
- }
- }
---- request
-GET /foo?world
---- response_body
-chinese
---- no_error_log
-[error]
-
-
-
-=== TEST 6: rewrite args (string arg with 'è¯è¨€=䏿–‡')
-ngx.req.set_uri_args with string argument should be carefully encoded.
-For backward compatibility, we are allowed to pass such parameters.
---- config
- location /foo {
- rewrite_by_lua_block {
- ngx.req.set_uri_args("è¯è¨€=䏿–‡")
- }
- content_by_lua_block {
- ngx.say(ngx.var.arg_è¯è¨€)
- }
- }
---- request
-GET /foo?world
---- response_body
-䏿–‡
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/030-uri-args.t b/src/deps/src/lua-nginx-module/t/030-uri-args.t
deleted file mode 100644
index 0633476c8..000000000
--- a/src/deps/src/lua-nginx-module/t/030-uri-args.t
+++ /dev/null
@@ -1,1769 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-
-plan tests => repeat_each() * (blocks() * 2 + 23);
-
-
-no_root_location();
-
-#no_shuffle();
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request
-GET /lua?a=3&b=4&c
---- response_body
-a = 3
-b = 4
-c = true
-
-
-
-=== TEST 2: args take no value
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request
-GET /lua?foo&baz=&bar=42
---- response_body
-bar = 42
-baz =
-foo = true
-
-
-
-=== TEST 3: arg key and value escaped
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("again...")
-
- args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request
-GET /lua?%3d&b%20r=4%61+2
---- response_body
-= = true
-b r = 4a 2
-again...
-= = true
-b r = 4a 2
-
-
-
-=== TEST 4: empty
---- config
- location /t {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /t
---- response_body
-done
-
-
-
-=== TEST 5: empty arg, but with = and &
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /lua?=&&
---- response_body
-done
-
-
-
-=== TEST 6: multi-value keys
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- local val = args[key]
- if type(val) == "table" then
- ngx.say(key, " = [", table.concat(val, ", "), "]")
- else
- ngx.say(key, " = ", val)
- end
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /lua?foo=32&foo==&foo=baz
---- response_body
-foo = [32, =, baz]
-done
-
-
-
-=== TEST 7: multi-value keys
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- local val = args[key]
- if type(val) == "table" then
- ngx.say(key, " = [", table.concat(val, ", "), "]")
- else
- ngx.say(key, " = ", val)
- end
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /lua?foo=32&foo==&bar=baz
---- response_body
-bar = baz
-foo = [32, =]
-done
-
-
-
-=== TEST 8: empty arg
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- -- ngx.say(args)
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /lua?&=
---- response_body
-done
-
-
-
-=== TEST 9: = in value
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- -- ngx.say(args)
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /lua?foo===
---- response_body
-foo = ==
-done
-
-
-
-=== TEST 10: empty key, but non-empty values
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /lua?=hello&=world
---- response_body
-done
-
-
-
-=== TEST 11: updating args with $args
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("updating args...")
-
- ngx.var.args = "a=3&b=4"
-
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /lua?foo=bar
---- response_body
-foo = bar
-updating args...
-a = 3
-b = 4
-done
-
-
-
-=== TEST 12: rewrite uri and args
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- rewrite_by_lua '
- ngx.req.set_uri_args("hello")
- ngx.req.set_uri("/bar", true);
- ';
- proxy_pass http://127.0.0.2:12345;
- }
---- request
- GET /foo?world
---- response_body
-hello
---- error_log
-lua set uri jump to "/bar"
---- log_level: debug
-
-
-
-=== TEST 13: rewrite args (not break cycle by default)
---- config
- location /bar {
- echo "bar: $uri?$args";
- }
- location /foo {
- #set $args 'hello';
- rewrite_by_lua '
- ngx.req.set_uri_args("hello")
- ngx.req.set_uri("/bar", true)
- ';
- echo "foo: $uri?$args";
- }
---- request
- GET /foo?world
---- response_body
-bar: /bar?hello
-
-
-
-=== TEST 14: rewrite (not break cycle explicitly)
---- config
- location /bar {
- echo "bar: $uri?$args";
- }
- location /foo {
- #set $args 'hello';
- rewrite_by_lua '
- ngx.req.set_uri_args("hello")
- ngx.req.set_uri("/bar", true)
- ';
- echo "foo: $uri?$args";
- }
---- request
- GET /foo?world
---- response_body
-bar: /bar?hello
-
-
-
-=== TEST 15: rewrite (break cycle explicitly)
---- config
- location /bar {
- echo "bar: $uri?$args";
- }
- location /foo {
- #set $args 'hello';
- rewrite_by_lua '
- ngx.req.set_uri("/bar")
- ngx.req.set_uri_args("hello")
- ';
- echo "foo: $uri?$args";
- }
---- request
- GET /foo?world
---- response_body
-foo: /bar?hello
-
-
-
-=== TEST 16: rewrite uri (zero-length)
---- config
- location /foo {
- #set $args 'hello';
- rewrite_by_lua '
- local res, err = pcall(ngx.req.set_uri, "")
- print("rewrite: err: ", err)
- ';
- content_by_lua '
- ngx.say("foo: ", ngx.var.uri, "?", ngx.var.args)
- ';
- }
---- request
- GET /foo?world
---- response_body
-foo: /foo?world
---- log_level: info
---- grep_error_log eval: qr/rewrite: .+?(?=,)/
---- grep_error_log_out
-rewrite: err: attempt to use zero-length uri
-
-
-
-=== TEST 17: rewrite uri and args
---- config
- location /bar {
- echo $server_protocol $query_string;
- }
- location /foo {
- #rewrite ^ /bar?hello? break;
- rewrite_by_lua '
- ngx.req.set_uri_args("hello")
- ngx.req.set_uri("/bar")
- ';
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
---- request
- GET /foo?world
---- response_body
-HTTP/1.0 hello
-
-
-
-=== TEST 18: rewrite uri and args (table args)
---- config
- location /bar {
- echo $server_protocol $query_string;
- }
- location /foo {
- #rewrite ^ /bar?hello? break;
- rewrite_by_lua '
- ngx.req.set_uri("/bar")
- ngx.req.set_uri_args({["ca t"] = "%"})
- ';
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
---- request
- GET /foo?world
---- response_body
-HTTP/1.0 ca%20t=%25
-
-
-
-=== TEST 19: rewrite uri and args (never returns)
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- rewrite_by_lua '
- ngx.req.set_uri_args("hello")
- ngx.req.set_uri("/bar", true);
- ngx.exit(503)
- ';
- proxy_pass http://127.0.0.2:12345;
- }
---- request
- GET /foo?world
---- response_body
-hello
-
-
-
-=== TEST 20: ngx.req.set_uri with jump not allowed in access phase
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- set $err '';
- access_by_lua '
- local res, err = pcall(ngx.req.set_uri, "/bar", true);
- ngx.var.err = err
- ';
- echo "err: $err";
- }
---- request
- GET /foo?world
---- response_body
-err: API disabled in the context of access_by_lua*
-
-
-
-=== TEST 21: ngx.req.set_uri without jump allowed in access phase
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- set $err '';
- access_by_lua '
- ngx.req.set_uri("/bar")
- ';
- echo "uri: $uri";
- }
---- request
- GET /foo?world
---- response_body
-uri: /bar
-
-
-
-=== TEST 22: ngx.req.set_uri with jump not allowed in content phase
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- content_by_lua '
- local res, err = pcall(ngx.req.set_uri, "/bar", true);
- ngx.say("err: ", err)
- ';
- }
---- request
- GET /foo?world
---- response_body
-err: API disabled in the context of content_by_lua*
-
-
-
-=== TEST 23: ngx.req.set_uri without jump allowed in content phase
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- set $err '';
- content_by_lua '
- ngx.req.set_uri("/bar")
- ngx.say("uri: ", ngx.var.uri)
- ';
- }
---- request
- GET /foo?world
---- response_body
-uri: /bar
-
-
-
-=== TEST 24: ngx.req.set_uri with jump not allowed in set_by_lua
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- set_by_lua $err '
- local res, err = pcall(ngx.req.set_uri, "/bar", true);
- return err
- ';
- echo "err: $err";
- }
---- request
- GET /foo?world
---- response_body
-err: API disabled in the context of set_by_lua*
-
-
-
-=== TEST 25: ngx.encode_args (sanity)
---- config
- location /lua {
- set_by_lua $args_str '
- local t = {a = "bar", b = "foo"}
- return ngx.encode_args(t)
- ';
- echo $args_str;
- }
---- request
-GET /lua
---- response_body eval
-qr/a=bar&b=foo|b=foo&a=bar/
-
-
-
-=== TEST 26: ngx.encode_args (empty table)
---- config
- location /lua {
- content_by_lua '
- local t = {a = nil}
- ngx.say("args:" .. ngx.encode_args(t))
- ';
- }
---- request
-GET /lua
---- response_body
-args:
-
-
-
-=== TEST 27: ngx.encode_args (value is table)
---- config
- location /lua {
- content_by_lua '
- local t = {a = {9, 2}, b = 3}
- ngx.say("args:" .. ngx.encode_args(t))
- ';
- }
---- request
-GET /lua
---- response_body_like
-(?x) ^args:
- (?= .*? \b a=9 \b ) # 3 chars
- (?= .*? \b a=2 \b ) # 3 chars
- (?= .*? \b b=3 \b ) # 3 chars
- (?= (?: [^&]+ & ){2} [^&]+ $ ) # requires exactly 2 &'s
- (?= .{11} $ ) # requires for total 11 chars (exactly) in the string
-
-
-
-=== TEST 28: ngx.encode_args (boolean values)
---- config
- location /lua {
- content_by_lua '
- local t = {a = true, foo = 3}
- ngx.say("args: " .. ngx.encode_args(t))
- ';
- }
---- request
-GET /lua
---- response_body_like
-^args: (?:a&foo=3|foo=3&a)$
-
-
-
-=== TEST 29: ngx.encode_args (boolean values, false)
---- config
- location /lua {
- content_by_lua '
- local t = {a = false, foo = 3}
- ngx.say("args: " .. ngx.encode_args(t))
- ';
- }
---- request
-GET /lua
---- response_body
-args: foo=3
-
-
-
-=== TEST 30: boolean values in ngx.encode_args
---- config
- location /lua {
- set_by_lua $args_str '
- local t = {bar = {32, true}, foo = 3}
- return ngx.encode_args(t)
- ';
- echo $args_str;
- }
---- request
-GET /lua
---- response_body_like
-(?x) ^
- (?= .*? \b bar=32 \b ) # 6 chars
- (?= .*? \b bar (?!=) \b ) # 3 chars
- (?= .*? \b foo=3 \b ) # 5 chars
- (?= (?: [^&]+ & ){2} [^&]+ $ ) # requires exactly 2 &'s
- (?= .{16} $ ) # requires for total 16 chars (exactly) in the string
---- no_error_log
-[error]
-
-
-
-=== TEST 31: ngx.encode_args (bad user data value)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location /lua {
- content_by_lua '
- local t = {bar = ngx.shared.dogs, foo = 3}
- local rc, err = pcall(ngx.encode_args, t)
- ngx.say("rc: ", rc, ", err: ", err)
- ';
- }
---- request
-GET /lua
---- response_body
-rc: false, err: attempt to use userdata as query arg value
-
-
-
-=== TEST 32: ngx.encode_args (empty table)
---- config
- location /lua {
- content_by_lua '
- local t = {}
- ngx.say("args: ", ngx.encode_args(t))
- ';
- }
---- request
-GET /lua
---- response_body
-args:
-
-
-
-=== TEST 33: ngx.encode_args (bad arg)
---- config
- location /lua {
- content_by_lua '
- local rc, err = pcall(ngx.encode_args, true)
- ngx.say("rc: ", rc, ", err: ", err)
- ';
- }
---- request
-GET /lua
---- response_body
-rc: false, err: bad argument #1 to '?' (table expected, got boolean)
-
-
-
-=== TEST 34: max args (limited after normal key=value)
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args(2)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request
-GET /lua?foo=3&bar=4&baz=2
---- response_body
-err: truncated
-bar = 4
-foo = 3
---- error_log
-lua hit query args limit 2
---- log_level: debug
-
-
-
-=== TEST 35: max args (limited after an orphan key)
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args(2)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request
-GET /lua?foo=3&bar&baz=2
---- response_body
-err: truncated
-bar = true
-foo = 3
---- error_log
-lua hit query args limit 2
---- log_level: debug
-
-
-
-=== TEST 36: max args (limited after an empty key, but non-empty values)
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args(2)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /lua?foo=3&=hello&=world
---- response_body
-err: truncated
-foo = 3
-done
---- error_log
-lua hit query args limit 2
---- log_level: debug
-
-
-
-=== TEST 37: default max 100 args
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request eval
-my $s = "GET /lua?";
-my $i = 1;
-while ($i <= 102) {
- if ($i != 1) {
- $s .= '&';
- }
- $s .= "a$i=$i";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-my $i = 1;
-while ($i <= 100) {
- push @k, "a$i";
- $i++;
-}
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= " = $&\n";
- }
-}
-
-"err: truncated\n" . CORE::join("", @k);
---- timeout: 4
---- error_log
-lua hit query args limit 100
---- log_level: debug
-
-
-
-=== TEST 38: custom max 102 args
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args(102)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request eval
-my $s = "GET /lua?";
-my $i = 1;
-while ($i <= 103) {
- if ($i != 1) {
- $s .= '&';
- }
- $s .= "a$i=$i";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-my $i = 1;
-while ($i <= 102) {
- push @k, "a$i";
- $i++;
-}
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= " = $&\n";
- }
-}
-
-"err: truncated\n" . CORE::join("", @k);
---- timeout: 4
---- error_log
-lua hit query args limit 102
---- log_level: debug
-
-
-
-=== TEST 39: custom unlimited args
---- config
- location /lua {
- content_by_lua '
- local args, err = ngx.req.get_uri_args(0)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request eval
-my $s = "GET /lua?";
-my $i = 1;
-while ($i <= 105) {
- if ($i != 1) {
- $s .= '&';
- }
- $s .= "a$i=$i";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-my $i = 1;
-while ($i <= 105) {
- push @k, "a$i";
- $i++;
-}
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= " = $&\n";
- }
-}
-CORE::join("", @k);
---- timeout: 4
-
-
-
-=== TEST 40: rewrite uri and args (multi-value args)
---- config
- location /bar {
- echo $server_protocol $query_string;
- }
- location /foo {
- #rewrite ^ /bar?hello? break;
- rewrite_by_lua '
- ngx.req.set_uri_args({a = 3, b = {5, 6}})
- ngx.req.set_uri("/bar")
- ';
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
---- request
- GET /foo?world
---- response_body eval
-qr/HTTP\/1.0 (a=3&b=5&b=6|b=5&b=6&a=3|b=6&b=5&a=3)/
-
-
-
-=== TEST 41: ngx.decode_args (sanity)
---- config
- location /lua {
- content_by_lua '
- local err
- local args = "a=bar&b=foo"
- args, err = ngx.decode_args(args)
-
- if err then
- ngx.say("err: ", err)
- end
-
- ngx.say("a = ", args.a)
- ngx.say("b = ", args.b)
- ';
- }
---- request
-GET /lua
---- response_body
-a = bar
-b = foo
-
-
-
-=== TEST 42: ngx.decode_args (multi-value)
---- config
- location /lua {
- content_by_lua '
- local err
- local args = "a=bar&b=foo&a=baz"
- args, err = ngx.decode_args(args)
-
- if err then
- ngx.say("err: ", err)
- end
-
- ngx.say("a = ", table.concat(args.a, ", "))
- ngx.say("b = ", args.b)
- ';
- }
---- request
-GET /lua
---- response_body
-a = bar, baz
-b = foo
-
-
-
-=== TEST 43: ngx.decode_args (empty string)
---- config
- location /lua {
- content_by_lua '
- local err
- local args = ""
- args, err = ngx.decode_args(args)
- if err then
- ngx.say("err: ", err)
- end
-
- ngx.say("n = ", #args)
- ';
- }
---- request
-GET /lua
---- response_body
-n = 0
-
-
-
-=== TEST 44: ngx.decode_args (boolean args)
---- config
- location /lua {
- content_by_lua '
- local err
- local args = "a&b"
- args, err = ngx.decode_args(args)
- if err then
- ngx.say("err: ", err)
- end
-
- ngx.say("a = ", args.a)
- ngx.say("b = ", args.b)
- ';
- }
---- request
-GET /lua
---- response_body
-a = true
-b = true
-
-
-
-=== TEST 45: ngx.decode_args (empty value args)
---- config
- location /lua {
- content_by_lua '
- local err
- local args = "a=&b="
- args, err = ngx.decode_args(args)
-
- if err then
- ngx.say("err: ", err)
- end
-
- ngx.say("a = ", args.a)
- ngx.say("b = ", args.b)
- ';
- }
---- request
-GET /lua
---- response_body
-a =
-b =
-
-
-
-=== TEST 46: ngx.decode_args (max_args = 1)
---- config
- location /lua {
- content_by_lua '
- local err
- local args = "a=bar&b=foo"
- args, err = ngx.decode_args(args, 1)
- if err then
- ngx.say("err: ", err)
- end
-
- ngx.say("a = ", args.a)
- ngx.say("b = ", args.b)
- ';
- }
---- request
-GET /lua
---- response_body
-err: truncated
-a = bar
-b = nil
-
-
-
-=== TEST 47: ngx.decode_args (max_args = -1)
---- config
- location /lua {
- content_by_lua '
- local err
- local args = "a=bar&b=foo"
- args, err = ngx.decode_args(args, -1)
-
- if err then
- ngx.say("err: ", err)
- end
-
- ngx.say("a = ", args.a)
- ngx.say("b = ", args.b)
- ';
- }
---- request
-GET /lua
---- response_body
-a = bar
-b = foo
-
-
-
-=== TEST 48: ngx.decode_args should not modify lua strings in place
---- config
- location /lua {
- content_by_lua '
- local s = "f+f=bar&B=foo"
- local args, err = ngx.decode_args(s)
- if err then
- ngx.say("err: ", err)
- end
-
- local arr = {}
- for k, v in pairs(args) do
- table.insert(arr, k)
- end
- table.sort(arr)
- for i, k in ipairs(arr) do
- ngx.say("key: ", k)
- end
- ngx.say("s = ", s)
- ';
- }
---- request
-GET /lua
---- response_body
-key: B
-key: f f
-s = f+f=bar&B=foo
---- no_error_log
-[error]
-
-
-
-=== TEST 49: ngx.decode_args should not modify lua strings in place (sample from Xu Jian)
---- config
- lua_need_request_body on;
- location /t {
- content_by_lua '
- local function split(s, delimiter)
- local result = {}
- local from = 1
- local delim_from, delim_to = string.find(s, delimiter, from)
- while delim_from do
- table.insert(result, string.sub(s, from, delim_from - 1))
- from = delim_to + 1
- delim_from, delim_to = string.find(s, delimiter, from)
- end
- table.insert(result, string.sub(s, from))
- return result
- end
-
- local post_data = ngx.req.get_body_data()
-
- local commands = split(post_data, "||")
- for _, command in pairs(commands) do
- --command = ngx.unescape_uri(command)
- local request_args, err = ngx.decode_args(command, 0)
- if err then
- ngx.say("err: ", err)
- end
-
- local arr = {}
- for k, v in pairs(request_args) do
- table.insert(arr, k)
- end
- table.sort(arr)
- for i, k in ipairs(arr) do
- ngx.say(k, ": ", request_args[k])
- end
- ngx.say(" ===============")
- end
- ';
- }
---- request
-POST /t
-method=zadd&key=User%3A1227713%3Alikes%3Atwitters&arg1=1356514698&arg2=780984852||method=zadd&key=User%3A1227713%3Alikes%3Atwitters&arg1=1356514698&arg2=780984852||method=zadd&key=User%3A1227713%3Alikes%3Atwitters&arg1=1356514698&arg2=780984852
---- response_body
-arg1: 1356514698
-arg2: 780984852
-key: User:1227713:likes:twitters
-method: zadd
- ===============
-arg1: 1356514698
-arg2: 780984852
-key: User:1227713:likes:twitters
-method: zadd
- ===============
-arg1: 1356514698
-arg2: 780984852
-key: User:1227713:likes:twitters
-method: zadd
- ===============
---- no_error_log
-[error]
-
-
-
-=== TEST 50: recursive rewrite
---- config
- rewrite_by_lua '
- local args = ngx.var.args
- if args == "jump" then
- ngx.req.set_uri("/jump",true)
- end
- ';
-
- location /jump {
- echo "Jump around!";
- }
-
- location / {
- echo "$scheme://$http_host$request_uri";
- }
---- request
-GET /?jump
-
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
---- no_error_log
-[alert]
-[crit]
---- error_log
-rewrite or internal redirection cycle while processing "/jump"
---- timeout: 10
---- log_level: debug
-
-
-
-=== TEST 51: boolean values in ngx.encode_args (trailing arg)
---- config
- location /lua {
- set_by_lua $args_str '
- local t = {a = {32, true}, foo = 3, bar = 5}
- return ngx.encode_args(t)
- ';
- echo $args_str;
- }
---- request
-GET /lua
---- response_body_like
-(?x) ^
- (?= .*? \b a=32 \b ) # 4 chars
- (?= .*? \b a (?=&|$) \b ) # 1 chars
- (?= .*? \b foo=3 \b ) # 5 chars
- (?= .*? \b bar=5 \b ) # 5 chars
- (?= (?: [^&]+ & ){3} [^&]+ $ ) # requires exactly 3 &'s
- (?= .{18} $ ) # requires for total 18 chars (exactly) in the string
---- no_error_log
-[error]
-
-
-
-=== TEST 52: false boolean values in ngx.encode_args
---- config
- location /lua {
- set_by_lua $args_str '
- local t = {a = {32, false}, foo = 3, bar = 5}
- return ngx.encode_args(t)
- ';
- echo $args_str;
- }
---- request
-GET /lua
---- response_body_like
-(?x) ^
- (?= .*? \b a=32 \b ) # 4 chars
- (?= .*? \b foo=3 \b ) # 5 chars
- (?= .*? \b bar=5 \b ) # 5 chars
- (?= (?: [^&]+ & ){2} [^&]+ $ ) # requires exactly 2 &'s
- (?= .{16} $ ) # requires for total 16 chars (exactly) in the string
---- no_error_log
-[error]
-
-
-
-=== TEST 53: false boolean values in ngx.encode_args (escaping)
---- config
- location /lua {
- set_by_lua $args_str '
- local t = {["a b"] = {32, false}, foo = 3, bar = 5}
- return ngx.encode_args(t)
- ';
- echo $args_str;
- }
---- request
-GET /lua
---- response_body_like
-(?x) ^
- (?= .*? \b a%20b=32 \b ) # 8 chars
- (?= .*? \b foo=3 \b ) # 5 chars
- (?= .*? \b bar=5 \b ) # 5 chars
- (?= (?: [^&]+ & ){2} [^&]+ $ ) # requires exactly 2 &'s
- (?= .{20} $ ) # requires for total 20 chars (exactly) in the string
---- no_error_log
-[error]
-
-
-
-=== TEST 54: true boolean values in ngx.encode_args (escaping)
---- config
- location /lua {
- set_by_lua $args_str '
- local t = {["a b"] = {32, true}, foo = 3, bar = 5}
- return ngx.encode_args(t)
- ';
- echo $args_str;
- }
---- request
-GET /lua
---- response_body_like
-(?x) ^
- (?= .*? \b a%20b=32 \b ) # 8 chars
- (?= .*? \b a%20b (?!=) \b ) # 5 chars
- (?= .*? \b foo=3 \b ) # 5 chars
- (?= .*? \b bar=5 \b ) # 5 chars
- (?= (?: [^&]+ & ){3} [^&]+ $ ) # requires exactly 3 &'s
- (?= .{26} $ ) # requires for total 26 chars (exactly) in the string
---- no_error_log
-[error]
-
-
-
-=== TEST 55: rewrite uri and args (boolean in multi-value args)
---- config
- location /bar {
- echo $server_protocol $query_string;
- }
- location /foo {
- #rewrite ^ /bar?hello? break;
- rewrite_by_lua '
- ngx.req.set_uri_args({a = 3, b = {5, true, 6}})
- ngx.req.set_uri("/bar")
- ';
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
---- request
- GET /foo?world
---- response_body_like
-(?x) ^HTTP/1.0 \s
- (?= .*? \b a=3 \b ) # 3 chars
- (?= .*? \b b=5 \b ) # 3 chars
- (?= .*? \b b (?!=) \b ) # 1 chars
- (?= .*? \b b=6 \b ) # 3 chars
- (?= (?: [^&]+ & ){3} [^&]+ $ ) # requires exactly 3 &'s
- (?= .{13} $ ) # requires for total 13 chars (exactly) in the string
-
-
-
-=== TEST 56: rewrite uri and args (boolean value)
---- config
- location /bar {
- echo $server_protocol $query_string;
- }
- location /foo {
- #rewrite ^ /bar?hello? break;
- rewrite_by_lua '
- ngx.req.set_uri_args({a = 3, b = true})
- ngx.req.set_uri("/bar")
- ';
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
---- request
- GET /foo?world
---- response_body_like
-^HTTP/1.0 (a=3&b|b&a=3)$
-
-
-
-=== TEST 57: ngx.encode_args (escaping)
---- config
- location /lua {
- content_by_lua_block {
- local t = {bar = "-_.!~*'()", foo = ",$@|`"}
- ngx.say("args: ", ngx.encode_args(t))
- }
- }
---- request
-GET /lua
---- response_body eval
-qr/(\Qargs: foo=%2C%24%40%7C%60&bar=-_.!~*'()\E)|(\Qargs: bar=-_.!~*'()&foo=%2C%24%40%7C%60\E)/
---- no_error_log
-[error]
-
-
-
-=== TEST 58: set_uri with unsafe uri (with '\t')
---- config
- location /t {
- content_by_lua_block {
- local new_uri = "/foo\tbar"
- ngx.req.set_uri(new_uri)
- ngx.say(ngx.var.uri)
- }
- }
---- request
- GET /t
---- response
-/foo bar
---- no_error_log
-
-
-
-=== TEST 59: set_uri with unsafe uri (with '\0')
---- config
- location /t {
- content_by_lua_block {
- local new_uri = '\0foo'
- ngx.req.set_uri(new_uri, false, true)
- ngx.say(ngx.var.uri)
- }
- }
---- request
- GET /t
---- error_code: 200
---- response_body eval
-qr/\0foo/
-
-
-
-=== TEST 60: set_uri with safe uri (with ' ')
---- config
- location /t {
- rewrite_by_lua_block {
- local new_uri = "/foo bar"
- ngx.req.set_uri(new_uri)
- }
-
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
-
- location /foo {
- content_by_lua_block {
- ngx.say("request_uri: ", ngx.var.request_uri)
- ngx.say("uri: ", ngx.var.uri)
- }
- }
---- request
- GET /t
---- response_body
-request_uri: /foo%20bar
-uri: /foo bar
---- no_error_log
-[error]
-
-
-
-=== TEST 61: set_uri_args with boolean
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- rewrite_by_lua_block {
- ngx.req.set_uri_args(true)
- ngx.req.set_uri("/bar", true)
- }
- proxy_pass http://127.0.0.2:12345;
- }
---- request
- GET /foo?world
---- response_body_like: 500 Internal Server Error
---- log_level: debug
---- error_code: 500
---- error_log
-bad argument #1 to 'set_uri_args' (string, number, or table expected, but got boolean)
-
-
-
-=== TEST 62: set_uri_args with nil
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- rewrite_by_lua_block {
- ngx.req.set_uri_args(nil)
- ngx.req.set_uri("/bar", true)
- }
- proxy_pass http://127.0.0.2:12345;
- }
---- request
- GET /foo?world
---- response_body_like: 500 Internal Server Error
---- log_level: debug
---- error_code: 500
---- error_log
-bad argument #1 to 'set_uri_args' (string, number, or table expected, but got nil)
-
-
-
-=== TEST 63: set_uri_args with userdata
---- config
- location /bar {
- echo $query_string;
- }
- location /foo {
- #set $args 'hello';
- rewrite_by_lua_block {
- ngx.req.set_uri_args(ngx.null)
- ngx.req.set_uri("/bar", true)
- }
- proxy_pass http://127.0.0.2:12345;
- }
---- request
- GET /foo?world
---- response_body_like: 500 Internal Server Error
---- log_level: debug
---- error_code: 500
---- error_log
-bad argument #1 to 'set_uri_args' (string, number, or table expected, but got userdata)
-
-
-
-=== TEST 64: set_uri binary option with unsafe uri
-explicit specify binary option to true
---- config
- location /t {
- rewrite_by_lua_block {
- local new_uri = "/foo\r\nbar"
- ngx.req.set_uri(new_uri, false, true)
- }
-
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
-
- location /foo {
- content_by_lua_block {
- ngx.say("request_uri: ", ngx.var.request_uri)
- ngx.say("uri: ", ngx.var.uri)
- }
- }
---- request
- GET /t
---- response_body eval
-["request_uri: /foo%0D%0Abar\nuri: /foo\r\nbar\n", "request_uri: /foo%0D%0Abar\nuri: /foo\r\nbar\n"]
---- no_error_log
-[error]
-
-
-
-=== TEST 65: set_uri binary option with unsafe uri
-explicit specify binary option to false
---- config
- location /t {
- rewrite_by_lua_block {
- local new_uri = "/foo\r\nbar"
- ngx.req.set_uri(new_uri, false, false)
- }
-
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
-
- location /foo {
- content_by_lua_block {
- ngx.say("request_uri: ", ngx.var.request_uri)
- ngx.say("uri: ", ngx.var.uri)
- }
- }
---- request
- GET /t
---- error_code: 500
---- error_log eval
-qr{\[error\] \d+#\d+: \*\d+ lua entry thread aborted: runtime error: rewrite_by_lua\(nginx.conf:\d+\):\d+: unsafe byte "0x0d" in uri "/foo\\x0D\\x0Abar" \(maybe you want to set the 'binary' argument\?\)}
-
-
-
-=== TEST 66: set_uri binary option with safe uri
-explicit specify binary option to false
---- config
- location /t {
- rewrite_by_lua_block {
- local new_uri = "/foo bar"
- ngx.req.set_uri(new_uri, false, true)
- }
-
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
-
- location /foo {
- content_by_lua_block {
- ngx.say("request_uri: ", ngx.var.request_uri)
- ngx.say("uri: ", ngx.var.uri)
- }
- }
---- request
- GET /t
---- response_body
-request_uri: /foo%20bar
-uri: /foo bar
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/031-post-args.t b/src/deps/src/lua-nginx-module/t/031-post-args.t
deleted file mode 100644
index 78805d372..000000000
--- a/src/deps/src/lua-nginx-module/t/031-post-args.t
+++ /dev/null
@@ -1,407 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 6);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /lua {
- lua_need_request_body on;
- content_by_lua '
- local args, err = ngx.req.get_post_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request
-POST /lua
-a=3&b=4&c
---- response_body
-a = 3
-b = 4
-c = true
-
-
-
-=== TEST 2: lua_need_request_body off
---- config
- location /lua {
- lua_need_request_body off;
- content_by_lua '
- local args, err = ngx.req.get_post_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request
-POST /lua
-a=3&b=4&c
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 3: empty request body
---- config
- location /lua {
- lua_need_request_body on;
- content_by_lua '
- local args, err = ngx.req.get_post_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- local val = args[key]
- if type(val) == "table" then
- ngx.say(key, ": ", table.concat(val, ", "))
- else
- ngx.say(key, ": ", val)
- end
- end
- ';
- }
---- request
-POST /lua
---- response_body
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 4: max args (limited after normal key=value)
---- config
- location /lua {
- content_by_lua '
- ngx.req.read_body();
- local args, err = ngx.req.get_post_args(2)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request
-POST /lua
-foo=3&bar=4&baz=2
---- response_body
-err: truncated
-bar = 4
-foo = 3
---- error_log
-lua hit query args limit 2
-
-
-
-=== TEST 5: max args (limited after an orphan key)
---- config
- location /lua {
- content_by_lua '
- ngx.req.read_body();
- local args, err = ngx.req.get_post_args(2)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request
-POST /lua
-foo=3&bar&baz=2
---- response_body
-err: truncated
-bar = true
-foo = 3
---- error_log
-lua hit query args limit 2
-
-
-
-=== TEST 6: max args (limited after an empty key, but non-empty values)
---- config
- location /lua {
- content_by_lua '
- ngx.req.read_body();
- local args, err = ngx.req.get_post_args(2)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
-
- ngx.say("done")
- ';
- }
---- request
-POST /lua
-foo=3&=hello&=world
---- response_body
-err: truncated
-foo = 3
-done
---- error_log
-lua hit query args limit 2
-
-
-
-=== TEST 7: default max 100 args
---- config
- location /lua {
- content_by_lua '
- ngx.req.read_body();
- local args, err = ngx.req.get_post_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request eval
-my $s = "POST /lua\n";
-my $i = 1;
-while ($i <= 102) {
- if ($i != 1) {
- $s .= '&';
- }
- $s .= "a$i=$i";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-my $i = 1;
-while ($i <= 100) {
- push @k, "a$i";
- $i++;
-}
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= " = $&\n";
- }
-}
-"err: truncated\n" . CORE::join("", @k);
---- timeout: 4
---- error_log
-lua hit query args limit 100
-
-
-
-=== TEST 8: custom max 102 args
---- config
- location /lua {
- content_by_lua '
- ngx.req.read_body()
- local args, err = ngx.req.get_post_args(102)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request eval
-my $s = "POST /lua\n";
-my $i = 1;
-while ($i <= 103) {
- if ($i != 1) {
- $s .= '&';
- }
- $s .= "a$i=$i";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-my $i = 1;
-while ($i <= 102) {
- push @k, "a$i";
- $i++;
-}
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= " = $&\n";
- }
-}
-"err: truncated\n" . CORE::join("", @k);
---- timeout: 4
---- error_log
-lua hit query args limit 102
-
-
-
-=== TEST 9: custom unlimited args
---- config
- location /lua {
- content_by_lua '
- ngx.req.read_body()
- local args, err = ngx.req.get_post_args(0)
-
- if err then
- ngx.say("err: ", err)
- end
-
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- ';
- }
---- request eval
-my $s = "POST /lua\n";
-my $i = 1;
-while ($i <= 105) {
- if ($i != 1) {
- $s .= '&';
- }
- $s .= "a$i=$i";
- $i++;
-}
-$s
---- response_body eval
-my @k;
-my $i = 1;
-while ($i <= 105) {
- push @k, "a$i";
- $i++;
-}
-@k = sort @k;
-for my $k (@k) {
- if ($k =~ /\d+/) {
- $k .= " = $&\n";
- }
-}
-CORE::join("", @k);
---- timeout: 4
-
-
-
-=== TEST 10: request body in temp file
---- config
- location /lua {
- lua_need_request_body on;
- client_body_in_file_only clean;
- content_by_lua_block {
- local args, err = ngx.req.get_post_args()
-
- if err then
- ngx.say("err: ", err)
- end
-
- if args then
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
-
- table.sort(keys)
- for i, key in ipairs(keys) do
- ngx.say(key, " = ", args[key])
- end
- end
- }
- }
---- request
-POST /lua
-a=3&b=4&c
---- response_body
-err: request body in temp file not supported
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/032-iolist.t b/src/deps/src/lua-nginx-module/t/032-iolist.t
deleted file mode 100644
index 3c5603289..000000000
--- a/src/deps/src/lua-nginx-module/t/032-iolist.t
+++ /dev/null
@@ -1,78 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /lua {
- content_by_lua '
- local table = {"hello", nil, true, false, 32.5, 56}
- ngx.say(table)
- ';
- }
---- request
-GET /lua
---- response_body
-helloniltruefalse32.556
-
-
-
-=== TEST 2: nested table
---- config
- location /lua {
- content_by_lua '
- local table = {"hello", nil, true, false, 32.5, 56}
- local table2 = {table, "--", table}
- ngx.say(table2)
- ';
- }
---- request
-GET /lua
---- response_body
-helloniltruefalse32.556--helloniltruefalse32.556
-
-
-
-=== TEST 3: non-array table
---- config
- location /lua {
- content_by_lua '
- local table = {foo = 3}
- ngx.say(table)
- ';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
-
-
-
-=== TEST 4: bad data type in table
---- config
- location /lua {
- content_by_lua '
- local f = function () return end
- local table = {1, 3, f}
- ngx.say(table)
- ';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
diff --git a/src/deps/src/lua-nginx-module/t/033-ctx.t b/src/deps/src/lua-nginx-module/t/033-ctx.t
deleted file mode 100644
index 782a0fab6..000000000
--- a/src/deps/src/lua-nginx-module/t/033-ctx.t
+++ /dev/null
@@ -1,444 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3 + 8);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /lua {
- content_by_lua '
- ngx.ctx.foo = 32;
- ngx.say(ngx.ctx.foo)
- ';
- }
---- request
-GET /lua
---- response_body
-32
---- no_error_log
-[error]
-
-
-
-=== TEST 2: rewrite, access, and content
---- config
- location /lua {
- rewrite_by_lua '
- print("foo = ", ngx.ctx.foo)
- ngx.ctx.foo = 76
- ';
- access_by_lua '
- ngx.ctx.foo = ngx.ctx.foo + 3
- ';
- content_by_lua '
- ngx.say(ngx.ctx.foo)
- ';
- }
---- request
-GET /lua
---- response_body
-79
---- no_error_log
-[error]
---- grep_error_log eval: qr/foo = [^,]+/
---- log_level: info
---- grep_error_log_out
-foo = nil
-
-
-
-=== TEST 3: interal redirect clears ngx.ctx
---- config
- location /echo {
- content_by_lua '
- ngx.say(ngx.ctx.foo)
- ';
- }
- location /lua {
- content_by_lua '
- ngx.ctx.foo = ngx.var.arg_data
- -- ngx.say(ngx.ctx.foo)
- ngx.exec("/echo")
- ';
- }
---- request
-GET /lua?data=hello
---- response_body
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 4: subrequest has its own ctx
---- config
- location /sub {
- content_by_lua '
- ngx.say("sub pre: ", ngx.ctx.blah)
- ngx.ctx.blah = 32
- ngx.say("sub post: ", ngx.ctx.blah)
- ';
- }
- location /main {
- content_by_lua '
- ngx.ctx.blah = 73
- ngx.say("main pre: ", ngx.ctx.blah)
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ngx.say("main post: ", ngx.ctx.blah)
- ';
- }
---- request
- GET /main
---- response_body
-main pre: 73
-sub pre: nil
-sub post: 32
-main post: 73
---- no_error_log
-[error]
-
-
-
-=== TEST 5: overriding ctx
---- config
- location /lua {
- content_by_lua '
- ngx.ctx = { foo = 32, bar = 54 };
- ngx.say(ngx.ctx.foo)
- ngx.say(ngx.ctx.bar)
-
- ngx.ctx = { baz = 56 };
- ngx.say(ngx.ctx.foo)
- ngx.say(ngx.ctx.baz)
- ';
- }
---- request
-GET /lua
---- response_body
-32
-54
-nil
-56
---- no_error_log
-[error]
-
-
-
-=== TEST 6: header filter
---- config
- location /lua {
- content_by_lua '
- ngx.ctx.foo = 32;
- ngx.say(ngx.ctx.foo)
- ';
- header_filter_by_lua '
- ngx.header.blah = ngx.ctx.foo + 1
- ';
- }
---- request
-GET /lua
---- response_headers
-blah: 33
---- response_body
-32
---- no_error_log
-[error]
-
-
-
-=== TEST 7: capture_multi
---- config
- location /other {
- content_by_lua '
- ngx.say("dog = ", ngx.ctx.dog)
- ';
- }
-
- location /lua {
- set $dog 'blah';
- set $cat 'foo';
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- {"/other/1",
- { ctx = { dog = "hello" }}
- },
- {"/other/2",
- { ctx = { dog = "hiya" }}
- }
- };
-
- ngx.print(res1.body)
- ngx.print(res2.body)
- ngx.say("parent: ", ngx.ctx.dog)
- ';
- }
---- request
-GET /lua
---- response_body
-dog = hello
-dog = hiya
-parent: nil
---- no_error_log
-[error]
-
-
-
-=== TEST 8: set_by_lua
---- config
- location /lua {
- set_by_lua $bar 'ngx.ctx.foo = 3 return 4';
- set_by_lua $foo 'return ngx.ctx.foo';
- echo "foo = $foo, bar = $bar";
- }
---- request
-GET /lua
---- response_body
-foo = 3, bar = 4
---- no_error_log
-[error]
-
-
-
-=== TEST 9: ngx.ctx leaks with ngx.exec + log_by_lua
---- config
- location = /t {
- content_by_lua '
- ngx.ctx.foo = 32;
- ngx.exec("/f")
- ';
- log_by_lua 'ngx.log(ngx.WARN, "ctx.foo = ", ngx.ctx.foo)';
- }
- location = /f {
- content_by_lua '
- ngx.say(ngx.ctx.foo)
- ';
- }
---- request
-GET /t
---- response_body
-nil
---- no_error_log
-[error]
-ctx.foo =
-
-
-
-=== TEST 10: memory leaks with ngx.ctx + ngx.req.set_uri + log_by_lua
---- config
- location = /t {
- rewrite_by_lua '
- ngx.ctx.foo = 32;
- ngx.req.set_uri("/f", true)
- ';
- log_by_lua 'ngx.log(ngx.WARN, "ctx.foo = ", ngx.ctx.foo)';
- }
- location = /f {
- content_by_lua '
- ngx.say(ngx.ctx.foo)
- ';
- }
---- request
-GET /t
---- response_body
-nil
---- no_error_log
-[error]
-ctx.foo =
-
-
-
-=== TEST 11: ngx.ctx + ngx.exit(ngx.ERROR) + log_by_lua
---- config
- location = /t {
- rewrite_by_lua '
- ngx.ctx.foo = 32;
- ngx.exit(ngx.ERROR)
- ';
- log_by_lua 'ngx.log(ngx.WARN, "ngx.ctx = ", ngx.ctx.foo)';
- }
---- request
-GET /t
---- ignore_response
---- no_error_log
-[error]
---- error_log
-ngx.ctx = 32
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 12: ngx.ctx + ngx.exit(200) + log_by_lua
---- config
- location = /t {
- rewrite_by_lua '
- ngx.ctx.foo = 32;
- ngx.say(ngx.ctx.foo)
- ngx.exit(200)
- ';
- log_by_lua 'ngx.log(ngx.WARN, "ctx.foo = ", ngx.ctx.foo)';
- }
---- request
-GET /t
---- response_body
-32
---- no_error_log
-[error]
---- error_log
-ctx.foo = 32
-
-
-
-=== TEST 13: ngx.ctx + ngx.redirect + log_by_lua
---- config
- location = /t {
- rewrite_by_lua '
- ngx.ctx.foo = 32;
- ngx.redirect("/f")
- ';
- log_by_lua 'ngx.log(ngx.WARN, "ngx.ctx.foo = ", 32)';
- }
---- request
-GET /t
---- response_body_like: 302 Found
---- error_code: 302
---- error_log
-ctx.foo = 32
---- no_error_log
-[error]
-
-
-
-=== TEST 14: set ngx.ctx before internal redirects performed by other nginx modules
---- config
- location = /t {
- rewrite_by_lua '
- ngx.ctx.foo = "hello world";
- ';
- echo_exec /foo;
- }
-
- location = /foo {
- echo hello;
- }
---- request
-GET /t
---- response_body
-hello
---- no_error_log
-[error]
---- log_level: debug
---- error_log
-lua release ngx.ctx at ref
-
-
-
-=== TEST 15: set ngx.ctx before internal redirects performed by other nginx modules (with log_by_lua)
---- config
- location = /t {
- rewrite_by_lua '
- ngx.ctx.foo = "hello world";
- ';
- echo_exec /foo;
- }
-
- location = /foo {
- echo hello;
- log_by_lua return;
- }
---- request
-GET /t
---- response_body
-hello
---- no_error_log
-[error]
---- log_level: debug
---- error_log
-lua release ngx.ctx at ref
-
-
-
-=== TEST 16: set ngx.ctx before simple uri rewrite performed by other nginx modules
---- config
- location = /t {
- set_by_lua $a 'ngx.ctx.foo = "hello world"; return 1';
- rewrite ^ /foo last;
- echo blah;
- }
-
- location = /foo {
- echo foo;
- }
---- request
-GET /t
---- response_body
-foo
---- no_error_log
-[error]
---- log_level: debug
---- error_log
-lua release ngx.ctx at ref
-
-
-
-=== TEST 17: ngx.ctx gets prematurely released ngx.exit()
---- config
- location = /t {
- rewrite_by_lua '
- ngx.ctx.foo = 3
- ';
- content_by_lua '
- -- if ngx.headers_sent ~= true then ngx.send_headers() end
- return ngx.exit(200)
- ';
- header_filter_by_lua '
- if ngx.ctx.foo ~= 3 then
- ngx.log(ngx.ERR, "bad ngx.ctx.foo: ", ngx.ctx.foo)
- end
- ';
- }
---- request
- GET /t
---- response_body
---- no_error_log
-[error]
-
-
-
-=== TEST 18: ngx.ctx gets prematurely released ngx.exit() (lua_code_cache off)
---- config
- location = /t {
- lua_code_cache off;
- rewrite_by_lua '
- ngx.ctx.foo = 3
- ';
- content_by_lua '
- -- if ngx.headers_sent ~= true then ngx.send_headers() end
- return ngx.exit(200)
- ';
- header_filter_by_lua '
- if ngx.ctx.foo ~= 3 then
- ngx.log(ngx.ERR, "bad ngx.ctx.foo: ", ngx.ctx.foo)
- end
- ';
- }
---- request
- GET /t
---- response_body
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/034-match.t b/src/deps/src/lua-nginx-module/t/034-match.t
deleted file mode 100644
index fd4d9439e..000000000
--- a/src/deps/src/lua-nginx-module/t/034-match.t
+++ /dev/null
@@ -1,1215 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 16);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 2: escaping sequences
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "(\\\\d+)")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 3: escaping sequences (bad)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "(\\d+)")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body_like: 500 Internal Server Error
---- error_log eval
-[qr/invalid escape sequence near '"\('/]
---- error_code: 500
-
-
-
-=== TEST 4: escaping sequences in [[ ... ]]
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "[[\\d+]]")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body_like: 500 Internal Server Error
---- error_log eval
-[qr/invalid escape sequence near '"\[\['/]
---- error_code: 500
-
-
-
-=== TEST 5: single capture
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]{2})[0-9]+")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-12
-
-
-
-=== TEST 6: multiple captures
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([a-z]+).*?([0-9]{2})[0-9]+", "")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-hello
-12
-
-
-
-=== TEST 7: multiple captures (with o)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([a-z]+).*?([0-9]{2})[0-9]+", "o")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-hello
-12
-
-
-
-=== TEST 8: not matched
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "foo")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched: nil
-
-
-
-=== TEST 9: case sensitive by default
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "HELLO")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched: nil
-
-
-
-=== TEST 10: case insensitive
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "HELLO", "i")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-
-
-
-=== TEST 11: UTF-8 mode
---- config
- location /re {
- content_by_lua '
- local rc, err = pcall(ngx.re.match, "helloç« äº¦æ˜¥", "HELLO.{2}", "iu")
- if not rc then
- ngx.say("FAIL: ", err)
- return
- end
- local m = err
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body_like chop
-^(?:FAIL: bad argument \#2 to '\?' \(pcre_compile\(\) failed: this version of PCRE is not compiled with PCRE_UTF8 support in "HELLO\.\{2\}" at "HELLO\.\{2\}"\)|helloç« äº¦)$
-
-
-
-=== TEST 12: multi-line mode (^ at line head)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", "^world", "m")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-world
-
-
-
-=== TEST 13: multi-line mode (. does not match \n)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", ".*", "m")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-
-
-
-=== TEST 14: single-line mode (^ as normal)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", "^world", "s")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched: nil
-
-
-
-=== TEST 15: single-line mode (dot all)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", ".*", "s")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-world
-
-
-
-=== TEST 16: extended mode (ignore whitespaces)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", "\\\\w \\\\w", "x")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-he
-
-
-
-=== TEST 17: bad pattern
---- config
- location /re {
- content_by_lua '
- local m, err = ngx.re.match("hello\\nworld", "(abc")
- if m then
- ngx.say(m[0])
-
- else
- if err then
- ngx.say("error: ", err)
-
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 18: bad option
---- config
- location /re {
- content_by_lua '
- local rc, m = pcall(ngx.re.match, "hello\\nworld", ".*", "Hm")
- if rc then
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- else
- ngx.say("error: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body_like chop
-error: .*?unknown flag "H" \(flags "Hm"\)
-
-
-
-=== TEST 19: extended mode (ignore whitespaces)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, world", "(world)|(hello)", "x")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-false
-hello
-
-
-
-=== TEST 20: optional trailing captures
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)(h?)")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-"1234
-1234
-
-"
-
-
-
-=== TEST 21: anchored match (failed)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)", "a")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched!
-
-
-
-=== TEST 22: anchored match (succeeded)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("1234, hello", "([0-9]+)", "a")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 23: match with ctx but no pos
---- config
- location /re {
- content_by_lua '
- local ctx = {}
- local m = ngx.re.match("1234, hello", "([0-9]+)", "", ctx)
- if m then
- ngx.say(m[0])
- ngx.say(ctx.pos)
- else
- ngx.say("not matched!")
- ngx.say(ctx.pos)
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-5
-
-
-
-=== TEST 24: match with ctx and a pos
---- config
- location /re {
- content_by_lua '
- local ctx = { pos = 3 }
- local m = ngx.re.match("1234, hello", "([0-9]+)", "", ctx)
- if m then
- ngx.say(m[0])
- ngx.say(ctx.pos)
- else
- ngx.say("not matched!")
- ngx.say(ctx.pos)
- end
- ';
- }
---- request
- GET /re
---- response_body
-34
-5
-
-
-
-=== TEST 25: sanity (set_by_lua)
---- config
- location /re {
- set_by_lua $res '
- local m = ngx.re.match("hello, 1234", "([0-9]+)")
- if m then
- return m[0]
- else
- return "not matched!"
- end
- ';
- echo $res;
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 26: match (look-behind assertion)
---- config
- location /re {
- content_by_lua '
- local ctx = {}
- local m = ngx.re.match("{foobarbaz}", "(?<=foo)bar|(?<=bar)baz", "", ctx)
- ngx.say(m and m[0])
-
- m = ngx.re.match("{foobarbaz}", "(?<=foo)bar|(?<=bar)baz", "", ctx)
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- response_body
-bar
-baz
-
-
-
-=== TEST 27: escaping sequences
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
---- user_files
->>> a.lua
-local m = ngx.re.match("hello, 1234", "(\\\s+)")
-if m then
- ngx.say("[", m[0], "]")
-else
- ngx.say("not matched!")
-end
---- request
- GET /re
---- response_body_like: 500 Internal Server Error
---- error_log eval
-[qr/invalid escape sequence near '"\(\\'/]
---- error_code: 500
-
-
-
-=== TEST 28: escaping sequences
---- config
- location /re {
- access_by_lua_file html/a.lua;
- content_by_lua return;
- }
---- user_files
->>> a.lua
-local uri = "2"
-local regex = '(?:>[\\w\\s]*?\\w{2,}>)';
-ngx.say("regex: ", regex)
-local m = ngx.re.match(uri, regex, "oi")
-if m then
- ngx.say("[", m[0], "]")
-else
- ngx.say("not matched!")
-end
---- request
- GET /re
---- response_body
-regex: (?:>[\w\s]*?\w{2,}>)
-[>2]
-
-
-
-=== TEST 29: long brackets
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", [[\\d+]])
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 30: bad pattern
---- config
- location /re {
- content_by_lua '
- local m, err = ngx.re.match("hello, 1234", "([0-9]+")
- if m then
- ngx.say(m[0])
-
- else
- if err then
- ngx.say("error: ", err)
-
- else
- ngx.say("not matched!")
- end
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile\(\) failed: missing closing parenthesis in \"\([0-9]+\"\n"
-:
-"error: pcre_compile\(\) failed: missing \) in \"\([0-9]+\"\n"
-
-
---- no_error_log
-[error]
-
-
-
-=== TEST 31: long brackets containing [...]
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", [[([0-9]+)]])
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 32: bug report (github issue #72)
---- config
- location /re {
- content_by_lua '
- ngx.re.match("hello", "hello", "j")
- ngx.say("done")
- ';
- header_filter_by_lua '
- ngx.re.match("hello", "world", "j")
- ';
- }
---- request
- GET /re
---- response_body
-done
-
-
-
-=== TEST 33: bug report (github issue #72)
---- config
- location /re {
- content_by_lua '
- ngx.re.match("hello", "hello", "j")
- ngx.exec("/foo")
- ';
- }
-
- location /foo {
- content_by_lua '
- ngx.re.match("hello", "world", "j")
- ngx.say("done")
- ';
- }
---- request
- GET /re
---- response_body
-done
-
-
-
-=== TEST 34: non-empty subject, empty pattern
---- config
- location /re {
- content_by_lua '
- local ctx = {}
- local m = ngx.re.match("hello, 1234", "", "", ctx)
- if m then
- ngx.say("pos: ", ctx.pos)
- ngx.say("m: ", m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-pos: 1
-m:
---- no_error_log
-[error]
-
-
-
-=== TEST 35: named subpatterns w/ extraction
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "(?[a-z]+), [0-9]+")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m.first)
- ngx.say(m.second)
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-hello
-hello
-nil
-
-
-
-=== TEST 36: duplicate named subpatterns w/ extraction
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "(?[a-z]+), (?[0-9]+)", "D")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(table.concat(m.first,"-"))
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-hello
-1234
-hello-1234
-
-
-
-=== TEST 37: named captures are empty strings
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("1234", "(?[a-z]*)([0-9]+)")
- if m then
- ngx.say(m[0])
- ngx.say(m.first)
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-1234
-
-
-
-=== TEST 38: named captures are false
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, world", "(world)|(hello)|(?howdy)")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(m[3])
- ngx.say(m["named"])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-false
-hello
-false
-false
-
-
-
-=== TEST 39: duplicate named subpatterns
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, world",
- "(?\\\\w+), (?\\\\w+)",
- "D")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(table.concat(m.named,"-"))
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world
-hello
-world
-hello-world
---- no_error_log
-[error]
-
-
-
-=== TEST 40: Javascript compatible mode
---- config
- location /t {
- content_by_lua '
- local m = ngx.re.match("ç« ", [[\\u7AE0]], "uJ")
- if m then
- ngx.say("matched: ", m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
-GET /t
---- response_body
-matched: ç«
---- no_error_log
-[error]
-
-
-
-=== TEST 41: empty duplicate captures
---- config
- location = /t {
- content_by_lua "
- local target = 'test'
- local regex = '^(?:(?(?:foo))|(?(?:bar))|(?(?:test)))$'
-
- -- Note the D here
- local m = ngx.re.match(target, regex, 'D')
-
- ngx.say(type(m.group1))
- ngx.say(type(m.group2))
- ";
- }
---- request
-GET /t
---- response_body
-nil
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 42: bad UTF-8
---- config
- location = /t {
- content_by_lua '
- local target = "ä½ å¥½"
- local regex = "ä½ å¥½"
-
- -- Note the D here
- local m, err = ngx.re.match(string.sub(target, 1, 4), regex, "u")
-
- if err then
- ngx.say("error: ", err)
- return
- end
-
- if m then
- ngx.say("matched: ", m[0])
- else
- ngx.say("not matched")
- end
- ';
- }
---- request
-GET /t
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre_exec\(\) failed: -4\n"
-:
-"error: pcre_exec\(\) failed: -10\n"
-
---- no_error_log
-[error]
-
-
-
-=== TEST 43: UTF-8 mode without UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("ä½ å¥½", ".", "U")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 2000
-
---- request
- GET /re
---- response_body
-ä½
---- no_error_log
-[error]
-
-
-
-=== TEST 44: UTF-8 mode with UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("ä½ å¥½", ".", "u")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 0
-
---- request
- GET /re
---- response_body
-ä½
---- no_error_log
-[error]
-
-
-
-=== TEST 45: just hit match limit
---- http_config
- lua_regex_match_limit 5000;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local res, err = ngx.re.match(s, re, "o")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if not res then
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("failed to match")
- return
-end
-
---- request
- GET /re
---- response_body eval
-# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
-# but PCRE2 replaces this with pcre2_set_match_limit interface,
-# which has different effects.
-$Test::Nginx::Util::PcreVersion == 2 ?
-"failed to match\n"
-:
-"error: pcre_exec() failed: -8\n"
-
-
-
-=== TEST 46: just not hit match limit
---- http_config
- lua_regex_match_limit 5100;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local res, err = ngx.re.match(s, re, "o")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if not res then
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("failed to match")
- return
-end
-
---- request
- GET /re
---- response_body
-failed to match
-
-
-
-=== TEST 47: extra table argument
---- config
- location /re {
- content_by_lua '
- local res = {}
- local s = "hello, 1234"
- local m = ngx.re.match(s, [[(\\d)(\\d)]], "o", nil, res)
- if m then
- ngx.say("1: m size: ", #m)
- ngx.say("1: res size: ", #res)
- else
- ngx.say("1: not matched!")
- end
- m = ngx.re.match(s, [[(\\d)]], "o", nil, res)
- if m then
- ngx.say("2: m size: ", #m)
- ngx.say("2: res size: ", #res)
- else
- ngx.say("2: not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1: m size: 2
-1: res size: 2
-2: m size: 2
-2: res size: 2
---- no_error_log
-[error]
-
-
-
-=== TEST 48: init_by_lua_block
---- http_config
- init_by_lua_block {
- local m, err = ngx.re.match("hello, 1234", [[(\d+)]])
- if not m then
- ngx.log(ngx.ERR, "failed to match: ", err)
- else
- package.loaded.m = m
- end
- }
---- config
- location /re {
- content_by_lua_block {
- local m = package.loaded.m
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- }
- }
---- request
- GET /re
---- response_body
-1234
---- no_error_log
-[error]
-
-
-
-=== TEST 49: trailing captures are false
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello", "(hello)(.+)?")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-hello
-false
-
-
-
-=== TEST 50: the 5th argument hides the 4th (GitHub #719)
---- config
- location /re {
- content_by_lua '
- local ctx, m = { pos = 5 }, {};
- local _, err = ngx.re.match("20172016-11-3 03:07:09", [=[(\d\d\d\d)]=], "", ctx, m);
- if m then
- ngx.say(m[0], " ", _[0], " ", ctx.pos)
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-2016 2016 9
diff --git a/src/deps/src/lua-nginx-module/t/035-gmatch.t b/src/deps/src/lua-nginx-module/t/035-gmatch.t
deleted file mode 100644
index 0a4efd2b2..000000000
--- a/src/deps/src/lua-nginx-module/t/035-gmatch.t
+++ /dev/null
@@ -1,916 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(5);
-
-plan tests => repeat_each() * (blocks() * 2 + 7);
-
-our $HtmlDir = html_dir;
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: gmatch
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("hello, world", "[a-z]+") do
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-world
-
-
-
-=== TEST 2: fail to match
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[0-9]")
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
- ';
- }
---- request
- GET /re
---- response_body
-nil
-nil
-nil
-
-
-
-=== TEST 3: match but iterate more times (not just match at the end)
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world!", "[a-z]+")
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-world
-nil
-nil
-
-
-
-=== TEST 4: match but iterate more times (just matched at the end)
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+")
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-world
-nil
-nil
-
-
-
-=== TEST 5: anchored match (failed)
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, 1234", "([0-9]+)", "a")
- ngx.say(it())
- ';
- }
---- request
- GET /re
---- response_body
-nil
-
-
-
-=== TEST 6: anchored match (succeeded)
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("12 hello 34", "[0-9]", "a")
- local m = it()
- ngx.say(m[0])
- m = it()
- ngx.say(m[0])
- ngx.say(it())
- ';
- }
---- request
- GET /re
---- response_body
-1
-2
-nil
-
-
-
-=== TEST 7: non-anchored gmatch (without regex cache)
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("12 hello 34", "[0-9]")
- local m = it()
- ngx.say(m and m[0])
- m = it()
- ngx.say(m and m[0])
- m = it()
- ngx.say(m and m[0])
- m = it()
- ngx.say(m and m[0])
- m = it()
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- response_body
-1
-2
-3
-4
-nil
-
-
-
-=== TEST 8: non-anchored gmatch (with regex cache)
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("12 hello 34", "[0-9]", "o")
- local m = it()
- ngx.say(m and m[0])
- m = it()
- ngx.say(m and m[0])
- m = it()
- ngx.say(m and m[0])
- m = it()
- ngx.say(m and m[0])
- m = it()
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- response_body
-1
-2
-3
-4
-nil
-
-
-
-=== TEST 9: anchored match (succeeded)
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("12 hello 34", "[0-9]", "a")
- local m = it()
- ngx.say(m[0])
- m = it()
- ngx.say(m[0])
- ngx.say(it())
- ';
- }
---- request
- GET /re
---- response_body
-1
-2
-nil
-
-
-
-=== TEST 10: anchored match (succeeded, set_by_lua)
---- config
- location /re {
- set_by_lua $res '
- local it = ngx.re.gmatch("12 hello 34", "[0-9]", "a")
- local m = it()
- return m[0]
- ';
- echo $res;
- }
---- request
- GET /re
---- response_body
-1
-
-
-
-=== TEST 11: gmatch (look-behind assertion)
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("{foobar}, {foobaz}", "(?<=foo)ba[rz]") do
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-bar
-baz
-
-
-
-=== TEST 12: gmatch (look-behind assertion 2)
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("{foobarbaz}", "(?<=foo)bar|(?<=bar)baz") do
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-bar
-baz
-
-
-
-=== TEST 13: with regex cache
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, 1234", "([A-Z]+)", "io")
- local m = it()
- ngx.say(m and m[0])
-
- it = ngx.re.gmatch("1234, okay", "([A-Z]+)", "io")
- m = it()
- ngx.say(m and m[0])
-
- it = ngx.re.gmatch("hi, 1234", "([A-Z]+)", "o")
- m = it()
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- stap2
-F(ngx_http_lua_ngx_re_gmatch_iterator) { println("iterator") }
-F(ngx_http_lua_ngx_re_gmatch_gc) { println("gc") }
-F(ngx_http_lua_ngx_re_gmatch_cleanup) { println("cleanup") }
---- response_body
-hello
-okay
-nil
-
-
-
-=== TEST 14: exceeding regex cache max entries
---- http_config
- lua_regex_cache_max_entries 2;
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, 1234", "([0-9]+)", "o")
- local m = it()
- ngx.say(m and m[0])
-
- it = ngx.re.gmatch("howdy, 567", "([0-9]+)", "oi")
- m = it()
- ngx.say(m and m[0])
-
- it = ngx.re.gmatch("hiya, 98", "([0-9]+)", "ox")
- m = it()
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- response_body
-1234
-567
-98
-
-
-
-=== TEST 15: disable regex cache completely
---- http_config
- lua_regex_cache_max_entries 0;
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, 1234", "([0-9]+)", "o")
- local m = it()
- ngx.say(m and m[0])
-
- it = ngx.re.gmatch("howdy, 567", "([0-9]+)", "oi")
- local m = it()
- ngx.say(m and m[0])
-
- it = ngx.re.gmatch("hiya, 98", "([0-9]+)", "ox")
- local m = it()
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- response_body
-1234
-567
-98
-
-
-
-=== TEST 16: gmatch matched but no iterate
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+")
- ngx.say("done")
- ';
- }
---- request
- GET /re
---- response_body
-done
-
-
-
-=== TEST 17: gmatch matched but only iterate once and still matches remain
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+")
- local m = it()
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-
-
-
-=== TEST 18: gmatch matched but no iterate and early forced GC
---- config
- location /re {
- content_by_lua '
- local a = {}
- for i = 1, 3 do
- local it = ngx.re.gmatch("hello, world", "[a-z]+")
- it()
- collectgarbage()
- table.insert(a, {"hello", "world"})
- end
- ngx.say("done")
- ';
- }
---- request
- GET /re
---- response_body
-done
-
-
-
-=== TEST 19: gmatch iterator used by another request
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;;';"
---- config
- location /main {
- content_by_lua '
- package.loaded.foo = nil
- collectgarbage()
-
- local res = ngx.location.capture("/t")
- if res.status == 200 then
- ngx.print(res.body)
- else
- ngx.say("sr failed: ", res.status)
- end
-
- res = ngx.location.capture("/t")
- if res.status == 200 then
- ngx.print(res.body)
- else
- ngx.say("sr failed: ", res.status)
- end
- ';
- }
-
- location /t {
- content_by_lua '
- local foo = require "foo"
- local m = foo.go()
- ngx.say(m and "matched" or "no")
- ';
- }
---- user_files
->>> foo.lua
-module("foo", package.seeall)
-
-local it
-
-function go()
- if not it then
- it = ngx.re.gmatch("hello, world", "[a-z]+")
- end
-
- return it()
-end
---- request
- GET /main
---- response_body
-matched
-matched
---- no_error_log
-[error]
-
-
-
-=== TEST 20: gmatch (empty matched string)
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("hello", "a|") do
- if m then
- ngx.say("matched: [", m[0], "]")
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-matched: []
-matched: []
-matched: []
-matched: []
-matched: []
-matched: []
-
-
-
-=== TEST 21: gmatch with named pattern
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("1234, 1234", "(?[0-9]+)")
- local m = it()
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m["first"])
- else
- ngx.say("not matched!")
- end
-
- m = it()
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m["first"])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-1234
-1234
-1234
-1234
-1234
-
-
-
-=== TEST 22: gmatch with multiple named pattern
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("1234, abcd, 1234", "(?[0-9]+)|(?[a-z]+)")
-
- local m = it()
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(m["first"])
- ngx.say(m["second"])
- else
- ngx.say("not matched!")
- end
-
- m = it()
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(m["first"])
- ngx.say(m["second"])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-1234
-false
-1234
-false
-abcd
-false
-abcd
-false
-abcd
-
-
-
-=== TEST 23: gmatch with duplicate named pattern w/ extraction
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, 1234", "(?[a-z]+), (?[0-9]+)", "D")
- local m = it()
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(table.concat(m.first,"-"))
- else
- ngx.say("not matched!")
- end
-
- m = it()
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(table.concat(m.first,"-"))
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-hello
-1234
-hello-1234
-not matched!
-
-
-
-=== TEST 24: named captures are empty
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("1234", "(?[a-z]*)([0-9]+)", "")
- local m = it()
- if m then
- ngx.say(m[0])
- ngx.say(m.first)
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-1234
-
-
-
-=== TEST 25: named captures are empty (with regex cache)
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("1234", "(?[a-z]*)([0-9]+)", "o")
- local m = it()
- if m then
- ngx.say(m[0])
- ngx.say(m.first)
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-1234
-
-
-
-=== TEST 26: bad pattern
---- config
- location /re {
- content_by_lua '
- local it, err = ngx.re.gmatch("hello\\nworld", "(abc")
- if not err then
- ngx.say("good")
-
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 27: bad UTF-8
---- config
- location = /t {
- content_by_lua '
- local target = "ä½ å¥½"
- local regex = "ä½ å¥½"
-
- -- Note the D here
- local it, err = ngx.re.gmatch(string.sub(target, 1, 4), regex, "u")
-
- if err then
- ngx.say("error: ", err)
- return
- end
-
- local m, err = it()
- if err then
- ngx.say("error: ", err)
- return
- end
-
- if m then
- ngx.say("matched: ", m[0])
- else
- ngx.say("not matched")
- end
- ';
- }
---- request
-GET /t
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre_exec\(\) failed: -4\n"
-:
-"error: pcre_exec\(\) failed: -10\n"
-
---- no_error_log
-[error]
-
-
-
-=== TEST 28: UTF-8 mode without UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("ä½ å¥½", ".", "U")
- local m = it()
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 2000
-
---- request
- GET /re
---- response_body
-ä½
---- no_error_log
-[error]
-
-
-
-=== TEST 29: UTF-8 mode with UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("ä½ å¥½", ".", "u")
- local m = it()
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 0
-
---- request
- GET /re
---- response_body
-ä½
---- no_error_log
-[error]
-
-
-
-=== TEST 30: just hit match limit
---- http_config
- lua_regex_match_limit 5000;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local it, err = ngx.re.gmatch(s, re, "o")
-if not it then
- ngx.say("failed to gen iterator: ", err)
- return
-end
-
-local res, err = it()
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if not res then
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("failed to match")
- return
-end
-
---- request
- GET /re
---- response_body eval
-# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
-# but PCRE2 replaces this with pcre2_set_match_limit interface,
-# which has different effects.
-$Test::Nginx::Util::PcreVersion == 2 ?
-"failed to match\n"
-:
-"error: pcre_exec() failed: -8\n"
-
-
-
-=== TEST 31: just not hit match limit
---- http_config
- lua_regex_match_limit 5100;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local it, err = ngx.re.gmatch(s, re, "o")
-if not it then
- ngx.say("failed to gen iterator: ", err)
- return
-end
-
-local res, err = it()
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if not res then
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("failed to match")
- return
-end
-
---- request
- GET /re
---- response_body
-failed to match
diff --git a/src/deps/src/lua-nginx-module/t/036-sub.t b/src/deps/src/lua-nginx-module/t/036-sub.t
deleted file mode 100644
index 0657ebb2c..000000000
--- a/src/deps/src/lua-nginx-module/t/036-sub.t
+++ /dev/null
@@ -1,769 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 19);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: matched but w/o variables
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[a-z]+", "howdy")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-howdy, world
-1
-
-
-
-=== TEST 2: not matched
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[A-Z]+", "howdy")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, world
-0
-
-
-
-=== TEST 3: matched and with variables
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("a b c d", "(b) (c)", "[$0] [$1] [$2] [$3] [$134]")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-a [b c] [b] [c] [] [] d
-1
-
-
-
-=== TEST 4: matched and with named variables
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("a b c d",
- "(b) (c)", "[$0] [$1] [$2] [$3] [$hello]")
- if s then
- ngx.say(s, ": ", n)
-
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-attempt to use named capturing variable "hello" (named captures not supported yet)
-
-
-
-=== TEST 5: matched and with named variables (bracketed)
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("a b c d",
- "(b) (c)", "[$0] [$1] [$2] [$3] [${hello}]")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-attempt to use named capturing variable "hello" (named captures not supported yet)
-
-
-
-=== TEST 6: matched and with bracketed variables
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${134}]")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[b c] [b] [c] [] [] d
-1
-
-
-
-=== TEST 7: matched and with bracketed variables (unmatched brackets)
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${134]")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-the closing bracket in "134" variable is missing
-
-
-
-=== TEST 8: matched and with bracketed variables (unmatched brackets)
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${134")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-the closing bracket in "134" variable is missing
-
-
-
-=== TEST 9: matched and with bracketed variables (unmatched brackets)
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-lua script: invalid capturing variable name found in "[$0] [$1] [${2}] [$3] [${"
-
-
-
-=== TEST 10: trailing $
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [$")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-lua script: invalid capturing variable name found in "[$0] [$1] [${2}] [$3] [$"
-
-
-
-=== TEST 11: matched but w/o variables and with literal $
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[a-z]+", "ho$$wdy")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-ho$wdy, world
-1
-
-
-
-=== TEST 12: non-anchored match
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234", "[0-9]", "x")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, x234
-1
-
-
-
-=== TEST 13: anchored match
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234", "[0-9]", "x", "a")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-0
-
-
-
-=== TEST 14: function replace
---- config
- location /re {
- content_by_lua '
- local repl = function (m)
- return "[" .. m[0] .. "] [" .. m[1] .. "]"
- end
-
- local s, n = ngx.re.sub("hello, 34", "([0-9])", repl)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, [3] [3]4
-1
-
-
-
-=== TEST 15: function replace (failed)
---- config
- location /re {
- content_by_lua '
- local repl = function (m)
- return "[" .. m[0] .. "] [" .. m[1] .. "]"
- end
-
- local s, n = ngx.re.sub("hello, 34", "([A-Z])", repl)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, 34
-0
-
-
-
-=== TEST 16: bad repl arg type
---- config
- location /re {
- content_by_lua '
- local rc, s, n = pcall(ngx.re.sub, "hello, 34", "([A-Z])", true)
- ngx.say(rc)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-false
-bad argument #3 to '?' (string, number, or function expected, got boolean)
-nil
---- SKIP
-
-
-
-=== TEST 17: use number to replace
---- config
- location /re {
- content_by_lua '
- local rc, s, n = pcall(ngx.re.sub, "hello, 34", "([0-9])", 72)
- ngx.say(rc)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-true
-hello, 724
-1
-
-
-
-=== TEST 18: bad function return value type
---- SKIP
---- config
- location /re {
- content_by_lua '
- local f = function (m) end
- local rc, s, n = pcall(ngx.re.sub, "hello, 34", "([0-9])", f)
- ngx.say(rc)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-false
-bad argument #3 to '?' (string or number expected to be returned by the replace function, got nil)
-nil
-
-
-
-=== TEST 19: matched but w/o variables (set_by_lua)
---- config
- location /re {
- set_by_lua $res '
- local s, n = ngx.re.sub("hello, world", "[a-z]+", "howdy")
- return s
- ';
- echo $res;
- }
---- request
- GET /re
---- response_body
-howdy, world
-
-
-
-=== TEST 20: matched and with variables w/o using named patterns in sub
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("a b c d", "(?b) (?c)", "[$0] [$1] [$2] [$3] [$134]")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-a [b c] [b] [c] [] [] d
-1
-
-
-
-=== TEST 21: matched and with variables using named patterns in func
---- config
- error_log /tmp/nginx_error debug;
- location /re {
- content_by_lua '
- local repl = function (m)
- return "[" .. m[0] .. "] [" .. m["first"] .. "] [" .. m[2] .. "]"
- end
-
- local s, n = ngx.re.sub("a b c d", "(?b) (?c)", repl)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-a [b c] [b] [c] d
-1
---- no_error_log
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 22: matched and with variables w/ using named patterns in sub
-This is still a TODO
---- SKIP
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("a b c d", "(?b) (?c)", "[$0] [${first}] [${second}] [$3] [$134]")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-a [b c] [b] [c] [] [] d
-1
---- no_error_log
-[error]
-
-
-
-=== TEST 23: $0 without parens
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("a b c d", [[\w]], "[$0]")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[a] b c d
-1
---- no_error_log
-[error]
-
-
-
-=== TEST 24: bad pattern
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("hello\\nworld", "(abc", "")
- if s then
- ngx.say("subs: ", n)
-
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 25: bad UTF-8
---- config
- location = /t {
- content_by_lua '
- local target = "ä½ å¥½"
- local regex = "ä½ å¥½"
-
- -- Note the D here
- local s, n, err = ngx.re.sub(string.sub(target, 1, 4), regex, "", "u")
-
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre_exec\(\) failed: -4\n"
-:
-"error: pcre_exec\(\) failed: -10\n"
-
---- no_error_log
-[error]
-
-
-
-=== TEST 26: UTF-8 mode without UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("ä½ å¥½", ".", "a", "U")
- if s then
- ngx.say("s: ", s)
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 2000
-
---- request
- GET /re
---- response_body
-s: a好
---- no_error_log
-[error]
-
-
-
-=== TEST 27: UTF-8 mode with UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("ä½ å¥½", ".", "a", "u")
- if s then
- ngx.say("s: ", s)
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 0
-
---- request
- GET /re
---- response_body
-s: a好
---- no_error_log
-[error]
-
-
-
-=== TEST 28: just hit match limit
---- http_config
- lua_regex_match_limit 5000;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local res, cnt, err = ngx.re.sub(s, re, "", "o")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if err then
- ngx.say("error: ", err)
- return
-end
-ngx.say("sub: ", cnt)
-
---- request
- GET /re
---- response_body eval
-# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
-# but PCRE2 replaces this with pcre2_set_match_limit interface,
-# which has different effects.
-$Test::Nginx::Util::PcreVersion == 2 ?
-"sub: 0\n"
-:
-"error: pcre_exec() failed: -8\n"
-
-
-
-=== TEST 29: just not hit match limit
---- http_config
- lua_regex_match_limit 5100;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local res, cnt, err = ngx.re.sub(s, re, "", "o")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if err then
- ngx.say("error: ", err)
- return
-end
-ngx.say("sub: ", cnt)
-
---- request
- GET /re
---- response_body
-sub: 0
-
-
-
-=== TEST 30: bug: sub incorrectly swallowed a character is the first character
-Original bad result: estCase
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("TestCase", "^ *", "", "o")
- if s then
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-TestCase
-
-
-
-=== TEST 31: bug: sub incorrectly swallowed a character is not the first character
-Original bad result: .b.d
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("abcd", "(?=c)", ".")
- if s then
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-ab.cd
-
-
-
-=== TEST 32: ngx.re.gsub: recursive calling (github #445)
---- config
-
-location = /t {
- content_by_lua '
- local function test()
- local data = [[
- OUTER {FIRST}
-]]
-
- local p1 = "(OUTER)(.+)"
- local p2 = "{([A-Z]+)}"
-
- ngx.print(data)
-
- local res = ngx.re.gsub(data, p1, function(m)
- -- ngx.say("pre: m[1]: [", m[1], "]")
- -- ngx.say("pre: m[2]: [", m[2], "]")
-
- local res = ngx.re.gsub(m[2], p2, function(_)
- return "REPLACED"
- end, "")
-
- -- ngx.say("post: m[1]: [", m[1], "]")
- -- ngx.say("post m[2]: [", m[2], "]")
- return m[1] .. res
- end, "")
-
- ngx.print(res)
- end
-
- test()
- ';
-}
---- request
-GET /t
---- response_body
- OUTER {FIRST}
- OUTER REPLACED
---- no_error_log
-[error]
-bad argument type
-NYI
-
-
-
-=== TEST 33: function replace (false for groups)
---- config
- location /re {
- content_by_lua '
- local repl = function (m)
- print("group 1: ", m[2])
- return "[" .. m[0] .. "] [" .. m[1] .. "]"
- end
-
- local s, n = ngx.re.sub("hello, 34", "([0-9])|(world)", repl)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, [3] [3]4
-1
---- error_log
-group 1: false
diff --git a/src/deps/src/lua-nginx-module/t/037-gsub.t b/src/deps/src/lua-nginx-module/t/037-gsub.t
deleted file mode 100644
index a6fe579bd..000000000
--- a/src/deps/src/lua-nginx-module/t/037-gsub.t
+++ /dev/null
@@ -1,708 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 17);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("[hello, world]", "[a-z]+", "howdy")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[howdy, howdy]
-2
-
-
-
-=== TEST 2: trimmed
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "[a-z]+", "howdy")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-howdy, howdy
-2
-
-
-
-=== TEST 3: not matched
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "[A-Z]+", "howdy")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, world
-0
-
-
-
-=== TEST 4: replace by function (trimmed)
---- config
- location /re {
- content_by_lua '
- local f = function (m)
- return "[" .. m[0] .. "," .. m[1] .. "]"
- end
-
- local s, n = ngx.re.gsub("hello, world", "([a-z])[a-z]+", f)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[hello,h], [world,w]
-2
-
-
-
-=== TEST 5: replace by function (not trimmed)
---- config
- location /re {
- content_by_lua '
- local f = function (m)
- return "[" .. m[0] .. "," .. m[1] .. "]"
- end
-
- local s, n = ngx.re.gsub("{hello, world}", "([a-z])[a-z]+", f)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-{[hello,h], [world,w]}
-2
-
-
-
-=== TEST 6: replace by script (trimmed)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "([a-z])[a-z]+", "[$0,$1]")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[hello,h], [world,w]
-2
-
-
-
-=== TEST 7: replace by script (not trimmed)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("{hello, world}", "([a-z])[a-z]+", "[$0,$1]")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-{[hello,h], [world,w]}
-2
-
-
-
-=== TEST 8: set_by_lua
---- config
- location /re {
- set_by_lua $res '
- local f = function (m)
- return "[" .. m[0] .. "," .. m[1] .. "]"
- end
-
- local s, n = ngx.re.gsub("{hello, world}", "([a-z])[a-z]+", f)
- return s
- ';
- echo $res;
- }
---- request
- GET /re
---- response_body
-{[hello,h], [world,w]}
-
-
-
-=== TEST 9: look-behind assertion
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("{foobarbaz}", "(?<=foo)bar|(?<=bar)baz", "h$0")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-{foohbarhbaz}
-2
-
-
-
-=== TEST 10: gsub with a patch matching an empty substring (string template)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello", "a|", "b")
- ngx.say("s: ", s)
- ngx.say("n: ", n)
- ';
- }
---- request
- GET /re
---- response_body
-s: bhbeblblbob
-n: 6
---- no_error_log
-[error]
-
-
-
-=== TEST 11: gsub with a patch matching an empty substring (string template, empty subj)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("", "a|", "b")
- ngx.say("s: ", s)
- ngx.say("n: ", n)
- ';
- }
---- request
- GET /re
---- response_body
-s: b
-n: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 12: gsub with a patch matching an empty substring (func)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello", "a|", function () return "b" end)
- ngx.say("s: ", s)
- ngx.say("n: ", n)
- ';
- }
---- request
- GET /re
---- response_body
-s: bhbeblblbob
-n: 6
---- no_error_log
-[error]
-
-
-
-=== TEST 13: gsub with a patch matching an empty substring (func, empty subj)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("", "a|", function () return "b" end)
- ngx.say("s: ", s)
- ngx.say("n: ", n)
- ';
- }
---- request
- GET /re
---- response_body
-s: b
-n: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 14: big subject string exceeding the luabuf chunk size (with trailing unmatched data, func repl)
---- config
- location /re {
- content_by_lua '
- local subj = string.rep("a", 8000)
- .. string.rep("b", 1000)
- .. string.rep("a", 8000)
- .. string.rep("b", 1000)
- .. "aaa"
-
- local function repl(m)
- return string.rep("c", string.len(m[0]))
- end
-
- local s, n = ngx.re.gsub(subj, "b+", repl)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body eval
-("a" x 8000) . ("c" x 1000) . ("a" x 8000) . ("c" x 1000)
-. "aaa
-2
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 15: big subject string exceeding the luabuf chunk size (without trailing unmatched data, func repl)
---- config
- location /re {
- content_by_lua '
- local subj = string.rep("a", 8000)
- .. string.rep("b", 1000)
- .. string.rep("a", 8000)
- .. string.rep("b", 1000)
-
- local function repl(m)
- return string.rep("c", string.len(m[0]))
- end
-
- local s, n = ngx.re.gsub(subj, "b+", repl)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body eval
-("a" x 8000) . ("c" x 1000) . ("a" x 8000) . ("c" x 1000)
-. "\n2\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 16: big subject string exceeding the luabuf chunk size (with trailing unmatched data, str repl)
---- config
- location /re {
- content_by_lua '
- local subj = string.rep("a", 8000)
- .. string.rep("b", 1000)
- .. string.rep("a", 8000)
- .. string.rep("b", 1000)
- .. "aaa"
-
- local s, n = ngx.re.gsub(subj, "b(b+)(b)", "$1 $2")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body eval
-("a" x 8000) . ("b" x 998) . " b" . ("a" x 8000) . ("b" x 998) . " baaa
-2
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 17: big subject string exceeding the luabuf chunk size (without trailing unmatched data, str repl)
---- config
- location /re {
- content_by_lua '
- local subj = string.rep("a", 8000)
- .. string.rep("b", 1000)
- .. string.rep("a", 8000)
- .. string.rep("b", 1000)
-
- local s, n = ngx.re.gsub(subj, "b(b+)(b)", "$1 $2")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body eval
-("a" x 8000) . ("b" x 998) . " b" . ("a" x 8000) . ("b" x 998) . " b\n2\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 18: named pattern repl w/ callback
---- config
- location /re {
- content_by_lua '
- local repl = function (m)
- return "[" .. m[0] .. "," .. m["first"] .. "]"
- end
-
- local s, n = ngx.re.gsub("hello, world", "(?[a-z])[a-z]+", repl)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[hello,h], [world,w]
-2
-
-
-
-=== TEST 19: $0 without parens
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("a b c d", [[\w]], "[$0]")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[a] [b] [c] [d]
-4
---- no_error_log
-[error]
-
-
-
-=== TEST 20: bad UTF-8
---- config
- location = /t {
- content_by_lua '
- local target = "ä½ å¥½"
- local regex = "ä½ å¥½"
-
- -- Note the D here
- local s, n, err = ngx.re.gsub(string.sub(target, 1, 4), regex, "", "u")
-
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre_exec\(\) failed: -4\n"
-:
-"error: pcre_exec\(\) failed: -10\n"
-
---- no_error_log
-[error]
-
-
-
-=== TEST 21: UTF-8 mode without UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.gsub("ä½ å¥½", ".", "a", "U")
- if s then
- ngx.say("s: ", s)
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 2000
-exec opts: 2000
-exec opts: 2000
-
---- request
- GET /re
---- response_body
-s: aa
---- no_error_log
-[error]
-
-
-
-=== TEST 22: UTF-8 mode with UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.gsub("ä½ å¥½", ".", "a", "u")
- if s then
- ngx.say("s: ", s)
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 0
-exec opts: 0
-exec opts: 0
-
---- request
- GET /re
---- response_body
-s: aa
---- no_error_log
-[error]
-
-
-
-=== TEST 23: just hit match limit
---- http_config
- lua_regex_match_limit 5000;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local res, cnt, err = ngx.re.gsub(s, re, "", "o")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if err then
- ngx.say("error: ", err)
- return
-end
-ngx.say("gsub: ", cnt)
-
---- request
- GET /re
---- response_body eval
-# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
-# but PCRE2 replaces this with pcre2_set_match_limit interface,
-# which has different effects.
-$Test::Nginx::Util::PcreVersion == 2 ?
-"gsub: 0\n"
-:
-"error: pcre_exec() failed: -8\n"
-
-
-
-=== TEST 24: just not hit match limit
---- http_config
- lua_regex_match_limit 5100;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local res, cnt, err = ngx.re.gsub(s, re, "", "o")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if err then
- ngx.say("error: ", err)
- return
-end
-ngx.say("gsub: ", cnt)
-
---- request
- GET /re
---- response_body
-gsub: 0
---- timeout: 10
-
-
-
-=== TEST 25: bug: gsub incorrectly swallowed a character is the first character
-Original bad result: estCase
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("TestCase", "^ *", "", "o")
- if s then
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-TestCase
-
-
-
-=== TEST 26: bug: gsub incorrectly swallowed a character is not the first character
-Original bad result: .b.d
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("abcd", "a|(?=c)", ".")
- if s then
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-.b.cd
-
-
-
-=== TEST 27: use of ngx.req.get_headers in the user callback
---- config
-
-location = /t {
- content_by_lua '
- local data = [[
- INNER
- INNER
-]]
-
- -- ngx.say(data)
-
- local res = ngx.re.gsub(data, "INNER", function(inner_matches)
- local header = ngx.req.get_headers()["Host"]
- -- local header = ngx.var["http_HEADER"]
- return "INNER_REPLACED"
- end, "s")
-
- ngx.print(res)
- ';
-}
-
---- request
-GET /t
---- response_body
- INNER_REPLACED
- INNER_REPLACED
-
---- no_error_log
-[error]
-
-
-
-=== TEST 28: use of ngx.var in the user callback
---- config
-
-location = /t {
- content_by_lua '
- local data = [[
- INNER
- INNER
-]]
-
- -- ngx.say(data)
-
- local res = ngx.re.gsub(data, "INNER", function(inner_matches)
- -- local header = ngx.req.get_headers()["Host"]
- local header = ngx.var["http_HEADER"]
- return "INNER_REPLACED"
- end, "s")
-
- ngx.print(res)
- ';
-}
-
---- request
-GET /t
---- response_body
- INNER_REPLACED
- INNER_REPLACED
-
---- no_error_log
-[error]
-
-
-
-=== TEST 29: function replace (false for groups)
---- config
- location /re {
- content_by_lua '
- local repl = function (m)
- print("group 1: ", m[2])
- return "[" .. m[0] .. "] [" .. m[1] .. "]"
- end
-
- local s, n = ngx.re.gsub("hello, 34", "([0-9])|(world)", repl)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, [3] [3][4] [4]
-2
---- error_log
-group 1: false
diff --git a/src/deps/src/lua-nginx-module/t/038-match-o.t b/src/deps/src/lua-nginx-module/t/038-match-o.t
deleted file mode 100644
index cc80244e8..000000000
--- a/src/deps/src/lua-nginx-module/t/038-match-o.t
+++ /dev/null
@@ -1,745 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)", "o")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 2: escaping sequences
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "(\\\\d+)", "o")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 3: escaping sequences (bad)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "(\\d+)", "o")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-[qr/invalid escape sequence near '"\('/]
-
-
-
-=== TEST 4: escaping sequences in [[ ... ]]
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "[[\\d+]]", "o")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-[qr/invalid escape sequence near '"\[\['/]
-
-
-
-=== TEST 5: single capture
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]{2})[0-9]+", "o")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-12
-
-
-
-=== TEST 6: multiple captures
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([a-z]+).*?([0-9]{2})[0-9]+", "o")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-hello
-12
-
-
-
-=== TEST 7: not matched
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "foo", "o")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched: nil
-
-
-
-=== TEST 8: case sensitive by default
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "HELLO", "o")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched: nil
-
-
-
-=== TEST 9: case sensitive by default
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "HELLO", "oi")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-
-
-
-=== TEST 10: UTF-8 mode
---- config
- location /re {
- content_by_lua '
- local rc, m = pcall(ngx.re.match, "helloç« äº¦æ˜¥", "HELLO.{2}", "iou")
- if not rc then
- ngx.say("error: ", m)
- return
- end
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body_like chop
-this version of PCRE is not compiled with PCRE_UTF8 support|^helloç« äº¦$
-
-
-
-=== TEST 11: multi-line mode (^ at line head)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", "^world", "mo")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-world
-
-
-
-=== TEST 12: multi-line mode (. does not match \n)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", ".*", "om")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-
-
-
-=== TEST 13: single-line mode (^ as normal)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", "^world", "so")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched: nil
-
-
-
-=== TEST 14: single-line mode (dot all)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", ".*", "os")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-world
-
-
-
-=== TEST 15: extended mode (ignore whitespaces)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello\\nworld", "\\\\w \\\\w", "xo")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-he
-
-
-
-=== TEST 16: bad pattern
---- config
- location /re {
- content_by_lua '
- local m, err = ngx.re.match("hello\\nworld", "(abc", "o")
- if m then
- ngx.say(m[0])
-
- else
- if err then
- ngx.say("error: ", err)
-
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 17: bad option
---- config
- location /re {
- content_by_lua '
- local rc, m = pcall(ngx.re.match, "hello\\nworld", ".*", "Ho")
- if rc then
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- else
- ngx.say("error: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body_like chop
-^error: .*?unknown flag "H"
-
-
-
-=== TEST 18: extended mode (ignore whitespaces)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, world", "(world)|(hello)", "xo")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched: ", m)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-false
-hello
-
-
-
-=== TEST 19: optional trailing captures
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)(h?)", "o")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-"1234
-1234
-
-"
-
-
-
-=== TEST 20: anchored match (failed)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)", "oa")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched!
-
-
-
-=== TEST 21: anchored match (succeeded)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("1234, hello", "([0-9]+)", "ao")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 22: match with ctx but no pos
---- config
- location /re {
- content_by_lua '
- local ctx = {}
- local m = ngx.re.match("1234, hello", "([0-9]+)", "o", ctx)
- if m then
- ngx.say(m[0])
- ngx.say(ctx.pos)
- else
- ngx.say("not matched!")
- ngx.say(ctx.pos)
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-5
-
-
-
-=== TEST 23: match with ctx and a pos
---- config
- location /re {
- content_by_lua '
- local ctx = { pos = 3 }
- local m = ngx.re.match("1234, hello", "([0-9]+)", "o", ctx)
- if m then
- ngx.say(m[0])
- ngx.say(ctx.pos)
- else
- ngx.say("not matched!")
- ngx.say(ctx.pos)
- end
- ';
- }
---- request
- GET /re
---- response_body
-34
-5
-
-
-
-=== TEST 24: sanity (set_by_lua)
---- config
- location /re {
- set_by_lua $res '
- local m = ngx.re.match("hello, 1234", "([0-9]+)", "o")
- if m then
- return m[0]
- else
- return "not matched!"
- end
- ';
- echo $res;
- }
---- request
- GET /re
---- response_body
-1234
-
-
-
-=== TEST 25: match (look-behind assertion)
---- config
- location /re {
- content_by_lua '
- local ctx = {}
- local m = ngx.re.match("{foobarbaz}", "(?<=foo)bar|(?<=bar)baz", "o", ctx)
- ngx.say(m and m[0])
-
- m = ngx.re.match("{foobarbaz}", "(?<=foo)bar|(?<=bar)baz", "o", ctx)
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- response_body
-bar
-baz
-
-
-
-=== TEST 26: match (with regex cache)
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([A-Z]+)", "io")
- ngx.say(m and m[0])
-
- m = ngx.re.match("1234, okay", "([A-Z]+)", "io")
- ngx.say(m and m[0])
-
- m = ngx.re.match("hello, 1234", "([A-Z]+)", "o")
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- response_body
-hello
-okay
-nil
-
-
-
-=== TEST 27: match (with regex cache and ctx)
---- config
- location /re {
- content_by_lua '
- local ctx = {}
- local m = ngx.re.match("hello, 1234", "([A-Z]+)", "io", ctx)
- ngx.say(m and m[0])
- ngx.say(ctx.pos)
-
- m = ngx.re.match("1234, okay", "([A-Z]+)", "io", ctx)
- ngx.say(m and m[0])
- ngx.say(ctx.pos)
-
- ctx.pos = 1
- m = ngx.re.match("hi, 1234", "([A-Z]+)", "o", ctx)
- ngx.say(m and m[0])
- ngx.say(ctx.pos)
- ';
- }
---- request
- GET /re
---- response_body
-hello
-6
-okay
-11
-nil
-1
-
-
-
-=== TEST 28: exceeding regex cache max entries
---- http_config
- lua_regex_cache_max_entries 2;
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)", "o")
- ngx.say(m and m[0])
-
- m = ngx.re.match("howdy, 567", "([0-9]+)", "oi")
- ngx.say(m and m[0])
-
- m = ngx.re.match("hiya, 98", "([0-9]+)", "ox")
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- response_body
-1234
-567
-98
-
-
-
-=== TEST 29: disable regex cache completely
---- http_config
- lua_regex_cache_max_entries 0;
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)", "o")
- ngx.say(m and m[0])
-
- m = ngx.re.match("howdy, 567", "([0-9]+)", "oi")
- ngx.say(m and m[0])
-
- m = ngx.re.match("hiya, 98", "([0-9]+)", "ox")
- ngx.say(m and m[0])
- ';
- }
---- request
- GET /re
---- response_body
-1234
-567
-98
-
-
-
-=== TEST 30: named subpatterns w/ extraction
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "(?[a-z]+), [0-9]+", "o")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m.first)
- ngx.say(m.second)
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-hello
-hello
-nil
-
-
-
-=== TEST 31: duplicate named subpatterns w/ extraction
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "(?[a-z]+), (?[0-9]+)", "Do")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(table.concat(m.first,"-"))
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-hello
-1234
-hello-1234
-
-
-
-=== TEST 32: named captures are empty strings
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("1234", "(?[a-z]*)([0-9]+)", "o")
- if m then
- ngx.say(m[0])
- ngx.say(m.first)
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
-
-1234
-
-
-
-=== TEST 33: named captures are false
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, world", "(world)|(hello)|(?howdy)", "o")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(m[3])
- ngx.say(m["named"])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-false
-hello
-false
-false
diff --git a/src/deps/src/lua-nginx-module/t/039-sub-o.t b/src/deps/src/lua-nginx-module/t/039-sub-o.t
deleted file mode 100644
index 580a67161..000000000
--- a/src/deps/src/lua-nginx-module/t/039-sub-o.t
+++ /dev/null
@@ -1,580 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 6);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: matched but w/o variables
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[a-z]+", "howdy", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-howdy, world
-1
-
-
-
-=== TEST 2: not matched
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[A-Z]+", "howdy", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, world
-0
-
-
-
-=== TEST 3: matched and with variables
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("a b c d", "(b) (c)", "[$0] [$1] [$2] [$3] [$134]", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-a [b c] [b] [c] [] [] d
-1
-
-
-
-=== TEST 4: matched and with named variables (bad template)
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("a b c d",
- "(b) (c)",
- "[$0] [$1] [$2] [$3] [$hello]",
- "o")
- if s then
- ngx.say(s, ": ", n)
-
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-attempt to use named capturing variable "hello" (named captures not supported yet)
-
-
-
-=== TEST 5: matched and with named variables (bracketed)
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("a b c d",
- "(b) (c)",
- "[$0] [$1] [$2] [$3] [${hello}]",
- "o")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-attempt to use named capturing variable "hello" (named captures not supported yet)
-
-
-
-=== TEST 6: matched and with bracketed variables
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${134}]", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[b c] [b] [c] [] [] d
-1
-
-
-
-=== TEST 7: matched and with bracketed variables (unmatched brackets)
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${134]", "o")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-the closing bracket in "134" variable is missing
-
-
-
-=== TEST 8: matched and with bracketed variables (unmatched brackets)
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${134", "o")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-the closing bracket in "134" variable is missing
-
-
-
-=== TEST 9: matched and with bracketed variables (unmatched brackets)
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [${", "o")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-lua script: invalid capturing variable name found in "[$0] [$1] [${2}] [$3] [${"
-
-
-
-=== TEST 10: trailing $
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("b c d", "(b) (c)", "[$0] [$1] [${2}] [$3] [$", "o")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: failed to compile the replacement template
---- error_log
-lua script: invalid capturing variable name found in "[$0] [$1] [${2}] [$3] [$"
-
-
-
-=== TEST 11: matched but w/o variables and with literal $
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[a-z]+", "ho$$wdy", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-ho$wdy, world
-1
-
-
-
-=== TEST 12: non-anchored match
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234", " [0-9] ", "x", "xo")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, x234
-1
-
-
-
-=== TEST 13: anchored match
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234", "[0-9]", "x", "ao")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, 1234
-0
-
-
-
-=== TEST 14: function replace
---- config
- location /re {
- content_by_lua '
- local repl = function (m)
- return "[" .. m[0] .. "] [" .. m[1] .. "]"
- end
-
- local s, n = ngx.re.sub("hello, 34", "([0-9])", repl, "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, [3] [3]4
-1
-
-
-
-=== TEST 15: function replace (failed)
---- config
- location /re {
- content_by_lua '
- local repl = function (m)
- return "[" .. m[0] .. "] [" .. m[1] .. "]"
- end
-
- local s, n = ngx.re.sub("hello, 34", "([A-Z])", repl, "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, 34
-0
-
-
-
-=== TEST 16: bad repl arg type
---- SKIP
---- config
- location /re {
- content_by_lua '
- local rc, s, n = pcall(ngx.re.sub, "hello, 34", "([A-Z])", true, "o")
- ngx.say(rc)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-false
-bad argument #3 to '?' (string, number, or function expected, got boolean)
-nil
-
-
-
-=== TEST 17: use number to replace
---- config
- location /re {
- content_by_lua '
- local rc, s, n = pcall(ngx.re.sub, "hello, 34", "([0-9])", 72, "o")
- ngx.say(rc)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-true
-hello, 724
-1
-
-
-
-=== TEST 18: bad function return value type
---- SKIP
---- config
- location /re {
- content_by_lua '
- local f = function (m) end
- local rc, s, n = pcall(ngx.re.sub, "hello, 34", "([0-9])", f, "o")
- ngx.say(rc)
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-false
-bad argument #3 to '?' (string or number expected to be returned by the replace function, got nil)
-nil
-
-
-
-=== TEST 19: matched but w/o variables (set_by_lua)
---- config
- location /re {
- set_by_lua $res '
- local s, n = ngx.re.sub("hello, world", "[a-z]+", "howdy", "o")
- return s
- ';
- echo $res;
- }
---- request
- GET /re
---- response_body
-howdy, world
-
-
-
-=== TEST 20: with regex cache (with text replace)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234", "([A-Z]+)", "baz", "io")
- ngx.say(s)
- ngx.say(n)
-
- local s, n = ngx.re.sub("howdy, 1234", "([A-Z]+)", "baz", "io")
- ngx.say(s)
- ngx.say(n)
-
-
- s, n = ngx.re.sub("1234, okay", "([A-Z]+)", "blah", "io")
- ngx.say(s)
- ngx.say(n)
-
- s, n = ngx.re.sub("hi, 1234", "([A-Z]+)", "hello", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-baz, 1234
-1
-baz, 1234
-1
-1234, blah
-1
-hi, 1234
-0
-
-
-
-=== TEST 21: with regex cache (with func replace)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234", "([A-Z]+)", "baz", "io")
- ngx.say(s)
- ngx.say(n)
-
- local s, n = ngx.re.sub("howdy, 1234", "([A-Z]+)", function () return "bah" end, "io")
- ngx.say(s)
- ngx.say(n)
-
- s, n = ngx.re.sub("1234, okay", "([A-Z]+)", function () return "blah" end, "io")
- ngx.say(s)
- ngx.say(n)
-
- s, n = ngx.re.sub("hi, 1234", "([A-Z]+)", "hello", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-baz, 1234
-1
-bah, 1234
-1
-1234, blah
-1
-hi, 1234
-0
-
-
-
-=== TEST 22: exceeding regex cache max entries
---- http_config
- lua_regex_cache_max_entries 2;
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234", "([0-9]+)", "hello", "o")
- ngx.say(s)
- ngx.say(n)
-
- s, n = ngx.re.sub("howdy, 567", "([0-9]+)", "hello", "oi")
- ngx.say(s)
- ngx.say(n)
-
- s, n = ngx.re.sub("hiya, 98", "([0-9]+)", "hello", "ox")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, hello
-1
-howdy, hello
-1
-hiya, hello
-1
-
-
-
-=== TEST 23: disable regex cache completely
---- http_config
- lua_regex_cache_max_entries 0;
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234", "([0-9]+)", "hello", "o")
- ngx.say(s)
- ngx.say(n)
-
- s, n = ngx.re.sub("howdy, 567", "([0-9]+)", "hello", "oi")
- ngx.say(s)
- ngx.say(n)
-
- s, n = ngx.re.sub("hiya, 98", "([0-9]+)", "hello", "ox")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, hello
-1
-howdy, hello
-1
-hiya, hello
-1
-
-
-
-=== TEST 24: empty replace
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234", "([0-9]+)", "", "o")
- ngx.say(s)
- ngx.say(n)
-
- local s, n = ngx.re.sub("hi, 5432", "([0-9]+)", "", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello,
-1
-hi,
-1
-
-
-
-=== TEST 25: matched and with variables w/o using named patterns in sub
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("a b c d", "(?b) (?c)", "[$0] [$1] [$2] [$3] [$134]", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-a [b c] [b] [c] [] [] d
-1
-
-
-
-=== TEST 26: matched and with variables using named patterns in func
---- config
- error_log /tmp/nginx_error debug;
- location /re {
- content_by_lua '
- local repl = function (m)
- return "[" .. m[0] .. "] [" .. m["first"] .. "] [" .. m[2] .. "]"
- end
-
- local s, n = ngx.re.sub("a b c d", "(?b) (?c)", repl, "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-a [b c] [b] [c] d
-1
diff --git a/src/deps/src/lua-nginx-module/t/040-gsub-o.t b/src/deps/src/lua-nginx-module/t/040-gsub-o.t
deleted file mode 100644
index 534726611..000000000
--- a/src/deps/src/lua-nginx-module/t/040-gsub-o.t
+++ /dev/null
@@ -1,200 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("[hello, world]", "[a-z]+", "howdy", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[howdy, howdy]
-2
-
-
-
-=== TEST 2: trimmed
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "[a-z]+", "howdy", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-howdy, howdy
-2
-
-
-
-=== TEST 3: not matched
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "[A-Z]+", "howdy", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-hello, world
-0
-
-
-
-=== TEST 4: replace by function (trimmed)
---- config
- location /re {
- content_by_lua '
- local f = function (m)
- return "[" .. m[0] .. "," .. m[1] .. "]"
- end
-
- local s, n = ngx.re.gsub("hello, world", "([a-z])[a-z]+", f, "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[hello,h], [world,w]
-2
-
-
-
-=== TEST 5: replace by function (not trimmed)
---- config
- location /re {
- content_by_lua '
- local f = function (m)
- return "[" .. m[0] .. "," .. m[1] .. "]"
- end
-
- local s, n = ngx.re.gsub("{hello, world}", "([a-z])[a-z]+", f, "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-{[hello,h], [world,w]}
-2
-
-
-
-=== TEST 6: replace by script (trimmed)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "([a-z])[a-z]+", "[$0,$1]", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[hello,h], [world,w]
-2
-
-
-
-=== TEST 7: replace by script (not trimmed)
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("{hello, world}", "([a-z])[a-z]+", "[$0,$1]", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-{[hello,h], [world,w]}
-2
-
-
-
-=== TEST 8: set_by_lua
---- config
- location /re {
- set_by_lua $res '
- local f = function (m)
- return "[" .. m[0] .. "," .. m[1] .. "]"
- end
-
- local s, n = ngx.re.gsub("{hello, world}", "([a-z])[a-z]+", f, "o")
- return s
- ';
- echo $res;
- }
---- request
- GET /re
---- response_body
-{[hello,h], [world,w]}
-
-
-
-=== TEST 9: look-behind assertion
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("{foobarbaz}", "(?<=foo)bar|(?<=bar)baz", "h$0", "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-{foohbarhbaz}
-2
-
-
-
-=== TEST 10: named pattern repl w/ callback
---- config
- location /re {
- content_by_lua '
- local repl = function (m)
- return "[" .. m[0] .. "," .. m["first"] .. "]"
- end
-
- local s, n = ngx.re.gsub("hello, world", "(?[a-z])[a-z]+", repl, "o")
- ngx.say(s)
- ngx.say(n)
- ';
- }
---- request
- GET /re
---- response_body
-[hello,h], [world,w]
-2
diff --git a/src/deps/src/lua-nginx-module/t/041-header-filter.t b/src/deps/src/lua-nginx-module/t/041-header-filter.t
deleted file mode 100644
index 23fdac02c..000000000
--- a/src/deps/src/lua-nginx-module/t/041-header-filter.t
+++ /dev/null
@@ -1,927 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 13);
-
-#no_diff();
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: set response content-type header
---- config
- location /read {
- echo "Hi";
- header_filter_by_lua '
- ngx.header.content_type = "text/my-plain";
- ';
-
- }
---- request
-GET /read
---- response_headers
-Content-Type: text/my-plain
---- response_body
-Hi
-
-
-
-=== TEST 2: server config
---- config
- header_filter_by_lua '
- ngx.header.content_type = "text/my-plain";
- ';
-
- location /read {
- echo "Hi";
-
- }
---- request
-GET /read
---- response_headers
-Content-Type: text/my-plain
---- response_body
-Hi
-
-
-
-=== TEST 3: set in http
---- http_config
- header_filter_by_lua '
- ngx.header.content_type = "text/my-plain";
- ';
---- config
- location /read {
- echo "Hi";
- }
---- request
-GET /read
---- response_headers
-Content-Type: text/my-plain
---- response_body
-Hi
-
-
-
-=== TEST 4: overriding config
---- config
- header_filter_by_lua '
- ngx.header.content_type = "text/my-plain";
- ';
- location /read {
- echo "Hi";
- header_filter_by_lua '
- ngx.header.content_type = "text/read-plain";
- ';
- }
---- request
-GET /read
---- response_headers
-Content-Type: text/read-plain
---- response_body
-Hi
-
-
-
-=== TEST 5: set response content-type header
---- config
- location /read {
- echo "Hi";
- header_filter_by_lua '
- ngx.header.content_type = "text/my-plain";
- ';
-
- }
---- request
-GET /read
---- response_headers
-Content-Type: text/my-plain
---- response_body
-Hi
-
-
-
-=== TEST 6: lua code run failed
---- config
- location /read {
- echo "Hi";
- header_filter_by_lua '
- ngx.header.content_length = "text/my-plain";
- ';
- }
---- request
-GET /read
---- error_code
---- response_body
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 7: use variable generated by content phrase
---- config
- location /read {
- set $strvar '1';
- content_by_lua '
- ngx.var.strvar = "127.0.0.1:8080";
- ngx.say("Hi");
- ';
- header_filter_by_lua '
- ngx.header.uid = ngx.var.strvar;
- ';
- }
---- request
-GET /read
---- response_headers
-uid: 127.0.0.1:8080
---- response_body
-Hi
-
-
-
-=== TEST 8: use variable generated by content phrase for HEAD
---- config
- location /read {
- set $strvar '1';
- content_by_lua '
- ngx.var.strvar = "127.0.0.1:8080";
- ngx.say("Hi");
- ';
- header_filter_by_lua '
- ngx.header.uid = ngx.var.strvar;
- ';
- }
---- request
-HEAD /read
---- response_headers
-uid: 127.0.0.1:8080
---- response_body
-
-
-
-=== TEST 9: use variable generated by content phrase for HTTP 1.0
---- config
- location /read {
- set $strvar '1';
- content_by_lua '
- ngx.var.strvar = "127.0.0.1:8080";
- ngx.say("Hi");
- ';
- header_filter_by_lua '
- ngx.header.uid = ngx.var.strvar;
- ';
-
- }
---- request
-GET /read HTTP/1.0
---- response_headers
-uid: 127.0.0.1:8080
---- response_body
-Hi
-
-
-
-=== TEST 10: use capture and header_filter_by
---- config
- location /sub {
- content_by_lua '
- ngx.say("Hi");
- ';
- header_filter_by_lua '
- ngx.header.uid = "sub";
- ';
- }
-
- location /parent {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- if res.status == 200 then
- ngx.say(res.header.uid)
- else
- ngx.say("parent")
- end
- ';
- header_filter_by_lua '
- ngx.header.uid = "parent";
- ';
- }
-
---- request
-GET /parent
---- response_headers
-uid: parent
---- response_body
-sub
-
-
-
-=== TEST 11: overriding ctx
---- config
- location /lua {
- content_by_lua '
- ngx.ctx.foo = 32;
- ngx.say(ngx.ctx.foo)
- ';
- header_filter_by_lua '
- ngx.ctx.foo = ngx.ctx.foo + 1;
- ngx.header.uid = ngx.ctx.foo;
- ';
- }
---- request
-GET /lua
---- response_headers
-uid: 33
---- response_body
-32
-
-
-
-=== TEST 12: use req
---- config
- location /lua {
- content_by_lua '
- ngx.say("Hi");
- ';
-
- header_filter_by_lua '
- local str = "";
- local args, err = ngx.req.get_uri_args()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
- local keys = {}
- for key, val in pairs(args) do
- table.insert(keys, key)
- end
- table.sort(keys)
- for i, key in ipairs(keys) do
- local val = args[key]
- if type(val) == "table" then
- str = str .. table.concat(val, ", ")
- else
- str = str .. ":" .. val
- end
- end
-
- ngx.header.uid = str;
- ';
- }
---- request
-GET /lua?a=1&b=2
---- response_headers
-uid: :1:2
---- response_body
-Hi
-
-
-
-=== TEST 13: use ngx md5 function
---- config
- location /lua {
- content_by_lua '
- ngx.say("Hi");
- ';
- header_filter_by_lua '
- ngx.header.uid = ngx.md5("Hi");
- ';
- }
---- request
-GET /lua
---- response_headers
-uid: c1a5298f939e87e8f962a5edfc206918
---- response_body
-Hi
-
-
-
-=== TEST 14: set response content-type header (by file)
---- config
- location /read {
- echo "Hi";
- header_filter_by_lua_file 'html/foo.lua';
- }
---- request
-GET /read
---- user_files
->>> foo.lua
-ngx.header.content_type = "text/my-plain";
---- response_headers
-Content-Type: text/my-plain
---- response_body
-Hi
-
-
-
-=== TEST 15: by_lua_file server config
---- config
- header_filter_by_lua_file 'html/foo.lua';
-
- location /read {
- echo "Hi";
- }
---- request
-GET /read
---- user_files
->>> foo.lua
-ngx.header.content_type = "text/my-plain";
---- response_headers
-Content-Type: text/my-plain
---- response_body
-Hi
-
-
-
-=== TEST 16: by_lua_file set in http
---- http_config
- header_filter_by_lua_file 'html/foo.lua';
---- config
- location /read {
- echo "Hi";
- }
---- request
-GET /read
---- user_files
->>> foo.lua
-ngx.header.content_type = "text/my-plain";
---- response_headers
-Content-Type: text/my-plain
---- response_body
-Hi
-
-
-
-=== TEST 17: by_lua_file overriding config
---- config
- header_filter_by_lua 'html/foo.lua';
- location /read {
- echo "Hi";
- header_filter_by_lua_file 'html/bar.lua';
- }
---- request
-GET /read
---- user_files
->>> foo.lua
-ngx.header.content_type = "text/my-plain";
->>> bar.lua
-ngx.header.content_type = "text/read-plain";
---- response_headers
-Content-Type: text/read-plain
---- response_body
-Hi
-
-
-
-=== TEST 18: ngx.ctx available in header_filter_by_lua (already defined)
---- config
- location /lua {
- content_by_lua 'ngx.ctx.counter = 3 ngx.say(ngx.ctx.counter)';
- header_filter_by_lua 'ngx.log(ngx.ERR, "ngx.ctx.counter: ", ngx.ctx.counter)';
- }
---- request
-GET /lua
---- response_body
-3
---- error_log
-ngx.ctx.counter: 3
-lua release ngx.ctx
-
-
-
-=== TEST 19: ngx.ctx available in header_filter_by_lua (not defined yet)
---- config
- location /lua {
- echo hello;
- header_filter_by_lua '
- ngx.log(ngx.ERR, "ngx.ctx.counter: ", ngx.ctx.counter)
- ngx.ctx.counter = "hello world"
- ';
- }
---- request
-GET /lua
---- response_body
-hello
---- error_log
-ngx.ctx.counter: nil
-lua release ngx.ctx
-
-
-
-=== TEST 20: globals are shared by all requests
---- config
- location /lua {
- set $foo '';
- content_by_lua '
- ngx.send_headers()
- ngx.say(ngx.var.foo)
- ';
- header_filter_by_lua '
- if not foo then
- foo = 1
- else
- ngx.log(ngx.INFO, "old foo: ", foo)
- foo = foo + 1
- end
- ngx.var.foo = foo
- ';
- }
---- request
-GET /lua
---- response_body_like
-^[12]$
---- no_error_log
-[error]
---- grep_error_log eval: qr/old foo: \d+/
---- grep_error_log_out eval
-["", "old foo: 1\n"]
-
-
-
-=== TEST 21: lua error (string)
---- config
- location /lua {
- set $foo '';
- content_by_lua '
- ngx.send_headers()
- ngx.say(ngx.var.foo)
- ';
- header_filter_by_lua '
- error("Something bad")
- ';
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-failed to run header_filter_by_lua*: header_filter_by_lua(nginx.conf:47):2: Something bad
---- no_error_log
-[alert]
---- curl_error eval
-qr/curl: \(56\) Failure when receiving data from the peer|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(52\) Empty reply from server|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 22: lua error (nil)
---- config
- location /lua {
- set $foo '';
- content_by_lua '
- ngx.send_headers()
- ngx.say(ngx.var.foo)
- ';
- header_filter_by_lua '
- error(nil)
- ';
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-failed to run header_filter_by_lua*: unknown reason
---- no_error_log
-[alert]
---- curl_error eval
-qr/curl: \(56\) Failure when receiving data from the peer|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(52\) Empty reply from server|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 23: no ngx.print
---- config
- location /lua {
- header_filter_by_lua "ngx.print(32) return 1";
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 24: no ngx.say
---- config
- location /lua {
- header_filter_by_lua "ngx.say(32) return 1";
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 25: no ngx.flush
---- config
- location /lua {
- header_filter_by_lua "ngx.flush()";
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 26: no ngx.eof
---- config
- location /lua {
- header_filter_by_lua "ngx.eof()";
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 27: no ngx.send_headers
---- config
- location /lua {
- header_filter_by_lua "ngx.send_headers()";
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 28: no ngx.location.capture
---- config
- location /lua {
- header_filter_by_lua 'ngx.location.capture("/sub")';
- echo ok;
- }
-
- location /sub {
- echo sub;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 29: no ngx.location.capture_multi
---- config
- location /lua {
- header_filter_by_lua 'ngx.location.capture_multi{{"/sub"}}';
- echo ok;
- }
-
- location /sub {
- echo sub;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 30: no ngx.redirect
---- config
- location /lua {
- header_filter_by_lua 'ngx.redirect("/blah")';
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 31: no ngx.exec
---- config
- location /lua {
- header_filter_by_lua 'ngx.exec("/blah")';
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 32: no ngx.req.set_uri(uri, true)
---- config
- location /lua {
- header_filter_by_lua 'ngx.req.set_uri("/blah", true)';
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 33: ngx.req.set_uri(uri) exists
---- config
- location /lua {
- header_filter_by_lua 'ngx.req.set_uri("/blah") return 1';
- content_by_lua '
- ngx.send_headers()
- ngx.say("uri: ", ngx.var.uri)
- ';
- }
---- request
-GET /lua
---- response_body
-uri: /blah
---- no_error_log
-[error]
-
-
-
-=== TEST 34: no ngx.req.read_body()
---- config
- location /lua {
- header_filter_by_lua 'ngx.req.read_body()';
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log eval
-qr/API disabled in the context of header_filter_by_lua\*|http3 requests are not supported without content-length header/ms
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 35: no ngx.req.socket()
---- config
- location /lua {
- header_filter_by_lua 'return ngx.req.socket()';
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log eval
-my $err_log;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $err_log = "http v3 not supported yet";
-} else {
- $err_log = "API disabled in the context of header_filter_by_lua*";
-}
-
-$err_log;
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 36: no ngx.socket.tcp()
---- config
- location /lua {
- header_filter_by_lua 'return ngx.socket.tcp()';
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 37: no ngx.socket.connect()
---- config
- location /lua {
- header_filter_by_lua 'return ngx.socket.connect("127.0.0.1", 80)';
- echo ok;
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 38: clear content-length
---- config
- location /lua {
- content_by_lua '
- ngx.header.content_length = 12
- ngx.say("hello world")
- ';
- header_filter_by_lua 'ngx.header.content_length = nil';
- }
---- request
-GET /lua
---- response_headers
-!content-length
---- response_body
-hello world
-
-
-
-=== TEST 39: backtrace
---- config
- location /t {
- header_filter_by_lua '
- local bar
- local function foo()
- bar()
- end
-
- function bar()
- error("something bad happened")
- end
-
- foo()
- ';
- echo ok;
- }
---- request
- GET /t
---- ignore_response
---- error_log
-something bad happened
-stack traceback:
-in function 'error'
-in function 'bar'
-in function 'foo'
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 40: Lua file does not exist
---- config
- location /lua {
- echo ok;
- header_filter_by_lua_file html/test2.lua;
- }
---- user_files
->>> test.lua
-v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- ignore_response
---- error_log eval
-qr/failed to load external Lua file ".*?test2\.lua": cannot open .*? No such file or directory/
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 41: filter finalize
---- config
- error_page 582 = /bar;
- location = /t {
- echo ok;
- header_filter_by_lua '
- return ngx.exit(582)
- ';
- }
-
- location = /bar {
- echo hi;
- header_filter_by_lua '
- return ngx.exit(302)
- ';
- }
---- request
-GET /t
---- response_body_like: 302 Found
---- error_code: 302
---- no_error_log
-[error]
-
-
-
-=== TEST 42: syntax error in header_filter_by_lua_block
---- config
- location /lua {
-
- header_filter_by_lua_block {
- 'for end';
- }
- content_by_lua_block {
- ngx.say("Hello world")
- }
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-failed to load inlined Lua code: header_filter_by_lua(nginx.conf:41):2: unexpected symbol near ''for end''
---- no_error_log
-no_such_error
---- curl_error eval
-qr/curl: \(56\) Failure when receiving data from the peer/
-
-
-
-=== TEST 43: syntax error in second content_by_lua_block
---- config
- location /foo {
- header_filter_by_lua_block {
- 'for end';
- }
- content_by_lua_block {
- ngx.say("Hello world")
- }
- }
-
- location /lua {
- header_filter_by_lua_block {
- 'for end';
- }
- content_by_lua_block {
- ngx.say("Hello world")
- }
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-failed to load inlined Lua code: header_filter_by_lua(nginx.conf:49):2: unexpected symbol near ''for end''
---- no_error_log
-no_such_error
---- curl_error eval
-qr/curl: \(56\) Failure when receiving data from the peer/
-
-
-
-=== TEST 44: syntax error in /tmp/12345678901234567890123456789012345.conf
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("Hello world")
- }
-
- include /tmp/12345678901234567890123456789012345.conf;
- }
---- user_files
->>> /tmp/12345678901234567890123456789012345.conf
- header_filter_by_lua_block {
- 'for end';
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-failed to load inlined Lua code: header_filter_by_lua(...901234567890123456789012345.conf:1):2: unexpected symbol near ''for end''
---- no_error_log
-[alert]
---- curl_error eval
-qr/curl: \(56\) Failure when receiving data from the peer/
diff --git a/src/deps/src/lua-nginx-module/t/042-crc32.t b/src/deps/src/lua-nginx-module/t/042-crc32.t
deleted file mode 100644
index 73aa1f433..000000000
--- a/src/deps/src/lua-nginx-module/t/042-crc32.t
+++ /dev/null
@@ -1,56 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: short sanity
---- config
- location = /test {
- content_by_lua '
- ngx.say(ngx.crc32_short("hello, world"))
- ';
- }
---- request
-GET /test
---- response_body
-4289425978
-
-
-
-=== TEST 2: long sanity
---- config
- location = /test {
- content_by_lua '
- ngx.say(ngx.crc32_long("hello, world"))
- ';
- }
---- request
-GET /test
---- response_body
-4289425978
-
-
-
-=== TEST 3: long sanity (empty)
---- config
- location = /test {
- content_by_lua '
- ngx.say(ngx.crc32_long(""))
- ';
- }
---- request
-GET /test
---- response_body
-0
diff --git a/src/deps/src/lua-nginx-module/t/043-shdict.t b/src/deps/src/lua-nginx-module/t/043-shdict.t
deleted file mode 100644
index 649683b9f..000000000
--- a/src/deps/src/lua-nginx-module/t/043-shdict.t
+++ /dev/null
@@ -1,2477 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-#repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 17);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: string key, int value
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- dogs:set("bah", 10502)
- local val = dogs:get("foo")
- ngx.say(val, " ", type(val))
- val = dogs:get("bah")
- ngx.say(val, " ", type(val))
- ';
- }
---- request
-GET /test
---- response_body
-32 number
-10502 number
---- no_error_log
-[error]
-
-
-
-=== TEST 2: string key, floating-point value
---- http_config
- lua_shared_dict cats 1m;
---- config
- location = /test {
- content_by_lua '
- local cats = ngx.shared.cats
- cats:set("foo", 3.14159)
- cats:set("baz", 1.28)
- cats:set("baz", 3.96)
- local val = cats:get("foo")
- ngx.say(val, " ", type(val))
- val = cats:get("baz")
- ngx.say(val, " ", type(val))
- ';
- }
---- request
-GET /test
---- response_body
-3.14159 number
-3.96 number
---- no_error_log
-[error]
-
-
-
-=== TEST 3: string key, boolean value
---- http_config
- lua_shared_dict cats 1m;
---- config
- location = /test {
- content_by_lua '
- local cats = ngx.shared.cats
- cats:set("foo", true)
- cats:set("bar", false)
- local val = cats:get("foo")
- ngx.say(val, " ", type(val))
- val = cats:get("bar")
- ngx.say(val, " ", type(val))
- ';
- }
---- request
-GET /test
---- response_body
-true boolean
-false boolean
---- no_error_log
-[error]
-
-
-
-=== TEST 4: number keys, string values
---- http_config
- lua_shared_dict cats 1m;
---- config
- location = /test {
- content_by_lua '
- local cats = ngx.shared.cats
- ngx.say(cats:set(1234, "cat"))
- ngx.say(cats:set("1234", "dog"))
- ngx.say(cats:set(256, "bird"))
- ngx.say(cats:get(1234))
- ngx.say(cats:get("1234"))
- local val = cats:get("256")
- ngx.say(val, " ", type(val))
- ';
- }
---- request
-GET /test
---- response_body
-truenilfalse
-truenilfalse
-truenilfalse
-dog
-dog
-bird string
---- no_error_log
-[error]
-
-
-
-=== TEST 5: different-size values set to the same key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", "hello")
- ngx.say(dogs:get("foo"))
- dogs:set("foo", "hello, world")
- ngx.say(dogs:get("foo"))
- dogs:set("foo", "hello")
- ngx.say(dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-hello
-hello, world
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 6: expired entries (can be auto-removed by get)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32, 0.01)
- ngx.location.capture("/sleep/0.01")
- ngx.say(dogs:get("foo"))
- ';
- }
- location ~ '^/sleep/(.+)' {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 7: expired entries (can NOT be auto-removed by get)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("bar", 56, 0.001)
- dogs:set("baz", 78, 0.001)
- dogs:set("foo", 32, 0.01)
- ngx.location.capture("/sleep/0.012")
- ngx.say(dogs:get("foo"))
- ';
- }
- location ~ '^/sleep/(.+)' {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 8: not yet expired entries
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32, 0.5)
- ngx.location.capture("/sleep/0.01")
- ngx.say(dogs:get("foo"))
- ';
- }
- location ~ '^/sleep/(.+)' {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-32
---- no_error_log
-[error]
-
-
-
-=== TEST 9: forcibly override other valid entries
---- http_config
- lua_shared_dict dogs 100k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local i = 0
- while i < 1000 do
- i = i + 1
- local val = string.rep(" hello", 10) .. i
- local res, err, forcible = dogs:set("key_" .. i, val)
- if not res or forcible then
- ngx.say(res, " ", err, " ", forcible)
- break
- end
- end
- ngx.say("abort at ", i)
- ngx.say("cur value: ", dogs:get("key_" .. i))
- if i > 1 then
- ngx.say("1st value: ", dogs:get("key_1"))
- end
- if i > 2 then
- ngx.say("2nd value: ", dogs:get("key_2"))
- end
- ';
- }
---- pipelined_requests eval
-["GET /test", "GET /test"]
---- response_body eval
-my $a = "true nil true\nabort at (353|705)\ncur value: " . (" hello" x 10) . "\\1\n1st value: nil\n2nd value: " . (" hello" x 10) . "2\n";
-[qr/$a/,
-"true nil true\nabort at 1\ncur value: " . (" hello" x 10) . "1\n"
-]
---- no_error_log
-[error]
-
-
-
-=== TEST 10: forcibly override other valid entries and test LRU
---- http_config
- lua_shared_dict dogs 100k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local i = 0
- while i < 1000 do
- i = i + 1
- local val = string.rep(" hello", 10) .. i
- if i == 10 then
- dogs:get("key_1")
- end
- local res, err, forcible = dogs:set("key_" .. i, val)
- if not res or forcible then
- ngx.say(res, " ", err, " ", forcible)
- break
- end
- end
- ngx.say("abort at ", i)
- ngx.say("cur value: ", dogs:get("key_" .. i))
- if i > 1 then
- ngx.say("1st value: ", dogs:get("key_1"))
- end
- if i > 2 then
- ngx.say("2nd value: ", dogs:get("key_2"))
- end
- ';
- }
---- pipelined_requests eval
-["GET /test", "GET /test"]
---- response_body eval
-my $a = "true nil true\nabort at (353|705)\ncur value: " . (" hello" x 10) . "\\1\n1st value: " . (" hello" x 10) . "1\n2nd value: nil\n";
-[qr/$a/,
-"true nil true\nabort at 2\ncur value: " . (" hello" x 10) . "2\n1st value: " . (" hello" x 10) . "1\n"
-]
---- no_error_log
-[error]
-
-
-
-=== TEST 11: dogs and cats dicts
---- http_config
- lua_shared_dict dogs 1m;
- lua_shared_dict cats 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local cats = ngx.shared.cats
- dogs:set("foo", 32)
- cats:set("foo", "hello, world")
- ngx.say(dogs:get("foo"))
- ngx.say(cats:get("foo"))
- dogs:set("foo", 56)
- ngx.say(dogs:get("foo"))
- ngx.say(cats:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-32
-hello, world
-56
-hello, world
---- no_error_log
-[error]
-
-
-
-=== TEST 12: get non-existent keys
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- ngx.say(dogs:get("foo"))
- ngx.say(dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-nil
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 13: not feed the object into the call
---- SKIP
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local rc, err = pcall(dogs.set, "foo", 3, 0.01)
- ngx.say(rc, " ", err)
- rc, err = pcall(dogs.set, "foo", 3)
- ngx.say(rc, " ", err)
- rc, err = pcall(dogs.get, "foo")
- ngx.say(rc, " ", err)
- ';
- }
---- request
-GET /test
---- response_body
-false bad argument #1 to '?' (userdata expected, got string)
-false expecting 3, 4 or 5 arguments, but only seen 2
-false expecting exactly two arguments, but only seen 1
---- no_error_log
-[error]
-
-
-
-=== TEST 14: too big value
---- http_config
- lua_shared_dict dogs 50k;
---- config
- location = /test {
- content_by_lua '
- collectgarbage("collect")
- local dogs = ngx.shared.dogs
- local res, err, forcible = dogs:set("foo", string.rep("helloworld", 10000))
- ngx.say(res, " ", err, " ", forcible)
- ';
- }
---- request
-GET /test
---- response_body
-false no memory false
---- log_level: info
---- no_error_log
-[error]
-[crit]
-ngx_slab_alloc() failed: no memory in lua_shared_dict zone
-
-
-
-=== TEST 15: set too large key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local key = string.rep("a", 65535)
- local rc, err = dogs:set(key, "hello")
- ngx.say(rc, " ", err)
- ngx.say(dogs:get(key))
-
- key = string.rep("a", 65536)
- local ok, err = dogs:set(key, "world")
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
-
- ';
- }
---- request
-GET /test
---- response_body
-true nil
-hello
-not ok: key too long
---- no_error_log
-[error]
-
-
-
-=== TEST 16: bad value type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:set("foo", dogs)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: bad value type
---- no_error_log
-[error]
-
-
-
-=== TEST 17: delete after setting values
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- ngx.say(dogs:get("foo"))
- dogs:delete("foo")
- ngx.say(dogs:get("foo"))
- dogs:set("foo", "hello, world")
- ngx.say(dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-32
-nil
-hello, world
---- no_error_log
-[error]
-
-
-
-=== TEST 18: delete at first
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:delete("foo")
- ngx.say(dogs:get("foo"))
- dogs:set("foo", "hello, world")
- ngx.say(dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-nil
-hello, world
---- no_error_log
-[error]
-
-
-
-=== TEST 19: set nil after setting values
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- ngx.say(dogs:get("foo"))
- dogs:set("foo", nil)
- ngx.say(dogs:get("foo"))
- dogs:set("foo", "hello, world")
- ngx.say(dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-32
-nil
-hello, world
---- no_error_log
-[error]
-
-
-
-=== TEST 20: set nil at first
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", nil)
- ngx.say(dogs:get("foo"))
- dogs:set("foo", "hello, world")
- ngx.say(dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-nil
-hello, world
---- no_error_log
-[error]
-
-
-
-=== TEST 21: fail to allocate memory
---- http_config
- lua_shared_dict dogs 100k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local i = 0
- while i < 1000 do
- i = i + 1
- local val = string.rep("hello", i )
- local res, err, forcible = dogs:set("key_" .. i, val)
- if not res or forcible then
- ngx.say(res, " ", err, " ", forcible)
- break
- end
- end
- ngx.say("abort at ", i)
- ';
- }
---- request
-GET /test
---- response_body_like
-^true nil true\nabort at (?:141|140)$
---- no_error_log
-[error]
-
-
-
-=== TEST 22: string key, int value (write_by_lua)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- rewrite_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- dogs:set("bah", 10502)
- local val = dogs:get("foo")
- ngx.say(val, " ", type(val))
- val = dogs:get("bah")
- ngx.say(val, " ", type(val))
- ';
- content_by_lua return;
- }
---- request
-GET /test
---- response_body
-32 number
-10502 number
---- no_error_log
-[error]
-
-
-
-=== TEST 23: string key, int value (access_by_lua)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- access_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- dogs:set("bah", 10502)
- local val = dogs:get("foo")
- ngx.say(val, " ", type(val))
- val = dogs:get("bah")
- ngx.say(val, " ", type(val))
- ';
- content_by_lua return;
- }
---- request
-GET /test
---- response_body
-32 number
-10502 number
---- no_error_log
-[error]
-
-
-
-=== TEST 24: string key, int value (set_by_lua)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- set_by_lua $res '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- return dogs:get("foo")
- ';
- echo $res;
- }
---- request
-GET /test
---- response_body
-32
---- no_error_log
-[error]
-
-
-
-=== TEST 25: string key, int value (header_by_lua)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- echo hello;
- header_filter_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- ngx.header["X-Foo"] = dogs:get("foo")
- ';
- }
---- request
-GET /test
---- response_headers
-X-Foo: 32
---- response_body
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 26: too big value (forcible)
---- http_config
- lua_shared_dict dogs 50k;
---- config
- location = /test {
- content_by_lua '
- collectgarbage("collect")
- local dogs = ngx.shared.dogs
- dogs:set("bah", "hello")
- local res, err, forcible = dogs:set("foo", string.rep("helloworld", 10000))
- ngx.say(res, " ", err, " ", forcible)
- ';
- }
---- request
-GET /test
---- response_body
-false no memory true
---- log_level: info
---- no_error_log
-[error]
-[crit]
-ngx_slab_alloc() failed: no memory in lua_shared_dict zone
-
-
-
-=== TEST 27: add key (key exists)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- local res, err, forcible = dogs:add("foo", 10502)
- ngx.say("add: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-add: false exists false
-foo = 32
---- no_error_log
-[error]
-
-
-
-=== TEST 28: add key (key not exists)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("bah", 32)
- local res, err, forcible = dogs:add("foo", 10502)
- ngx.say("add: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-add: true nil false
-foo = 10502
---- no_error_log
-[error]
-
-
-
-=== TEST 29: add key (key expired)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("bar", 32, 0.001)
- dogs:set("baz", 32, 0.001)
- dogs:set("foo", 32, 0.001)
- ngx.location.capture("/sleep/0.003")
- local res, err, forcible = dogs:add("foo", 10502)
- ngx.say("add: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
- location ~ ^/sleep/(.+) {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-add: true nil false
-foo = 10502
---- no_error_log
-[error]
-
-
-
-=== TEST 30: add key (key expired and value size unmatched)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("bar", 32, 0.001)
- dogs:set("baz", 32, 0.001)
- dogs:set("foo", "hi", 0.001)
- ngx.location.capture("/sleep/0.003")
- local res, err, forcible = dogs:add("foo", "hello")
- ngx.say("add: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
- location ~ ^/sleep/(.+) {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-add: true nil false
-foo = hello
---- no_error_log
-[error]
-
-
-
-=== TEST 31: replace key (key exists)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- local res, err, forcible = dogs:replace("foo", 10502)
- ngx.say("replace: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
-
- local res, err, forcible = dogs:replace("foo", "hello")
- ngx.say("replace: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
-
- ';
- }
---- request
-GET /test
---- response_body
-replace: true nil false
-foo = 10502
-replace: true nil false
-foo = hello
---- no_error_log
-[error]
-
-
-
-=== TEST 32: replace key (key not exists)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("bah", 32)
- local res, err, forcible = dogs:replace("foo", 10502)
- ngx.say("replace: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-replace: false not found false
-foo = nil
---- no_error_log
-[error]
-
-
-
-=== TEST 33: replace key (key expired)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("bar", 3, 0.001)
- dogs:set("baz", 2, 0.001)
- dogs:set("foo", 32, 0.001)
- ngx.location.capture("/sleep/0.002")
- local res, err, forcible = dogs:replace("foo", 10502)
- ngx.say("replace: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
- location ~ ^/sleep/(.+) {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-replace: false not found false
-foo = nil
---- no_error_log
-[error]
-
-
-
-=== TEST 34: replace key (key expired and value size unmatched)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("bar", 32, 0.001)
- dogs:set("baz", 32, 0.001)
- dogs:set("foo", "hi", 0.001)
- ngx.location.capture("/sleep/0.002")
- local rc, err, forcible = dogs:replace("foo", "hello")
- ngx.say("replace: ", rc, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
- location ~ ^/sleep/(.+) {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-replace: false not found false
-foo = nil
---- no_error_log
-[error]
-
-
-
-=== TEST 35: incr key (key exists)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- local res, err = dogs:incr("foo", 10502)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-incr: 10534 nil
-foo = 10534
---- no_error_log
-[error]
-
-
-
-=== TEST 36: incr key (key not exists)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("bah", 32)
- local res, err = dogs:incr("foo", 2)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-incr: nil not found
-foo = nil
---- no_error_log
-[error]
-
-
-
-=== TEST 37: incr key (key expired)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("bar", 3, 0.001)
- dogs:set("baz", 2, 0.001)
- dogs:set("foo", 32, 0.001)
- ngx.location.capture("/sleep/0.002")
- local res, err = dogs:incr("foo", 10502)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
- location ~ ^/sleep/(.+) {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-incr: nil not found
-foo = nil
---- no_error_log
-[error]
-
-
-
-=== TEST 38: incr key (incr by 0)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- local res, err = dogs:incr("foo", 0)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-incr: 32 nil
-foo = 32
---- no_error_log
-[error]
-
-
-
-=== TEST 39: incr key (incr by floating point number)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- local res, err = dogs:incr("foo", 0.14)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-incr: 32.14 nil
-foo = 32.14
---- no_error_log
-[error]
-
-
-
-=== TEST 40: incr key (incr by negative numbers)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- local res, err = dogs:incr("foo", -0.14)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-incr: 31.86 nil
-foo = 31.86
---- no_error_log
-[error]
-
-
-
-=== TEST 41: incr key (original value is not number)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", true)
- local res, err = dogs:incr("foo", -0.14)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
---- request
-GET /test
---- response_body
-incr: nil not a number
-foo = true
---- no_error_log
-[error]
-
-
-
-=== TEST 42: get and set with flags
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32, 0, 199)
- dogs:set("bah", 10502, 202)
- local val, flags = dogs:get("foo")
- ngx.say(val, " ", type(val))
- ngx.say(flags, " ", type(flags))
- val, flags = dogs:get("bah")
- ngx.say(val, " ", type(val))
- ngx.say(flags, " ", type(flags))
- ';
- }
---- request
-GET /test
---- response_body
-32 number
-199 number
-10502 number
-nil nil
---- no_error_log
-[error]
-
-
-
-=== TEST 43: expired entries (can be auto-removed by get), with flags set
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32, 0.01, 255)
- ngx.location.capture("/sleep/0.01")
- local res, flags = dogs:get("foo")
- ngx.say("res = ", res, ", flags = ", flags)
- ';
- }
- location ~ '^/sleep/(.+)' {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-res = nil, flags = nil
---- no_error_log
-[error]
-
-
-
-=== TEST 44: flush_all
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- dogs:set("bah", 10502)
-
- local val = dogs:get("foo")
- ngx.say(val, " ", type(val))
- val = dogs:get("bah")
- ngx.say(val, " ", type(val))
-
- dogs:flush_all()
-
- val = dogs:get("foo")
- ngx.say(val, " ", type(val))
- val = dogs:get("bah")
- ngx.say(val, " ", type(val))
- ';
- }
---- request
-GET /t
---- response_body
-32 number
-10502 number
-nil nil
-nil nil
---- no_error_log
-[error]
-
-
-
-=== TEST 45: flush_expires
---- quic_max_idle_timeout: 1.6
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", "x", 1)
- dogs:set("bah", "y", 0)
- dogs:set("bar", "z", 100)
-
- ngx.sleep(1.5)
-
- local num = dogs:flush_expired()
- ngx.say(num)
- ';
- }
---- request
-GET /t
---- response_body
-1
---- no_error_log
-[error]
-
-
-
-=== TEST 46: flush_expires with number
---- quic_max_idle_timeout: 1.6
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- for i=1,100 do
- dogs:set(tostring(i), "x", 1)
- end
-
- dogs:set("bah", "y", 0)
- dogs:set("bar", "z", 100)
-
- ngx.sleep(1.5)
-
- local num = dogs:flush_expired(42)
- ngx.say(num)
- ';
- }
---- request
-GET /t
---- response_body
-42
---- no_error_log
-[error]
-
-
-
-=== TEST 47: flush_expires an empty dict
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local num = dogs:flush_expired()
- ngx.say(num)
- ';
- }
---- request
-GET /t
---- response_body
-0
---- no_error_log
-[error]
-
-
-
-=== TEST 48: flush_expires a dict without expired items
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- dogs:set("bah", "y", 0)
- dogs:set("bar", "z", 100)
-
- local num = dogs:flush_expired()
- ngx.say(num)
- ';
- }
---- request
-GET /t
---- response_body
-0
---- no_error_log
-[error]
-
-
-
-=== TEST 49: list all keys in a shdict
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- dogs:set("bah", "y", 0)
- dogs:set("bar", "z", 0)
- local keys = dogs:get_keys()
- ngx.say(#keys)
- table.sort(keys)
- for _,k in ipairs(keys) do
- ngx.say(k)
- end
- ';
- }
---- request
-GET /t
---- response_body
-2
-bah
-bar
---- no_error_log
-[error]
-
-
-
-=== TEST 50: list keys in a shdict with limit
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- dogs:set("bah", "y", 0)
- dogs:set("bar", "z", 0)
- local keys = dogs:get_keys(1)
- ngx.say(#keys)
- ';
- }
---- request
-GET /t
---- response_body
-1
---- no_error_log
-[error]
-
-
-
-=== TEST 51: list all keys in a shdict with expires
---- quic_max_idle_timeout: 1.6
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", "x", 1)
- dogs:set("bah", "y", 0)
- dogs:set("bar", "z", 100)
-
- ngx.sleep(1.5)
-
- local keys = dogs:get_keys()
- ngx.say(#keys)
- ';
- }
---- request
-GET /t
---- response_body
-2
---- no_error_log
-[error]
-
-
-
-=== TEST 52: list keys in a shdict with limit larger than number of keys
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- dogs:set("bah", "y", 0)
- dogs:set("bar", "z", 0)
- local keys = dogs:get_keys(3)
- ngx.say(#keys)
- ';
- }
---- request
-GET /t
---- response_body
-2
---- no_error_log
-[error]
-
-
-
-=== TEST 53: list keys in an empty shdict
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local keys = dogs:get_keys()
- ngx.say(#keys)
- ';
- }
---- request
-GET /t
---- response_body
-0
---- no_error_log
-[error]
-
-
-
-=== TEST 54: list keys in an empty shdict with a limit
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local keys = dogs:get_keys(4)
- ngx.say(#keys)
- ';
- }
---- request
-GET /t
---- response_body
-0
---- no_error_log
-[error]
-
-
-
-=== TEST 55: list all keys in a shdict with all keys expired
---- quic_max_idle_timeout: 1.6
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", "x", 1)
- dogs:set("bah", "y", 1)
- dogs:set("bar", "z", 1)
-
- ngx.sleep(1.5)
-
- local keys = dogs:get_keys()
- ngx.say(#keys)
- ';
- }
---- request
-GET /t
---- response_body
-0
---- no_error_log
-[error]
-
-
-
-=== TEST 56: list all keys in a shdict with more than 1024 keys with no limit set
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
- for i=1,2048 do
- dogs:set(tostring(i), i)
- end
- local keys = dogs:get_keys()
- ngx.say(#keys)
- ';
- }
---- request
-GET /t
---- response_body
-1024
---- no_error_log
-[error]
-
-
-
-=== TEST 57: list all keys in a shdict with more than 1024 keys with 0 limit set
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /t {
- content_by_lua '
- local dogs = ngx.shared.dogs
- for i=1,2048 do
- dogs:set(tostring(i), i)
- end
- local keys = dogs:get_keys(0)
- ngx.say(#keys)
- ';
- }
---- request
-GET /t
---- response_body
-2048
---- no_error_log
-[error]
-
-
-
-=== TEST 58: safe_set
---- http_config
- lua_shared_dict dogs 100k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local i = 0
- while i < 1000 do
- i = i + 1
- local val = string.rep(" hello", 10) .. i
- local res, err = dogs:safe_set("key_" .. i, val)
- if not res then
- ngx.say(res, " ", err)
- break
- end
- end
- ngx.say("abort at ", i)
- ngx.say("cur value: ", dogs:get("key_" .. i))
- if i > 1 then
- ngx.say("1st value: ", dogs:get("key_1"))
- end
- if i > 2 then
- ngx.say("2nd value: ", dogs:get("key_2"))
- end
- ';
- }
---- pipelined_requests eval
-["GET /test", "GET /test"]
---- response_body eval
-my $a = "false no memory\nabort at (353|705)\ncur value: nil\n1st value: " . (" hello" x 10) . "1\n2nd value: " . (" hello" x 10) . "2\n";
-[qr/$a/, qr/$a/]
---- no_error_log
-[error]
-
-
-
-=== TEST 59: safe_add
---- http_config
- lua_shared_dict dogs 100k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local i = 0
- while i < 1000 do
- i = i + 1
- local val = string.rep(" hello", 10) .. i
- local res, err = dogs:safe_add("key_" .. i, val)
- if not res then
- ngx.say(res, " ", err)
- break
- end
- end
- ngx.say("abort at ", i)
- ngx.say("cur value: ", dogs:get("key_" .. i))
- if i > 1 then
- ngx.say("1st value: ", dogs:get("key_1"))
- end
- if i > 2 then
- ngx.say("2nd value: ", dogs:get("key_2"))
- end
- ';
- }
---- pipelined_requests eval
-["GET /test", "GET /test"]
---- response_body eval
-my $a = "false no memory\nabort at (353|705)\ncur value: nil\n1st value: " . (" hello" x 10) . "1\n2nd value: " . (" hello" x 10) . "2\n";
-[qr/$a/,
-q{false exists
-abort at 1
-cur value: hello hello hello hello hello hello hello hello hello hello1
-}
-]
---- no_error_log
-[error]
-
-
-
-=== TEST 60: get_stale: expired entries can still be fetched
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32, 0.01)
- dogs:set("blah", 33, 0.3)
- ngx.sleep(0.02)
- local val, flags, stale = dogs:get_stale("foo")
- ngx.say(val, ", ", flags, ", ", stale)
- local val, flags, stale = dogs:get_stale("blah")
- ngx.say(val, ", ", flags, ", ", stale)
- ';
- }
---- request
-GET /test
---- response_body
-32, nil, true
-33, nil, false
---- no_error_log
-[error]
-
-
-
-=== TEST 61: set nil key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:set(nil, 32)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: nil key
---- no_error_log
-[error]
-
-
-
-=== TEST 62: set bad zone argument
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs.set(nil, "foo", 32)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad "zone" argument
-
-
-
-=== TEST 63: set empty string keys
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:set("", 32)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: empty key
---- no_error_log
-[error]
-
-
-
-=== TEST 64: get bad zone argument
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs.get(nil, "foo")
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad "zone" argument
-
-
-
-=== TEST 65: get nil key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:get(nil)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: nil key
---- no_error_log
-[error]
-
-
-
-=== TEST 66: get empty key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:get("")
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: empty key
---- no_error_log
-[error]
-
-
-
-=== TEST 67: get a too-long key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:get(string.rep("a", 65536))
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: key too long
---- no_error_log
-[error]
-
-
-
-=== TEST 68: set & get large values
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:set("foo", string.rep("helloworld", 1024))
- if not ok then
- ngx.say("set not ok: ", err)
- return
- end
- ngx.say("set ok")
-
- local data, err = dogs:get("foo")
- if data == nil and err then
- ngx.say("get not ok: ", err)
- return
- end
- ngx.say("get ok: ", #data)
-
- ';
- }
---- request
-GET /test
---- response_body
-set ok
-get ok: 10240
---- no_error_log
-[error]
-
-
-
-=== TEST 69: get_stale nil key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:get_stale(nil)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: nil key
---- no_error_log
-[error]
-
-
-
-=== TEST 70: get_stale empty key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:get_stale("")
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: empty key
---- no_error_log
-[error]
-
-
-
-=== TEST 71: get_stale number key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:set(1024, "hello")
- if not ok then
- ngx.say("set not ok: ", err)
- return
- end
- ngx.say("set ok")
- local data, err = dogs:get_stale(1024)
- if not ok then
- ngx.say("get_stale not ok: ", err)
- return
- end
- ngx.say("get_stale: ", data)
- ';
- }
---- request
-GET /test
---- response_body
-set ok
-get_stale: hello
---- no_error_log
-[error]
-
-
-
-=== TEST 72: get_stale a too-long key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:get_stale(string.rep("a", 65536))
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: key too long
---- no_error_log
-[error]
-
-
-
-=== TEST 73: get_stale a non-existent key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local data, err = dogs:get_stale("not_found")
- if data == nil and err then
- ngx.say("get not ok: ", err)
- return
- end
- ngx.say("get ok: ", data)
- ';
- }
---- request
-GET /test
---- response_body
-get ok: nil
---- no_error_log
-[error]
-
-
-
-=== TEST 74: set & get_stale large values
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:set("foo", string.rep("helloworld", 1024))
- if not ok then
- ngx.say("set not ok: ", err)
- return
- end
- ngx.say("set ok")
-
- local data, err, stale = dogs:get_stale("foo")
- if data == nil and err then
- ngx.say("get not ok: ", err)
- return
- end
- ngx.say("get_stale ok: ", #data, ", stale: ", stale)
-
- ';
- }
---- request
-GET /test
---- response_body
-set ok
-get_stale ok: 10240, stale: false
---- no_error_log
-[error]
-
-
-
-=== TEST 75: set & get_stale boolean values (true)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:set("foo", true)
- if not ok then
- ngx.say("set not ok: ", err)
- return
- end
- ngx.say("set ok")
-
- local data, err, stale = dogs:get_stale("foo")
- if data == nil and err then
- ngx.say("get not ok: ", err)
- return
- end
- ngx.say("get_stale ok: ", data, ", stale: ", stale)
-
- ';
- }
---- request
-GET /test
---- response_body
-set ok
-get_stale ok: true, stale: false
---- no_error_log
-[error]
-
-
-
-=== TEST 76: set & get_stale boolean values (false)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:set("foo", false)
- if not ok then
- ngx.say("set not ok: ", err)
- return
- end
- ngx.say("set ok")
-
- local data, err, stale = dogs:get_stale("foo")
- if data == nil and err then
- ngx.say("get not ok: ", err)
- return
- end
- ngx.say("get_stale ok: ", data, ", stale: ", stale)
-
- ';
- }
---- request
-GET /test
---- response_body
-set ok
-get_stale ok: false, stale: false
---- no_error_log
-[error]
-
-
-
-=== TEST 77: set & get_stale with a flag
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:set("foo", false, 0, 325)
- if not ok then
- ngx.say("set not ok: ", err)
- return
- end
- ngx.say("set ok")
-
- local data, err, stale = dogs:get_stale("foo")
- if data == nil and err then
- ngx.say("get not ok: ", err)
- return
- end
- local flags = err
- ngx.say("get_stale ok: ", data, ", flags: ", flags,
- ", stale: ", stale)
-
- ';
- }
---- request
-GET /test
---- response_body
-set ok
-get_stale ok: false, flags: 325, stale: false
---- no_error_log
-[error]
-
-
-
-=== TEST 78: incr nil key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:incr(nil, 32)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: nil key
---- no_error_log
-[error]
-
-
-
-=== TEST 79: incr bad zone argument
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs.incr(nil, "foo", 32)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad "zone" argument
-
-
-
-=== TEST 80: incr empty string keys
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:incr("", 32)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: empty key
---- no_error_log
-[error]
-
-
-
-=== TEST 81: incr too long key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local key = string.rep("a", 65536)
- local ok, err = dogs:incr(key, 32)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
-
- ';
- }
---- request
-GET /test
---- response_body
-not ok: key too long
---- no_error_log
-[error]
-
-
-
-=== TEST 82: incr number key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local key = 56
- local ok, err = dogs:set(key, 1)
- if not ok then
- ngx.say("set not ok: ", err)
- return
- end
- ngx.say("set ok")
- ok, err = dogs:incr(key, 32)
- if not ok then
- ngx.say("incr not ok: ", err)
- return
- end
- ngx.say("incr ok")
- local data, err = dogs:get(key)
- if data == nil and err then
- ngx.say("get not ok: ", err)
- return
- end
- local flags = err
- ngx.say("get ok: ", data, ", flags: ", flags)
-
- ';
- }
---- request
-GET /test
---- response_body
-set ok
-incr ok
-get ok: 33, flags: nil
---- no_error_log
-[error]
-
-
-
-=== TEST 83: incr a number-like string key
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local key = 56
- local ok, err = dogs:set(key, 1)
- if not ok then
- ngx.say("set not ok: ", err)
- return
- end
- ngx.say("set ok")
- ok, err = dogs:incr(key, "32")
- if not ok then
- ngx.say("incr not ok: ", err)
- return
- end
- ngx.say("incr ok")
- local data, err = dogs:get(key)
- if data == nil and err then
- ngx.say("get not ok: ", err)
- return
- end
- local flags = err
- ngx.say("get ok: ", data, ", flags: ", flags)
-
- ';
- }
---- request
-GET /test
---- response_body
-set ok
-incr ok
-get ok: 33, flags: nil
---- no_error_log
-[error]
-
-
-
-=== TEST 84: add nil values
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local ok, err = dogs:add("foo", nil)
- if not ok then
- ngx.say("not ok: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /test
---- response_body
-not ok: attempt to add or replace nil values
---- no_error_log
-[error]
-
-
-
-=== TEST 85: replace key with exptime
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 2, 0)
- dogs:replace("foo", 32, 0.01)
- local data = dogs:get("foo")
- ngx.say("get foo: ", data)
- ngx.location.capture("/sleep/0.02")
- local res, err, forcible = dogs:replace("foo", 10502)
- ngx.say("replace: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- ';
- }
- location ~ ^/sleep/(.+) {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-get foo: 32
-replace: false not found false
-foo = nil
---- no_error_log
-[error]
-
-
-
-=== TEST 86: the lightuserdata ngx.null has no methods of shared dicts.
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local lightuserdata = ngx.null
- lightuserdata:set("foo", 1)
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- grep_error_log chop
-attempt to index local 'lightuserdata' (a userdata value)
---- grep_error_log_out
-attempt to index local 'lightuserdata' (a userdata value)
---- error_log
-[error]
---- no_error_log
-bad "zone" argument
-
-
-
-=== TEST 87: set bad zone table
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs.set({1}, "foo", 1)
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad "zone" argument
-
-
-
-=== TEST 88: get bad zone table
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs.get({1}, "foo")
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad "zone" argument
-
-
-
-=== TEST 89: incr bad zone table
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs.incr({1}, "foo", 32)
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-
-
-
-=== TEST 90: check the type of the shdict object
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- ngx.say("type: ", type(ngx.shared.dogs))
- ';
- }
---- request
-GET /test
---- response_body
-type: table
---- no_error_log
-[error]
-
-
-
-=== TEST 91: dogs, cat mixing
---- http_config
- lua_shared_dict dogs 1m;
- lua_shared_dict cats 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- dogs:set("bah", 10502)
- local val = dogs:get("foo")
- ngx.say(val, " ", type(val))
- val = dogs:get("bah")
- ngx.say(val, " ", type(val))
-
- local cats = ngx.shared.cats
- val = cats:get("foo")
- ngx.say(val or "nil")
- val = cats:get("bah")
- ngx.say(val or "nil")
- ';
- }
---- request
-GET /test
---- response_body
-32 number
-10502 number
-nil
-nil
---- no_error_log
-[error]
-
-
-
-=== TEST 92: invalid expire time
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32, -1)
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad "exptime" argument
-
-
-
-=== TEST 93: duplicate zones
---- http_config
- lua_shared_dict dogs 1m;
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- ngx.say("error")
- ';
- }
---- request
- GET /test
---- request_body_unlike
-error
---- must_die
---- error_log
-lua_shared_dict "dogs" is already defined as "dogs"
---- error_log
-[emerg]
diff --git a/src/deps/src/lua-nginx-module/t/044-req-body.t b/src/deps/src/lua-nginx-module/t/044-req-body.t
deleted file mode 100644
index d72b1eb63..000000000
--- a/src/deps/src/lua-nginx-module/t/044-req-body.t
+++ /dev/null
@@ -1,1776 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 58);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-run_tests();
-
-__DATA__
-
-=== TEST 1: read buffered body
---- config
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ';
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 2: read buffered body (timed out)
---- config
- client_body_timeout 1ms;
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ';
- }
---- raw_request eval
-"POST /test HTTP/1.1\r
-Host: localhost\r
-Content-Length: 100\r
-Connection: close\r
-\r
-hello, world"
---- response_body:
---- error_code_like: ^(?:500)?$
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 3: read buffered body and then subrequest
---- config
- location /foo {
- echo -n foo;
- }
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- local res = ngx.location.capture("/foo");
- ngx.say(ngx.var.request_body)
- ngx.say("sub: ", res.body)
- ';
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
-sub: foo
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 4: first subrequest and then read buffered body
---- config
- location /foo {
- echo -n foo;
- }
- location = /test {
- content_by_lua '
- local res = ngx.location.capture("/foo");
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ngx.say("sub: ", res.body)
- ';
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
-sub: foo
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 5: discard body
---- config
- location = /foo {
- content_by_lua '
- ngx.req.discard_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
-
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-["body: nil\n",
-"body: hiya, world\n"]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 6: not discard body (content_by_lua falls through)
---- config
- location = /foo {
- content_by_lua '
- -- ngx.req.discard_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-["body: nil\n",
-"body: hiya, world\n",
-]
---- error_code eval
-[200, 200]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 7: read buffered body and retrieve the data
---- config
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_data())
- ';
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 8: read buffered body to file and call get_body_data
---- config
- client_body_in_file_only on;
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_data())
- ';
- }
---- request
-POST /test
-hello, world
---- response_body
-nil
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 9: read buffered body to file and call get_body_file
---- config
- client_body_in_file_only on;
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_file())
- ';
- }
---- request
-POST /test
-hello, world
---- response_body_like: client_body_temp/
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 10: read buffered body to memory and retrieve the file
---- config
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_file())
- ';
- }
---- request
-POST /test
-hello, world
---- response_body
-nil
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 11: read buffered body to memory and reset it with data in memory
---- config
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- ngx.req.set_body_data("hiya, dear")
- ngx.say(ngx.req.get_body_data())
- ngx.say(ngx.var.request_body)
- ngx.say(ngx.var.echo_request_body)
- ';
- }
---- request
-POST /test
-hello, world
---- response_body
-hiya, dear
-hiya, dear
-hiya, dear
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 12: read body to file and then override it with data in memory
---- config
- client_body_in_file_only on;
-
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- ngx.req.set_body_data("hello, baby")
- ngx.say(ngx.req.get_body_data())
- ngx.say(ngx.var.request_body)
- ';
- }
---- request
-POST /test
-yeah
---- response_body
-hello, baby
-hello, baby
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 13: do not read the current request body but replace it with our own in memory
---- config
- client_body_in_file_only on;
-
- location = /test {
- content_by_lua '
- ngx.req.set_body_data("hello, baby")
- ngx.say(ngx.req.get_body_data())
- ngx.say(ngx.var.request_body)
- -- ngx.location.capture("/sleep")
- ';
- }
- location = /sleep {
- echo_sleep 0.5;
- }
---- request
-POST /test
-yeah
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/lua entry thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):2: request body not read yet/
---- no_error_log
-[alert]
-
-
-
-=== TEST 14: read buffered body to file and reset it to a new file
---- config
-
- location = /test {
- client_body_in_file_only on;
- set $old '';
- set $new '';
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.var.old = ngx.req.get_body_file()
- ngx.req.set_body_file(ngx.var.realpath_root .. "/a.txt")
- ngx.var.new = ngx.req.get_body_file()
- ';
- #echo_request_body;
- proxy_pass http://127.0.0.1:$server_port/echo;
- #proxy_pass http://127.0.0.1:7890/echo;
- add_header X-Old $old;
- add_header X-New $new;
- }
- location /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
-hello, world
---- user_files
->>> a.txt
-Will you change this world?
---- raw_response_headers_like eval
-my $headers;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $headers = qr#x-old: \S+/client_body_temp/\d+\r
-.*?x-new: \S+/html/a\.txt\r#;
-} else {
- $headers = qr#X-Old: \S+/client_body_temp/\d+\r
-.*?X-New: \S+/html/a\.txt\r#;
-}
-
-$headers;
---- response_body
-Will you change this world?
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 15: read buffered body to file and reset it to a new file
---- config
- location = /test {
- client_body_in_file_only on;
- set $old '';
- set $new '';
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.var.old = ngx.req.get_body_file() or ""
- ngx.req.set_body_file(ngx.var.realpath_root .. "/a.txt")
- ngx.var.new = ngx.req.get_body_file()
- ';
- #echo_request_body;
- proxy_pass http://127.0.0.1:$server_port/echo;
- #proxy_pass http://127.0.0.1:7890/echo;
- add_header X-Old $old;
- add_header X-New $new;
- }
- location /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
-hello, world!
---- user_files
->>> a.txt
-Will you change this world?
---- raw_response_headers_like eval
-my $headers;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $headers = qr#x-old: \S+/client_body_temp/\d+\r
-.*?x-new: \S+/html/a\.txt\r#;
-} else {
- $headers = qr#X-Old: \S+/client_body_temp/\d+\r
-.*?X-New: \S+/html/a\.txt\r#;
-}
-
-$headers;
---- response_body
-Will you change this world?
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 16: read buffered body to file and reset it to a new file (auto-clean)
---- config
- client_body_in_file_only on;
-
- location = /test {
- set $old '';
- set $new '';
- content_by_lua '
- ngx.req.read_body()
- ngx.var.old = ngx.req.get_body_file()
- local a_file = ngx.var.realpath_root .. "/a.txt"
- ngx.req.set_body_file(a_file, true)
- local b_file = ngx.var.realpath_root .. "/b.txt"
- ngx.req.set_body_file(b_file, true)
- ngx.say("a.txt exists: ", io.open(a_file) and "yes" or "no")
- ngx.say("b.txt exists: ", io.open(b_file) and "yes" or "no")
- ';
- }
- location /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
-hello, world
---- user_files
->>> a.txt
-Will you change this world?
->>> b.txt
-Sure I will!
---- response_body
-a.txt exists: no
-b.txt exists: yes
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 17: read buffered body to memory and reset it to a new file (auto-clean)
---- config
- client_body_in_file_only off;
-
- location = /test {
- set $old '';
- set $new '';
- rewrite_by_lua '
- ngx.req.read_body()
- local a_file = ngx.var.realpath_root .. "/a.txt"
- ngx.req.set_body_file(a_file, true)
- ';
- echo_request_body;
- }
- location /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- pipelined_requests eval
-["POST /test
-hello, world",
-"POST /test
-hey, you"]
---- user_files
->>> a.txt
-Will you change this world?
---- response_body eval
-["Will you change this world?\n",
-qr/500 Internal Server Error/]
---- error_code eval
-[200, 500]
---- no_error_log
-[alert]
-
-
-
-=== TEST 18: read buffered body to memory and reset it to a new file (no auto-clean)
---- config
- client_body_in_file_only off;
-
- location = /test {
- set $old '';
- set $new '';
- rewrite_by_lua '
- ngx.req.read_body()
- local a_file = ngx.var.realpath_root .. "/a.txt"
- ngx.req.set_body_file(a_file, false)
- ';
- echo_request_body;
- }
- location /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- pipelined_requests eval
-["POST /test
-hello, world",
-"POST /test
-hey, you"]
---- user_files
->>> a.txt
-Will you change this world?
---- response_body eval
-["Will you change this world?\n",
-"Will you change this world?\n"]
---- error_code eval
-[200, 200]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 19: request body discarded and reset it to a new file (auto-clean)
---- config
- client_body_in_file_only off;
- client_header_buffer_size 80;
-
- location = /test {
- set $old '';
- set $new '';
- rewrite_by_lua '
- ngx.req.discard_body()
- local a_file = ngx.var.realpath_root .. "/a.txt"
- ngx.req.set_body_file(a_file, false)
- ';
- echo_request_body;
- }
- location /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
-hello, world
-
---- user_files
->>> a.txt
-Will you change this world?
-
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- no_error_log
-[alert]
-
-
-
-=== TEST 20: no request body and reset it to a new file (no auto-clean)
---- config
- client_body_in_file_only off;
-
- location = /test {
- set $old '';
- set $new '';
- rewrite_by_lua '
- local a_file = ngx.var.realpath_root .. "/a.txt"
- ngx.req.set_body_file(a_file, true)
- ';
- echo_request_body;
- }
- location /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
-hello, world
-
---- user_files
->>> a.txt
-Will you change this world?
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/lua entry thread aborted: runtime error: rewrite_by_lua\(nginx\.conf:\d+\):3: request body not read yet/
-
---- no_error_log
-[alert]
-
-
-
-=== TEST 21: read buffered body to memory and reset it with data in memory + proxy
---- config
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.req.set_body_data("hiya, dear dear friend!")
- ';
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
- location = /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
-hello, world
---- response_body chomp
-hiya, dear dear friend!
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 22: discard request body and reset it to a new file (no auto-clean)
---- config
- client_body_in_file_only off;
-
- location = /test {
- set $old '';
- set $new '';
- rewrite_by_lua '
- ngx.req.discard_body()
- local a_file = ngx.var.realpath_root .. "/a.txt"
- ngx.req.set_body_file(a_file, true)
- ';
- echo_request_body;
- }
- location /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
-hello, world
-
---- user_files
->>> a.txt
-Will you change this world?
-
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- no_error_log
-[alert]
-
-
-
-=== TEST 23: discard body and then read
---- config
- location = /test {
- content_by_lua '
- ngx.req.discard_body()
- ngx.req.read_body()
- ngx.print(ngx.req.get_body_data())
- ';
- }
---- pipelined_requests eval
-["POST /test
-hello, world",
-"POST /test
-hello, world"]
---- response_body eval
-["nil","nil"]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 24: set empty request body in memory
---- config
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.req.set_body_data("")
- ';
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
- location = /echo {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: [", ngx.req.get_body_data(), "]")
- ';
- }
---- pipelined_requests eval
-["POST /test
-hello, world",
-"POST /test
-hello, world"]
---- response_body eval
-["body: [nil]\n","body: [nil]\n"]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 25: set empty request body in file
---- config
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.req.set_body_file(ngx.var.realpath_root .. "/a.txt")
- ';
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
- location = /echo {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: [", ngx.req.get_body_data(), "]")
- ';
- }
---- user_files
->>> a.txt
---- pipelined_requests eval
-["POST /test
-hello, world",
-"POST /test
-hello, world"]
---- response_body eval
-["body: [nil]\n","body: [nil]\n"]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 26: read and set body
---- config
- location /test {
- lua_need_request_body on;
- access_by_lua_file html/myscript.lua;
- echo_request_body;
- }
---- user_files
->>> myscript.lua
- local data, err = ngx.req.get_post_args()
- if err then
- ngx.log(ngx.ERR, "err: ", err)
- return ngx.exit(500)
- end
-
- local data2 = {}
- for k, v in pairs(data) do
- if type(v) == "table" then
- for i, val in ipairs(v) do
- local s = ngx.escape_uri(string.upper(k)) .. '='
- .. ngx.escape_uri(string.upper(val))
- table.insert(data2, s)
- end
- else
- local s = ngx.escape_uri(string.upper(k)) .. '='
- .. ngx.escape_uri(string.upper(v))
- table.insert(data2, s)
- end
- end
- ngx.req.set_body_data(table.concat(data2, "&"))
---- request
-POST /test
-a=1&a=2&b=hello&c=world
---- response_body
-B=HELLO&A=1&A=2&C=WORLD
---- no_error_log
-[error]
---- SKIP
-
-
-
-=== TEST 27: read buffered body to memory and reset it with data in memory + proxy twice
---- config
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.req.set_body_data("hiya, dear dear friend!")
- ngx.req.set_body_data("howdy, my dear little sister!")
- ';
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
- location = /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
-hello, world
---- response_body chomp
-howdy, my dear little sister!
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 28: read buffered body to memory and reset it with data in memory and then reset it to file
---- config
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.req.set_body_data("hiya, dear dear friend!")
- ngx.req.set_body_file(ngx.var.realpath_root .. "/a.txt")
- ';
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
- location = /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- user_files
->>> a.txt
-howdy, my dear little sister!
---- request
-POST /test
-hello, world
---- response_body
-howdy, my dear little sister!
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 29: read buffered body to memory and reset it with empty string + proxy twice
---- config
- location = /test {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.req.set_body_data("hiya, dear dear friend!")
- ngx.req.set_body_data("")
- ';
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
- location = /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
-hello, world
---- response_body chomp
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 30: multi-buffer request body
---- config
- location /foo {
- default_type text/css;
- srcache_store POST /store;
-
- echo hello;
- echo world;
- }
-
- location /store {
- content_by_lua '
- local body = ngx.req.get_body_data()
- ngx.log(ngx.WARN, "srcache_store: request body len: ", #body)
- ';
- }
---- request
-GET /foo
---- response_body
-hello
-world
---- error_log
-srcache_store: request body len: 55
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 31: init & append & finish (just in buffer)
---- config
- location /t {
- content_by_lua '
- ngx.req.read_body()
- ngx.req.init_body(4)
- ngx.req.append_body("h")
- ngx.req.append_body("ell")
- ngx.req.finish_body()
-
- ngx.say("content length: ", ngx.var.http_content_length)
-
- local data = ngx.req.get_body_data()
- ngx.say("body: ", data)
-
- ';
- }
---- request
- GET /t
---- stap2
-F(ngx_http_lua_write_request_body) {
- b = ngx_chain_buf($body)
- println("buf: ", b,
- ", in-mem: ", ngx_buf_in_memory(b),
- ", size: ", ngx_buf_size(b),
- ", data: ", ngx_buf_data(b))
-}
---- response_body
-content length: 4
-body: hell
---- no_error_log
-[error]
-[alert]
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 32: init & append & finish (exceeding the buffer size)
---- config
- location /t {
- content_by_lua '
- ngx.req.read_body()
- ngx.req.init_body(4)
- ngx.req.append_body("h")
- ngx.req.append_body("ell")
- ngx.req.append_body("o")
- ngx.req.finish_body()
-
- ngx.say("content length: ", ngx.var.http_content_length)
-
- local data = ngx.req.get_body_data()
- ngx.say("body: ", data)
-
- local file = ngx.req.get_body_file()
- if not file then
- ngx.say("body file: ", file)
- return
- end
-
- local f, err = io.open(file, "r")
- if not f then
- ngx.say("failed to open file: ", err)
- return
- end
-
- local data = f:read("*a")
- f:close()
- ngx.say("body file: ", data)
- ';
- }
---- request
- GET /t
---- stap2
-F(ngx_http_lua_write_request_body) {
- b = ngx_chain_buf($body)
- println("buf: ", b,
- ", in-mem: ", ngx_buf_in_memory(b),
- ", size: ", ngx_buf_size(b),
- ", data: ", ngx_buf_data(b))
-}
-F(ngx_open_tempfile) {
- println("open temp file ", user_string($name), ", persist: ", $persistent)
-}
-F(ngx_pool_delete_file) {
- println("delete ", ngx_pool_cleanup_file_name($data))
-}
---- response_body
-content length: 5
-body: nil
-body file: hello
---- no_error_log
-[error]
-[alert]
---- error_log
-a client request body is buffered to a temporary file
---- skip_eval: 5:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 33: init & append & finish (use default buffer size) - body not read yet
---- config
- location /t {
- client_body_buffer_size 4;
- content_by_lua '
- ngx.req.init_body()
- ngx.req.append_body("h")
- ngx.req.append_body("ell")
- ngx.req.finish_body()
-
- ngx.say("content length: ", ngx.var.http_content_length)
-
- local data = ngx.req.get_body_data()
- ngx.say("body: ", data)
-
- ';
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/lua entry thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):2: request body not read yet/
---- no_error_log
-[alert]
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 34: init & append & finish (use default buffer size)
---- config
- location /t {
- client_body_buffer_size 4;
- content_by_lua '
- ngx.req.read_body()
- ngx.req.init_body()
- ngx.req.append_body("h")
- ngx.req.append_body("ell")
- ngx.req.finish_body()
-
- ngx.say("content length: ", ngx.var.http_content_length)
-
- local data = ngx.req.get_body_data()
- ngx.say("body: ", data)
-
- ';
- }
---- request
- GET /t
---- response_body
-content length: 4
-body: hell
---- no_error_log
-[error]
-[alert]
-a client request body is buffered to a temporary file
---- skip_eval: 5:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 35: init & append & finish (exceeding the buffer size, proxy)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.req.init_body(4)
- ngx.req.append_body("h")
- ngx.req.append_body("ell")
- ngx.req.append_body("o\\n")
- ngx.req.finish_body()
- ';
-
- proxy_pass http://127.0.0.1:$server_port/back;
- }
-
- location = /back {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /t
-i do like the sky
-
---- stap
-global valid = 0
-
-F(ngx_http_handler) { valid = 1 }
-
-probe syscall.unlink {
- if (valid && pid() == target()) {
- println(name, "(", argstr, ")")
- }
-}
-
---- stap_out_like chop
-^unlink\(".*?client_body_temp/\d+"\)$
---- response_body
-hello
---- no_error_log
-[error]
-[alert]
---- error_log
-a client request body is buffered to a temporary file
-
-
-
-=== TEST 36: init & append & finish (just in buffer, proxy)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.req.init_body(4)
- ngx.req.append_body("h")
- ngx.req.append_body("ell")
- ngx.req.finish_body()
- ';
-
- proxy_pass http://127.0.0.1:$server_port/back;
- }
-
- location = /back {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /t
-i do like the sky
---- response_body chop
-hell
---- no_error_log
-[error]
-[alert]
-a client request body is buffered to a temporary file
-
-
-
-=== TEST 37: init & append & finish (exceeding buffer size, discard on-disk buffer)
---- config
- client_header_buffer_size 100;
- location /t {
- client_body_buffer_size 4;
-
- content_by_lua '
- ngx.req.read_body()
-
- -- ngx.say("original body: ", ngx.req.get_body_data())
- -- ngx.say("original body file: ", ngx.req.get_body_file())
-
- ngx.req.init_body(4)
- ngx.req.append_body("h")
- ngx.req.append_body("ell")
- ngx.req.append_body("o")
- ngx.req.finish_body()
-
- ngx.say("content length: ", ngx.var.http_content_length)
-
- local data = ngx.req.get_body_data()
- ngx.say("body: ", data)
-
- local file = ngx.req.get_body_file()
- if not file then
- ngx.say("body file: ", file)
- return
- end
-
- local f, err = io.open(file, "r")
- if not f then
- ngx.say("failed to open file: ", err)
- return
- end
-
- local data = f:read("*a")
- f:close()
- ngx.say("body file: ", data)
- ';
- }
---- request eval
-"POST /t
-" . ("howdyworld" x 15)
---- stap
-/*
-F(ngx_http_read_client_request_body) { T() }
-M(http-read-body-abort) { println("read body aborted: ", user_string($arg2)) }
-M(http-read-req-header-done) { println("req header: ", ngx_table_elt_key($arg2), ": ", ngx_table_elt_value($arg2)) }
-#probe syscall.open { if (isinstr(argstr, "temp")) { println(name, ": ", argstr) } }
-
-probe syscall.unlink {
- println(name, ": ", argstr, " :", target(), " == ", pid(), ": ", execname())
- system(sprintf("ps aux|grep %d|grep -v grep > /dev/stderr", target()))
- system(sprintf("ps aux|grep %d|grep -v grep > /dev/stderr", pid()))
-}
-*/
-
-global valid = 0
-
-F(ngx_http_handler) { valid = 1 }
-#F(ngx_http_free_request) { valid = 0 }
-
-probe syscall.unlink {
- if (valid && pid() == target()) {
- println(name, "(", argstr, ")")
- #print_ubacktrace()
- }
-}
-
-/*
-probe syscall.close, syscall.open, syscall.unlink {
- if (valid && pid() == target()) {
- print(name, "(", argstr, ")")
- #print_ubacktrace()
- }
-}
-
-probe syscall.close.return, syscall.open.return, syscall.unlink.return {
- if (valid && pid() == target()) {
- println(" = ", retstr)
- }
-}
-*/
---- stap_out_like chop
-^unlink\(".*?client_body_temp/\d+"\)
-unlink\(".*?client_body_temp/\d+"\)$
---- response_body
-content length: 5
-body: nil
-body file: hello
---- no_error_log
-[error]
-[alert]
---- error_log
-a client request body is buffered to a temporary file
-
-
-
-=== TEST 38: ngx.req.socket + init & append & finish (requests)
---- config
- location = /t {
- client_body_buffer_size 1;
- lua_socket_buffer_size 1;
- content_by_lua '
- local sock,err = ngx.req.socket()
- if not sock then
- ngx.say("failed to get req socket: ", err)
- return
- end
-
- ngx.req.init_body(100)
-
- while true do
- local data, err = sock:receive(1)
- if not data then
- if err == "closed" then
- break
- else
- ngx.say("failed to read body: ", err)
- return
- end
- end
- ngx.req.append_body(data)
- end
-
- ngx.req.finish_body()
-
- ngx.say("content length: ", ngx.var.http_content_length)
-
- local data = ngx.req.get_body_data()
- ngx.say("body: ", data)
-
- ';
- }
---- request
-POST /t
-hello, my dear friend!
---- response_body
-content length: 22
-body: hello, my dear friend!
---- no_error_log
-[error]
-[alert]
-a client request body is buffered to a temporary file
---- skip_eval: 5:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 39: ngx.req.socket + init & append & finish (pipelined requests, small buffer size)
---- config
- location = /t {
- client_body_buffer_size 1;
- lua_socket_buffer_size 1;
- content_by_lua '
- local sock,err = ngx.req.socket()
- if not sock then
- ngx.say("failed to get req socket: ", err)
- return
- end
-
- ngx.req.init_body(100)
-
- while true do
- local data, err = sock:receive(1)
- if not data then
- if err == "closed" then
- break
- else
- ngx.say("failed to read body: ", err)
- return
- end
- end
- ngx.req.append_body(data)
- end
-
- ngx.req.finish_body()
-
- ngx.say("content length: ", ngx.var.http_content_length)
-
- local data = ngx.req.get_body_data()
- ngx.say("body: ", data)
-
- ';
- }
---- pipelined_requests eval
-["POST /t
-hello, my dear friend!",
-"POST /t
-blah blah blah"]
---- response_body eval
-["content length: 22
-body: hello, my dear friend!
-","content length: 14
-body: blah blah blah
-"]
---- no_error_log
-[error]
-[alert]
---- no_error_log
-a client request body is buffered to a temporary file
-
-
-
-=== TEST 40: ngx.req.socket + init & append & finish (pipelined requests, big buffer size)
---- config
- location = /t {
- client_body_buffer_size 100;
- lua_socket_buffer_size 100;
- content_by_lua '
- local sock,err = ngx.req.socket()
- if not sock then
- ngx.say("failed to get req socket: ", err)
- return
- end
-
- ngx.req.init_body(100)
-
- while true do
- local data, err, partial = sock:receive(100)
- if not data then
- if err == "closed" then
- ngx.req.append_body(partial)
- break
- else
- ngx.say("failed to read body: ", err)
- return
- end
- end
- ngx.req.append_body(data)
- end
-
- ngx.req.finish_body()
-
- ngx.say("content length: ", ngx.var.http_content_length)
-
- local data = ngx.req.get_body_data()
- ngx.say("body: ", data)
-
- ';
- }
---- pipelined_requests eval
-["POST /t
-hello, my dear friend!",
-"POST /t
-blah blah blah"]
---- response_body eval
-["content length: 22
-body: hello, my dear friend!
-","content length: 14
-body: blah blah blah
-"]
---- no_error_log
-[error]
-[alert]
---- no_error_log
-a client request body is buffered to a temporary file
-
-
-
-=== TEST 41: calling ngx.req.socket after ngx.req.read_body
---- config
- location = /t {
- client_body_buffer_size 100;
- lua_socket_buffer_size 100;
- content_by_lua '
- ngx.req.read_body()
-
- local sock, err = ngx.req.socket()
- if not sock then
- ngx.say("failed to get req socket: ", err)
- return
- end
-
- ngx.say("done")
- ';
- }
---- request
-POST /t
-hello, my dear friend!
---- response_body
-failed to get req socket: request body already exists
---- no_error_log
-[error]
-[alert]
-a client request body is buffered to a temporary file
---- skip_eval: 5:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 42: failed to write 100 continue
---- config
- location = /test {
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- ';
- }
---- request
-POST /test
-hello, world
---- more_headers
-Expect: 100-Continue
---- ignore_response
---- no_error_log
-[alert]
-[error]
-http finalize request: 500, "/test?" a:1, c:0
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 43: chunked support in ngx.req.read_body
---- config
- location /t {
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_data())
- ';
- }
---- raw_request eval
-"POST /t HTTP/1.1\r
-Host: localhost\r
-Transfer-Encoding: chunked\r
-Connection: close\r
-\r
-5\r
-hello\r
-1\r
-,\r
-1\r
- \r
-5\r
-world\r
-0\r
-\r
-"
-
---- response_body
-hello, world
---- no_error_log
-[error]
-[alert]
---- skip_nginx: 4: <1.3.9
-
-
-
-=== TEST 44: zero size request body and reset it to a new file
---- config
- location = /test {
- client_body_in_file_only on;
- set $old '';
- set $new '';
- rewrite_by_lua '
- ngx.req.read_body()
- ngx.req.set_body_file(ngx.var.realpath_root .. "/a.txt")
- ngx.var.new = ngx.req.get_body_file()
- ';
- #echo_request_body;
- proxy_pass http://127.0.0.1:$server_port/echo;
- #proxy_pass http://127.0.0.1:7890/echo;
- add_header X-Old $old;
- add_header X-New $new;
- }
- location /echo {
- echo_read_request_body;
- echo_request_body;
- }
---- request
-POST /test
---- user_files
->>> a.txt
-Will you change this world?
-
---- stap
-probe syscall.fcntl {
- O_DIRECT = 0x4000
- if (pid() == target() && ($arg & O_DIRECT)) {
- println("fcntl(O_DIRECT)")
- }
-}
---- stap_out_unlike
-fcntl\(O_DIRECT\)
-
---- raw_response_headers_like eval
-my $headers;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $headers = qr#.*?x-new: \S+/html/a\.txt\r#;
-} else {
- $headers = qr#.*?X-New: \S+/html/a\.txt\r#;
-}
-
-$headers;
---- response_body
-Will you change this world?
---- no_error_log
-[error]
-[alert]
---- skip_eval: 6:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 45: not discard body (content_by_lua exit 200)
---- config
- location = /foo {
- content_by_lua '
- -- ngx.req.discard_body()
- ngx.say("body: ", ngx.var.request_body)
- ngx.exit(200)
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-["body: nil\n",
-"body: hiya, world\n",
-]
---- error_code eval
-[200, 200]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 46: not discard body (content_by_lua exit 201)
---- config
- location = /foo {
- content_by_lua '
- -- ngx.req.discard_body()
- ngx.say("body: ", ngx.var.request_body)
- ngx.exit(201)
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-["body: nil\n",
-"body: hiya, world\n",
-]
---- error_code eval
-[200, 200]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 47: not discard body (content_by_lua exit 302)
---- config
- location = /foo {
- content_by_lua '
- -- ngx.req.discard_body()
- -- ngx.say("body: ", ngx.var.request_body)
- ngx.redirect("/blah")
- ';
- }
- location = /bar {
- content_by_lua '
- ngx.req.read_body()
- ngx.say("body: ", ngx.var.request_body)
- ';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /bar
-hiya, world"]
---- response_body eval
-[qr/302 Found/,
-"body: hiya, world\n",
-]
---- error_code eval
-[302, 200]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 48: not discard body (custom error page)
---- config
- error_page 404 = /err;
-
- location = /foo {
- content_by_lua '
- ngx.exit(404)
- ';
- }
- location = /err {
- content_by_lua 'ngx.say("error")';
- }
---- pipelined_requests eval
-["POST /foo
-hello, world",
-"POST /foo
-hiya, world"]
---- response_body eval
-["error\n",
-"error\n",
-]
---- error_code eval
-[404, 404]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 49: get body data at log phase
---- config
- location = /test {
- content_by_lua_block {
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_data())
- }
- log_by_lua_block {
- ngx.log(ngx.WARN, "request body:", ngx.req.get_body_data())
- }
- }
---- request
-POST /test
-hello, world
---- response_body
-hello, world
---- error_log
-request body:hello, world
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 50: init & append & finish (content_length = 0)
---- config
- location /t {
- content_by_lua '
- local old_http_content_length = ngx.var.http_content_length
-
- ngx.req.read_body()
- ngx.req.init_body()
- ngx.req.append_body("he")
- ngx.req.append_body("llo")
- ngx.req.finish_body()
-
- ngx.say("old content length: ", old_http_content_length)
-
- local data = ngx.req.get_body_data()
- local data_file = ngx.req.get_body_file()
-
- if not data and data_file then
- ngx.say("no data in buf, go to data file")
- end
-
- ngx.say("content length: ", ngx.var.http_content_length)
- ';
- }
---- request
- GET /t
---- more_headers
-Content-Length: 0
---- response_body
-old content length: 0
-content length: 5
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 51: init & append & finish (init_body(0))
---- config
- location /t {
- content_by_lua '
- local old_http_content_length = ngx.var.http_content_length
-
- ngx.req.read_body()
- ngx.req.init_body(0)
- ngx.req.append_body("he")
- ngx.req.append_body("llo")
- ngx.req.finish_body()
-
- ngx.say("old content length: ", old_http_content_length)
-
- local data = ngx.req.get_body_data()
- local data_file = ngx.req.get_body_file()
-
- if not data and data_file then
- ngx.say("no data in buf, go to data file")
- end
-
- ngx.say("content length: ", ngx.var.http_content_length)
- ';
- }
---- request
- GET /t
---- more_headers
-Content-Length: 0
---- response_body
-old content length: 0
-no data in buf, go to data file
-content length: 5
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 52: init & append & finish (client_body_buffer_size = 0)
---- http_config
- client_body_buffer_size 0;
---- config
- location /t {
- content_by_lua '
- ngx.req.read_body()
- ngx.req.init_body()
- ngx.req.append_body("he")
- ngx.req.append_body("llo")
- ngx.req.finish_body()
-
- local data = ngx.req.get_body_data()
- local data_file = ngx.req.get_body_file()
-
- if not data and data_file then
- ngx.say("no data in buf, go to data file")
- end
-
- ngx.say("content length: ", ngx.var.http_content_length)
- ';
- }
---- request
- GET /t
---- response_body
-no data in buf, go to data file
-content length: 5
---- no_error_log
-[error]
-[alert]
diff --git a/src/deps/src/lua-nginx-module/t/045-ngx-var.t b/src/deps/src/lua-nginx-module/t/045-ngx-var.t
deleted file mode 100644
index 6fe5590d9..000000000
--- a/src/deps/src/lua-nginx-module/t/045-ngx-var.t
+++ /dev/null
@@ -1,292 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 9);
-
-#no_diff();
-#no_long_string();
-#master_on();
-#workers(2);
-run_tests();
-
-__DATA__
-
-=== TEST 1: set indexed variables to nil
---- config
- location = /test {
- set $var 32;
- content_by_lua '
- ngx.say("old: ", ngx.var.var)
- ngx.var.var = nil
- ngx.say("new: ", ngx.var.var)
- ';
- }
---- request
-GET /test
---- response_body
-old: 32
-new: nil
-
-
-
-=== TEST 2: set variables with set_handler to nil
---- config
- location = /test {
- content_by_lua '
- ngx.say("old: ", ngx.var.args)
- ngx.var.args = nil
- ngx.say("new: ", ngx.var.args)
- ';
- }
---- request
-GET /test?hello=world
---- response_body
-old: hello=world
-new: nil
-
-
-
-=== TEST 3: reference nonexistent variable
---- config
- location = /test {
- set $var 32;
- content_by_lua '
- ngx.say("value: ", ngx.var.notfound)
- ';
- }
---- request
-GET /test
---- response_body
-value: nil
-
-
-
-=== TEST 4: no-hash variables
---- config
- location = /test {
- proxy_pass http://127.0.0.1:$server_port/foo;
- header_filter_by_lua '
- ngx.header["X-My-Host"] = ngx.var.proxy_host
- ';
- }
-
- location = /foo {
- echo foo;
- }
---- request
-GET /test
---- response_headers
-X-My-Host: foo
---- response_body
-foo
---- SKIP
-
-
-
-=== TEST 5: variable name is caseless
---- config
- location = /test {
- set $Var 32;
- content_by_lua '
- ngx.say("value: ", ngx.var.VAR)
- ';
- }
---- request
-GET /test
---- response_body
-value: 32
-
-
-
-=== TEST 6: true $invalid_referer variable value in Lua
-github issue #239
---- config
- location = /t {
- valid_referers www.foo.com;
- content_by_lua '
- ngx.say("invalid referer: ", ngx.var.invalid_referer)
- ngx.exit(200)
- ';
- #echo $invalid_referer;
- }
-
---- request
-GET /t
---- more_headers
-Referer: http://www.foo.com/
-
---- response_body
-invalid referer:
-
---- no_error_log
-[error]
-
-
-
-=== TEST 7: false $invalid_referer variable value in Lua
-github issue #239
---- config
- location = /t {
- valid_referers www.foo.com;
- content_by_lua '
- ngx.say("invalid referer: ", ngx.var.invalid_referer)
- ngx.exit(200)
- ';
- #echo $invalid_referer;
- }
-
---- request
-GET /t
---- more_headers
-Referer: http://www.bar.com
-
---- response_body
-invalid referer: 1
-
---- no_error_log
-[error]
-
-
-
-=== TEST 8: $proxy_host & $proxy_port & $proxy_add_x_forwarded_for
---- config
- location = /t {
- proxy_pass http://127.0.0.1:$server_port/back;
- header_filter_by_lua_block {
- ngx.header["Proxy-Host"] = ngx.var.proxy_host
- ngx.header["Proxy-Port"] = ngx.var.proxy_port
- ngx.header["Proxy-Add-X-Forwarded-For"] = ngx.var.proxy_add_x_forwarded_for
- }
- }
-
- location = /back {
- echo hello;
- }
---- request
-GET /t
---- raw_response_headers_like eval
-my $headers;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $headers =
-qr/proxy-host: 127.0.0.1\:\d+\r
-proxy-port: \d+\r
-proxy-add-x-forwarded-for: 127.0.0.1\r/;
-} else {
- $headers =
-qr/Proxy-Host: 127.0.0.1\:\d+\r
-Proxy-Port: \d+\r
-Proxy-Add-X-Forwarded-For: 127.0.0.1\r/;
-}
-
-$headers;
---- response_body
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 9: get a bad variable name
---- config
- location = /test {
- set $true 32;
- content_by_lua '
- ngx.say("value: ", ngx.var[true])
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_log
-bad variable name
---- error_code: 500
-
-
-
-=== TEST 10: set a bad variable name
---- config
- location = /test {
- set $true 32;
- content_by_lua '
- ngx.var[true] = 56
- ';
- }
---- request
-GET /test
---- response_body_like: 500 Internal Server Error
---- error_log
-bad variable name
---- error_code: 500
-
-
-
-=== TEST 11: set a variable that is not changeable
---- config
- location = /test {
- content_by_lua '
- ngx.var.query_string = 56
- ';
- }
---- request
-GET /test?hello
---- response_body_like: 500 Internal Server Error
---- error_log
-variable "query_string" not changeable
---- error_code: 500
-
-
-
-=== TEST 12: get a variable in balancer_by_lua_block
---- http_config
- upstream balancer {
- server 127.0.0.1;
- balancer_by_lua_block {
- local balancer = require "ngx.balancer"
- local host = "127.0.0.1"
- local port = ngx.var.port;
- local ok, err = balancer.set_current_peer(host, port)
- if not ok then
- ngx.log(ngx.ERR, "failed to set the current peer: ", err)
- return ngx.exit(500)
- end
- }
- }
- server {
- # this is the real entry point
- listen $TEST_NGINX_RAND_PORT_1;
- location / {
- content_by_lua_block{
- ngx.print("this is backend peer $TEST_NGINX_RAND_PORT_1")
- }
- }
- }
- server {
- # this is the real entry point
- listen $TEST_NGINX_RAND_PORT_2;
- location / {
- content_by_lua_block{
- ngx.print("this is backend peer $TEST_NGINX_RAND_PORT_2")
- }
- }
- }
---- config
- location =/balancer {
- set $port '';
- set_by_lua_block $port {
- local args, _ = ngx.req.get_uri_args()
- local port = args['port']
- return port
- }
- proxy_pass http://balancer;
- }
---- pipelined_requests eval
-["GET /balancer?port=\$TEST_NGINX_RAND_PORT_1", "GET /balancer?port=\$TEST_NGINX_RAND_PORT_2"]
---- response_body eval
-["this is backend peer \$TEST_NGINX_RAND_PORT_1", "this is backend peer \$TEST_NGINX_RAND_PORT_2"]
diff --git a/src/deps/src/lua-nginx-module/t/046-hmac.t b/src/deps/src/lua-nginx-module/t/046-hmac.t
deleted file mode 100644
index 32e222ba7..000000000
--- a/src/deps/src/lua-nginx-module/t/046-hmac.t
+++ /dev/null
@@ -1,31 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /lua {
- content_by_lua '
- local digest = ngx.hmac_sha1("thisisverysecretstuff", "some string we want to sign")
- ngx.say(ngx.encode_base64(digest))
- ';
- }
---- request
-GET /lua
---- response_body
-R/pvxzHC4NLtj7S+kXFg/NePTmk=
diff --git a/src/deps/src/lua-nginx-module/t/047-match-jit.t b/src/deps/src/lua-nginx-module/t/047-match-jit.t
deleted file mode 100644
index 9b40a889d..000000000
--- a/src/deps/src/lua-nginx-module/t/047-match-jit.t
+++ /dev/null
@@ -1,242 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 5);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: matched with j
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)", "j")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 2: not matched with j
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, world", "([0-9]+)", "j")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched!
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 3: matched with jo
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, 1234", "([0-9]+)", "jo")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-1234
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 4: not matched with jo
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello, world", "([0-9]+)", "jo")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched!
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 5: bad pattern
---- config
- location /re {
- content_by_lua '
- local m, err = ngx.re.match("hello\\nworld", "(abc", "j")
- if m then
- ngx.say(m[0])
-
- else
- if err then
- ngx.say("error: ", err)
-
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 6: just hit match limit
---- http_config
- lua_regex_match_limit 2940;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 21)
-
-local start = ngx.now()
-
-local res, err = ngx.re.match(s, re, "jo")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if not res then
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("failed to match")
- return
-end
-
---- request
- GET /re
---- response_body eval
-# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
-# but PCRE2 replaces this with pcre2_set_match_limit interface,
-# which has different effects.
-$Test::Nginx::Util::PcreVersion == 2 ?
-# PCRE2_ERROR_MATCHLIMIT (-47)
-"error: pcre_exec() failed: -47\n"
-:
-"error: pcre_exec() failed: -8\n"
-
-
-
-=== TEST 7: just not hit match limit
---- http_config
- lua_regex_match_limit 2950;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 21)
-
-local start = ngx.now()
-
-local res, err = ngx.re.match(s, re, "jo")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if not res then
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("failed to match")
- return
-end
-
---- request
- GET /re
---- response_body
-failed to match
diff --git a/src/deps/src/lua-nginx-module/t/048-match-dfa.t b/src/deps/src/lua-nginx-module/t/048-match-dfa.t
deleted file mode 100644
index 023231b5c..000000000
--- a/src/deps/src/lua-nginx-module/t/048-match-dfa.t
+++ /dev/null
@@ -1,247 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 4);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: matched with d
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello", "(he|hell)", "d")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hell
-nil
-nil
-
-
-
-=== TEST 2: matched with d + o
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello", "(he|hell)", "do")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hell
-nil
-nil
-
-
-
-=== TEST 3: matched with d + j
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello", "(he|hell)", "jd")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hell
-
-
-
-=== TEST 4: not matched with j
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("world", "(he|hell)", "d")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched!
-
-
-
-=== TEST 5: matched with do
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello", "he|hell", "do")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hell
-nil
-nil
-
-
-
-=== TEST 6: not matched with do
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("world", "([0-9]+)", "do")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched!
-
-
-
-=== TEST 7: UTF-8 mode without UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("ä½ å¥½", ".", "Ud")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 2000
-
---- request
- GET /re
---- response_body
-ä½
---- no_error_log
-[error]
-
-
-
-=== TEST 8: UTF-8 mode with UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("ä½ å¥½", ".", "ud")
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 0
-
---- request
- GET /re
---- response_body
-ä½
---- no_error_log
-[error]
-
-
-
-=== TEST 9: matched with do
---- config
- location /re {
- content_by_lua '
- local m = ngx.re.match("hello", "(h)(e)(l)", "jo")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(m[3])
- else
- ngx.say("not matched!")
- end
- local m = ngx.re.match("horld", "(h)(e)?(l)?", "jo")
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- ngx.say(m[3])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hel
-h
-e
-l
-h
-h
-false
-false
diff --git a/src/deps/src/lua-nginx-module/t/049-gmatch-jit.t b/src/deps/src/lua-nginx-module/t/049-gmatch-jit.t
deleted file mode 100644
index b76df35e9..000000000
--- a/src/deps/src/lua-nginx-module/t/049-gmatch-jit.t
+++ /dev/null
@@ -1,267 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 9);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: gmatch matched
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("hello, world", "[a-z]+", "j") do
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-world
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 2: fail to match
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[0-9]", "j")
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
- ';
- }
---- request
- GET /re
---- response_body
-nil
-nil
-nil
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 3: gmatch matched but no iterate
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+", "j")
- ngx.say("done")
- ';
- }
---- request
- GET /re
---- response_body
-done
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 4: gmatch matched but only iterate once and still matches remain
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+", "j")
- local m = it()
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 5: gmatch matched + o
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("hello, world", "[a-z]+", "jo") do
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-world
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 6: fail to match + o
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[0-9]", "jo")
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
- ';
- }
---- request
- GET /re
---- response_body
-nil
-nil
-nil
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 7: gmatch matched but no iterate + o
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+", "jo")
- ngx.say("done")
- ';
- }
---- request
- GET /re
---- response_body
-done
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 8: gmatch matched but only iterate once and still matches remain + o
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+", "jo")
- local m = it()
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 9: bad pattern
---- config
- location /re {
- content_by_lua '
- local m, err = ngx.re.gmatch("hello\\nworld", "(abc", "j")
- if not m then
- ngx.say("error: ", err)
- return
- end
- ngx.say("success")
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/050-gmatch-dfa.t b/src/deps/src/lua-nginx-module/t/050-gmatch-dfa.t
deleted file mode 100644
index 4c5f820e4..000000000
--- a/src/deps/src/lua-nginx-module/t/050-gmatch-dfa.t
+++ /dev/null
@@ -1,341 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 5);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: gmatch matched
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("hello, halo", "h[a-z]|h[a-z][a-z]", "d") do
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-hel
-nil
-hal
-nil
-
-
-
-=== TEST 2: d + j
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("hello, halo", "h[a-z]|h[a-z][a-z]", "dj") do
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-hel
-hal
-
-
-
-=== TEST 3: fail to match
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[0-9]", "d")
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
- ';
- }
---- request
- GET /re
---- response_body
-nil
-nil
-nil
-
-
-
-=== TEST 4: gmatch matched but no iterate
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+", "d")
- ngx.say("done")
- ';
- }
---- request
- GET /re
---- response_body
-done
-
-
-
-=== TEST 5: gmatch matched but only iterate once and still matches remain
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+", "d")
- local m = it()
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-
-
-
-=== TEST 6: gmatch matched + o
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("hello, world", "[a-z]+", "do") do
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched: ", m)
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-world
-
-
-
-=== TEST 7: fail to match + o
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[0-9]", "do")
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
-
- local m = it()
- if m then ngx.say(m[0]) else ngx.say(m) end
- ';
- }
---- request
- GET /re
---- response_body
-nil
-nil
-nil
-
-
-
-=== TEST 8: gmatch matched but no iterate + o
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+", "do")
- ngx.say("done")
- ';
- }
---- request
- GET /re
---- response_body
-done
-
-
-
-=== TEST 9: gmatch matched but only iterate once and still matches remain + o
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("hello, world", "[a-z]+", "do")
- local m = it()
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched")
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello
-
-
-
-=== TEST 10: bad pattern
---- config
- location /re {
- content_by_lua '
- local it, err = ngx.re.gmatch("hello\\nworld", "(abc", "d")
- if not it then
- ngx.say("error: ", err)
- return
- end
- ngx.say("success")
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 11: UTF-8 mode without UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("ä½ å¥½", ".", "Ud")
- local m = it()
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 2000
-
---- request
- GET /re
---- response_body
-ä½
---- no_error_log
-[error]
-
-
-
-=== TEST 12: UTF-8 mode with UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local it = ngx.re.gmatch("ä½ å¥½", ".", "ud")
- local m = it()
- if m then
- ngx.say(m[0])
- else
- ngx.say("not matched!")
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 0
-
---- request
- GET /re
---- response_body
-ä½
---- no_error_log
-[error]
-
-
-
-=== TEST 13: gmatched with submatch captures
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("hello", "(he|hell)", "d") do
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-hell
-nil
-nil
-
-
-
-=== TEST 14: gmatched with submatch captures (compile once)
---- config
- location /re {
- content_by_lua '
- for m in ngx.re.gmatch("hello", "(he|hell)", "od") do
- if m then
- ngx.say(m[0])
- ngx.say(m[1])
- ngx.say(m[2])
- else
- ngx.say("not matched!")
- end
- end
- ';
- }
---- request
- GET /re
---- response_body
-hell
-nil
-nil
diff --git a/src/deps/src/lua-nginx-module/t/051-sub-jit.t b/src/deps/src/lua-nginx-module/t/051-sub-jit.t
deleted file mode 100644
index 7aec7ccb7..000000000
--- a/src/deps/src/lua-nginx-module/t/051-sub-jit.t
+++ /dev/null
@@ -1,173 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 6);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: matched with j
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234 5678", "([0-9]+)", "world", "j")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world 5678: 1
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 2: not matched with j
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[0-9]+", "hiya", "j")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world: 0
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 3: matched with jo
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234 5678", "([0-9]+)", "world", "jo")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world 5678: 1
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 4: not matched with jo
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[0-9]+", "hiya", "jo")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world: 0
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 5: bad pattern
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("hello\\nworld", "(abc", "world", "j")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 6: bad pattern + o
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub( "hello\\nworld", "(abc", "world", "jo")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/052-sub-dfa.t b/src/deps/src/lua-nginx-module/t/052-sub-dfa.t
deleted file mode 100644
index 2329c77aa..000000000
--- a/src/deps/src/lua-nginx-module/t/052-sub-dfa.t
+++ /dev/null
@@ -1,241 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 8);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: matched with d
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234 5678", "[0-9]|[0-9][0-9]", "world", "d")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world34 5678: 1
-
-
-
-=== TEST 2: not matched with d
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[0-9]+", "hiya", "d")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world: 0
-
-
-
-=== TEST 3: matched with do
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, 1234 5678", "[0-9]|[0-9][0-9]", "world", "do")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world34 5678: 1
-
-
-
-=== TEST 4: not matched with do
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.sub("hello, world", "[0-9]+", "hiya", "do")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world: 0
-
-
-
-=== TEST 5: bad pattern
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("hello\\nworld", "(abc", "world", "j")
- if s then
- ngx.say(s, ": ", n)
-
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 6: bad pattern + o
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("hello\\nworld", "(abc", "world", "jo")
- if s then
- ngx.say(s, ": ", n)
-
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 7: UTF-8 mode without UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("ä½ å¥½", ".", "a", "Ud")
- if s then
- ngx.say("s: ", s)
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 2000
-
---- request
- GET /re
---- response_body
-s: a好
---- no_error_log
-[error]
-
-
-
-=== TEST 8: UTF-8 mode with UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.sub("ä½ å¥½", ".", "a", "ud")
- if s then
- ngx.say("s: ", s)
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 0
-
---- request
- GET /re
---- response_body
-s: a好
---- no_error_log
-[error]
-
-
-
-=== TEST 9: sub with d
---- config
- location /re {
- content_by_lua '
- ngx.say(ngx.re.sub("hello", "(he|hell)", function (m) ngx.say(m[0]) ngx.say(m[1]) return "x" end, "d"))
- ';
- }
---- request
- GET /re
---- response_body
-hell
-nil
-xo1
---- no_error_log
-[error]
-
-
-
-=== TEST 10: sub with d + o
---- config
- location /re {
- content_by_lua '
- ngx.say(ngx.re.sub("hello", "(he|hell)", function (m) ngx.say(m[0]) ngx.say(m[1]) return "x" end, "do"))
- ';
- }
---- request
- GET /re
---- response_body
-hell
-nil
-xo1
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/053-gsub-jit.t b/src/deps/src/lua-nginx-module/t/053-gsub-jit.t
deleted file mode 100644
index c7c87ee29..000000000
--- a/src/deps/src/lua-nginx-module/t/053-gsub-jit.t
+++ /dev/null
@@ -1,173 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 6);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: matched with j
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, 1234 5678", "([0-9]+)", "world", "j")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world world: 2
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 2: not matched with j
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "[0-9]+", "hiya", "j")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world: 0
---- error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully\n"
-:
-"pcre JIT compiling result: 1\n"
-
-
-
-=== TEST 3: matched with jo
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, 1234 5678", "([0-9]+)", "world", "jo")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world world: 2
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 4: not matched with jo
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "[0-9]+", "hiya", "jo")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world: 0
-
---- grep_error_log eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"pcre2 JIT compiled successfully"
-:
-"pcre JIT compiling result: 1"
-
---- grep_error_log_out eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-["pcre2 JIT compiled successfully\n", ""]
-:
-["pcre JIT compiling result: 1\n", ""]
-
-
-
-=== TEST 5: bad pattern
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.gsub("hello\\nworld", "(abc", "world", "j")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 6: bad pattern + o
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.gsub("hello\\nworld", "(abc", "world", "jo")
- if s then
- ngx.say(s, ": ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/054-gsub-dfa.t b/src/deps/src/lua-nginx-module/t/054-gsub-dfa.t
deleted file mode 100644
index bd0825d4b..000000000
--- a/src/deps/src/lua-nginx-module/t/054-gsub-dfa.t
+++ /dev/null
@@ -1,242 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 7);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: matched with d
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, 1234 5678", "[0-9]|[0-9][0-9]", "world", "d")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, worldworld worldworld: 4
-
-
-
-=== TEST 2: not matched with d
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "[0-9]+", "hiya", "d")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world: 0
-
-
-
-=== TEST 3: matched with do
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, 1234 5678", "[0-9]|[0-9][0-9]", "world", "do")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, worldworld worldworld: 4
-
-
-
-=== TEST 4: not matched with do
---- config
- location /re {
- content_by_lua '
- local s, n = ngx.re.gsub("hello, world", "[0-9]+", "hiya", "do")
- if n then
- ngx.say(s, ": ", n)
- else
- ngx.say(s)
- end
- ';
- }
---- request
- GET /re
---- response_body
-hello, world: 0
-
-
-
-=== TEST 5: bad pattern
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.gsub("hello\\nworld", "(abc", "world", "j")
- if s then
- ngx.say("gsub: ", n)
-
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
-
-
-
-=== TEST 6: bad pattern + o
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.gsub("hello\\nworld", "(abc", "world", "jo")
- if s then
- ngx.say("gsub: ", n)
- else
- ngx.say("error: ", err)
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 7: UTF-8 mode without UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.gsub("ä½ å¥½", ".", "a", "Ud")
- if s then
- ngx.say("s: ", s)
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 2000
-exec opts: 2000
-exec opts: 2000
-
---- request
- GET /re
---- response_body
-s: aa
---- no_error_log
-[error]
-
-
-
-=== TEST 8: UTF-8 mode with UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local s, n, err = ngx.re.gsub("ä½ å¥½", ".", "a", "ud")
- if s then
- ngx.say("s: ", s)
- end
- ';
- }
---- stap
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_dfa_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 0
-exec opts: 0
-exec opts: 0
-
---- request
- GET /re
---- response_body
-s: aa
---- no_error_log
-[error]
-
-
-
-=== TEST 9: gsub with d
---- config
- location /re {
- content_by_lua '
- ngx.say(ngx.re.gsub("hello", "(he|hell)", function (m) ngx.say(m[0]) ngx.say(m[1]) return "x" end, "d"))
- ';
- }
---- request
- GET /re
---- response_body
-hell
-nil
-xo1
---- no_error_log
-[error]
-
-
-
-=== TEST 10: gsub with d + o
---- config
- location /re {
- content_by_lua '
- ngx.say(ngx.re.gsub("hello", "(he|hell)", function (m) ngx.say(m[0]) ngx.say(m[1]) return "x" end, "do"))
- ';
- }
---- request
- GET /re
---- response_body
-hell
-nil
-xo1
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/055-subreq-vars.t b/src/deps/src/lua-nginx-module/t/055-subreq-vars.t
deleted file mode 100644
index 1369992f2..000000000
--- a/src/deps/src/lua-nginx-module/t/055-subreq-vars.t
+++ /dev/null
@@ -1,338 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 5);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: set non-existent variables via "vars" option
---- config
- location /other {
- content_by_lua '
- ngx.say("dog = ", ngx.var.dog)
- ngx.say("cat = ", ngx.var.cat)
- ';
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { vars = { dog = "hello", cat = 32 }});
-
- ngx.print(res.body)
- ';
- }
-
---- stap2
-
-global delta = " "
-
-F(ngx_http_finalize_request) {
- uri = ngx_http_req_uri($r)
- printf("finalize req %s: %d\n", uri, $rc)
- if ($rc == 500) {
- print_ubacktrace()
- }
-}
-
-F(ngx_http_lua_run_thread) {
- uri = ngx_http_req_uri($r)
- printf("lua run thread %s\n", uri)
-}
-
-M(http-subrequest-start) {
- r = $arg1
- n = ngx_http_subreq_depth(r)
- pr = ngx_http_req_parent(r)
- printf("%sbegin %s -> %s (%d)\n", ngx_indent(n, delta),
- ngx_http_req_uri(pr),
- ngx_http_req_uri(r),
- n)
-}
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_log eval
-qr/variable "(dog|cat)" cannot be assigned a value \(maybe you forgot to define it first\?\)/
---- error_code: 500
-
-
-
-=== TEST 2: set non-existent variables via "vars" option
---- config
- location /other {
- content_by_lua '
- ngx.say("dog = ", ngx.var.dog)
- ngx.say("cat = ", ngx.var.cat)
- ';
- }
-
- location /lua {
- set $dog '';
- content_by_lua '
- local res = ngx.location.capture("/other",
- { vars = { dog = "hello", cat = 32 }});
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_log chop
-variable "cat" cannot be assigned a value (maybe you forgot to define it first?)
---- error_code: 500
-
-
-
-=== TEST 3: good "vars" option: user variables
---- config
- location /other {
- content_by_lua '
- ngx.say("dog = ", ngx.var.dog)
- ngx.say("cat = ", ngx.var.cat)
- ';
- }
-
- location /lua {
- set $dog '';
- set $cat '';
- content_by_lua '
- local res = ngx.location.capture("/other",
- { vars = { dog = "hello", cat = 32 }});
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-dog = hello
-cat = 32
-
-
-
-=== TEST 4: bad "vars" option value
---- config
- location /other {
- content_by_lua '
- ngx.say("dog = ", ngx.var.dog)
- ngx.say("cat = ", ngx.var.cat)
- ';
- }
-
- location /lua {
- set $dog '';
- set $cat '';
- content_by_lua '
- local res = ngx.location.capture("/other",
- { vars = "hello" });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log chop
-Bad vars option value
-
-
-
-=== TEST 5: bad "vars" option value value
---- config
- location /other {
- content_by_lua '
- ngx.say("dog = ", ngx.var.dog)
- ngx.say("cat = ", ngx.var.cat)
- ';
- }
-
- location /lua {
- set $dog '';
- set $cat '';
- content_by_lua '
- local res = ngx.location.capture("/other",
- { vars = { cat = true } });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log chop
-attempt to use bad variable value type boolean
-
-
-
-=== TEST 6: good "vars" option: builtin variables
---- config
- location /other {
- echo "args: $args";
- }
-
- location /lua {
- content_by_lua '
- local res = ngx.location.capture("/other",
- { vars = { args = "a=hello&b=32" }});
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-args: a=hello&b=32
-
-
-
-=== TEST 7: setting non-changeable vars
---- config
- location /other {
- echo "query string: $query_string";
- }
-
- location /lua {
- content_by_lua '
- res = ngx.location.capture("/other",
- { vars = { query_string = "hello" } });
-
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log chop
-variable "query_string" not changeable
-
-
-
-=== TEST 8: copy all vars
---- config
- location /other {
- set $dog "$dog world";
- echo "$uri dog: $dog";
- }
-
- location /lua {
- set $dog 'hello';
- content_by_lua '
- local res = ngx.location.capture("/other",
- { copy_all_vars = true });
-
- ngx.print(res.body)
- ngx.say(ngx.var.uri, ": ", ngx.var.dog)
- ';
- }
---- request
-GET /lua
---- response_body
-/other dog: hello world
-/lua: hello
-
-
-
-=== TEST 9: share all vars
---- config
- location /other {
- set $dog "$dog world";
- echo "$uri dog: $dog";
- }
-
- location /lua {
- set $dog 'hello';
- content_by_lua '
- local res = ngx.location.capture("/other",
- { share_all_vars = true });
-
- ngx.print(res.body)
- ngx.say(ngx.var.uri, ": ", ngx.var.dog)
- ';
- }
---- request
-GET /lua
---- response_body
-/other dog: hello world
-/lua: hello world
-
-
-
-=== TEST 10: vars takes priority over copy_all_vars
---- config
- location /other {
- set $dog "$dog world";
- echo "$uri dog: $dog";
- }
-
- location /lua {
- set $dog 'hello';
- content_by_lua '
- local res = ngx.location.capture("/other",
- { vars = { dog = "hiya" }, copy_all_vars = true });
-
- ngx.print(res.body)
- ngx.say(ngx.var.uri, ": ", ngx.var.dog)
- ';
- }
---- request
-GET /lua
---- response_body
-/other dog: hiya world
-/lua: hello
-
-
-
-=== TEST 11: capture_multi: good "vars" option: user variables
---- config
- location /other {
- content_by_lua '
- ngx.say("dog = ", ngx.var.dog)
- ngx.say("cat = ", ngx.var.cat)
- ';
- }
-
- location /lua {
- set $dog 'blah';
- set $cat 'foo';
- content_by_lua '
- local res1, res2 = ngx.location.capture_multi{
- {"/other/1",
- { vars = { dog = "hello", cat = 32 }}
- },
- {"/other/2",
- { vars = { dog = "hiya", cat = 56 }}
- }
- };
-
- ngx.print(res1.body)
- ngx.print(res2.body)
- ngx.say("parent dog: ", ngx.var.dog)
- ngx.say("parent cat: ", ngx.var.cat)
- ';
- }
---- request
-GET /lua
---- response_body
-dog = hello
-cat = 32
-dog = hiya
-cat = 56
-parent dog: blah
-parent cat: foo
diff --git a/src/deps/src/lua-nginx-module/t/056-flush.t b/src/deps/src/lua-nginx-module/t/056-flush.t
deleted file mode 100644
index 4376b1893..000000000
--- a/src/deps/src/lua-nginx-module/t/056-flush.t
+++ /dev/null
@@ -1,532 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-BEGIN {
- $ENV{TEST_NGINX_POSTPONE_OUTPUT} = 1;
-}
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * 60;
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: flush wait - content
---- config
- location /test {
- content_by_lua '
- ngx.say("hello, world")
- local ok, err = ngx.flush(true)
- if not ok then
- ngx.log(ngx.ERR, "flush failed: ", err)
- return
- end
- ngx.say("hiya")
- ';
- }
---- request
-GET /test
---- response_body
-hello, world
-hiya
---- no_error_log
-[error]
---- error_log
-lua reuse free buf chain, but reallocate memory because 5 >= 0
-
-
-
-=== TEST 2: flush no wait - content
---- config
- send_timeout 500ms;
- location /test {
- content_by_lua '
- ngx.say("hello, world")
- local ok, err = ngx.flush(false)
- if not ok then
- ngx.log(ngx.ERR, "flush failed: ", err)
- return
- end
- ngx.say("hiya")
- ';
- }
---- request
-GET /test
---- response_body
-hello, world
-hiya
-
-
-
-=== TEST 3: flush wait - rewrite
---- config
- location /test {
- rewrite_by_lua '
- ngx.say("hello, world")
- ngx.flush(true)
- ngx.say("hiya")
- ';
- content_by_lua return;
- }
---- request
-GET /test
---- response_body
-hello, world
-hiya
-
-
-
-=== TEST 4: flush no wait - rewrite
---- config
- location /test {
- rewrite_by_lua '
- ngx.say("hello, world")
- ngx.flush(false)
- ngx.say("hiya")
- ';
- content_by_lua return;
- }
---- request
-GET /test
---- response_body
-hello, world
-hiya
-
-
-
-=== TEST 5: http 1.0 (sync)
---- config
- location /test {
- content_by_lua '
- ngx.say("hello, world")
- ngx.flush(true)
- ngx.say("hiya")
- ngx.flush(true)
- ngx.say("blah")
- ';
- }
---- request
-GET /test HTTP/1.0
---- response_body
-hello, world
-hiya
-blah
---- response_headers
-Content-Length: 23
---- timeout: 5
---- error_log
-lua buffering output bufs for the HTTP 1.0 request
-lua http 1.0 buffering makes ngx.flush() a no-op
-
-
-
-=== TEST 6: http 1.0 (async)
---- config
- location /test {
- content_by_lua '
- ngx.say("hello, world")
- local ok, err = ngx.flush(false)
- if not ok then
- ngx.log(ngx.WARN, "1: failed to flush: ", err)
- end
- ngx.say("hiya")
- local ok, err = ngx.flush(false)
- if not ok then
- ngx.log(ngx.WARN, "2: failed to flush: ", err)
- end
- ngx.say("blah")
- ';
- }
---- request
-GET /test HTTP/1.0
---- response_body
-hello, world
-hiya
-blah
---- response_headers
-Content-Length: 23
---- error_log
-lua buffering output bufs for the HTTP 1.0 request
-lua http 1.0 buffering makes ngx.flush() a no-op
-1: failed to flush: buffering
-2: failed to flush: buffering
---- timeout: 5
-
-
-
-=== TEST 7: flush wait - big data
---- config
- location /test {
- content_by_lua '
- ngx.say(string.rep("a", 1024 * 64))
- ngx.flush(true)
- ngx.say("hiya")
- ';
- }
---- request
-GET /test
---- response_body
-hello, world
-hiya
---- SKIP
-
-
-
-=== TEST 8: flush wait - content
---- config
- location /test {
- content_by_lua '
- ngx.say("hello, world")
- ngx.flush(true)
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ngx.flush(true)
- ';
- }
- location /sub {
- echo sub;
- }
---- request
-GET /test
---- response_body
-hello, world
-sub
-
-
-
-=== TEST 9: http 1.0 (sync + buffering off)
---- config
- lua_http10_buffering off;
- location /test {
- content_by_lua '
- ngx.say("hello, world")
- ngx.flush(true)
- ngx.say("hiya")
- ngx.flush(true)
- ngx.say("blah")
- ';
- }
---- request
-GET /test HTTP/1.0
---- response_body
-hello, world
-hiya
-blah
---- response_headers
-!Content-Length
---- timeout: 5
---- no_error_log
-lua buffering output bufs for the HTTP 1.0 request
-lua http 1.0 buffering makes ngx.flush() a no-op
-
-
-
-=== TEST 10: http 1.0 (async)
---- config
- lua_http10_buffering on;
- location /test {
- lua_http10_buffering off;
- content_by_lua '
- ngx.say("hello, world")
- ngx.flush(false)
- ngx.say("hiya")
- ngx.flush(false)
- ngx.say("blah")
- ';
- }
---- request
-GET /test HTTP/1.0
---- response_body
-hello, world
-hiya
-blah
---- response_headers
-!Content-Length
---- no_error_log
-lua buffering output bufs for the HTTP 1.0 request
-lua http 1.0 buffering makes ngx.flush() a no-op
---- timeout: 5
-
-
-
-=== TEST 11: http 1.0 (sync) - buffering explicitly off
---- config
- location /test {
- lua_http10_buffering on;
- content_by_lua '
- ngx.say("hello, world")
- ngx.flush(true)
- ngx.say("hiya")
- ngx.flush(true)
- ngx.say("blah")
- ';
- }
---- request
-GET /test HTTP/1.0
---- response_body
-hello, world
-hiya
-blah
---- response_headers
-Content-Length: 23
---- timeout: 5
---- error_log
-lua buffering output bufs for the HTTP 1.0 request
-lua http 1.0 buffering makes ngx.flush() a no-op
-
-
-
-=== TEST 12: http 1.0 (async) - buffering explicitly off
---- config
- location /test {
- lua_http10_buffering on;
- content_by_lua '
- ngx.say("hello, world")
- ngx.flush(false)
- ngx.say("hiya")
- ngx.flush(false)
- ngx.say("blah")
- ';
- }
---- request
-GET /test HTTP/1.0
---- response_body
-hello, world
-hiya
-blah
---- response_headers
-Content-Length: 23
---- error_log
-lua buffering output bufs for the HTTP 1.0 request
-lua http 1.0 buffering makes ngx.flush() a no-op
---- timeout: 5
-
-
-
-=== TEST 13: flush wait in a user coroutine
---- config
- location /test {
- content_by_lua '
- local function f()
- ngx.say("hello, world")
- ngx.flush(true)
- coroutine.yield()
- ngx.say("hiya")
- end
- local c = coroutine.create(f)
- ngx.say(coroutine.resume(c))
- ngx.say(coroutine.resume(c))
- ';
- }
---- request
-GET /test
---- stap2
-F(ngx_http_lua_wev_handler) {
- printf("wev handler: wev:%d\n", $r->connection->write->ready)
-}
-
-global ids, cur
-
-function gen_id(k) {
- if (ids[k]) return ids[k]
- ids[k] = ++cur
- return cur
-}
-
-F(ngx_http_handler) {
- delete ids
- cur = 0
-}
-
-/*
-F(ngx_http_lua_run_thread) {
- id = gen_id($ctx->cur_co)
- printf("run thread %d\n", id)
-}
-
-probe process("/usr/local/openresty-debug/luajit/lib/libluajit-5.1.so.2").function("lua_resume") {
- id = gen_id($L)
- printf("lua resume %d\n", id)
-}
-*/
-
-M(http-lua-user-coroutine-resume) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("resume %x in %x\n", c, p)
-}
-
-M(http-lua-entry-coroutine-yield) {
- println("entry coroutine yield")
-}
-
-/*
-F(ngx_http_lua_coroutine_yield) {
- printf("yield %x\n", gen_id($L))
-}
-*/
-
-M(http-lua-user-coroutine-yield) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("yield %x in %x\n", c, p)
-}
-
-F(ngx_http_lua_atpanic) {
- printf("lua atpanic(%d):", gen_id($L))
- print_ubacktrace();
-}
-
-M(http-lua-user-coroutine-create) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("create %x in %x\n", c, p)
-}
-
-F(ngx_http_lua_ngx_exec) { println("exec") }
-
-F(ngx_http_lua_ngx_exit) { println("exit") }
-
-F(ngx_http_writer) { println("http writer") }
-
---- response_body
-hello, world
-true
-hiya
-true
---- error_log
-lua reuse free buf memory 13 >= 5
-
-
-
-=== TEST 14: flush before sending out the header
---- config
- location /test {
- content_by_lua '
- ngx.flush()
- ngx.status = 404
- ngx.say("not found")
- ';
- }
---- request
-GET /test
---- response_body
-not found
---- error_code: 404
---- no_error_log
-[error]
-
-
-
-=== TEST 15: flush wait - gzip
---- config
- gzip on;
- gzip_min_length 1;
- gzip_types text/plain;
-
- location /test {
- content_by_lua '
- ngx.say("hello, world")
- local ok, err = ngx.flush(true)
- if not ok then
- ngx.log(ngx.ERR, "flush failed: ", err)
- return
- end
- ngx.say("hiya")
- ';
- }
---- request
-GET /test
---- more_headers
-Accept-Encoding: gzip
---- response_body_like: .{15}
---- response_headers
-Content-Encoding: gzip
---- no_error_log
-[error]
-
-
-
-=== TEST 16: flush wait - gunzip
---- config
- location /test {
- gunzip on;
- content_by_lua '
- local f, err = io.open(ngx.var.document_root .. "/gzip.bin", "r")
- if not f then
- ngx.say("failed to open file: ", err)
- return
- end
- local data = f:read(100)
- ngx.header.content_encoding = "gzip"
- ngx.print(data)
- local ok, err = ngx.flush(true)
- if not ok then
- ngx.log(ngx.ERR, "flush failed: ", err)
- return
- end
- data = f:read("*a")
- ngx.print(data)
- ';
- }
---- user_files eval
-">>> gzip.bin
-\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x62\x64\x62\x62\x61\x62\x64\x63\x61\xe4\xe0\xe2\xe6\xe4\x61\xe4\xe4\xe7\x63\x12\xe4\xe1\xe0\x60\x14\x12\xe3\x91\xe4\xe4\xe4\x13\x60\xe3\x95\x12\x90\x15\xe0\x11\x50\x92\xd1\x16\x17\xe2\xd3\x17\x14\x11\x95\x95\x57\x96\x63\x37\xd2\x36\xd6\x51\x34\xb1\xe6\x62\x17\x95\xb0\x77\x60\xe3\x96\x33\x95\xb6\x91\x75\x97\x30\xe4\x66\x0c\xd0\xe3\xe0\xb5\xd3\x33\xf6\x90\x16\xb2\x90\x77\x56\x31\xe7\x55\x32\x11\x74\xe0\x02\x00\x00\x00\xff\xff\xcb\xc8\xac\x4c\xe4\x02\x00\x19\x15\xa9\x77\x6a\x00\x00\x00"
---- request
-GET /test
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 17: limit_rate
---- quic_max_idle_timeout: 2
---- config
- location /test {
- limit_rate 150;
- content_by_lua '
- local begin = ngx.now()
- for i = 1, 2 do
- ngx.print(string.rep("a", 100))
- local ok, err = ngx.flush(true)
- if not ok then
- ngx.log(ngx.ERR, "failed to flush: ", err)
- end
- end
- local elapsed = ngx.now() - begin
- ngx.log(ngx.WARN, "lua writes elapsed ", elapsed, " sec")
- ';
- }
---- request
-GET /test
---- response_body eval
-"a" x 200
---- error_log eval
-my @errlog;
-if (defined $ENV{TEST_NGINX_USE_HTTP2}) {
- @errlog = [
-qr/lua writes elapsed 0\.[7-9]\d+ sec/,
-qr/lua flush requires waiting: buffered 0x[0-9a-f]+, delayed:1/,
-];
-} else {
- @errlog = [
-qr/lua writes elapsed [12](?:\.\d+)? sec/,
-qr/lua flush requires waiting: buffered 0x[0-9a-f]+, delayed:1/,
-];
-}
-@errlog;
-
---- no_error_log
-[error]
---- timeout: 4
diff --git a/src/deps/src/lua-nginx-module/t/057-flush-timeout.t b/src/deps/src/lua-nginx-module/t/057-flush-timeout.t
deleted file mode 100644
index 8f0b7790a..000000000
--- a/src/deps/src/lua-nginx-module/t/057-flush-timeout.t
+++ /dev/null
@@ -1,325 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-BEGIN {
- if (!defined $ENV{LD_PRELOAD}) {
- $ENV{LD_PRELOAD} = '';
- }
-
- if ($ENV{LD_PRELOAD} !~ /\bmockeagain\.so\b/) {
- $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}";
- }
-
- if ($ENV{MOCKEAGAIN} eq 'r') {
- $ENV{MOCKEAGAIN} = 'rw';
-
- } else {
- $ENV{MOCKEAGAIN} = 'w';
- }
-
- $ENV{TEST_NGINX_EVENT_TYPE} = 'poll';
- $ENV{MOCKEAGAIN_WRITE_TIMEOUT_PATTERN} = 'hello, world';
- $ENV{TEST_NGINX_POSTPONE_OUTPUT} = 1;
- delete($ENV{TEST_NGINX_USE_HTTP2});
-
- if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "HTTP3 does not support mockeagain";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * 17;
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: flush wait - timeout
---- config
- send_timeout 100ms;
- location /test {
- content_by_lua '
- ngx.say("hello, world")
- ngx.flush(true)
- ngx.say("hiya")
- ';
- }
---- request
-GET /test
---- ignore_response
---- error_log eval
-qr/client timed out \(\d+: .*?timed out\)/
---- no_error_log
-[error]
-
-
-
-=== TEST 2: send timeout timer got removed in time
---- config
- send_timeout 1234ms;
- location /test {
- content_by_lua '
- ngx.say(string.rep("blah blah blah", 10))
- -- ngx.flush(true)
- ngx.eof()
- for i = 1, 20 do
- ngx.sleep(0.1)
- end
- ';
- }
---- request
-GET /test
---- stap
-global evtime
-
-F(ngx_http_handler) {
- delete evtime
-}
-
-M(timer-add) {
- if ($arg2 == 1234) {
- printf("add timer %d\n", $arg2)
- evtime[$arg1] = $arg2
- }
-}
-
-M(timer-del) {
- time = evtime[$arg1]
- if (time == 1234) {
- printf("del timer %d\n", time)
- }
-}
-
-M(timer-expire) {
- time = evtime[$arg1]
- if (time == 1234) {
- printf("expire timer %d\n", time)
- #print_ubacktrace()
- }
-}
-/*
-probe syscall.writev.return {
- if (pid() == target()) {
- printf("writev: %s\n", retstr)
- }
-}
-*/
---- stap_out
-add timer 1234
-del timer 1234
---- ignore_response
---- no_error_log
-[error]
---- timeout: 3
-
-
-
-=== TEST 3: exit in user thread (entry thread is still pending on ngx.flush)
---- config
- send_timeout 200ms;
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.say("hello, world!")
- ngx.flush(true)
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-
-/*
-F(ngx_http_finalize_request) {
- printf("finalize request: c:%d, a:%d, cb:%d, rb:%d\n", $r->main->count,
- $r == $r->connection->data, $r->connection->buffered, $r->buffered)
-}
-
-F(ngx_http_set_write_handler) {
- println("set write handler")
-}
-*/
-
-F(ngx_http_lua_flush_cleanup) {
- println("lua flush cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua flush cleanup
-delete timer 200
-delete thread 1
-add timer 200
-expire timer 200
-free request
-
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 4: flush wait - return "timeout" error
---- config
- send_timeout 100ms;
- location /test {
- content_by_lua '
- ngx.say("hello, world")
- local ok, err = ngx.flush(true)
- if not ok then
- ngx.log(ngx.ERR, "failed to flush: ", err)
- return
- end
- ngx.say("hiya")
- ';
- }
---- request
-GET /test
---- ignore_response
---- error_log eval
-[
-qr/client timed out \(\d+: .*?timed out\)/,
-'failed to flush: timeout',
-]
---- no_error_log
-[alert]
-
-
-
-=== TEST 5: flush wait in multiple user threads - return "timeout" error
---- config
- send_timeout 100ms;
- location /test {
- content_by_lua '
- ngx.say("hello, world")
-
- local function run(tag)
- local ok, err = ngx.flush(true)
- if not ok then
- ngx.log(ngx.ERR, "thread ", tag, ": failed to flush: ", err)
- return
- end
- ngx.say("hiya")
- end
-
- local function new_thread(tag)
- local ok, err = ngx.thread.spawn(run, tag)
- if not ok then
- return error("failed to spawn thread: ", err)
- end
- end
-
- new_thread("A")
- new_thread("B")
- run("main")
- ';
- }
---- request
-GET /test
---- ignore_response
---- error_log eval
-[
-qr/client timed out \(\d+: .*?timed out\)/,
-'thread main: failed to flush: timeout',
-'thread A: failed to flush: timeout',
-'thread B: failed to flush: timeout',
-]
---- no_error_log
-[alert]
-
-
-
-=== TEST 6: flush wait - client abort connection prematurely
---- config
- #send_timeout 100ms;
- location /test {
- limit_rate 2;
- content_by_lua '
- ngx.say("hello, lua")
- local ok, err = ngx.flush(true)
- if not ok then
- ngx.log(ngx.ERR, "failed to flush: ", err)
- return
- end
- ngx.say("hiya")
- ';
- }
---- request
-GET /test
---- ignore_response
---- error_log eval
-[
-qr/writev\(\) failed .*? Broken pipe/i,
-qr/failed to flush: client aborted/,
-]
---- no_error_log
-[alert]
-
---- timeout: 0.2
---- abort
---- wait: 1
diff --git a/src/deps/src/lua-nginx-module/t/058-tcp-socket.t b/src/deps/src/lua-nginx-module/t/058-tcp-socket.t
deleted file mode 100644
index ef2b05f0d..000000000
--- a/src/deps/src/lua-nginx-module/t/058-tcp-socket.t
+++ /dev/null
@@ -1,4499 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 21);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 2: no trailing newline
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 1234;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- sock:close()
- ngx.say("closed")
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.print("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 3
-received: Connection: close
-received:
-failed to receive a line: closed [foo]
-closed
---- no_error_log
-[error]
-
-
-
-=== TEST 3: no resolver defined
---- config
- server_tokens off;
- location /t {
- #set $port 1234;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("agentzh.org", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
- ';
- }
---- request
-GET /t
---- response_body
-failed to connect: no resolver defined to resolve "agentzh.org"
-connected: nil
-failed to send request: closed
---- error_log
-attempt to send data on a closed socket:
-
-
-
-=== TEST 4: with resolver
---- timeout: 10
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = 80
- local ok, err = sock:connect("agentzh.org", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET / HTTP/1.0\\r\\nHost: agentzh.org\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local line, err = sock:receive()
- if line then
- ngx.say("first line received: ", line)
-
- else
- ngx.say("failed to receive the first line: ", err)
- end
-
- line, err = sock:receive()
- if line then
- ngx.say("second line received: ", line)
-
- else
- ngx.say("failed to receive the second line: ", err)
- end
- ';
- }
-
---- request
-GET /t
---- response_body_like
-connected: 1
-request sent: 56
-first line received: HTTP\/1\.1 200 OK
-second line received: (?:Date|Server): .*?
---- no_error_log
-[error]
---- timeout: 10
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 5: connection refused (tcp)
---- no_http2
---- config
- location /test {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", 16787)
- ngx.say("connect: ", ok, " ", err)
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
---- request
- GET /test
---- response_body
-connect: nil connection refused
-send: nil closed
-receive: nil closed
-close: nil closed
---- error_log eval
-qr/connect\(\) failed \(\d+: Connection refused\)/
-
-
-
-=== TEST 6: connection timeout (tcp)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_socket_connect_timeout 100ms;
- lua_socket_send_timeout 100ms;
- lua_socket_read_timeout 100ms;
- resolver_timeout 3s;
- location /test {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.2", 12345)
- ngx.say("connect: ", ok, " ", err)
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
---- request
- GET /test
---- response_body
-connect: nil timeout
-send: nil closed
-receive: nil closed
-close: nil closed
---- error_log
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
---- timeout: 10
-
-
-
-=== TEST 7: not closed manually
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 8: resolver error (host not found)
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = 80
- local ok, err = sock:connect("blah-blah-not-found.agentzh.org", port)
- print("connected: ", ok, " ", err, " ", not ok)
- if not ok then
- ngx.say("failed to connect: ", err)
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET / HTTP/1.0\\r\\nHost: agentzh.org\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
- ';
- }
---- request
-GET /t
---- response_body_like
-^failed to connect: blah-blah-not-found\.agentzh\.org could not be resolved(?: \(3: Host not found\))?
-connected: nil
-failed to send request: closed$
---- error_log
-attempt to send data on a closed socket
---- timeout: 10
-
-
-
-=== TEST 9: resolver error (timeout)
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 1ms;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = 80
- local ok, err = sock:connect("blah-blah-not-found.agentzh.org", port)
- print("connected: ", ok, " ", err, " ", not ok)
- if not ok then
- ngx.say("failed to connect: ", err)
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET / HTTP/1.0\\r\\nHost: agentzh.org\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
- ';
- }
---- request
-GET /t
---- response_body_like
-^failed to connect: blah-blah-not-found\.agentzh\.org could not be resolved(?: \(\d+: (?:Operation timed out|Host not found)\))?
-connected: nil
-failed to send request: closed$
---- error_log
-attempt to send data on a closed socket
-
-
-
-=== TEST 10: explicit *l pattern for receive
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err = sock:receive("*l")
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err)
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 11: *a pattern for receive
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local data, err = sock:receive("*a")
- if data then
- ngx.say("receive: ", data)
- ngx.say("err: ", err)
-
- else
- ngx.say("failed to receive: ", err)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-receive: HTTP/1.1 200 OK\r
-Server: nginx\r
-Content-Type: text/plain\r
-Content-Length: 4\r
-Connection: close\r
-\r
-foo
-
-err: nil
-close: 1 nil
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 12: mixing *a and *l patterns for receive
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local line, err = sock:receive("*l")
- if line then
- ngx.say("receive: ", line)
- ngx.say("err: ", err)
-
- else
- ngx.say("failed to receive: ", err)
- end
-
- local data
- data, err = sock:receive("*a")
- if data then
- ngx.say("receive: ", data)
- ngx.say("err: ", err)
-
- else
- ngx.say("failed to receive: ", err)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-receive: HTTP/1.1 200 OK
-err: nil
-receive: Server: nginx\r
-Content-Type: text/plain\r
-Content-Length: 4\r
-Connection: close\r
-\r
-foo
-
-err: nil
-close: 1 nil
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 13: receive by chunks
---- no_http2
---- timeout: 5
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local data, err, partial = sock:receive(10)
- if data then
- local len = string.len(data)
- if len == 10 then
- ngx.print("[", data, "]")
- else
- ngx.say("ERROR: returned invalid length of data: ", len)
- end
-
- else
- ngx.say("failed to receive a line: ", err, " [", partial, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-[HTTP/1.1 2][00 OK\r
-Ser][ver: nginx][\r
-Content-][Type: text][/plain\r
-Co][ntent-Leng][th: 4\r
-Con][nection: c][lose\r
-\r
-fo]failed to receive a line: closed [o
-]
-close: 1 nil
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 14: receive by chunks (very small buffer)
---- no_http2
---- timeout: 5
---- config
- server_tokens off;
- lua_socket_buffer_size 1;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local data, err, partial = sock:receive(10)
- if data then
- local len = string.len(data)
- if len == 10 then
- ngx.print("[", data, "]")
- else
- ngx.say("ERROR: returned invalid length of data: ", len)
- end
-
- else
- ngx.say("failed to receive a line: ", err, " [", partial, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-[HTTP/1.1 2][00 OK\r
-Ser][ver: nginx][\r
-Content-][Type: text][/plain\r
-Co][ntent-Leng][th: 4\r
-Con][nection: c][lose\r
-\r
-fo]failed to receive a line: closed [o
-]
-close: 1 nil
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 15: line reading (very small buffer)
---- no_http2
---- config
- server_tokens off;
- lua_socket_buffer_size 1;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 16: ngx.socket.connect (working)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local port = ngx.var.port
- local sock, err = ngx.socket.connect("127.0.0.1", port)
- if not sock then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected.")
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected.
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 17: ngx.socket.connect() shortcut (connection refused)
---- config
- location /test {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local sock, err = sock:connect("127.0.0.1", 16787)
- if not sock then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
---- request
- GET /test
-
---- stap2
-M(http-lua-info) {
- printf("tcp resume: %p\n", $coctx)
- print_ubacktrace()
-}
-
---- response_body
-failed to connect: connection refused
---- error_log eval
-qr/connect\(\) failed \(\d+: Connection refused\)/
-
-
-
-=== TEST 18: receive by chunks (stringified size)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local data, err, partial = sock:receive("10")
- if data then
- local len = string.len(data)
- if len == 10 then
- ngx.print("[", data, "]")
- else
- ngx.say("ERROR: returned invalid length of data: ", len)
- end
-
- else
- ngx.say("failed to receive a line: ", err, " [", partial, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 57
-[HTTP/1.1 2][00 OK\r
-Ser][ver: nginx][\r
-Content-][Type: text][/plain\r
-Co][ntent-Leng][th: 4\r
-Con][nection: c][lose\r
-\r
-fo]failed to receive a line: closed [o
-]
-close: 1 nil
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 19: cannot survive across request boundary (send)
---- no_http2
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local test = require "test"
- test.go(ngx.var.port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function go(port)
- if not sock then
- sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-end
---- request
-GET /t
---- response_body_like eval
-"^(?:connected: 1
-request sent: 11
-received: OK|failed to send request: closed)\$"
-
-
-
-=== TEST 20: cannot survive across request boundary (receive)
---- no_http2
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local test = require "test"
- test.go(ngx.var.port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function go(port)
- if not sock then
- sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- else
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
- return
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-end
-
---- stap2
-M(http-lua-info) {
- printf("tcp resume\n")
- print_ubacktrace()
-}
---- request
-GET /t
---- response_body_like eval
-qr/^(?:connected: 1
-request sent: 11
-received: OK|failed to receive a line: closed \[nil\])$/
-
-
-
-=== TEST 21: cannot survive across request boundary (close)
---- no_http2
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local test = require "test"
- test.go(ngx.var.port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function go(port)
- if not sock then
- sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- else
- local ok, err = sock:close()
- if ok then
- ngx.say("successfully closed")
-
- else
- ngx.say("failed to close: ", err)
- end
- return
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-end
---- request
-GET /t
---- response_body_like eval
-qr/^(?:connected: 1
-request sent: 11
-received: OK|failed to close: closed)$/
-
-
-
-=== TEST 22: cannot survive across request boundary (connect)
---- no_http2
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local test = require "test"
- test.go(ngx.var.port)
- test.go(ngx.var.port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function go(port)
- if not sock then
- sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- else
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect again: ", err)
- return
- end
-
- ngx.say("connected again: ", ok)
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-end
---- request
-GET /t
---- response_body_like eval
-qr/^(?:connected(?: again)?: 1
-request sent: 11
-received: OK
-){2}$/
---- error_log
-lua reuse socket upstream ctx
---- no_error_log
-[error]
---- SKIP
-
-
-
-=== TEST 23: connect again immediately
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected again: ", ok)
-
- local req = "flush_all\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-connected again: 1
-request sent: 11
-received: OK
-close: 1 nil
---- no_error_log
-[error]
---- error_log eval
-["lua reuse socket upstream", "lua tcp socket reconnect without shutting down"]
-
-
-
-=== TEST 24: two sockets mix together
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port1 $TEST_NGINX_MEMCACHED_PORT;
- set $port2 $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock1 = ngx.socket.tcp()
- local sock2 = ngx.socket.tcp()
-
- local port1 = ngx.var.port1
- local port2 = ngx.var.port2
-
- local ok, err = sock1:connect("127.0.0.1", port1)
- if not ok then
- ngx.say("1: failed to connect: ", err)
- return
- end
-
- ngx.say("1: connected: ", ok)
-
- ok, err = sock2:connect("127.0.0.1", port2)
- if not ok then
- ngx.say("2: failed to connect: ", err)
- return
- end
-
- ngx.say("2: connected: ", ok)
-
- local req1 = "flush_all\\r\\n"
- local bytes, err = sock1:send(req1)
- if not bytes then
- ngx.say("1: failed to send request: ", err)
- return
- end
- ngx.say("1: request sent: ", bytes)
-
- local req2 = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock2:send(req2)
- if not bytes then
- ngx.say("2: failed to send request: ", err)
- return
- end
- ngx.say("2: request sent: ", bytes)
-
- local line, err, part = sock1:receive()
- if line then
- ngx.say("1: received: ", line)
-
- else
- ngx.say("1: failed to receive a line: ", err, " [", part, "]")
- end
-
- line, err, part = sock2:receive()
- if line then
- ngx.say("2: received: ", line)
-
- else
- ngx.say("2: failed to receive a line: ", err, " [", part, "]")
- end
-
- ok, err = sock1:close()
- ngx.say("1: close: ", ok, " ", err)
-
- ok, err = sock2:close()
- ngx.say("2: close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-1: connected: 1
-2: connected: 1
-1: request sent: 11
-2: request sent: 57
-1: received: OK
-2: received: HTTP/1.1 200 OK
-1: close: 1 nil
-2: close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 25: send tables of string fragments (with integers too)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", 1, ".", 0, "\\r\\n",
- "Host: localhost\\r\\n", "Connection: close\\r\\n",
- "\\r\\n"}
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 26: send tables of string fragments (bad type "nil")
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", nil, 1, ".", 0, "\\r\\n",
- "Host: localhost\\r\\n", "Connection: close\\r\\n",
- "\\r\\n"}
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- ignore_response
---- error_log
-bad argument #1 to 'send' (bad data type nil found)
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
-
-
-
-=== TEST 27: send tables of string fragments (bad type "boolean")
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", true, 1, ".", 0, "\\r\\n",
- "Host: localhost\\r\\n", "Connection: close\\r\\n",
- "\\r\\n"}
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- ignore_response
---- error_log
-bad argument #1 to 'send' (bad data type boolean found)
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
-
-
-
-=== TEST 28: send tables of string fragments (bad type ngx.null)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", ngx.null, 1, ".", 0, "\\r\\n",
- "Host: localhost\\r\\n", "Connection: close\\r\\n",
- "\\r\\n"}
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- ignore_response
---- error_log
-bad argument #1 to 'send' (bad data type userdata found)
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
-
-
-
-=== TEST 29: cosocket before location capture (tcpsock:send did not clear u->waiting)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
-
- local resp = ngx.location.capture("/memc")
- if type(resp) ~= "table" then
- ngx.say("bad resp: type ", type(resp), ": ", resp)
- return
- end
-
- ngx.print("subrequest: ", resp.status, ", ", resp.body)
- ';
- }
-
- location /memc {
- set $memc_cmd flush_all;
- memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-request sent: 11
-received: OK
-close: 1 nil
-subrequest: 200, OK\r
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 30: CR in a line
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo "foo\r\rbar\rbaz";
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 13
-received: Connection: close
-received:
-received: foobarbaz
-failed to receive a line: closed []
-close: nil closed
---- no_error_log
-[error]
---- SKIP
-
-
-
-=== TEST 31: receive(0)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local data, err, part = sock:receive(0)
- if not data then
- ngx.say("failed to receive(0): ", err)
- return
- end
-
- ngx.say("receive(0): [", data, "]")
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-receive(0): []
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 32: send("")
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local bytes, err = sock:send("")
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("send(\\"\\"): ", bytes)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-send(""): 0
-close: 1 nil
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 33: github issue #215: Handle the posted requests in lua cosocket api (failed to resolve)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
-
- location = /sub {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("xxx", 80)
- if not ok then
- ngx.say("failed to connect to xxx: ", err)
- return
- end
- ngx.say("successfully connected to xxx!")
- sock:close()
- ';
- }
-
- location = /lua {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
-
---- stap
-F(ngx_resolve_name_done) {
- println("resolve name done")
- #print_ubacktrace()
-}
-
---- stap_out
-resolve name done
-
---- response_body_like chop
-^failed to connect to xxx: xxx could not be resolved.*?Host not found
-
---- no_error_log
-[error]
-
-
-
-=== TEST 34: github issue #215: Handle the posted requests in lua cosocket api (successfully resolved)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 5s;
-
- location = /sub {
- content_by_lua '
- if not package.i then
- package.i = 1
- end
-
- local servers = {"openresty.org", "agentzh.org", "sregex.org"}
- local server = servers[package.i]
- package.i = package.i + 1
-
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect(server, 80)
- if not ok then
- ngx.say("failed to connect to ", server, ": ", err)
- return
- end
- ngx.say("successfully connected to xxx!")
- sock:close()
- ';
- }
-
- location = /lua {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-successfully connected to xxx!
-
---- stap
-F(ngx_http_lua_socket_resolve_handler) {
- println("lua socket resolve handler")
-}
-
-F(ngx_http_lua_socket_tcp_conn_retval_handler) {
- println("lua socket tcp connect retval handler")
-}
-
-F(ngx_http_run_posted_requests) {
- println("run posted requests")
-}
-
---- stap_out_like
-run posted requests
-lua socket resolve handler
-run posted requests
-lua socket tcp connect retval handler
-run posted requests
-
---- no_error_log
-[error]
---- timeout: 10
-
-
-
-=== TEST 35: connection refused (tcp) - lua_socket_log_errors off
---- config
- location /test {
- lua_socket_log_errors off;
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", 16787)
- ngx.say("connect: ", ok, " ", err)
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
---- request
- GET /test
---- response_body
-connect: nil connection refused
-send: nil closed
-receive: nil closed
-close: nil closed
---- no_error_log eval
-[qr/connect\(\) failed \(\d+: Connection refused\)/]
-
-
-
-=== TEST 36: reread after a read time out happen (receive -> receive)
---- config
- server_tokens off;
- lua_socket_read_timeout 100ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
-
- line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- end
- end
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
-failed to receive: timeout
---- error_log
-lua tcp socket read timeout: 100
-lua tcp socket connect timeout: 60000
-lua tcp socket read timed out
-
-
-
-=== TEST 37: successful reread after a read time out happen (receive -> receive)
---- no_http2
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("GET /back HTTP/1.1\\r\\nHost: localhost\\r\\n\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local header, err = reader()
- if not header then
- ngx.say("failed to read the response header: ", err)
- return
- end
-
- sock:settimeout(100)
-
- local data, err, partial = sock:receive(100)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, ", partial: ", partial)
-
- sock:settimeout(123)
- ngx.sleep(0.1)
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
- ngx.say("received: ", line)
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
- ngx.say("received: ", line)
- end
- ';
- }
-
- location /back {
- content_by_lua '
- ngx.print("hi")
- ngx.flush(true)
- ngx.sleep(0.2)
- ngx.print("world")
- ';
- }
---- request
-GET /t
---- response_body eval
-"failed to receive: timeout, partial: 2\r
-hi\r
-
-received: 5
-received: world
-"
---- error_log
-lua tcp socket read timed out
---- no_error_log
-[alert]
-
-
-
-=== TEST 38: successful reread after a read time out happen (receive -> receiveuntil)
---- no_http2
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("GET /back HTTP/1.1\\r\\nHost: localhost\\r\\n\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local header, err = reader()
- if not header then
- ngx.say("failed to read the response header: ", err)
- return
- end
-
- sock:settimeout(100)
-
- local data, err, partial = sock:receive(100)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, ", partial: ", partial)
-
- ngx.sleep(0.1)
-
- sock:settimeout(123)
- local reader = sock:receiveuntil("\\r\\n")
-
- local line, err = reader()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
- ngx.say("received: ", line)
-
- local line, err = reader()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
- ngx.say("received: ", line)
- end
- ';
- }
-
- location /back {
- content_by_lua '
- ngx.print("hi")
- ngx.flush(true)
- ngx.sleep(0.2)
- ngx.print("world")
- ';
- }
---- request
-GET /t
---- response_body eval
-"failed to receive: timeout, partial: 2\r
-hi\r
-
-received: 5
-received: world
-"
---- error_log
-lua tcp socket read timed out
---- no_error_log
-[alert]
-
-
-
-=== TEST 39: successful reread after a read time out happen (receiveuntil -> receiveuntil)
---- no_http2
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("GET /back HTTP/1.1\\r\\nHost: localhost\\r\\n\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local header, err = reader()
- if not header then
- ngx.say("failed to read the response header: ", err)
- return
- end
-
- sock:settimeout(100)
-
- local reader = sock:receiveuntil("no-such-terminator")
- local data, err, partial = reader()
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, ", partial: ", partial)
-
- ngx.sleep(0.1)
-
- sock:settimeout(123)
-
- local reader = sock:receiveuntil("\\r\\n")
-
- local line, err = reader()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
- ngx.say("received: ", line)
-
- local line, err = reader()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
- ngx.say("received: ", line)
- end
- ';
- }
-
- location /back {
- content_by_lua '
- ngx.print("hi")
- ngx.flush(true)
- ngx.sleep(0.2)
- ngx.print("world")
- ';
- }
---- request
-GET /t
---- response_body eval
-"failed to receive: timeout, partial: 2\r
-hi\r
-
-received: 5
-received: world
-"
---- error_log
-lua tcp socket read timed out
---- no_error_log
-[alert]
-
-
-
-=== TEST 40: successful reread after a read time out happen (receiveuntil -> receive)
---- no_http2
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("GET /back HTTP/1.1\\r\\nHost: localhost\\r\\n\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local header, err = reader()
- if not header then
- ngx.say("failed to read the response header: ", err)
- return
- end
-
- sock:settimeout(100)
-
- local reader = sock:receiveuntil("no-such-terminator")
- local data, err, partial = reader()
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, ", partial: ", partial)
-
- ngx.sleep(0.1)
-
- sock:settimeout(123)
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
- ngx.say("received: ", line)
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
- ngx.say("received: ", line)
- end
- ';
- }
-
- location /back {
- content_by_lua '
- ngx.print("hi")
- ngx.flush(true)
- ngx.sleep(0.2)
- ngx.print("world")
- ';
- }
---- request
-GET /t
---- response_body eval
-"failed to receive: timeout, partial: 2\r
-hi\r
-
-received: 5
-received: world
-"
---- error_log
-lua tcp socket read timed out
---- no_error_log
-[alert]
-
-
-
-=== TEST 41: receive(0)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local data, err = sock:receive(0)
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("received: ", data)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-received:
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 42: empty options table
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port, {})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 43: u->coctx left over bug
---- no_http2
---- config
- server_tokens off;
- location = /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local ready = false
- local fatal = false
-
- local function f()
- local line, err, part = sock:receive()
- if not line then
- ngx.say("failed to receive the 1st line: ", err, " [", part, "]")
- fatal = true
- return
- end
- ready = true
- ngx.sleep(1)
- end
-
- local st = ngx.thread.spawn(f)
- while true do
- if fatal then
- return
- end
-
- if not ready then
- ngx.sleep(0.01)
- else
- break
- end
- end
-
- while true do
- local line, err, part = sock:receive()
- if line then
- -- ngx.say("received: ", line)
-
- else
- -- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ngx.exit(0)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.sleep(0.1) ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-close: 1 nil
---- no_error_log
-[error]
---- error_log
-lua clean up the timer for pending ngx.sleep
-
-
-
-=== TEST 44: bad request tries to connect
---- no_http2
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location = /main {
- echo_location /t?reset=1;
- echo_location /t;
- }
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local test = require "test"
- if ngx.var.arg_reset then
- test.new_sock()
- end
- local sock = test.get_sock()
- local ok, err = sock:connect("127.0.0.1", ngx.var.port)
- if not ok then
- ngx.say("failed to connect: ", err)
- else
- ngx.say("connected")
- end
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.tcp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^connected
->> myfoo.lua
-local sock = ngx.socket.tcp()
-local ok, err = sock:connect("agentzh.org", 12345)
-if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
-end
-
---- response_body_like: 500 Internal Server Error
---- wait: 0.3
---- error_code: 500
---- error_log
-resolve name done
-runtime error: attempt to yield across C-call boundary
---- no_error_log
-[alert]
-
-
-
-=== TEST 51: cosocket resolving aborted by coroutine yielding failures (xpcall err)
---- http_config
- lua_package_path "$prefix/html/?.lua;;";
- resolver $TEST_NGINX_RESOLVER ipv6=off;
-
---- config
- location = /t {
- content_by_lua '
- local function f()
- return error(1)
- end
- local function err()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("agentzh.org", 12345)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
- end
- xpcall(f, err)
- ngx.say("ok")
- ';
- }
---- request
- GET /t
---- response_body
-ok
---- wait: 0.3
---- error_log
-resolve name done
---- no_error_log
-[error]
-[alert]
-could not cancel
-
-
-
-=== TEST 52: tcp_nodelay on
---- no_http2
---- config
- tcp_nodelay on;
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
-
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- error_log
-lua socket tcp_nodelay
---- no_error_log
-[error]
-
-
-
-=== TEST 53: tcp_nodelay off
---- no_http2
---- config
- tcp_nodelay off;
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
-
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-lua socket tcp_nodelay
-[error]
-
-
-
-=== TEST 54: IPv6
---- http_config
- server_tokens off;
-
- server {
- listen [::1]:$TEST_NGINX_SERVER_PORT;
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
- }
---- config
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("[::1]", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
---- skip_eval: 3: system("ping6 -c 1 ::1 >/dev/null 2>&1") ne 0
-
-
-
-=== TEST 55: kill a thread with a connecting socket
---- config
- server_tokens off;
- lua_socket_connect_timeout 1s;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- content_by_lua '
- local sock
-
- local thr = ngx.thread.spawn(function ()
- sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- end)
-
- ngx.sleep(0.002)
- ngx.thread.kill(thr)
- ngx.sleep(0.001)
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to setkeepalive: ", err)
- else
- ngx.say("setkeepalive: ", ok)
- end
- ';
- }
-
---- request
-GET /t
---- response_body
-failed to setkeepalive: closed
---- error_log
-lua tcp socket connect timeout: 100
---- timeout: 10
-
-
-
-=== TEST 56: reuse cleanup
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- for i = 1, 2 do
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if not line then
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end
- }
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-failed to receive a line: closed []
-close: 1 nil
-connected: 1
-request sent: 57
-failed to receive a line: closed []
-close: 1 nil
---- error_log
-lua http cleanup reuse
-
-
-
-=== TEST 57: reuse cleanup in ngx.timer (fake_request)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local total_send_bytes = 0
- local port = ngx.var.port
-
- local function network()
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.log(ngx.ERR, "failed to send request: ", err)
- return
- end
-
- total_send_bytes = total_send_bytes + bytes
-
- while true do
- local line, err, part = sock:receive()
- if not line then
- break
- end
- end
-
- ok, err = sock:close()
- end
-
- local done = false
-
- local function double_network()
- network()
- network()
- done = true
- end
-
- local ok, err = ngx.timer.at(0, double_network)
- if not ok then
- ngx.say("failed to create timer: ", err)
- end
-
- local i = 1
- while not done do
- local time = 0.005 * i
- if time > 0.1 then
- time = 0.1
- end
- ngx.sleep(time)
- i = i + 1
- end
-
- collectgarbage("collect")
-
- ngx.say("total_send_bytes: ", total_send_bytes)
- }
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-total_send_bytes: 114
---- error_log
-lua http cleanup reuse
-
-
-
-=== TEST 58: free cleanup in ngx.timer (without sock:close)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local total_send_bytes = 0
- local port = ngx.var.port
-
- local function network()
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.log(ngx.ERR, "failed to send request: ", err)
- return
- end
-
- total_send_bytes = total_send_bytes + bytes
-
- while true do
- local line, err, part = sock:receive()
- if not line then
- break
- end
- end
- end
-
- local done = false
-
- local function double_network()
- network()
- network()
- done = true
- end
-
- local ok, err = ngx.timer.at(0, double_network)
- if not ok then
- ngx.say("failed to create timer: ", err)
- end
-
- local i = 1
- while not done do
- local time = 0.005 * i
- if time > 0.1 then
- time = 0.1
- end
- ngx.sleep(time)
- i = i + 1
- end
-
- collectgarbage("collect")
-
- ngx.say("total_send_bytes: ", total_send_bytes)
- }
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-total_send_bytes: 114
---- no_error_log
-[error]
-
-
-
-=== TEST 59: reuse cleanup in subrequest
---- no_http2
---- config
- server_tokens off;
- location /t {
- echo_location /tt;
- }
-
- location /tt {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- for i = 1, 2 do
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if not line then
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-failed to receive a line: closed []
-close: 1 nil
-connected: 1
-request sent: 57
-failed to receive a line: closed []
-close: 1 nil
---- error_log
-lua http cleanup reuse
-
-
-
-=== TEST 60: setkeepalive on socket already shutdown
---- no_http2
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local ok, err = sock:close()
- if not ok then
- ngx.log(ngx.ERR, "failed to close socket: ", err)
- return
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.log(ngx.ERR, "failed to setkeepalive: ", err)
- end
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
---- error_log
-failed to setkeepalive: closed
-
-
-
-=== TEST 61: options_table is nil
---- no_http2
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port, nil)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 11
-received: OK
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 62: resolver send query failing immediately in connect()
-this case did not clear coctx->cleanup properly and would lead to memory invalid accesses.
-
-this test case requires the following iptables rule to work properly:
-
-sudo iptables -I OUTPUT 1 -p udp --dport 10086 -j REJECT
-
---- config
- location /t {
- resolver 127.0.0.1:10086 ipv6=off;
- resolver_timeout 10ms;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- for i = 1, 3 do -- retry
- local ok, err = sock:connect("www.google.com", 80)
- if not ok then
- ngx.say("failed to connect: ", err)
- end
- end
-
- ngx.say("hello!")
- }
- }
---- request
-GET /t
---- response_body_like
-failed to connect: www.google.com could not be resolved(?: \(\d+: Operation timed out\))?
-failed to connect: www.google.com could not be resolved(?: \(\d+: Operation timed out\))?
-failed to connect: www.google.com could not be resolved(?: \(\d+: Operation timed out\))?
-hello!
---- error_log eval
-qr{\[alert\] .*? send\(\) failed \(\d+: Operation not permitted\) while resolving}
-
-
-
-=== TEST 63: the upper bound of port range should be 2^16 - 1
---- config
- location /t {
- content_by_lua_block {
- local sock, err = ngx.socket.connect("127.0.0.1", 65536)
- if not sock then
- ngx.say("failed to connect: ", err)
- end
- }
- }
---- request
-GET /t
---- response_body
-failed to connect: bad port number: 65536
---- no_error_log
-[error]
-
-
-
-=== TEST 64: send boolean and nil
---- no_http2
---- config
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local function send(data)
- local bytes, err = sock:send(data)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- end
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\nTest: "
- send(req)
- send(true)
- send(false)
- send(nil)
- send("\r\n\r\n")
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- break
- end
- end
-
- ok, err = sock:close()
- }
- }
-
- location /foo {
- server_tokens off;
- more_clear_headers Date;
- echo $http_test;
- }
-
---- request
-GET /t
---- response_body
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Connection: close
-received:
-received: truefalsenil
---- no_error_log
-[error]
-
-
-
-=== TEST 65: receiveany method in cosocket
---- no_http2
---- config
- server_tokens off;
- location = /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(500)
- assert(sock:connect("127.0.0.1", ngx.var.port))
- local req = {
- 'GET /foo HTTP/1.0\r\n',
- 'Host: localhost\r\n',
- 'Connection: close\r\n\r\n',
- }
- local ok, err = sock:send(req)
- if not ok then
- ngx.say("send request failed: ", err)
- return
- end
-
- -- skip http header
- while true do
- local data, err, _ = sock:receive('*l')
- if err then
- ngx.say('unexpected error occurs when receiving http head: ', err)
- return
- end
-
- if #data == 0 then -- read last line of head
- break
- end
- end
-
- -- receive http body
- while true do
- local data, err = sock:receiveany(1024)
- if err then
- if err ~= 'closed' then
- ngx.say('unexpected err: ', err)
- end
- break
- end
- ngx.say(data)
- end
-
- sock:close()
- }
- }
-
- location = /foo {
- content_by_lua_block {
- local resp = {
- '1',
- '22',
- 'hello world',
- }
-
- local length = 0
- for _, v in ipairs(resp) do
- length = length + #v
- end
-
- -- flush http header
- ngx.header['Content-Length'] = length
- ngx.flush(true)
- ngx.sleep(0.01)
-
- -- send http body
- for _, v in ipairs(resp) do
- ngx.print(v)
- ngx.flush(true)
- ngx.sleep(0.01)
- end
- }
- }
-
---- request
-GET /t
---- response_body
-1
-22
-hello world
---- no_error_log
-[error]
---- error_log
-lua tcp socket read any
-
-
-
-=== TEST 66: receiveany send data after read side closed
---- config
- server_tokens off;
- location = /t {
- set $port $TEST_NGINX_RAND_PORT_1;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- sock:settimeout(500)
- assert(sock:connect("127.0.0.1", port))
-
- while true do
- local data, err = sock:receiveany(1024)
- if err then
- if err ~= 'closed' then
- ngx.say('unexpected err: ', err)
- break
- end
-
- local data = "send data after read side closed"
- local bytes, err = sock:send(data)
- if not bytes then
- ngx.say(err)
- end
-
- break
- end
- ngx.say(data)
- end
-
- sock:close()
- }
- }
-
---- request
-GET /t
---- tcp_listen: $TEST_NGINX_RAND_PORT_1
---- tcp_shutdown: 1
---- tcp_query eval: "send data after read side closed"
---- tcp_query_len: 32
---- response_body
---- no_error_log
-[error]
-
-
-
-=== TEST 67: receiveany with limited, max <= 0
---- no_http2
---- config
- location = /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(500)
- assert(sock:connect("127.0.0.1", ngx.var.port))
-
- local function receiveany_say_err(...)
- local ok, err = pcall(sock.receiveany, sock, ...)
- if not ok then
- ngx.say(err)
- end
- end
-
-
- receiveany_say_err(0)
- receiveany_say_err(-1)
- receiveany_say_err()
- receiveany_say_err(nil)
- }
- }
-
---- response_body
-bad argument #2 to '?' (bad max argument)
-bad argument #2 to '?' (bad max argument)
-expecting 2 arguments (including the object), but got 1
-bad argument #2 to '?' (bad max argument)
---- request
-GET /t
---- no_error_log
-[error]
-
-
-
-=== TEST 68: receiveany with limited, max is larger than data
---- no_http2
---- config
- server_tokens off;
- location = /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(500)
- assert(sock:connect("127.0.0.1", ngx.var.port))
- local req = {
- 'GET /foo HTTP/1.0\r\n',
- 'Host: localhost\r\n',
- 'Connection: close\r\n\r\n',
- }
- local ok, err = sock:send(req)
- if not ok then
- ngx.say("send request failed: ", err)
- return
- end
-
- while true do
- local data, err, _ = sock:receive('*l')
- if err then
- ngx.say('unexpected error occurs when receiving http head: ', err)
- return
- end
-
- if #data == 0 then -- read last line of head
- break
- end
- end
-
- local data, err = sock:receiveany(128)
- if err then
- if err ~= 'closed' then
- ngx.say('unexpected err: ', err)
- end
- else
- ngx.say(data)
- end
-
- sock:close()
- }
- }
-
- location = /foo {
- content_by_lua_block {
- local resp = 'hello world'
- local length = #resp
-
- ngx.header['Content-Length'] = length
- ngx.flush(true)
- ngx.sleep(0.01)
-
- ngx.print(resp)
- }
- }
-
---- request
-GET /t
---- response_body
-hello world
---- no_error_log
-[error]
---- error_log
-lua tcp socket calling receiveany() method to read at most 128 bytes
-
-
-
-=== TEST 69: receiveany with limited, max is smaller than data
---- no_http2
---- config
- server_tokens off;
- location = /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(500)
- assert(sock:connect("127.0.0.1", ngx.var.port))
- local req = {
- 'GET /foo HTTP/1.0\r\n',
- 'Host: localhost\r\n',
- 'Connection: close\r\n\r\n',
- }
- local ok, err = sock:send(req)
- if not ok then
- ngx.say("send request failed: ", err)
- return
- end
-
- while true do
- local data, err, _ = sock:receive('*l')
- if err then
- ngx.say('unexpected error occurs when receiving http head: ', err)
- return
- end
-
- if #data == 0 then -- read last line of head
- break
- end
- end
-
- while true do
- local data, err = sock:receiveany(7)
- if err then
- if err ~= 'closed' then
- ngx.say('unexpected err: ', err)
- end
- break
-
- else
- ngx.say(data)
- end
- end
-
- sock:close()
- }
- }
-
- location = /foo {
- content_by_lua_block {
- local resp = 'hello world'
- local length = #resp
-
- ngx.header['Content-Length'] = length
- ngx.flush(true)
- ngx.sleep(0.01)
-
- ngx.print(resp)
- }
- }
-
---- request
-GET /t
---- response_body
-hello w
-orld
---- no_error_log
-[error]
---- error_log
-lua tcp socket calling receiveany() method to read at most 7 bytes
-
-
-
-=== TEST 70: send tables of string fragments (with floating point number too)
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", 1, ".", 0, "\r\n",
- "Host: localhost\r\n", "Connection: close\r\n",
- "Foo: ", 3.1415926, "\r\n",
- "\r\n"}
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
-
- location /foo {
- content_by_lua_block {
- ngx.say(ngx.req.get_headers()["Foo"])
- }
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 73
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 10
-received: Connection: close
-received:
-received: 3.1415926
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 71: send numbers
-the maximum number of significant digits is 14 in lua
---- no_http2
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = {"GET", " ", "/foo", " HTTP/", 1, ".", 0, "\r\n",
- "Host: localhost\r\n", "Connection: close\r\n",
- "Foo: "}
- -- req = "OK"
-
- local total_bytes = 0;
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- total_bytes = total_bytes + bytes;
-
- bytes, err = sock:send(3.14159265357939723846)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- total_bytes = total_bytes + bytes;
-
- bytes, err = sock:send(31415926)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- total_bytes = total_bytes + bytes;
-
- bytes, err = sock:send("\r\n\r\n")
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- total_bytes = total_bytes + bytes;
-
- ngx.say("request sent: ", total_bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
-
- location /foo {
- content_by_lua_block {
- ngx.say(ngx.req.get_headers()["Foo"])
- }
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 87
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 24
-received: Connection: close
-received:
-received: 3.141592653579431415926
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 72: port is not number
---- config
- server_tokens off;
- location = /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(500)
-
- local ok, err = sock:connect("127.0.0.1")
- if not ok then
- ngx.say("connect failed: ", err)
- end
-
- local ok, err = sock:connect("127.0.0.1", nil)
- if not ok then
- ngx.say("connect failed: ", err)
- end
-
- local ok, err = sock:connect("127.0.0.1", {})
- if not ok then
- ngx.say("connect failed: ", err)
- end
-
- ngx.say("finish")
- }
- }
-
---- request
-GET /t
---- response_body
-connect failed: missing the port number
-connect failed: missing the port number
-connect failed: missing the port number
-finish
---- no_error_log
-[error]
-
-
-
-=== TEST 73: reset the buffer pos when keepalive
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- for i = 1, 10
- do
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET /hi HTTP/1.1\r\nHost: localhost\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- local line, err, part = sock:receive()
- if not line then
- ngx.say("receive err: ", err)
- return
- end
-
- data, err = sock:receiveany(4096)
- if not data then
- ngx.say("receiveany er: ", err)
- return
- end
-
- ok, err = sock:setkeepalive(10000, 32)
- if not ok then
- ngx.say("reused times: ", i, ", setkeepalive err: ", err)
- return
- end
- end
- ngx.say("END")
- }
- }
-
- location /hi {
- keepalive_requests 3;
- content_by_lua_block {
- ngx.say("Hello")
- }
-
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-reused times: 3, setkeepalive err: closed
---- no_error_log
-[error]
---- skip_eval: 3: $ENV{TEST_NGINX_EVENT_TYPE} && $ENV{TEST_NGINX_EVENT_TYPE} ne 'epoll'
diff --git a/src/deps/src/lua-nginx-module/t/059-unix-socket.t b/src/deps/src/lua-nginx-module/t/059-unix-socket.t
deleted file mode 100644
index bd83006ba..000000000
--- a/src/deps/src/lua-nginx-module/t/059-unix-socket.t
+++ /dev/null
@@ -1,339 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 1);
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-
-no_long_string();
-#no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: connection refused (unix domain socket)
---- config
- location /test {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:/tmp/nosuchfile.sock")
- ngx.say("connect: ", ok, " ", err)
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
---- request
- GET /test
---- response_body
-connect: nil no such file or directory
-send: nil closed
-receive: nil closed
-close: nil closed
---- error_log eval
-qr{\[crit\] .*? connect\(\) to unix:/tmp/nosuchfile\.sock failed}
-
-
-
-=== TEST 2: invalid host argument
---- config
- location /test {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("/tmp/test-nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
- }
---- request
- GET /test
---- response_body
-failed to connect: missing the port number
-
-
-
-=== TEST 3: sanity
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
- }
---- config
- location /test {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- print("calling receive")
- local line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err)
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
---- request
- GET /test
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed
-close: 1 nil
-
-
-
-=== TEST 4: ngx.socket.stream
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- content_by_lua_block { ngx.say("foo") }
- more_clear_headers Date;
- }
- }
---- config
- location /test {
- content_by_lua_block {
- local sock = ngx.socket.stream()
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- print("calling receive")
- local line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err)
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
---- request
- GET /test
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed
-close: 1 nil
-
-
-
-=== TEST 5: port will be ignored
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
- }
---- config
- location /test {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock", 80)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- print("calling receive")
- local line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err)
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
---- request
- GET /test
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed
-close: 1 nil
-
-
-
-=== TEST 6: second parameter is nil
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
- }
---- config
- location /test {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock", nil)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- print("calling receive")
- local line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err)
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
---- request
- GET /test
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed
-close: 1 nil
diff --git a/src/deps/src/lua-nginx-module/t/060-lua-memcached.t b/src/deps/src/lua-nginx-module/t/060-lua-memcached.t
deleted file mode 100644
index 075123862..000000000
--- a/src/deps/src/lua-nginx-module/t/060-lua-memcached.t
+++ /dev/null
@@ -1,168 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 1);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-my $pwd = `pwd`;
-chomp $pwd;
-$ENV{TEST_NGINX_PWD} ||= $pwd;
-
-#master_on();
-workers(1);
-#log_level('warn');
-#worker_connections(1014);
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- http_config
- lua_package_path '$TEST_NGINX_PWD/t/lib/?.lua;;';
---- config
- location /test {
- content_by_lua '
- package.loaded["socket"] = ngx.socket
- local Memcached = require "Memcached"
- Memcached.socket = ngx.socket
-
- local memc = Memcached.Connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
-
- memc:set("some_key", "hello 1234")
- local data = memc:get("some_key")
- ngx.say("some_key: ", data)
- ';
- }
---- request
- GET /test
---- response_body
-some_key: hello 1234
---- no_error_log
-[error]
-
-
-
-=== TEST 2: raw memcached
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;;';"
---- config
- location /t {
- content_by_lua '
- local memcached = require "resty.memcached"
- local memc, err = memcached.connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
-
- local ok, err = memc:set("some_key", "hello 1234")
- if not ok then
- ngx.log(ngx.ERR, "failed to set some_key: ", err)
- ngx.exit(500)
- end
-
- local data, err = memc:get("some_key")
- if not data and err then
- ngx.log(ngx.ERR, "failed to get some_key: ", err)
- ngx.exit(500)
- end
-
- ngx.say("some_key: ", data)
-
- local res, err = memc:set_keepalive()
- if not res then
- ngx.say("failed to set keepalive: ", err)
- return
- end
- ';
- }
---- user_files
->>> resty/memcached.lua
-module("resty.memcached", package.seeall)
-
-local mt = { __index = resty.memcached }
-local sub = string.sub
-local escape_uri = ngx.escape_uri
-local socket_connect = ngx.socket.connect
-local match = string.match
-
-function connect(...)
- local sock, err = socket_connect(...)
- return setmetatable({ sock = sock }, mt)
-end
-
-function get(self, key)
- local cmd = "get " .. escape_uri(key) .. "\r\n"
- local bytes, err = self.sock:send(cmd)
- if not bytes then
- return nil, err
- end
-
- local line, err = self.sock:receive()
- if line == 'END' then
- return nil, nil
- end
-
- local flags, len = match(line, [[^VALUE %S+ (%d+) (%d+)]])
- if not flags then
- return nil, "bad response: " .. line
- end
-
- print("size: ", size, ", flags: ", len)
-
- local data, err = self.sock:receive(len)
- if not data then
- return nil, err
- end
-
- line, err = self.sock:receive(2) -- discard the trailing CRLF
- if not line then
- return nil, nil, "failed to receive CRLF: " .. (err or "")
- end
-
- line, err = self.sock:receive() -- discard "END\r\n"
- if not line then
- return nil, nil, "failed to receive END CRLF: " .. (err or "")
- end
-
- return data
-end
-
-function set(self, key, value, exptime, flags)
- if not exptime then
- exptime = 0
- end
-
- if not flags then
- flags = 0
- end
-
- local cmd = table.concat({"set ", escape_uri(key), " ", flags, " ", exptime, " ", #value, "\r\n", value, "\r\n"}, "")
-
- local bytes, err = self.sock:send(cmd)
- if not bytes then
- return nil, err
- end
-
- local data, err = self.sock:receive()
- if sub(data, 1, 6) == "STORED" then
- return true
- end
-
- return false, err
-end
-
-function set_keepalive(self)
- return self.sock:setkeepalive(0, 100)
-end
---- request
- GET /t
---- response_body
-some_key: hello 1234
---- no_error_log
-[error]
---- error_log
-lua reuse free buf memory
diff --git a/src/deps/src/lua-nginx-module/t/061-lua-redis.t b/src/deps/src/lua-nginx-module/t/061-lua-redis.t
deleted file mode 100644
index ebfa6d199..000000000
--- a/src/deps/src/lua-nginx-module/t/061-lua-redis.t
+++ /dev/null
@@ -1,184 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
-
-#log_level "warn";
-#worker_connections(1024);
-#master_on();
-
-my $pwd = `pwd`;
-chomp $pwd;
-$ENV{TEST_NGINX_PWD} ||= $pwd;
-
-our $LuaCpath = $ENV{LUA_CPATH} ||
- '/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;';
-
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- http_config
- lua_package_path '$TEST_NGINX_PWD/t/lib/?.lua;;';
---- config
- location /test {
- content_by_lua '
- package.loaded["socket"] = ngx.socket
- local Redis = require "Redis"
-
- local redis = Redis.connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
-
- redis:set("some_key", "hello 1234")
- local data = redis:get("some_key")
- ngx.say("some_key: ", data)
- ';
- }
---- request
- GET /test
---- response_body
-some_key: hello 1234
---- no_error_log
-[error]
-
-
-
-=== TEST 2: coroutine-based pub/sub
---- http_config eval
-qq{
- lua_package_path '\$TEST_NGINX_PWD/t/lib/?.lua;;';
- lua_package_cpath '$::LuaCpath';
-}
---- config
- location /test {
- content_by_lua '
- package.loaded["socket"] = ngx.socket
- local Redis = require "Redis"
-
- local ljson = require "ljson"
-
- local r1 = Redis.connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
-
- local r2 = Redis.connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
-
- local loop = r2:pubsub({ subscribe = "foo" })
- local msg, abort = loop()
- ngx.say("msg type: ", type(msg))
- ngx.say("abort: ", type(abort))
-
- if msg then
- ngx.say("msg: ", ljson.encode(msg))
- end
-
- for i = 1, 3 do
- r1:publish("foo", "test " .. i)
- msg, abort = loop()
- if msg then
- ngx.say("msg: ", ljson.encode(msg))
- end
- ngx.say("abort: ", type(abort))
- end
-
- abort()
-
- msg, abort = loop()
- ngx.say("msg type: ", type(msg))
- ';
- }
---- stap2
-global ids, cur
-
-function gen_id(k) {
- if (ids[k]) return ids[k]
- ids[k] = ++cur
- return cur
-}
-
-F(ngx_http_handler) {
- delete ids
- cur = 0
-}
-
-/*
-probe process("/usr/local/openresty-debug/luajit/lib/libluajit-5.1.so.2").function("lua_yield") {
- id = gen_id($L)
- printf("raw lua yield %d\n", id)
- #print_ubacktrace()
-}
-
-probe process("/usr/local/openresty-debug/luajit/lib/libluajit-5.1.so.2").function("lua_resume") {
- id = gen_id($L)
- printf("raw lua resume %d\n", id)
-}
-*/
-
-/*
-F(ngx_http_lua_run_thread) {
- id = gen_id($ctx->cur_co)
- printf("run thread %d\n", id)
-}
-*/
-
-M(http-lua-user-coroutine-resume) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("resume %x in %x\n", c, p)
-}
-
-M(http-lua-entry-coroutine-yield) {
- println("entry coroutine yield")
-}
-
-F(ngx_http_lua_coroutine_yield) {
- printf("yield %x\n", gen_id($L))
-}
-
-/*
-F(ngx_http_lua_coroutine_resume) {
- printf("resume %x\n", gen_id($L))
-}
-*/
-
-M(http-lua-user-coroutine-yield) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("yield %x in %x\n", c, p)
-}
-
-F(ngx_http_lua_atpanic) {
- printf("lua atpanic(%d):", gen_id($L))
- print_ubacktrace();
-}
-
-M(http-lua-user-coroutine-create) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("create %x in %x\n", c, p)
-}
-
-F(ngx_http_lua_ngx_exec) { println("exec") }
-
-F(ngx_http_lua_ngx_exit) { println("exit") }
-
---- request
- GET /test
---- response_body
-msg type: table
-abort: function
-msg: {"channel":"foo","kind":"subscribe","payload":1}
-msg: {"channel":"foo","kind":"message","payload":"test 1"}
-abort: function
-msg: {"channel":"foo","kind":"message","payload":"test 2"}
-abort: function
-msg: {"channel":"foo","kind":"message","payload":"test 3"}
-abort: function
-msg type: nil
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/062-count.t b/src/deps/src/lua-nginx-module/t/062-count.t
deleted file mode 100644
index 957590292..000000000
--- a/src/deps/src/lua-nginx-module/t/062-count.t
+++ /dev/null
@@ -1,595 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(4);
-#log_level('warn');
-no_root_location();
-
-#repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-
-#$ENV{LUA_CPATH} = "/usr/local/openresty/lualib/?.so;" . $ENV{LUA_CPATH};
-
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: entries under ngx. (content by lua)
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx) do
- n = n + 1
- end
- ngx.say("ngx: ", n)
- ';
- }
---- request
-GET /test
---- response_body
-ngx: 116
---- no_error_log
-[error]
-
-
-
-=== TEST 2: entries under ngx. (set by lua)
---- config
- location = /test {
- set_by_lua $n '
- local n = 0
- for k, v in pairs(ngx) do
- n = n + 1
- end
- return n;
- ';
- echo $n;
- }
---- request
-GET /test
---- response_body
-116
---- no_error_log
-[error]
-
-
-
-=== TEST 3: entries under ngx. (header filter by lua)
---- config
- location = /test {
- set $n '';
-
- content_by_lua '
- ngx.send_headers()
- ngx.say("n = ", ngx.var.n)
- ';
-
- header_filter_by_lua '
- local n = 0
- for k, v in pairs(ngx) do
- n = n + 1
- end
-
- ngx.var.n = n
- ';
- }
---- request
-GET /test
---- response_body
-n = 116
---- no_error_log
-[error]
-
-
-
-=== TEST 4: entries under ndk. (content by lua)
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ndk) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 1
---- no_error_log
-[error]
-
-
-
-=== TEST 5: entries under ngx.req (content by lua)
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx.req) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 23
---- no_error_log
-[error]
-
-
-
-=== TEST 6: entries under ngx.req (set by lua)
---- config
- location = /test {
- set_by_lua $n '
- local n = 0
- for k, v in pairs(ngx.req) do
- n = n + 1
- end
- return n
- ';
-
- echo "n = $n";
- }
---- request
-GET /test
---- response_body
-n = 23
---- no_error_log
-[error]
-
-
-
-=== TEST 7: entries under ngx.req (header filter by lua)
---- config
- location = /test {
- set $n '';
-
- header_filter_by_lua '
- local n = 0
- for k, v in pairs(ngx.req) do
- n = n + 1
- end
- ngx.var.n = n
- ';
-
- content_by_lua '
- ngx.send_headers()
- ngx.say("n = ", ngx.var.n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 23
---- no_error_log
-[error]
-
-
-
-=== TEST 8: entries under ngx.location
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx.location) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 2
---- no_error_log
-[error]
-
-
-
-=== TEST 9: entries under ngx.socket
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx.socket) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 4
---- no_error_log
-[error]
-
-
-
-=== TEST 10: entries under ngx._tcp_meta
---- SKIP
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx._tcp_meta) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 10
---- no_error_log
-[error]
-
-
-
-=== TEST 11: entries under the metatable of req sockets
---- config
- location = /test {
- content_by_lua '
- local n = 0
- local sock, err = ngx.req.socket()
- if not sock then
- ngx.say("failed to get the request socket: ", err)
- end
-
- for k, v in pairs(getmetatable(sock)) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-POST /test
-hello world
---- response_body
-n = 6
---- no_error_log
-[error]
---- skip_eval: 3: $ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 12: shdict metatable
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- local mt = dogs.__index
- local n = 0
- for k, v in pairs(mt) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 22
---- no_error_log
-[error]
-
-
-
-=== TEST 13: entries under ngx. (log by lua)
---- config
- location = /t {
- log_by_lua '
- local n = 0
- for k, v in pairs(ngx) do
- n = n + 1
- end
- ngx.log(ngx.ERR, "ngx. entry count: ", n)
- ';
- }
---- request
-GET /t
---- response_body_like: 404 Not Found
---- error_code: 404
---- error_log
-ngx. entry count: 116
-
-
-
-=== TEST 14: entries under ngx.timer
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx.timer) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 4
---- no_error_log
-[error]
-
-
-
-=== TEST 15: entries under ngx.config
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx.config) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 6
---- no_error_log
-[error]
-
-
-
-=== TEST 16: entries under ngx.re
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx.re) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 5
---- no_error_log
-[error]
-
-
-
-=== TEST 17: entries under coroutine. (content by lua)
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(coroutine) do
- n = n + 1
- end
- ngx.say("coroutine: ", n)
- ';
- }
---- request
-GET /test
---- stap2
-global c
-probe process("$LIBLUA_PATH").function("rehashtab") {
- c++
- printf("rehash: %d\n", c)
-}
---- stap_out2
-3
---- response_body
-coroutine: 16
---- no_error_log
-[error]
-
-
-
-=== TEST 18: entries under ngx.thread. (content by lua)
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx.thread) do
- n = n + 1
- end
- ngx.say("thread: ", n)
- ';
- }
---- request
-GET /test
---- stap2
-global c
-probe process("$LIBLUA_PATH").function("rehashtab") {
- c++
- printf("rehash: %d\n", c)
-}
---- stap_out2
---- response_body
-thread: 3
---- no_error_log
-[error]
-
-
-
-=== TEST 19: entries under ngx.worker
---- config
- location = /test {
- content_by_lua '
- local n = 0
- for k, v in pairs(ngx.worker) do
- n = n + 1
- end
- ngx.say("worker: ", n)
- ';
- }
---- request
-GET /test
---- response_body
-worker: 5
---- no_error_log
-[error]
-
-
-
-=== TEST 20: entries under the metatable of tcp sockets
---- config
- location = /test {
- content_by_lua_block {
- local n = 0
- local sock = ngx.socket.tcp()
- for k, v in pairs(getmetatable(sock)) do
- n = n + 1
- end
- ngx.say("n = ", n)
- }
- }
---- request
-GET /test
---- response_body
-n = 16
---- no_error_log
-[error]
-
-
-
-=== TEST 21: entries under the metatable of udp sockets
---- config
- location = /test {
- content_by_lua '
- local n = 0
- local sock = ngx.socket.udp()
- for k, v in pairs(getmetatable(sock)) do
- n = n + 1
- end
- ngx.say("n = ", n)
- ';
- }
---- request
-GET /test
---- response_body
-n = 7
---- no_error_log
-[error]
-
-
-
-=== TEST 22: entries under the metatable of req raw sockets
---- config
- location = /test {
- content_by_lua '
- local n = 0
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
-
- for k, v in pairs(getmetatable(sock)) do
- n = n + 1
- end
-
- local ok, err = sock:send("HTTP/1.1 200 OK\\r\\nContent-Length: 6\\r\\n\\r\\nn = "..n.."\\n")
- if not ok then
- ngx.log(ngx.ERR, "failed to send: ", err)
- return
- end
- ';
- }
---- request
-GET /test
---- response_body
-n = 7
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 23: entries under the req raw sockets
---- config
- location = /test {
- content_by_lua_block {
- local narr = 0
- local nrec = 0
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
- sock:settimeouts(1000, 2000, 3000)
- for k, v in ipairs(sock) do
- narr = narr + 1
- end
- for k, v in pairs(sock) do
- nrec = nrec + 1
- end
- -- include '__index'
- nrec = nrec - narr + 1
-
- local ok, err = sock:send("HTTP/1.1 200 OK\r\n\r\nnarr = "..narr.."\nnrec = "..nrec.."\n")
- if not ok then
- ngx.log(ngx.ERR, "failed to send: ", err)
- return
- end
- }
- }
---- request
-GET /test
---- response_body
-narr = 2
-nrec = 3
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 24: entries under the req sockets
---- config
- location = /test {
- content_by_lua_block {
- local narr = 0
- local nrec = 0
- local sock, err = ngx.req.socket()
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get req socket: ", err)
- return
- end
- sock:settimeouts(1000, 2000, 3000)
- for k, v in ipairs(sock) do
- narr = narr + 1
- end
- for k, v in pairs(sock) do
- nrec = nrec + 1
- end
- -- include '__index'
- nrec = nrec - narr + 1
-
- ngx.say("narr = "..narr.."\nnrec = "..nrec)
- }
- }
---- request
-POST /test
-hello world
---- response_body
-narr = 2
-nrec = 3
---- no_error_log
-[error]
---- skip_eval: 3: $ENV{TEST_NGINX_USE_HTTP3}
diff --git a/src/deps/src/lua-nginx-module/t/063-abort.t b/src/deps/src/lua-nginx-module/t/063-abort.t
deleted file mode 100644
index 7c90eaafa..000000000
--- a/src/deps/src/lua-nginx-module/t/063-abort.t
+++ /dev/null
@@ -1,1019 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-worker_connections(1014);
-#master_on();
-#workers(4);
-#log_level('warn');
-no_root_location();
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 2);
-
-our $HtmlDir = html_dir;
-
-#$ENV{LUA_CPATH} = "/usr/local/openresty/lualib/?.so;" . $ENV{LUA_CPATH};
-
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: ngx.exit(400) should abort print
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /memc_query {
- internal;
- set $memc_cmd $arg_cmd;
- set_unescape_uri $memc_key $arg_key;
- set_unescape_uri $memc_value $arg_value;
- set $memc_exptime $arg_exptime;
-
- memc_cmds_allowed get set add delete;
- memc_pass 127.0.0.1:11211;
- }
-
- location = /test {
- content_by_lua_file html/test.lua;
- }
---- user_files
->>> test.lua
-local memd = require 'memd'
-ngx.exit(400)
-local res = memd.query( { cmd = 'get', key = id } )
->>> memd.lua
-module('memd', package.seeall)
-
-local URL = '/memc_query'
-local capture = ngx.location.capture
-
-function query(arg)
- if type(arg) ~= 'table' then
- return nil
- end
-
- print("HELLO WORLD")
- return capture(URL, { args = arg } )
-end
---- request
-GET /test?a
---- response_body_like: 400 Bad Request
---- no_error_log eval
-["lua print: HELLO WORLD", q{the "$memc_key" variable is not set}]
---- error_code: 400
-
-
-
-=== TEST 2: ngx.exit(400) should abort ngx.log
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /memc_query {
- internal;
- set $memc_cmd $arg_cmd;
- set_unescape_uri $memc_key $arg_key;
- set_unescape_uri $memc_value $arg_value;
- set $memc_exptime $arg_exptime;
-
- memc_cmds_allowed get set add delete;
- memc_pass 127.0.0.1:11211;
- }
-
- location = /test {
- content_by_lua_file html/test.lua;
- }
---- user_files
->>> test.lua
-local memd = require 'memd'
-ngx.exit(400)
-local res = memd.query( { cmd = 'get', key = id } )
->>> memd.lua
-module('memd', package.seeall)
-
-local URL = '/memc_query'
-local capture = ngx.location.capture
-local log = ngx.log
-local level = ngx.ERR
-
-function query(arg)
- if type(arg) ~= 'table' then
- return nil
- end
-
- log(level, "HELLO WORLD")
- return capture(URL, { args = arg } )
-end
---- request
-GET /test?a
---- response_body_like: 400 Bad Request
---- no_error_log eval
-["HELLO WORLD", q{the "$memc_key" variable is not set}]
---- error_code: 400
-
-
-
-=== TEST 3: ngx.exit(400) should abort ngx.location.capture
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /memc_query {
- internal;
- set $memc_cmd $arg_cmd;
- set_unescape_uri $memc_key $arg_key;
- set_unescape_uri $memc_value $arg_value;
- set $memc_exptime $arg_exptime;
-
- memc_cmds_allowed get set add delete;
- memc_pass 127.0.0.1:11211;
- }
-
- location = /test {
- content_by_lua_file html/test.lua;
- }
---- user_files
->>> test.lua
-local memd = require 'memd'
-ngx.exit(400)
-local res = memd.query( { cmd = 'get', key = id } )
->>> memd.lua
-module('memd', package.seeall)
-
-local URL = '/memc_query'
-local capture = ngx.location.capture
-
-function query(arg)
- if type(arg) ~= 'table' then
- return nil
- end
-
- return capture(URL, { args = arg } )
-end
---- request
-GET /test?a
---- response_body_like: 400 Bad Request
---- no_error_log
-the "$memc_key" variable is not set
---- error_code: 400
-
-
-
-=== TEST 4: ngx.exit(400) should abort ngx.location.capture_multi
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /memc_query {
- internal;
- set $memc_cmd $arg_cmd;
- set_unescape_uri $memc_key $arg_key;
- set_unescape_uri $memc_value $arg_value;
- set $memc_exptime $arg_exptime;
-
- memc_cmds_allowed get set add delete;
- memc_pass 127.0.0.1:11211;
- }
-
- location = /test {
- content_by_lua_file html/test.lua;
- }
---- user_files
->>> test.lua
-local memd = require 'memd'
-ngx.exit(400)
-local res = memd.query( { cmd = 'get', key = id } )
->>> memd.lua
-module('memd', package.seeall)
-
-local URL = '/memc_query'
-local capture_multi = ngx.location.capture_multi
-
-function query(arg)
- if type(arg) ~= 'table' then
- return nil
- end
-
- return capture_multi{ {URL, { args = arg }} }
-end
---- request
-GET /test?a
---- response_body_like: 400 Bad Request
---- no_error_log
-the "$memc_key" variable is not set
---- error_code: 400
-
-
-
-=== TEST 5: ngx.exit(400) should abort ngx.redirect
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.redirect("/blah")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua redirect to "/blah" with code 302
---- error_code: 400
-
-
-
-=== TEST 6: ngx.exit(400) should abort ngx.exit
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.exit(503)
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua exit with code 503
---- error_code: 400
-
-
-
-=== TEST 7: ngx.exit(400) should abort ngx.exec
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.exec("/blah")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua exec "/blah?"
---- error_code: 400
-
-
-
-=== TEST 8: ngx.exit(400) should abort ngx.send_headers
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.send_headers()
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua send headers
---- error_code: 400
-
-
-
-=== TEST 9: ngx.exit(400) should abort ngx.print
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.print("HELLO WORLD")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua print response
---- error_code: 400
-
-
-
-=== TEST 10: ngx.exit(400) should abort ngx.say
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.say("HELLO WORLD")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua say response
---- error_code: 400
-
-
-
-=== TEST 11: ngx.exit(400) should abort ngx.flush
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.flush()
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua flush asynchronously
---- error_code: 400
-
-
-
-=== TEST 12: ngx.exit(400) should abort ngx.eof
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.eof()
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua send eof
---- error_code: 400
-
-
-
-=== TEST 13: ngx.exit(400) should abort ngx.re.match
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.re.match("a", "a", "jo")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua compiling match regex "a" with options "jo"
---- error_code: 400
-
-
-
-=== TEST 14: ngx.exit(400) should abort ngx.re.gmatch
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.re.gmatch("a", "a", "jo")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua compiling gmatch regex "a" with options "jo"
---- error_code: 400
-
-
-
-=== TEST 15: ngx.exit(400) should abort ngx.re.sub
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.re.sub("a", "a", "", "jo")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua compiling sub regex "a" with options "jo"
---- error_code: 400
-
-
-
-=== TEST 16: ngx.exit(400) should abort ngx.re.gsub
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go()
- ngx.re.gsub("a", "a", "", "jo")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-lua compiling gsub regex "a" with options "jo"
---- error_code: 400
-
-
-
-=== TEST 17: ngx.exit(400) should abort ngx.shared.DICT (set)
---- http_config eval
- "lua_shared_dict dogs 1m; lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- local dogs = ngx.shared.dogs
- print("foo = ", dogs:get("foo"))
- dogs:set("foo", 32)
- ngx.exit(400)
- test.go(dogs)
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go(dogs)
- dogs:set("foo", 56)
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-foo = 56
---- error_code: 400
-
-
-
-=== TEST 18: ngx.exit(400) should abort ngx.shared.DICT (replace)
---- http_config eval
- "lua_shared_dict dogs 1m; lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- local dogs = ngx.shared.dogs
- print("foo = ", dogs:get("foo"))
- dogs:set("foo", 32)
- ngx.exit(400)
- test.go(dogs)
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go(dogs)
- dogs:replace("foo", 56)
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-foo = 56
---- error_code: 400
-
-
-
-=== TEST 19: ngx.exit(400) should abort ngx.shared.DICT (incr)
---- http_config eval
- "lua_shared_dict dogs 1m; lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- local dogs = ngx.shared.dogs
- print("foo = ", dogs:get("foo"))
- dogs:set("foo", 32)
- ngx.exit(400)
- test.go(dogs)
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go(dogs)
- dogs:incr("foo", 56)
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-foo = 88
---- error_code: 400
-
-
-
-=== TEST 20: ngx.exit(400) should abort ngx.shared.DICT (get)
---- http_config eval
- "lua_shared_dict dogs 1m; lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- ngx.exit(400)
- test.go(dogs)
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-function go(dogs)
- dogs:get("foo")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-fetching key "foo" in shared dict "dogs"
---- error_code: 400
-
-
-
-=== TEST 21: ngx.exit(400) should skip os.execute
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- ngx.exit(400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-local exec = os.execute
-
-function go()
- exec("sleep 5")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- error_code: 400
---- no_error_log
-[error]
---- timeout: 2
-
-
-
-=== TEST 22: ngx.exit(400) should break pcall and skip os.execute
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- pcall(ngx.exit, 400)
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-local exec = os.execute
-
-function go()
- exec("sleep 5")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- no_error_log
-fetching key "foo" in shared dict "dogs"
---- error_code: 400
---- timeout: 2
-
-
-
-=== TEST 23: ngx.exit(400) should break pcall and skip os.execute (all in user module)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-local exec = os.execute
-
-function go()
- pcall(ngx.exit, 400)
- exec("sleep 5")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- error_code: 400
---- no_error_log
-[error]
---- timeout: 2
-
-
-
-=== TEST 24: ngx.redirect() should break pcall and skip os.execute (all in user module)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-local exec = os.execute
-
-function go()
- pcall(ngx.redirect, "/blah")
- exec("sleep 5")
-end
---- request
-GET /test
---- response_body_like: 302 Found
---- no_error_log
-[error]
---- error_code: 302
---- timeout: 2
-
-
-
-=== TEST 25: ngx.redirect() should skip os.execute (all in user module)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-local exec = os.execute
-
-function go()
- ngx.redirect("/blah")
- exec("sleep 5")
-end
---- request
-GET /test
---- response_body_like: 302 Found
---- no_error_log
-[error]
---- error_code: 302
---- timeout: 2
-
-
-
-=== TEST 26: ngx.exec() should break pcall and skip os.execute (all in user module)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- test.go()
- ';
- }
- location = /foo {
- echo foo;
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-local exec = os.execute
-
-function go()
- pcall(ngx.exec, "/foo")
- exec("sleep 5")
-end
---- request
-GET /test
---- response_body
-foo
---- no_error_log
-[error]
---- timeout: 2
-
-
-
-=== TEST 27: ngx.exec() should skip os.execute (all in user module)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- test.go()
- ';
- }
- location = /foo {
- echo foo;
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-local exec = os.execute
-
-function go()
- ngx.exec("/foo")
- exec("sleep 5")
-end
---- request
-GET /test
---- response_body
-foo
---- no_error_log
-[error]
---- timeout: 2
-
-
-
-=== TEST 28: ngx.set_uri(uri, true) should break pcall and skip os.execute (all in user module)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- rewrite_by_lua '
- local test = require "test"
- test.go()
- ';
- echo hello;
- }
- location = /foo {
- echo foo;
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-local exec = os.execute
-
-function go()
- local ok, err = pcall(ngx.req.set_uri, "/foo", true)
- if not ok then
- ngx.log(ngx.ERR, "error: ", err)
- end
-
- exec("sleep 5")
-end
---- request
-GET /test
---- response_body
-foo
---- no_error_log
-[error]
---- timeout: 2
-
-
-
-=== TEST 29: abort does not affect following coroutines
---- config
- location = /test {
- rewrite_by_lua 'ngx.exit(0)';
- content_by_lua '
- pcall(ngx.say, "hello world")
- ';
- }
---- request
-GET /test
---- response_body
-hello world
---- no_error_log
-[error]
---- timeout: 2
-
-
-
-=== TEST 30: ngx.exit(400) should break xpcall and skip os.execute (all in user module)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- test.go()
- ';
- }
---- user_files
->>> test.lua
-module('test', package.seeall)
-
-local exec = os.execute
-
-function myexit()
- ngx.exit(400)
-end
-
-function go()
- xpcall(myexit, function () end)
- exec("sleep 5")
-end
---- request
-GET /test
---- response_body_like: 400 Bad Request
---- error_code: 400
---- no_error_log
-[error]
---- timeout: 2
-
-
-
-=== TEST 31: ngx.exec() should skip os.execute (all in user module)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- test.go()
- ';
- }
- location = /foo {
- echo foo;
- }
---- user_files
->>> test.lua
-local os_exec = os.execute
-local ngx_exec = ngx.exec
-module('test')
-
-function go()
- ngx_exec("/foo")
- os_exec("sleep 5")
-end
---- request
-GET /test
---- response_body
-foo
---- no_error_log
-[error]
---- timeout: 2
-
-
-
-=== TEST 32: ngx.exec() should break pcall and skip os.execute (all in user module)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local test = require "test"
- test.go()
- ';
- }
- location = /foo {
- echo foo;
- }
---- user_files
->>> test.lua
-local os_exec = os.execute
-local ngx_exec = ngx.exec
-local pcall = pcall
-module('test')
-
-function go()
- pcall(ngx_exec, "/foo")
- os_exec("sleep 5")
-end
---- request
-GET /test
---- response_body
-foo
---- no_error_log
-[error]
---- timeout: 2
diff --git a/src/deps/src/lua-nginx-module/t/064-pcall.t b/src/deps/src/lua-nginx-module/t/064-pcall.t
deleted file mode 100644
index 9af2de7d9..000000000
--- a/src/deps/src/lua-nginx-module/t/064-pcall.t
+++ /dev/null
@@ -1,106 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-worker_connections(1014);
-#master_on();
-#workers(4);
-#log_level('warn');
-no_root_location();
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-
-#$ENV{LUA_CPATH} = "/usr/local/openresty/lualib/?.so;" . $ENV{LUA_CPATH};
-
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: pcall works
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local function f(a, b)
- if a == 0 and b == 0 then
- error("zero error")
- end
-
- return 23, "hello", true
- end
-
- local res = {pcall(f, 0, 0)}
- ngx.say("res len: ", #res)
- ngx.say("res: ", unpack(res))
-
- res = {pcall(f, 0)}
- ngx.say("res len: ", #res)
- ngx.say("res: ", unpack(res))
- ';
- }
---- request
-GET /test
---- response_body eval
-qr/^res len: 2
-res: falsecontent_by_lua\(nginx\.conf:\d+\):4: zero error
-res len: 4
-res: true23hellotrue
-$/s
---- no_error_log
-[error]
-
-
-
-=== TEST 2: xpcall works
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location = /test {
- content_by_lua '
- local function f(a, b)
- if a == 0 and b == 0 then
- error("zero error")
- end
-
- return 23, "hello", true
- end
-
- local function g()
- return f(0, 0)
- end
-
- local function h()
- return f(0)
- end
-
- local function err(...)
- ngx.say("error handler called: ", ...)
- return "this is the new err"
- end
-
- local res = {xpcall(g, err)}
- ngx.say("res len: ", #res)
- ngx.say("res: ", unpack(res))
-
- res = {xpcall(h, err)}
- ngx.say("res len: ", #res)
- ngx.say("res: ", unpack(res))
- ';
- }
---- request
-GET /test
---- response_body eval
-qr/^error handler called: content_by_lua\(nginx\.conf:\d+\):4: zero error
-res len: 2
-res: falsethis is the new err
-res len: 4
-res: true23hellotrue
-$/
-
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/065-tcp-socket-timeout.t b/src/deps/src/lua-nginx-module/t/065-tcp-socket-timeout.t
deleted file mode 100644
index 14563f70c..000000000
--- a/src/deps/src/lua-nginx-module/t/065-tcp-socket-timeout.t
+++ /dev/null
@@ -1,1020 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-BEGIN {
- if (!defined $ENV{LD_PRELOAD}) {
- $ENV{LD_PRELOAD} = '';
- }
-
- if ($ENV{LD_PRELOAD} !~ /\bmockeagain\.so\b/) {
- $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}";
- }
-
- if ($ENV{MOCKEAGAIN} eq 'r') {
- $ENV{MOCKEAGAIN} = 'rw';
-
- } else {
- $ENV{MOCKEAGAIN} = 'w';
- }
-
- delete($ENV{TEST_NGINX_USE_HTTP2});
- $ENV{TEST_NGINX_EVENT_TYPE} = 'poll';
- $ENV{MOCKEAGAIN_WRITE_TIMEOUT_PATTERN} = 'get helloworld';
-}
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 6);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-log_level("debug");
-no_long_string();
-#no_diff();
-run_tests();
-
-__DATA__
-
-=== TEST 1: lua_socket_connect_timeout only
---- config
- server_tokens off;
- lua_socket_connect_timeout 100ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
- }
---- request
-GET /t
---- response_body
-failed to connect: timeout
---- error_log
-lua tcp socket connect timeout: 100
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
---- timeout: 10
-
-
-
-=== TEST 2: sock:settimeout() overrides lua_socket_connect_timeout
---- config
- server_tokens off;
- lua_socket_connect_timeout 60s;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(150)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
- }
---- request
-GET /t
---- response_body
-failed to connect: timeout
---- error_log
-lua tcp socket connect timeout: 150
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
---- timeout: 10
-
-
-
-=== TEST 3: sock:settimeout(nil) does not override lua_socket_connect_timeout
---- config
- server_tokens off;
- lua_socket_connect_timeout 102ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(nil)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
- }
---- request
-GET /t
---- response_body
-failed to connect: timeout
---- error_log
-lua tcp socket connect timeout: 102
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
-
-
-
-=== TEST 4: sock:settimeout(0) does not override lua_socket_connect_timeout
---- config
- server_tokens off;
- lua_socket_connect_timeout 102ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(0)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
- }
---- request
-GET /t
---- response_body
-failed to connect: timeout
---- error_log
-lua tcp socket connect timeout: 102
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
---- timeout: 10
-
-
-
-=== TEST 5: -1 is bad timeout value
---- config
- server_tokens off;
- lua_socket_connect_timeout 102ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(-1)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- ';
- }
---- request
-GET /t
---- response_body_like chomp
-500 Internal Server Error
---- error_log
-bad timeout value
---- error_code: 500
-
-
-
-=== TEST 6: lua_socket_read_timeout only
---- config
- server_tokens off;
- lua_socket_read_timeout 100ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua tcp socket read timeout: 100
-lua tcp socket connect timeout: 60000
-lua tcp socket read timed out
-
-
-
-=== TEST 7: sock:settimeout() overrides lua_socket_read_timeout
---- config
- server_tokens off;
- lua_socket_read_timeout 60s;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(150)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket read timeout: 150
-lua tcp socket read timed out
-
-
-
-=== TEST 8: sock:settimeout(nil) does not override lua_socket_read_timeout
---- config
- server_tokens off;
- lua_socket_read_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(nil)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket read timeout: 102
-lua tcp socket read timed out
-
-
-
-=== TEST 9: sock:settimeout(0) does not override lua_socket_read_timeout
---- config
- server_tokens off;
- lua_socket_read_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(0)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
-
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket read timeout: 102
-lua tcp socket read timed out
-
-
-
-=== TEST 10: -1 is bad timeout value
---- config
- server_tokens off;
- lua_socket_read_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- sock:settimeout(-1)
-
- local line
- line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body_like chomp
-500 Internal Server Error
---- error_code: 500
---- error_log
-bad timeout value
-
-
-
-=== TEST 11: lua_socket_send_timeout only
---- config
- server_tokens off;
- lua_socket_send_timeout 100ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
- }
---- request
-GET /t
---- stap2
-global active = 0
-F(ngx_http_lua_socket_send) {
- active = 1
- println(probefunc())
-}
-probe syscall.send,
- syscall.sendto,
- syscall.writev
-{
- if (active && pid() == target()) {
- println(probefunc())
- }
-}
---- response_body
-connected: 1
-failed to send: timeout
---- error_log
-lua tcp socket send timeout: 100
-lua tcp socket connect timeout: 60000
-lua tcp socket write timed out
-
-
-
-=== TEST 12: sock:settimeout() overrides lua_socket_send_timeout
---- config
- server_tokens off;
- lua_socket_send_timeout 60s;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(150)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to send: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket send timeout: 150
-lua tcp socket write timed out
-
-
-
-=== TEST 13: sock:settimeout(nil) does not override lua_socket_send_timeout
---- config
- server_tokens off;
- lua_socket_send_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(nil)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to send: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket send timeout: 102
-lua tcp socket write timed out
-
-
-
-=== TEST 14: sock:settimeout(0) does not override lua_socket_send_timeout
---- config
- server_tokens off;
- lua_socket_send_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(0)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to send: timeout
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket send timeout: 102
-lua tcp socket write timed out
-
-
-
-=== TEST 15: sock:settimeout(-1) does not override lua_socket_send_timeout
---- config
- server_tokens off;
- lua_socket_send_timeout 102ms;
- #resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- sock:settimeout(-1)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body_like chomp
-500 Internal Server Error
---- error_log
-bad timeout value
---- error_code: 500
-
-
-
-=== TEST 16: exit in user thread (entry thread is still pending on tcpsock:send)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local bytes, ok = sock:send("get helloworld!")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 17: re-connect after timed out
---- config
- server_tokens off;
- lua_socket_connect_timeout 100ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("1: failed to connect: ", err)
-
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
- if not ok then
- ngx.say("2: failed to connect: ", err)
- return
- end
-
- ngx.say("2: connected: ", ok)
- return
- end
-
- ngx.say("1: connected: ", ok)
- ';
- }
---- request
-GET /t
---- response_body
-1: failed to connect: timeout
-2: connected: 1
---- error_log
-lua tcp socket connect timeout: 100
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
---- timeout: 10
-
-
-
-=== TEST 18: re-send on the same object after a send timeout happens
---- config
- server_tokens off;
- lua_socket_send_timeout 100ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- bytes, err = sock:send("blah")
- if not bytes then
- ngx.say("failed to send again: ", err)
- end
- end
- ';
- }
---- request
-GET /t
---- stap2
-global active = 0
-F(ngx_http_lua_socket_send) {
- active = 1
- println(probefunc())
-}
-probe syscall.send,
- syscall.sendto,
- syscall.writev
-{
- if (active && pid() == target()) {
- println(probefunc())
- }
-}
---- response_body
-connected: 1
-failed to send: timeout
-failed to send again: closed
---- error_log
-lua tcp socket send timeout: 100
-lua tcp socket connect timeout: 60000
-lua tcp socket write timed out
-
-
-
-=== TEST 19: abort when upstream sockets pending on writes
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(100)
- ngx.thread.spawn(function () ngx.sleep(0.001) ngx.say("done") ngx.exit(200) end)
- local bytes
- bytes, err = sock:send("get helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
- }
---- request
-GET /t
---- stap2
-global active = 0
-F(ngx_http_lua_socket_send) {
- active = 1
- println(probefunc())
-}
-probe syscall.send,
- syscall.sendto,
- syscall.writev
-{
- if (active && pid() == target()) {
- println(probefunc())
- }
-}
---- response_body
-connected: 1
-done
---- error_log
-lua tcp socket send timeout: 100
-lua tcp socket connect timeout: 60000
---- no_error_log
-lua tcp socket write timed out
-
-
-
-=== TEST 20: abort when downstream socket pending on writes
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- ngx.send_headers()
- ngx.flush(true)
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.say("failed to acquire the req socket: ", err)
- return
- end
-
- sock:settimeout(100)
- ngx.thread.spawn(function ()
- ngx.sleep(0.001)
- ngx.log(ngx.WARN, "quitting request now")
- ngx.exit(200)
- end)
- local bytes
- bytes, err = sock:send("e\\r\\nget helloworld!")
- if bytes then
- ngx.say("sent: ", bytes)
- else
- ngx.say("failed to send: ", err)
- end
- ';
- }
---- request
-GET /t
---- stap2
-global active = 0
-F(ngx_http_lua_socket_send) {
- active = 1
- println(probefunc())
-}
-probe syscall.send,
- syscall.sendto,
- syscall.writev
-{
- if (active && pid() == target()) {
- println(probefunc())
- }
-}
---- ignore_response
---- error_log
-lua tcp socket send timeout: 100
-quitting request now
---- no_error_log
-lua tcp socket write timed out
-[alert]
---- skip_eval: 4: $ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 21: read timeout on receive(N)
---- config
- server_tokens off;
- lua_socket_read_timeout 100ms;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(10)
-
- local line
- line, err = sock:receive(3)
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive: ", err)
- end
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua tcp socket read timeout: 10
-lua tcp socket connect timeout: 60000
-lua tcp socket read timed out
-
-
-
-=== TEST 22: concurrent operations while writing
---- config
- server_tokens off;
- lua_socket_log_errors off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ready = false
-
- local function f()
- while not ready do
- ngx.sleep(0.001)
- end
-
- local bytes, err = sock:send("flush_all")
- ngx.say("send: ", bytes, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
-
- local ok, err = sock:getreusedtimes()
- ngx.say("getreusedtimes: ", ok, " ", err)
-
- local ok, err = sock:setkeepalive()
- ngx.say("setkeepalive: ", ok, " ", err)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- ngx.say("connect: ", ok, " ", err)
-
- sock:settimeout(1)
- local res, err = sock:receive(1)
- ngx.say("receive: ", res, " ", err)
- end
-
- local ok, err = ngx.thread.spawn(f)
- if not ok then
- ngx.say("failed to spawn writer thread: ", err)
- return
- end
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- ngx.say("connect: ", ok, " ", err)
-
- ready = true
-
- sock:settimeout(300)
- local bytes, err = sock:send("get helloworld!")
- if not bytes then
- ngx.say("send failed: ", err)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
---- request
-GET /t
---- response_body
-connect: 1 nil
-send: nil socket busy writing
-close: nil socket busy writing
-getreusedtimes: 0 nil
-setkeepalive: nil socket busy writing
-connect: nil socket busy writing
-receive: nil timeout
-send failed: timeout
-close: 1 nil
-
---- no_error_log
-[error]
-
-
-
-=== TEST 23: timeout overflow detection
---- config
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local ok, err = pcall(sock.settimeout, sock, (2 ^ 31) - 1)
- if not ok then
- ngx.say("failed to set timeout: ", err)
- else
- ngx.say("settimeout: ok")
- end
-
- ok, err = pcall(sock.settimeout, sock, 2 ^ 31)
- if not ok then
- ngx.say("failed to set timeout: ", err)
- else
- ngx.say("settimeout: ok")
- end
- }
- }
---- request
-GET /t
---- response_body_like
-settimeout: ok
-failed to set timeout: bad timeout value
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/066-socket-receiveuntil.t b/src/deps/src/lua-nginx-module/t/066-socket-receiveuntil.t
deleted file mode 100644
index 43744a372..000000000
--- a/src/deps/src/lua-nginx-module/t/066-socket-receiveuntil.t
+++ /dev/null
@@ -1,2014 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-no_long_string();
-#no_diff();
-#log_level 'warn';
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: memcached read lines
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local readline = sock:receiveuntil("\\r\\n")
- local line, err, part = readline()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 11
-received: OK
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 2: http read lines
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local readline = sock:receiveuntil("\\r\\n")
- local line, err, part
-
- for i = 1, 7 do
- line, err, part = readline()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: HTTP/1.1 200 OK
-read: Server: nginx
-read: Content-Type: text/plain
-read: Content-Length: 4
-read: Connection: close
-read:
-failed to read a line: closed [foo
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 3: http read all the headers in a single run
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local line, err, part
-
- for i = 1, 2 do
- line, err, part = read_headers()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: HTTP/1.1 200 OK\r
-Server: nginx\r
-Content-Type: text/plain\r
-Content-Length: 4\r
-Connection: close
-failed to read a line: closed [foo
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 4: ambiguous boundary patterns (abcabd)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("abcabd")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("abcabcabd")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abc
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 5: ambiguous boundary patterns (aa)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aa")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- content_by_lua 'ngx.say("abcabcaad")';
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abcabc
-failed to read a line: closed [d
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 6: ambiguous boundary patterns (aaa)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aaa")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abaabcaaaef;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abaabc
-failed to read a line: closed [ef
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 7: ambiguous boundary patterns (aaaaad)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aaaaad")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo baaaaaaaaeaaaaaaadf;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: baaaaaaaaeaa
-failed to read a line: closed [f
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 8: ambiguous boundary patterns (aaaaad), small buffer, 2 bytes
---- no_http2
---- config
- server_tokens off;
- lua_socket_buffer_size 2;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aaaaad")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo baaaaaaaaeaaaaaaadf;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: baaaaaaaaeaa
-failed to read a line: closed [f
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 9: ambiguous boundary patterns (aaaaad), small buffer, 1 byte
---- no_http2
---- config
- server_tokens off;
- lua_socket_buffer_size 1;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aaaaad")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo baaaaaaaaeaaaaaaadf;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: baaaaaaaaeaa
-failed to read a line: closed [f
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 10: ambiguous boundary patterns (abcabdabcabe)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("abcabdabcabe")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabdabcabdabcabe;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abcabd
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 11: ambiguous boundary patterns (abcabdabcabe 2)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("abcabdabcabe")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabdabcabcabdabcabe;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abcabdabc
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 12: ambiguous boundary patterns (abcabdabcabe 3)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("abcabdabcabe")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabcabdabcabe;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abc
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 13: ambiguous boundary patterns (abcabdabcabe 4)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("abcabdabcabe")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo ababcabdabcabe;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: ab
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 14: ambiguous boundary patterns (--abc)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("--abc")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo -- ----abc;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: --
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 15: ambiguous boundary patterns (--abc)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("--abc")
-
- for i = 1, 6 do
- local line, err, part = reader(4)
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo "hello, world ----abc";
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: hell
-read: o, w
-read: orld
-read: --
-failed to read a line: nil [nil]
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 16: ambiguous boundary patterns (--abc), small buffer
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- lua_socket_buffer_size 1;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("--abc")
-
- for i = 1, 6 do
- local line, err, part = reader(4)
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo "hello, world ----abc";
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: hell
-read: o, w
-read: orld
-read: --
-failed to read a line: nil [nil]
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 17: ambiguous boundary patterns (--abc), small buffer, mixed by other reading calls
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- lua_socket_buffer_size 1;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("--abc")
-
- for i = 1, 7 do
- local line, err, part = reader(4)
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a chunk: ", err, " [", part, "]")
- end
-
- local data, err, part = sock:receive(1)
- if not data then
- ngx.say("failed to read a byte: ", err, " [", part, "]")
- break
- else
- ngx.say("read one byte: ", data)
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo "hello, world ----abc";
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: hell
-read one byte: o
-read: , wo
-read one byte: r
-read: ld -
-read one byte: -
-read:
-read one byte:
-
-failed to read a chunk: nil [nil]
-failed to read a byte: closed []
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 18: ambiguous boundary patterns (abcabd), small buffer
---- no_http2
---- config
- server_tokens off;
- lua_socket_buffer_size 3;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("abcabd")
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabcabd;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abc
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 19: long patterns
-this exposed a memory leak in receiveuntil
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
- if not sock then
- ngx.say("failed to get req socket: ", err)
- return
- end
- local reader, err = sock:receiveuntil("------------------------------------------- abcdefghijklmnopqrstuvwxyz")
- if not reader then
- ngx.say("failed to get reader: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
- POST /t
-
---- more_headers: Content-Length: 1024
---- response_body
-ok
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 20: add pending bytes
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- lua_socket_buffer_size 1;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("--abc")
-
- for i = 1, 4 do
- local line, err, part = reader(2)
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo -- -----abc;
- more_clear_headers Date;
- }
---- request
-GET /t
-
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: --
-read: -
-failed to read a line: nil [nil]
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 21: ambiguous boundary patterns (--abc), mixed by other reading calls consume boundary
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\r\n\r\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("--abc")
-
- for i = 1, 5 do
- local line, err, part = reader(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
- break
-
- else
- ngx.say("read: ", line)
- end
-
- local data, err, part = sock:receive(1)
- if not data then
- ngx.say("failed to read a byte: ", err, " [", part, "]")
- break
-
- else
- ngx.say("read one byte: ", data)
- end
- end
-
- local line, err, part = reader(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
-
- location /foo {
- echo -- ----abc----abc-;
- more_clear_headers Date;
- }
---- request
-GET /t
-
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: --
-read one byte: -
-read: -a
-read one byte: b
-read: c-
-read one byte: -
-read:
-read one byte: -
-failed to read a line: nil [nil]
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 22: ambiguous boundary patterns (--abc), mixed by other reading calls (including receiveuntil) consume boundary
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\r\n\r\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader1 = sock:receiveuntil("--abc")
- local reader2 = sock:receiveuntil("-ab")
-
- local line, err, part = reader1(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- local data, err, part = sock:receive(1)
- if not data then
- ngx.say("failed to read a byte: ", err, " [", part, "]")
-
- else
- ngx.say("read one byte: ", data)
- end
-
- local line, err, part = reader1(1)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- local line, err, part = reader2(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- local line, err, part = reader1()
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- local line, err, part = reader1()
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
-
- location /foo {
- echo -- ------abd----abc;
- more_clear_headers Date;
- }
---- request
-GET /t
-
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: --
-read one byte: -
-read: -
-read: -
-read: d--
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 23: ambiguous boundary patterns (--abc), mixed by other reading calls consume boundary, small buffer
---- config
- lua_socket_buffer_size 3;
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\r\n\r\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("--abc")
-
- for i = 1, 5 do
- local line, err, part = reader(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
- break
-
- else
- ngx.say("read: ", line)
- end
-
- local data, err, part = sock:receive(1)
- if not data then
- ngx.say("failed to read a byte: ", err, " [", part, "]")
- break
-
- else
- ngx.say("read one byte: ", data)
- end
- end
-
- local line, err, part = reader(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
-
- location /foo {
- echo -- ----abc----abc-;
- more_clear_headers Date;
- }
---- request
-GET /t
-
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: --
-read one byte: -
-read: -a
-read one byte: b
-read: c-
-read one byte: -
-read:
-read one byte: -
-failed to read a line: nil [nil]
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 24: ambiguous boundary patterns (--abc), mixed by other reading calls (including receiveuntil) consume boundary, small buffer
---- config
- lua_socket_buffer_size 3;
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\r\n\r\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader1 = sock:receiveuntil("--abc")
- local reader2 = sock:receiveuntil("-ab")
-
- local line, err, part = reader1(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- local data, err, part = sock:receive(1)
- if not data then
- ngx.say("failed to read a byte: ", err, " [", part, "]")
-
- else
- ngx.say("read one byte: ", data)
- end
-
- local line, err, part = reader1(1)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- local line, err, part = reader2(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- local line, err, part = reader1()
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- local line, err, part = reader1()
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
-
- location /foo {
- echo -- ------abd----abc;
- more_clear_headers Date;
- }
---- request
-GET /t
-
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: --
-read one byte: -
-read: -
-read: -
-read: d--
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 25: ambiguous boundary patterns (ab1ab2), ends half way
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\r\n\r\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- if true then
- local reader = sock:receiveuntil("ab1ab2")
-
- local line, err, part = reader(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
- end
-
- collectgarbage("collect")
-
- local data, err, part = sock:receive(3)
- if not data then
- ngx.say("failed to read three bytes: ", err, " [", part, "]")
-
- else
- ngx.say("read three bytes: ", data)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
-
- location /foo {
- echo -- ab1ab1;
- more_clear_headers Date;
- }
---- request
-GET /t
-
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: ab1
-read three bytes: ab1
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 26: ambiguous boundary patterns (ab1ab2), ends half way, small buffer
---- config
- lua_socket_buffer_size 3;
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\r\n\r\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- if true then
- local reader = sock:receiveuntil("ab1ab2")
-
- local line, err, part = reader(2)
- if not line then
- ngx.say("failed to read a line: ", err, " [", part, "]")
-
- else
- ngx.say("read: ", line)
- end
- end
-
- collectgarbage("collect")
-
- local data, err, part = sock:receive(3)
- if not data then
- ngx.say("failed to read three bytes: ", err, " [", part, "]")
-
- else
- ngx.say("read three bytes: ", data)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
-
- location /foo {
- echo -- ab1ab1;
- more_clear_headers Date;
- }
---- request
-GET /t
-
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: ab1
-read three bytes: ab1
-close: 1 nil
-}
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
diff --git a/src/deps/src/lua-nginx-module/t/067-req-socket.t b/src/deps/src/lua-nginx-module/t/067-req-socket.t
deleted file mode 100644
index 9aff58b64..000000000
--- a/src/deps/src/lua-nginx-module/t/067-req-socket.t
+++ /dev/null
@@ -1,1178 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "http3 does not support ngx.req.socket";
- } elsif ($ENV{TEST_NGINX_USE_HTTP2}) {
- $SkipReason = "http2 does not support ngx.req.socket";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 9);
-
-our $HtmlDir = html_dir;
-
-#$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-no_long_string();
-#no_diff();
-#log_level 'warn';
-no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
-
- for i = 1, 3 do
- local data, err, part = sock:receive(5)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
- end
- ';
- }
---- request
-POST /t
-hello world
---- response_body
-got the request socket
-received: hello
-received: worl
-failed to receive: closed [d]
---- no_error_log
-[error]
-
-
-
-=== TEST 2: multipart rfc sample (just partial streaming)
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
-
- local boundary
- local header = ngx.var.http_content_type
- local m = ngx.re.match(header, [[; +boundary=(?:"(.*?)"|(\\w+))]], "jo")
- if m then
- boundary = m[1] or m[2]
-
- else
- ngx.say("invalid content-type header")
- return
- end
-
- local read_to_boundary = sock:receiveuntil("\\r\\n--" .. boundary)
- local read_line = sock:receiveuntil("\\r\\n")
-
- local data, err, part = read_to_boundary()
- if data then
- ngx.say("preamble: [" .. data .. "]")
- else
- ngx.say("failed to read the first boundary: ", err)
- return
- end
-
- local i = 1
- while true do
- local line, err = read_line()
-
- if not line then
- ngx.say("failed to read post-boundary line: ", err)
- return
- end
-
- m = ngx.re.match(line, "--$", "jo")
- if m then
- ngx.say("found the end of the stream")
- return
- end
-
- while true do
- local line, err = read_line()
- if not line then
- ngx.say("failed to read part ", i, " header: ", err)
- return
- end
-
- if line == "" then
- -- the header part completes
- break
- end
-
- ngx.say("part ", i, " header: [", line, "]")
- end
-
- local data, err, part = read_to_boundary()
- if data then
- ngx.say("part ", i, " body: [" .. data .. "]")
- else
- ngx.say("failed to read part ", i + 1, " boundary: ", err)
- return
- end
-
- i = i + 1
- end
- ';
- }
---- request eval
-"POST /t
-This is the preamble. It is to be ignored, though it
-is a handy place for mail composers to include an
-explanatory note to non-MIME compliant readers.\r
---simple boundary\r
-\r
-This is implicitly typed plain ASCII text.
-It does NOT end with a linebreak.\r
---simple boundary\r
-Content-type: text/plain; charset=us-ascii\r
-\r
-This is explicitly typed plain ASCII text.
-It DOES end with a linebreak.
-\r
---simple boundary--\r
-This is the epilogue. It is also to be ignored.
-"
---- more_headers
-Content-Type: multipart/mixed; boundary="simple boundary"
---- response_body
-got the request socket
-preamble: [This is the preamble. It is to be ignored, though it
-is a handy place for mail composers to include an
-explanatory note to non-MIME compliant readers.]
-part 1 body: [This is implicitly typed plain ASCII text.
-It does NOT end with a linebreak.]
-part 2 header: [Content-type: text/plain; charset=us-ascii]
-part 2 body: [This is explicitly typed plain ASCII text.
-It DOES end with a linebreak.
-]
-found the end of the stream
---- no_error_log
-[error]
-
-
-
-=== TEST 3: multipart rfc sample (completely streaming)
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
-
- local boundary
- local header = ngx.var.http_content_type
- local m = ngx.re.match(header, [[; +boundary=(?:"(.*?)"|(\\w+))]], "jo")
- if m then
- boundary = m[1] or m[2]
-
- else
- ngx.say("invalid content-type header")
- return
- end
-
- local read_to_boundary = sock:receiveuntil("\\r\\n--" .. boundary)
- local read_line = sock:receiveuntil("\\r\\n")
-
- local preamble = ""
- while true do
- local data, err, part = read_to_boundary(1)
- if data then
- preamble = preamble .. data
-
- elseif not err then
- break
-
- else
- ngx.say("failed to read the first boundary: ", err)
- return
- end
- end
-
- ngx.say("preamble: [" .. preamble .. "]")
-
- local i = 1
- while true do
- local line, err = read_line(50)
-
- if not line and err then
- ngx.say("1: failed to read post-boundary line: ", err)
- return
- end
-
- if line then
- local dummy
- dummy, err = read_line(1)
- if err then
- ngx.say("2: failed to read post-boundary line: ", err)
- return
- end
-
- if dummy then
- ngx.say("bad post-boundary line: ", dummy)
- return
- end
-
- m = ngx.re.match(line, "--$", "jo")
- if m then
- ngx.say("found the end of the stream")
- return
- end
- end
-
- while true do
- local line, err = read_line(50)
- if not line and err then
- ngx.say("failed to read part ", i, " header: ", err)
- return
- end
-
- if line then
- local line, err = read_line(1)
- if line or err then
- ngx.say("error")
- return
- end
- end
-
- if line == "" then
- -- the header part completes
- break
- end
-
- ngx.say("part ", i, " header: [", line, "]")
- end
-
- local body = ""
-
- while true do
- local data, err, part = read_to_boundary(1)
- if data then
- body = body .. data
-
- elseif err then
- ngx.say("failed to read part ", i + 1, " boundary: ", err)
- return
-
- else
- break
- end
- end
-
- ngx.say("part ", i, " body: [" .. body .. "]")
-
- i = i + 1
- end
- ';
- }
---- request eval
-"POST /t
-This is the preamble. It is to be ignored, though it
-is a handy place for mail composers to include an
-explanatory note to non-MIME compliant readers.\r
---simple boundary\r
-\r
-This is implicitly typed plain ASCII text.
-It does NOT end with a linebreak.\r
---simple boundary\r
-Content-type: text/plain; charset=us-ascii\r
-\r
-This is explicitly typed plain ASCII text.
-It DOES end with a linebreak.
-\r
---simple boundary--\r
-This is the epilogue. It is also to be ignored.
-"
---- more_headers
-Content-Type: multipart/mixed; boundary="simple boundary"
---- response_body
-got the request socket
-preamble: [This is the preamble. It is to be ignored, though it
-is a handy place for mail composers to include an
-explanatory note to non-MIME compliant readers.]
-part 1 body: [This is implicitly typed plain ASCII text.
-It does NOT end with a linebreak.]
-part 2 header: [Content-type: text/plain; charset=us-ascii]
-part 2 body: [This is explicitly typed plain ASCII text.
-It DOES end with a linebreak.
-]
-found the end of the stream
---- no_error_log
-[error]
-
-
-
-=== TEST 4: attempt to use the req socket across request boundary
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- content_by_lua '
- local test = require "test"
- test.go()
- ngx.say("done")
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock, err
-
-function go()
- if not sock then
- sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
- else
- for i = 1, 3 do
- local data, err, part = sock:receive(5)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
- end
- end
-end
---- request
-POST /t
-hello world
---- response_body_like
-(?:got the request socket
-|failed to receive: closed [d]
-)?done
---- no_error_log
-[alert]
-
-
-
-=== TEST 5: receive until on request_body - receiveuntil(1) on the last byte of the body
-See https://groups.google.com/group/openresty/browse_thread/thread/43cf01da3c681aba for details
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- content_by_lua '
- local test = require "test"
- test.go()
- ngx.say("done")
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go()
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- return
- end
-
- local data, err, part = sock:receive(56)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
-
- local discard_line = sock:receiveuntil('\r\n')
-
- local data, err, part = discard_line(8192)
- if data then
- ngx.say("received len: ", #data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
-
- local data, err, part = discard_line(1)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
-end
---- request
-POST /t
------------------------------820127721219505131303151179################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################$
---- response_body
-got the request socket
-received: -----------------------------820127721219505131303151179
-received len: 8192
-received: $
-done
---- no_error_log
-[error]
---- timeout: 10
-
-
-
-=== TEST 6: pipelined POST requests
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- content_by_lua '
- local test = require "test"
- test.go()
- ngx.say("done")
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go()
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- return
- end
-
- while true do
- local data, err, part = sock:receive(4)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- return
- end
- end
-end
---- pipelined_requests eval
-["POST /t
-hello, world",
-"POST /t
-hiya, world"]
---- response_body eval
-["got the request socket
-received: hell
-received: o, w
-received: orld
-failed to receive: closed []
-done
-",
-"got the request socket
-received: hiya
-received: , wo
-failed to receive: closed [rld]
-done
-"]
---- no_error_log
-[error]
-
-
-
-=== TEST 7: Expect & 100 Continue
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- return
- end
-
- for i = 1, 3 do
- local data, err, part = sock:receive(5)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
- end
- ';
- }
---- request
-POST /t
-hello world
---- more_headers
-Expect: 100-Continue
---- error_code: 100
---- response_body_like chomp
-\breceived: hello\b.*?\breceived: worl\b
---- no_error_log
-[error]
-
-
-
-=== TEST 8: pipelined requests, big buffer, small steps
---- config
- location /t {
- lua_socket_buffer_size 5;
- content_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
-
- for i = 1, 6 do
- local data, err, part = sock:receive(2)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
- end
- ';
- }
---- stap2
-M(http-lua-req-socket-consume-preread) {
- println("preread: ", user_string_n($arg2, $arg3))
-}
-
---- pipelined_requests eval
-["POST /t
-hello world","POST /t
-hiya globe"]
---- response_body eval
-["got the request socket
-received: he
-received: ll
-received: o
-received: wo
-received: rl
-failed to receive: closed [d]
-","got the request socket
-received: hi
-received: ya
-received: g
-received: lo
-received: be
-failed to receive: closed []
-"]
---- no_error_log
-[error]
-
-
-
-=== TEST 9: chunked support is still a TODO
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.req.read_body()
- ngx.say("failed to get the request socket: ", err)
- return
- end
-
- for i = 1, 3 do
- local data, err, part = sock:receive(5)
- if data then
- ngx.say("received: ", data)
- else
- ngx.say("failed to receive: ", err, " [", part, "]")
- end
- end
- ';
- }
---- raw_request eval
-"POST /t HTTP/1.1\r
-Host: localhost\r
-Transfer-Encoding: chunked\r
-Connection: close\r
-\r
-b\r
-hello world\r
-0\r
-\r
-"
---- stap2
-/*
-F(ngx_http_finalize_request) {
- if ($r->main->count == 2) {
- print_ubacktrace()
- }
-}
-F(ngx_http_free_request) {
- print_ubacktrace()
-}
-*/
---- response_body
-failed to get the request socket: chunked request bodies not supported yet
---- no_error_log
-[error]
-[alert]
---- skip_nginx: 4: <1.3.9
-
-
-
-=== TEST 10: chunked support in ngx.req.read_body
---- config
- location /t {
- content_by_lua '
- ngx.req.read_body()
- ngx.say(ngx.req.get_body_data())
- ';
- }
---- raw_request eval
-"POST /t HTTP/1.1\r
-Host: localhost\r
-Transfer-Encoding: chunked\r
-Connection: close\r
-\r
-b\r
-hello world\r
-0\r
-\r
-"
---- stap2
-/*
-F(ngx_http_finalize_request) {
- if ($r->main->count == 2) {
- print_ubacktrace()
- }
-}
-F(ngx_http_free_request) {
- print_ubacktrace()
-}
-*/
---- response_body
-hello world
---- no_error_log
-[error]
-[alert]
---- skip_nginx: 4: <1.3.9
-
-
-
-=== TEST 11: downstream cosocket for GET requests (w/o request bodies)
---- config
- #resolver 8.8.8.8;
- location = /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
-
- if not sock then
- ngx.say("failed to get socket: ", err)
- return nil
- end
-
- while true do
- local data, err, partial = sock:receive(4096)
-
- ngx.log(ngx.INFO, "Received data")
-
- if err then
- ngx.say("err: ", err)
- if partial then
- ngx.print(partial)
- end
-
- break
- end
-
- if data then
- ngx.print(data)
- end
- end
- ';
- }
-
---- request
-GET /t
---- response_body
-failed to get socket: no body
---- no_error_log
-[error]
-
-
-
-=== TEST 12: downstream cosocket for POST requests with 0 size bodies
---- config
- #resolver 8.8.8.8;
- location = /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
-
- if not sock then
- ngx.say("failed to get socket: ", err)
- return nil
- end
-
- while true do
- local data, err, partial = sock:receive(4096)
-
- ngx.log(ngx.INFO, "Received data")
-
- if err then
- ngx.say("err: ", err)
- if partial then
- ngx.print(partial)
- end
-
- break
- end
-
- if data then
- ngx.print(data)
- end
- end
- ';
- }
-
---- request
-POST /t
---- more_headers
-Content-Length: 0
---- response_body
-failed to get socket: no body
---- no_error_log
-[error]
-
-
-
-=== TEST 13: failing reread after reading timeout happens
---- config
- location = /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
-
- if not sock then
- ngx.say("failed to get socket: ", err)
- return nil
- end
-
- sock:settimeout(100);
-
- local data, err, partial = sock:receive(4096)
- if err then
- ngx.say("err: ", err, ", partial: ", partial)
- end
-
- local data, err, partial = sock:receive(4096)
- if err then
- ngx.say("err: ", err, ", partial: ", partial)
- return
- end
- ';
- }
-
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Content-Length: 10245\r
-\r
-hello"
---- response_body
-err: timeout, partial: hello
-err: timeout, partial:
-
---- error_log
-lua tcp socket read timed out
-
-
-
-=== TEST 14: successful reread after reading timeout happens (receive -> receive)
---- config
- location = /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("POST /back HTTP/1.0\\r\\nHost: localhost\\r\\nContent-Length: 1024\\r\\n\\r\\nabc")
- if not bytes then
- ngx.say("failed to send: ", err)
- else
- ngx.say("sent: ", bytes)
- end
-
- ngx.sleep(0.2)
-
- local bytes, err = sock:send("hello world")
- if not bytes then
- ngx.say("failed to send: ", err)
- else
- ngx.say("sent: ", bytes)
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local header, err = reader()
- if not header then
- ngx.say("failed to receive header: ", err)
- return
- end
-
- for i = 1, 2 do
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive line: ", err)
- return
- end
- ngx.say("received: ", line)
- end
- ';
- }
-
- location = /back {
- content_by_lua '
- ngx.send_headers()
- ngx.flush(true)
-
- local sock, err = ngx.req.socket()
-
- if not sock then
- ngx.say("failed to get socket: ", err)
- return nil
- end
-
- sock:settimeout(100);
-
- local data, err, partial = sock:receive(4096)
- if err then
- ngx.say("err: ", err, ", partial: ", partial)
- else
- ngx.say("received: ", data)
- end
-
- ngx.sleep(0.1)
-
- local data, err, partial = sock:receive(11)
- if err then
- ngx.say("err: ", err, ", partial: ", partial)
- else
- ngx.say("received: ", data)
- end
- ';
- }
-
---- request
-GET /t
---- response_body
-sent: 65
-sent: 11
-received: err: timeout, partial: abc
-received: received: hello world
-
---- error_log
-lua tcp socket read timed out
-
-
-
-=== TEST 15: successful reread after reading timeout happens (receive -> receiveuntil)
---- config
- location = /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("POST /back HTTP/1.0\\r\\nHost: localhost\\r\\nContent-Length: 1024\\r\\n\\r\\nabc")
- if not bytes then
- ngx.say("failed to send: ", err)
- else
- ngx.say("sent: ", bytes)
- end
-
- ngx.sleep(0.2)
-
- local bytes, err = sock:send("hello world\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- else
- ngx.say("sent: ", bytes)
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local header, err = reader()
- if not header then
- ngx.say("failed to receive header: ", err)
- return
- end
-
- for i = 1, 2 do
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive line: ", err)
- return
- end
- ngx.say("received: ", line)
- end
- ';
- }
-
- location = /back {
- content_by_lua '
- ngx.send_headers()
- ngx.flush(true)
-
- local sock, err = ngx.req.socket()
-
- if not sock then
- ngx.say("failed to get socket: ", err)
- return nil
- end
-
- sock:settimeout(100);
-
- local data, err, partial = sock:receive(4096)
- if err then
- ngx.say("err: ", err, ", partial: ", partial)
- else
- ngx.say("received: ", data)
- end
-
- ngx.sleep(0.1)
-
- local reader = sock:receiveuntil("\\n")
- local data, err, partial = reader()
- if err then
- ngx.say("err: ", err, ", partial: ", partial)
- else
- ngx.say("received: ", data)
- end
- ';
- }
-
---- request
-GET /t
---- response_body
-sent: 65
-sent: 12
-received: err: timeout, partial: abc
-received: received: hello world
-
---- error_log
-lua tcp socket read timed out
-
-
-
-=== TEST 16: successful reread after reading timeout happens (receiveuntil -> receive)
---- config
- location = /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("POST /back HTTP/1.0\\r\\nHost: localhost\\r\\nContent-Length: 1024\\r\\n\\r\\nabc")
- if not bytes then
- ngx.say("failed to send: ", err)
- else
- ngx.say("sent: ", bytes)
- end
-
- ngx.sleep(0.2)
-
- local bytes, err = sock:send("hello world\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- else
- ngx.say("sent: ", bytes)
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local header, err = reader()
- if not header then
- ngx.say("failed to receive header: ", err)
- return
- end
-
- for i = 1, 2 do
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive line: ", err)
- return
- end
- ngx.say("received: ", line)
- end
- ';
- }
-
- location = /back {
- content_by_lua '
- ngx.send_headers()
- ngx.flush(true)
-
- local sock, err = ngx.req.socket()
-
- if not sock then
- ngx.say("failed to get socket: ", err)
- return nil
- end
-
- sock:settimeout(100);
-
- local reader = sock:receiveuntil("no-such-terminator")
- local data, err, partial = reader()
- if not data then
- ngx.say("err: ", err, ", partial: ", partial)
- else
- ngx.say("received: ", data)
- end
-
- ngx.sleep(0.1)
-
- local data, err, partial = sock:receive()
- if err then
- ngx.say("err: ", err, ", partial: ", partial)
- else
- ngx.say("received: ", data)
- end
- ';
- }
-
---- request
-GET /t
---- response_body
-sent: 65
-sent: 12
-received: err: timeout, partial: abc
-received: received: hello world
-
---- error_log
-lua tcp socket read timed out
-
-
-
-=== TEST 17: req socket GC'd
---- config
- location /t {
- content_by_lua '
- do
- local sock, err = ngx.req.socket()
- if sock then
- ngx.say("got the request socket")
- else
- ngx.say("failed to get the request socket: ", err)
- end
- end
- collectgarbage()
- ngx.log(ngx.WARN, "GC cycle done")
-
- ngx.say("done")
- ';
- }
---- request
-POST /t
-hello world
---- response_body
-got the request socket
-done
---- no_error_log
-[error]
---- grep_error_log eval: qr/lua finalize socket|GC cycle done/
---- grep_error_log_out
-lua finalize socket
-GC cycle done
-
-
-
-=== TEST 18: receiveany
---- config
- location = /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("POST /back HTTP/1.0\r\nHost: localhost\r\nContent-Length: 1024\r\n\r\nabc")
- if not bytes then
- ngx.say("failed to send: ", err)
- end
-
- ngx.sleep(0.2)
-
- local bytes, err = sock:send("hello world\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- end
-
- local reader = sock:receiveuntil("\r\n\r\n")
- local header, err = reader()
- if not header then
- ngx.say("failed to receive header: ", err)
- return
- end
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive line: ", err)
- return
- end
- ngx.say("received: ", line)
- }
- }
-
- location = /back {
- content_by_lua_block {
- ngx.send_headers()
- ngx.flush(true)
-
- local sock, err = ngx.req.socket()
-
- if not sock then
- ngx.say("failed to get socket: ", err)
- return nil
- end
-
- local data, err = sock:receiveany(4096)
- if not data then
- ngx.say("err: ", err)
- return nil
- end
-
- ngx.say("received: ", data)
- }
- }
-
---- request
-GET /t
---- response_body
-received: received: abc
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/068-socket-keepalive.t b/src/deps/src/lua-nginx-module/t/068-socket-keepalive.t
deleted file mode 100644
index 626b44167..000000000
--- a/src/deps/src/lua-nginx-module/t/068-socket-keepalive.t
+++ /dev/null
@@ -1,3195 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 34);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_HTML_DIR} = $HtmlDir;
-$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-$ENV{LUA_PATH} ||=
- '/usr/local/openresty-debug/lualib/?.lua;/usr/local/openresty/lualib/?.lua;;';
-
-no_long_string();
-#no_diff();
-
-#log_level 'warn';
-log_level 'debug';
-
-no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port)
- test.go(port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-request sent: 11
-received: OK
-connected: 1, reused: 1
-request sent: 11
-received: OK
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for "]
---- error_log eval
-qq{lua tcp socket get keepalive peer: using connection
-lua tcp socket keepalive create connection pool for key "127.0.0.1:$ENV{TEST_NGINX_MEMCACHED_PORT}"
-}
-
-
-
-=== TEST 2: free up the whole connection pool if no active connections
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port, true)
- test.go(port, false)
- ';
- }
---- request
-GET /t
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port, keepalive)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- if keepalive then
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- else
- sock:close()
- end
-end
---- response_body
-connected: 1, reused: 0
-request sent: 11
-received: OK
-connected: 1, reused: 1
-request sent: 11
-received: OK
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket get keepalive peer: using connection",
-"lua tcp socket keepalive: free connection pool for "]
-
-
-
-=== TEST 3: upstream sockets close prematurely
---- no_http3
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- keepalive_timeout 100ms;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for "]
---- timeout: 3
-
-
-
-=== TEST 4: http keepalive
---- quic_max_idle_timeout: 1.2
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive close handler: fd:",
-"lua tcp socket keepalive: free connection pool for "]
---- timeout: 4
-
-
-
-=== TEST 5: lua_socket_keepalive_timeout
---- quic_max_idle_timeout: 1.2
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 100ms;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive timeout: 100 ms",
-qr/lua tcp socket connection pool size: 30\b/]
---- timeout: 4
-
-
-
-=== TEST 6: lua_socket_pool_size
---- quic_max_idle_timeout: 1.2
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 100ms;
- lua_socket_pool_size 1;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive timeout: 100 ms",
-qr/lua tcp socket connection pool size: 1\b/]
---- timeout: 4
-
-
-
-=== TEST 7: "lua_socket_keepalive_timeout 0" means unlimited
---- quic_max_idle_timeout: 1.2
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 0;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive timeout: unlimited",
-qr/lua tcp socket connection pool size: 30\b/]
---- timeout: 4
-
-
-
-=== TEST 8: setkeepalive(timeout) overrides lua_socket_keepalive_timeout
---- quic_max_idle_timeout: 1.2
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 60s;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive(123)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive timeout: 123 ms",
-qr/lua tcp socket connection pool size: 30\b/]
---- timeout: 4
-
-
-
-=== TEST 9: sock:setkeepalive(timeout, size) overrides lua_socket_pool_size
---- quic_max_idle_timeout: 1.2
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 100ms;
- lua_socket_pool_size 100;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive(101, 25)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive timeout: 101 ms",
-qr/lua tcp socket connection pool size: 25\b/]
---- timeout: 4
-
-
-
-=== TEST 10: setkeepalive() 'pool_size' should be greater than zero
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua_block {
- local sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port)
- if not sock then
- ngx.say(err)
- return
- end
-
- local ok, err = pcall(sock.setkeepalive, sock, 0, 0)
- if not ok then
- ngx.say(err)
- return
- end
- ngx.say(ok)
- }
- }
---- request
-GET /t
---- response_body
-bad argument #3 to '?' (bad "pool_size" option value: 0)
---- no_error_log
-[error]
-
-
-
-=== TEST 11: sock:keepalive_timeout(0) means unlimited
---- quic_max_idle_timeout: 1.2
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
- lua_socket_keepalive_timeout 1000ms;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: keepalive\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\\r\\n0\\r\\n\\r\\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive(0)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- ';
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive timeout: unlimited",
-qr/lua tcp socket connection pool size: 30\b/]
---- timeout: 4
-
-
-
-=== TEST 12: sanity (uds)
---- http_config eval
-"
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
- server {
- listen unix:$::HtmlDir/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
- }
-"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local path = "$TEST_NGINX_HTML_DIR/nginx.sock";
- local port = ngx.var.port
- test.go(path, port)
- test.go(path, port)
- ';
- }
---- request
-GET /t
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(path, port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:" .. path)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keepalive\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\r\n0\r\n\r\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- response_body
-connected: 1, reused: 0
-request sent: 61
-received response of 119 bytes
-connected: 1, reused: 1
-request sent: 61
-received response of 119 bytes
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for "]
---- error_log eval
-["lua tcp socket get keepalive peer: using connection",
-'lua tcp socket keepalive create connection pool for key "unix:']
-
-
-
-=== TEST 13: github issue #108: ngx.location.capture + redis.set_keepalive
---- http_config eval
- qq{
- lua_package_path "$::HtmlDir/?.lua;;";
- }
---- config
- location /t {
- default_type text/html;
- set $port $TEST_NGINX_MEMCACHED_PORT;
- #lua_code_cache off;
- lua_need_request_body on;
- content_by_lua_file html/t.lua;
- }
-
- location /anyurl {
- internal;
- proxy_pass http://127.0.0.1:$server_port/dummy;
- }
-
- location = /dummy {
- echo dummy;
- }
---- user_files
->>> t.lua
-local sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port)
-if not sock then ngx.say(err) return end
-sock:send("flush_all\r\n")
-sock:receive()
-sock:setkeepalive()
-
-sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port)
-if not sock then ngx.say(err) return end
-local res = ngx.location.capture("/anyurl") --3
-
-ngx.say("ok")
---- request
- GET /t
---- response_body
-ok
---- error_log
-lua tcp socket get keepalive peer: using connection
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 14: github issue #110: ngx.exit with HTTP_NOT_FOUND causes worker process to exit
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- error_page 404 /404.html;
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- access_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port)
- ngx.exit(404)
- ';
- echo hello;
- }
---- user_files
->>> 404.html
-Not found, dear...
->>> test.lua
-module("test", package.seeall)
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.log(ngx.ERR, "failed to send request: ", err)
- return
- end
-
- local line, err, part = sock:receive()
- if not line then
- ngx.log(ngx.ERR, "failed to receive a line: ", err, " [", part, "]")
- return
- end
-
- -- local ok, err = sock:setkeepalive()
- -- if not ok then
- -- ngx.log(ngx.ERR, "failed to set reusable: ", err)
- -- return
- -- end
-end
---- request
-GET /t
---- response_body
-Not found, dear...
---- error_code: 404
---- no_error_log
-[error]
-
-
-
-=== TEST 15: custom pools (different pool for the same host:port) - tcp
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port, "A")
- test.go(port, "B")
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port, pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port, {pool = pool})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-connected: 1, reused: 0
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket get keepalive peer: using connection"
-]
---- error_log
-lua tcp socket keepalive create connection pool for key "A"
-lua tcp socket keepalive create connection pool for key "B"
-
-
-
-=== TEST 16: custom pools (same pool for different host:port) - tcp
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go($TEST_NGINX_MEMCACHED_PORT, "foo")
- test.go($TEST_NGINX_SERVER_PORT, "foo")
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port, pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port, {pool = pool})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-connected: 1, reused: 1
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for ",
-]
---- error_log
-lua tcp socket keepalive create connection pool for key "foo"
-lua tcp socket get keepalive peer: using connection
-
-
-
-=== TEST 17: custom pools (different pool for the same host:port) - unix
---- http_config eval
-"
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
- server {
- listen unix:$::HtmlDir/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
- }
-"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local path = "$TEST_NGINX_HTML_DIR/nginx.sock";
- test.go(path, "A")
- test.go(path, "B")
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(path, pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:" .. path, {pool = pool})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-connected: 1, reused: 0
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket get keepalive peer: using connection"
-]
---- error_log
-lua tcp socket keepalive create connection pool for key "A"
-lua tcp socket keepalive create connection pool for key "B"
-
-
-
-=== TEST 18: custom pools (same pool for the same path) - unix
---- http_config eval
-"
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
- server {
- listen unix:$::HtmlDir/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- }
-"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local path = "$TEST_NGINX_HTML_DIR/nginx.sock";
- test.go(path, "A")
- test.go(path, "A")
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(path, pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:" .. path, {pool = pool})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-connected: 1, reused: 1
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for ",
-]
---- error_log
-lua tcp socket keepalive create connection pool for key "A"
-lua tcp socket get keepalive peer: using connection
-
-
-
-=== TEST 19: numeric pool option value
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go($TEST_NGINX_MEMCACHED_PORT, 3.14)
- test.go($TEST_NGINX_SERVER_PORT, 3.14)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port, pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port, {pool = pool})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-connected: 1, reused: 1
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for ",
-]
---- error_log
-lua tcp socket keepalive create connection pool for key "3.14"
-lua tcp socket get keepalive peer: using connection
-
-
-
-=== TEST 20: nil pool option value
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go($TEST_NGINX_MEMCACHED_PORT, nil)
- test.go($TEST_NGINX_SERVER_PORT, nil)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port, pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port, {pool = pool})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-connected: 1, reused: 0
---- error_code: 200
---- no_error_log
-[error]
-
-
-
-=== TEST 21: (bad) table pool option value
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go($TEST_NGINX_MEMCACHED_PORT, {})
- test.go($TEST_NGINX_SERVER_PORT, {})
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port, pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port, {pool = pool})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad argument #3 to 'connect' (bad "pool" option type: table)
-
-
-
-=== TEST 22: (bad) boolean pool option value
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go($TEST_NGINX_MEMCACHED_PORT, true)
- test.go($TEST_NGINX_SERVER_PORT, false)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port, pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port, {pool = pool})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad argument #3 to 'connect' (bad "pool" option type: boolean)
-
-
-
-=== TEST 23: clear the redis store
---- config
- location /t {
- redis2_query flushall;
- redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
- }
---- request
- GET /t
---- response_body eval
-"+OK\r\n"
---- no_error_log
-[error]
-[alert]
-[warn]
-
-
-
-=== TEST 24: bug in send(): clear the chain writer ctx
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /t {
- set $port $TEST_NGINX_REDIS_PORT;
- content_by_lua '
- local test = require "test"
- local port = ngx.var.port
- test.go(port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send({})
- if err then
- ngx.say("failed to send empty request: ", err)
- return
- end
-
- local req = "*2\r\n$3\r\nget\r\n$3\r\ndog\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.say("done")
-end
---- request
-GET /t
---- stap2
-global active
-M(http-lua-socket-tcp-send-start) {
- active = 1
- printf("send [%s] %d\n", text_str(user_string_n($arg3, $arg4)), $arg4)
-}
-M(http-lua-socket-tcp-receive-done) {
- printf("receive [%s]\n", text_str(user_string_n($arg3, $arg4)))
-}
-F(ngx_output_chain) {
- #printf("ctx->in: %s\n", ngx_chain_dump($ctx->in))
- #printf("ctx->busy: %s\n", ngx_chain_dump($ctx->busy))
- printf("output chain: %s\n", ngx_chain_dump($in))
-}
-F(ngx_linux_sendfile_chain) {
- printf("linux sendfile chain: %s\n", ngx_chain_dump($in))
-}
-F(ngx_chain_writer) {
- printf("chain writer ctx out: %p\n", $data)
- printf("nginx chain writer: %s\n", ngx_chain_dump($in))
-}
-F(ngx_http_lua_socket_tcp_setkeepalive) {
- delete active
-}
-M(http-lua-socket-tcp-setkeepalive-buf-unread) {
- printf("setkeepalive unread: [%s]\n", text_str(user_string_n($arg3, $arg4)))
-}
-probe syscall.recvfrom {
- if (active && pid() == target()) {
- printf("recvfrom(%s)", argstr)
- }
-}
-probe syscall.recvfrom.return {
- if (active && pid() == target()) {
- printf(" = %s, data [%s]\n", retstr, text_str(user_string_n($ubuf, $size)))
- }
-}
-probe syscall.writev {
- if (active && pid() == target()) {
- printf("writev(%s)", ngx_iovec_dump($vec, $vlen))
- /*
- for (i = 0; i < $vlen; i++) {
- printf(" %p [%s]", $vec[i]->iov_base, text_str(user_string_n($vec[i]->iov_base, $vec[i]->iov_len)))
- }
- */
- }
-}
-probe syscall.writev.return {
- if (active && pid() == target()) {
- printf(" = %s\n", retstr)
- }
-}
---- response_body
-received: $-1
-done
---- no_error_log
-[error]
-
-
-
-=== TEST 25: setkeepalive() with explicit nil args
---- quic_max_idle_timeout: 1.2
---- config
- server_tokens off;
- location /t {
- lua_socket_keepalive_timeout 100ms;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keepalive\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\r\n0\r\n\r\n")
- local data, res = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- local ok, err = sock:setkeepalive(nil, nil)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ngx.location.capture("/sleep")
-
- ngx.say("done")
- }
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 61
-received response of 156 bytes
-done
---- no_error_log
-[error]
---- error_log eval
-["lua tcp socket keepalive close handler",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket keepalive timeout: 100 ms",
-qr/lua tcp socket connection pool size: 30\b/]
---- timeout: 4
-
-
-
-=== TEST 26: conn queuing: connect() verifies the options for connection pool
---- config
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local function check_opts_for_connect(opts)
- local ok, err = pcall(function()
- sock:connect("127.0.0.1", ngx.var.port, opts)
- end)
- if not ok then
- ngx.say(err)
- else
- ngx.say("ok")
- end
- end
-
- check_opts_for_connect({pool_size = 'a'})
- check_opts_for_connect({pool_size = 0})
- check_opts_for_connect({backlog = -1})
- check_opts_for_connect({backlog = 0})
- }
- }
---- request
-GET /t
---- response_body_like
-.+ 'connect' \(bad "pool_size" option type: string\)
-.+ 'connect' \(bad "pool_size" option value: 0\)
-.+ 'connect' \(bad "backlog" option value: -1\)
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 27: conn queuing: connect() can specify 'pool_size' which overrides setkeepalive()
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local function go()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port, {pool_size = 1})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive(0, 20)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
- end
-
- -- reuse ok
- go()
- go()
-
- local sock1 = ngx.socket.connect("127.0.0.1", port)
- local sock2 = ngx.socket.connect("127.0.0.1", port)
- local ok, err = sock1:setkeepalive(0, 20)
- if not ok then
- ngx.say(err)
- end
- local ok, err = sock2:setkeepalive(0, 20)
- if not ok then
- ngx.say(err)
- end
-
- -- the pool_size is 1 instead of 20
- sock1 = ngx.socket.connect("127.0.0.1", port)
- sock2 = ngx.socket.connect("127.0.0.1", port)
- ngx.say("reused: ", sock1:getreusedtimes())
- ngx.say("reused: ", sock2:getreusedtimes())
- sock1:setkeepalive(0, 20)
- sock2:setkeepalive(0, 20)
- }
- }
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-request sent: 11
-received: OK
-connected: 1, reused: 1
-request sent: 11
-received: OK
-reused: 1
-reused: 0
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket connection pool size: 20"]
---- error_log eval
-[qq{lua tcp socket keepalive create connection pool for key "127.0.0.1:$ENV{TEST_NGINX_MEMCACHED_PORT}"},
-"lua tcp socket connection pool size: 1",
-]
-
-
-
-=== TEST 28: conn queuing: connect() can specify 'pool_size' for unix domain socket
---- http_config eval
-"
- server {
- listen unix:$::HtmlDir/nginx.sock;
- }
-"
---- config
- location /t {
- content_by_lua_block {
- local path = "unix:" .. "$TEST_NGINX_HTML_DIR/nginx.sock";
- local function go()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect(path, {pool_size = 1})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive(0, 20)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
- end
-
- go()
- go()
-
- local sock1 = ngx.socket.connect(path)
- local sock2 = ngx.socket.connect(path)
- local ok, err = sock1:setkeepalive(0, 20)
- if not ok then
- ngx.say(err)
- end
- local ok, err = sock2:setkeepalive(0, 20)
- if not ok then
- ngx.say(err)
- end
-
- -- the pool_size is 1 instead of 20
- sock1 = ngx.socket.connect(path)
- sock2 = ngx.socket.connect(path)
- ngx.say("reused: ", sock1:getreusedtimes())
- ngx.say("reused: ", sock2:getreusedtimes())
- sock1:setkeepalive(0, 20)
- sock2:setkeepalive(0, 20)
- }
- }
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-connected: 1, reused: 1
-reused: 1
-reused: 0
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket connection pool size: 20"]
---- error_log eval
-["lua tcp socket get keepalive peer: using connection",
-'lua tcp socket keepalive create connection pool for key "unix:',
-"lua tcp socket connection pool size: 1",
-]
-
-
-
-=== TEST 29: conn queuing: connect() can specify 'pool_size' for custom pool
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local function go(pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port, {pool = pool, pool_size = 1})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", pool, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive(0, 20)
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
- end
-
- go('A')
- go('B')
- go('A')
- go('B')
-
- local sock1 = ngx.socket.connect("127.0.0.1", port, {pool = 'A'})
- local sock2 = ngx.socket.connect("127.0.0.1", port, {pool = 'A'})
- local ok, err = sock1:setkeepalive(0, 20)
- if not ok then
- ngx.say(err)
- end
- local ok, err = sock2:setkeepalive(0, 20)
- if not ok then
- ngx.say(err)
- end
-
- -- the pool_size is 1 instead of 20
- sock1 = ngx.socket.connect("127.0.0.1", port, {pool = 'A'})
- sock2 = ngx.socket.connect("127.0.0.1", port, {pool = 'A'})
- ngx.say("reused: ", sock1:getreusedtimes())
- ngx.say("reused: ", sock2:getreusedtimes())
- sock1:setkeepalive(0, 20)
- sock2:setkeepalive(0, 20)
- }
- }
---- request
-GET /t
---- response_body
-connected: A, reused: 0
-connected: B, reused: 0
-connected: A, reused: 1
-connected: B, reused: 1
-reused: 1
-reused: 0
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket connection pool size: 20"]
---- error_log eval
-[qq{lua tcp socket keepalive create connection pool for key "A"},
-qq{lua tcp socket keepalive create connection pool for key "B"},
-"lua tcp socket connection pool size: 1",
-]
-
-
-
-=== TEST 30: conn queuing: connect() uses lua_socket_pool_size as default if 'backlog' is given
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- lua_socket_pool_size 1234;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {backlog = 0}
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.say(err)
- else
- ngx.say("ok")
- end
- }
- }
---- request
-GET /t
---- response_body
-ok
---- error_log
-lua tcp socket connection pool size: 1234
---- no_error_log
-[error]
-
-
-
-=== TEST 31: conn queuing: more connect operations than 'backlog' size
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool_size = 2, backlog = 0}
- local sock = ngx.socket.connect("127.0.0.1", port, opts)
- local not_reused_socket, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not not_reused_socket then
- ngx.say(err)
- return
- end
- -- burst
- local ok, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not ok then
- ngx.say(err)
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say(err)
- return
- end
-
- ok, err = sock:connect("127.0.0.1", port, opts)
- if not ok then
- ngx.say(err)
- end
- ngx.say("reused: ", sock:getreusedtimes())
- -- both queue and pool is full
- ok, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not ok then
- ngx.say(err)
- end
- }
- }
---- request
-GET /t
---- response_body
-too many waiting connect operations
-reused: 1
-too many waiting connect operations
---- no_error_log
-[error]
-
-
-
-=== TEST 32: conn queuing: once 'pool_size' is reached and pool has 'backlog'
---- quic_max_idle_timeout: 1.2
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool_size = 2, backlog = 2}
- local sock1 = ngx.socket.connect("127.0.0.1", port, opts)
-
- ngx.timer.at(0, function(premature)
- local sock2, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock2 then
- ngx.log(ngx.ERR, err)
- return
- end
-
- ngx.log(ngx.WARN, "start to handle timer")
- ngx.sleep(0.1)
- sock2:close()
- -- resume connect operation
- ngx.log(ngx.WARN, "continue to handle timer")
- end)
-
- ngx.sleep(0.05)
- ngx.log(ngx.WARN, "start to handle cosocket")
- local sock3, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock3 then
- ngx.say(err)
- return
- end
- ngx.log(ngx.WARN, "continue to handle cosocket")
-
- local req = "flush_all\r\n"
- local bytes, err = sock3:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock3:receive()
- if line then
- ngx.say("received: ", line)
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock3:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
- ngx.say("setkeepalive: OK")
- }
- }
---- request
-GET /t
---- response_body
-request sent: 11
-received: OK
-setkeepalive: OK
---- no_error_log
-[error]
---- error_log
-lua tcp socket queue connect operation for connection pool "127.0.0.1
---- grep_error_log eval: qr/(start|continue) to handle \w+/
---- grep_error_log_out
-start to handle timer
-start to handle cosocket
-continue to handle timer
-continue to handle cosocket
-
-
-
-=== TEST 33: conn queuing: do not count failed connect operations
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool = "test", pool_size = 1, backlog = 0}
-
- local sock = ngx.socket.tcp()
- sock:settimeouts(100, 3000, 3000)
- local ok, err = sock:connect("127.0.0.2", 12345, opts)
- if not ok then
- ngx.say(err)
- end
-
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.say(err)
- end
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- error_log
-lua tcp socket connect timed out, when connecting to
---- response_body
-timeout
-ok
-
-
-
-=== TEST 34: conn queuing: connect until backlog is reached
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool_size = 1, backlog = 1}
- local sock1 = ngx.socket.connect("127.0.0.1", port, opts)
-
- ngx.timer.at(0.01, function(premature)
- ngx.log(ngx.WARN, "start to handle timer")
- local sock2, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock2 then
- ngx.log(ngx.ERR, err)
- return
- end
-
- ngx.sleep(0.02)
- local ok, err = sock2:close()
- if not ok then
- ngx.log(ngx.ERR, err)
- end
- ngx.log(ngx.WARN, "continue to handle timer")
- end)
-
- ngx.sleep(0.02)
- local sock3, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock3 then
- ngx.say(err)
- end
- local ok, err = sock1:setkeepalive()
- if not ok then
- ngx.say(err)
- return
- end
- ngx.sleep(0.01) -- run sock2
-
- ngx.log(ngx.WARN, "start to handle cosocket")
- local sock3, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock3 then
- ngx.say(err)
- return
- end
- ngx.log(ngx.WARN, "continue to handle cosocket")
-
- local ok, err = sock3:setkeepalive()
- if not ok then
- ngx.say(err)
- end
- }
- }
---- request
-GET /t
---- response_body
-too many waiting connect operations
---- no_error_log
-[error]
---- error_log
-lua tcp socket queue connect operation for connection pool "127.0.0.1
---- grep_error_log eval: qr/queue connect operation for connection pool|(start|continue) to handle \w+/
---- grep_error_log_out
-start to handle timer
-queue connect operation for connection pool
-start to handle cosocket
-queue connect operation for connection pool
-continue to handle timer
-continue to handle cosocket
-
-
-
-=== TEST 35: conn queuing: memory reuse for host in queueing connect operation ctx
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool = "test", pool_size = 1, backlog = 3}
- local sock = ngx.socket.connect("127.0.0.1", port, opts)
-
- ngx.timer.at(0.01, function(premature)
- local sock, err = ngx.socket.connect("0.0.0.0", port, opts)
- if not sock then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local ok, err = sock:close()
- if not ok then
- ngx.log(ngx.ERR, err)
- end
- end)
-
- ngx.timer.at(0.015, function(premature)
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local ok, err = sock:close()
- if not ok then
- ngx.log(ngx.ERR, err)
- end
- end)
-
- ngx.timer.at(0.02, function(premature)
- local sock, err = ngx.socket.connect("0.0.0.0", port, opts)
- if not sock then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local ok, err = sock:close()
- if not ok then
- ngx.log(ngx.ERR, err)
- end
- end)
-
- ngx.sleep(0.03)
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say(err)
- return
- end
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/queue connect operation for connection pool/
---- grep_error_log_out
-queue connect operation for connection pool
-queue connect operation for connection pool
-queue connect operation for connection pool
-
-
-
-=== TEST 36: conn queuing: connect() returns error after connect operation resumed
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool = "test", pool_size = 1, backlog = 1}
- local sock = ngx.socket.connect("127.0.0.1", port, opts)
-
- ngx.timer.at(0, function(premature)
- local sock, err = ngx.socket.connect("", port, opts)
- if not sock then
- ngx.log(ngx.WARN, err)
- end
- end)
-
- ngx.sleep(0.01)
- -- use 'close' to force parsing host instead of reusing conn
- local ok, err = sock:close()
- if not ok then
- ngx.say(err)
- return
- end
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- error_log
-failed to parse host name
---- grep_error_log eval: qr/queue connect operation for connection pool/
---- grep_error_log_out
-queue connect operation for connection pool
-
-
-
-=== TEST 37: conn queuing: in uthread
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool_size = 1, backlog = 2}
-
- local conn_sock = function()
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.say(err)
- return
- end
- ngx.say("start to handle uthread")
-
- ngx.sleep(0.01)
- sock:close()
- ngx.say("continue to handle other uthread")
- end
-
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local co1 = ngx.thread.spawn(conn_sock)
- local co2 = ngx.thread.spawn(conn_sock)
- local co3 = ngx.thread.spawn(conn_sock)
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.log(ngx.ERR, err)
- end
-
- ngx.thread.wait(co1)
- ngx.thread.wait(co2)
- ngx.thread.wait(co3)
- ngx.say("all uthreads ok")
- }
- }
---- request
-GET /t
---- response_body
-too many waiting connect operations
-start to handle uthread
-continue to handle other uthread
-start to handle uthread
-continue to handle other uthread
-all uthreads ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/queue connect operation for connection pool/
---- grep_error_log_out
-queue connect operation for connection pool
-queue connect operation for connection pool
-
-
-
-=== TEST 38: conn queuing: in access_by_lua
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- access_by_lua_block {
- local port = ngx.var.port
- local opts = {pool_size = 1, backlog = 2}
-
- local conn_sock = function()
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.say(err)
- return
- end
- ngx.say("start to handle uthread")
-
- ngx.sleep(0.01)
- sock:close()
- ngx.say("continue to handle other uthread")
- end
-
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local co1 = ngx.thread.spawn(conn_sock)
- local co2 = ngx.thread.spawn(conn_sock)
- local co3 = ngx.thread.spawn(conn_sock)
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.log(ngx.ERR, err)
- end
-
- ngx.thread.wait(co1)
- ngx.thread.wait(co2)
- ngx.thread.wait(co3)
- ngx.say("all uthreads ok")
- }
- }
---- request
-GET /t
---- response_body
-too many waiting connect operations
-start to handle uthread
-continue to handle other uthread
-start to handle uthread
-continue to handle other uthread
-all uthreads ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/queue connect operation for connection pool/
---- grep_error_log_out
-queue connect operation for connection pool
-queue connect operation for connection pool
-
-
-
-=== TEST 39: conn queuing: in rewrite_by_lua
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- rewrite_by_lua_block {
- local port = ngx.var.port
- local opts = {pool_size = 1, backlog = 2}
-
- local conn_sock = function()
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.say(err)
- return
- end
- ngx.say("start to handle uthread")
-
- ngx.sleep(0.01)
- sock:close()
- ngx.say("continue to handle other uthread")
- end
-
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local co1 = ngx.thread.spawn(conn_sock)
- local co2 = ngx.thread.spawn(conn_sock)
- local co3 = ngx.thread.spawn(conn_sock)
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.log(ngx.ERR, err)
- end
-
- ngx.thread.wait(co1)
- ngx.thread.wait(co2)
- ngx.thread.wait(co3)
- ngx.say("all uthreads ok")
- }
- }
---- request
-GET /t
---- response_body
-too many waiting connect operations
-start to handle uthread
-continue to handle other uthread
-start to handle uthread
-continue to handle other uthread
-all uthreads ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/queue connect operation for connection pool/
---- grep_error_log_out
-queue connect operation for connection pool
-queue connect operation for connection pool
-
-
-
-=== TEST 40: conn queuing: in subrequest
---- config
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- location /t {
- content_by_lua_block {
- local port = ngx.var.port
- ngx.timer.at(0, function()
- local opts = {pool_size = 1, backlog = 2}
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.log(ngx.ERR, err)
- return
- end
-
- ngx.sleep(0.1)
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.log(ngx.ERR, err)
- end
- end)
-
- ngx.sleep(0.01)
- local res1, res2, res3 = ngx.location.capture_multi{
- {"/conn"}, {"/conn"}, {"/conn"}
- }
- ngx.say(res1.body)
- ngx.say(res2.body)
- ngx.say(res3.body)
- }
- }
-
- location /conn {
- content_by_lua_block {
- local port = ngx.var.port
- local sock, err = ngx.socket.connect("127.0.0.1", port)
- if not sock then
- ngx.print(err)
- return
- end
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.print(err)
- else
- ngx.print("ok")
- end
- }
- }
---- request
-GET /t
---- response_body
-ok
-ok
-too many waiting connect operations
---- no_error_log
-[error]
---- grep_error_log eval: qr/queue connect operation for connection pool/
---- grep_error_log_out
-queue connect operation for connection pool
-queue connect operation for connection pool
-
-
-
-=== TEST 41: conn queuing: timeouts when 'connect_timeout' is reached
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool_size = 1, backlog = 1}
- local sock1 = ngx.socket.connect("127.0.0.1", port, opts)
-
- local sock2 = ngx.socket.tcp()
- sock2:settimeouts(10, 3000, 3000)
- local ok, err = sock2:connect("127.0.0.1", port, opts)
- if not ok then
- ngx.say(err)
- end
- }
- }
---- request
-GET /t
---- response_body
-timeout
---- error_log eval
-"lua tcp socket queued connect timed out, when trying to connect to 127.0.0.1:$ENV{TEST_NGINX_MEMCACHED_PORT}"
-
-
-
-=== TEST 42: conn queuing: set timeout via lua_socket_connect_timeout
---- config
- lua_socket_connect_timeout 10ms;
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool_size = 1, backlog = 1}
- local sock1 = ngx.socket.connect("127.0.0.1", port, opts)
-
- local sock2 = ngx.socket.tcp()
- local ok, err = sock2:connect("127.0.0.1", port, opts)
- if not ok then
- ngx.say(err)
- end
- }
- }
---- request
-GET /t
---- response_body
-timeout
---- error_log eval
-"lua tcp socket queued connect timed out, when trying to connect to 127.0.0.1:$ENV{TEST_NGINX_MEMCACHED_PORT}"
-
-
-
-=== TEST 43: conn queuing: client aborting while connect operation is queued
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool_size = 1, backlog = 1}
- local sock1 = ngx.socket.connect("127.0.0.1", port, opts)
-
- local sock2 = ngx.socket.tcp()
- sock2:settimeouts(3000, 3000, 3000)
- local ok, err = sock2:connect("127.0.0.1", port, opts)
- if not ok then
- ngx.say(err)
- end
- }
- }
---- request
-GET /t
---- ignore_response
---- timeout: 0.1
---- abort
---- no_error_log
-[error]
---- curl_error eval
-qr/curl: \(28\) Operation timed out after \d+ milliseconds with 0 bytes received/
-
-
-
-=== TEST 44: conn queuing: resume next connect operation if resumed connect failed immediately
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool = "test", pool_size = 1, backlog = 2}
-
- local conn_sock = function(should_timeout)
- local sock = ngx.socket.tcp()
- local ok, err
- if should_timeout then
- ok, err = sock:connect("", port, opts)
- else
- ok, err = sock:connect("127.0.0.1", port, opts)
- end
- if not ok then
- ngx.say(err)
- return
- end
- ngx.say("connected in uthread")
- sock:close()
- end
-
- local sock, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local co1 = ngx.thread.spawn(conn_sock, true)
- local co2 = ngx.thread.spawn(conn_sock)
-
- local ok, err = sock:close()
- if not ok then
- ngx.log(ngx.ERR, err)
- end
-
- ngx.thread.wait(co1)
- ngx.thread.wait(co2)
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-failed to parse host name "": no host
-connected in uthread
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 45: conn queuing: resume connect operation if resumed connect failed (timeout)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool = "test", pool_size = 1, backlog = 1}
-
- local conn_sock = function(should_timeout)
- local sock = ngx.socket.tcp()
- local ok, err
- if should_timeout then
- sock:settimeouts(100, 3000, 3000)
- ok, err = sock:connect("127.0.0.2", 12345, opts)
- else
- ok, err = sock:connect("127.0.0.1", port, opts)
- end
- if not ok then
- ngx.say(err)
- return
- end
- ngx.say("connected in uthread")
- sock:close()
- end
-
- local co1 = ngx.thread.spawn(conn_sock, true)
- local co2 = ngx.thread.spawn(conn_sock)
-
- ngx.thread.wait(co1)
- ngx.thread.wait(co2)
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-timeout
-connected in uthread
-ok
---- error_log
-queue connect operation for connection pool "test"
-lua tcp socket connect timed out, when connecting to
-
-
-
-=== TEST 46: conn queuing: resume connect operation if resumed connect failed (could not be resolved)
---- quic_max_idle_timeout: 1.2
---- config
- resolver 127.0.0.2:12345 ipv6=off;
- resolver_timeout 1s;
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool = "test", pool_size = 1, backlog = 1}
-
- local conn_sock = function(should_timeout)
- local sock = ngx.socket.tcp()
- local ok, err
- if should_timeout then
- sock:settimeouts(1, 3000, 3000)
- ok, err = sock:connect("agentzh.org", 80, opts)
- else
- ok, err = sock:connect("127.0.0.1", port, opts)
- end
- if not ok then
- ngx.say(err)
- return
- end
- ngx.say("connected in uthread")
- sock:close()
- end
-
- local co1 = ngx.thread.spawn(conn_sock, true)
- local co2 = ngx.thread.spawn(conn_sock)
-
- ngx.thread.wait(co1)
- ngx.thread.wait(co2)
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-agentzh.org could not be resolved (110: Operation timed out)
-connected in uthread
-ok
---- error_log
-queue connect operation for connection pool "test"
-
-
-
-=== TEST 47: conn queuing: resume connect operation if resumed connect failed (connection refused)
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local port = ngx.var.port
- local opts = {pool = "test", pool_size = 1, backlog = 1}
-
- local conn_sock = function(should_timeout)
- local sock = ngx.socket.tcp()
- local ok, err
- if should_timeout then
- sock:settimeouts(100, 3000, 3000)
- ok, err = sock:connect("127.0.0.1", 62345, opts)
- else
- ok, err = sock:connect("127.0.0.1", port, opts)
- end
- if not ok then
- ngx.say(err)
- return
- end
- ngx.say("connected in uthread")
- sock:close()
- end
-
- local co1 = ngx.thread.spawn(conn_sock, true)
- local co2 = ngx.thread.spawn(conn_sock)
-
- ngx.thread.wait(co1)
- ngx.thread.wait(co2)
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-connection refused
-connected in uthread
-ok
---- error_log
-queue connect operation for connection pool "test"
-
-
-
-=== TEST 48: conn queuing: resume connect operation if resumed connect failed (uthread aborted while resolving)
---- http_config
- lua_package_path '../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;';
---- config
- resolver 127.0.0.1 ipv6=off;
- resolver_timeout 100s;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- location /sub {
- content_by_lua_block {
- local semaphore = require "ngx.semaphore"
- local sem = semaphore.new()
-
- local function f()
- sem:wait(0.1)
- ngx.exit(0)
- end
-
- local opts = {pool = "test", pool_size = 1, backlog = 1}
- local port = ngx.var.port
- ngx.timer.at(0, function()
- sem:post()
- local sock2, err = ngx.socket.connect("127.0.0.1", port, opts)
- package.loaded.for_timer_to_resume:post()
- if not sock2 then
- ngx.log(ngx.ALERT, "resume connect failed: ", err)
- return
- end
-
- ngx.log(ngx.INFO, "resume success")
- end)
-
- ngx.thread.spawn(f)
- local sock1, err = ngx.socket.connect("openresty.org", 80, opts)
- if not sock1 then
- ngx.say(err)
- return
- end
- }
- }
-
- location /t {
- content_by_lua_block {
- local semaphore = require "ngx.semaphore"
- local for_timer_to_resume = semaphore.new()
- package.loaded.for_timer_to_resume = for_timer_to_resume
-
- ngx.location.capture("/sub")
- for_timer_to_resume:wait(0.1)
- }
- }
---- request
-GET /t
---- no_error_log
-[alert]
---- error_log
-resume success
-
-
-
-=== TEST 49: conn queuing: resume connect operation if resumed connect failed (uthread killed while resolving)
---- config
- resolver 127.0.0.1 ipv6=off;
- resolver_timeout 100s;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- location /t {
- content_by_lua_block {
- local opts = {pool = "test", pool_size = 1, backlog = 1}
- local port = ngx.var.port
-
- local function resolve()
- local sock1, err = ngx.socket.connect("openresty.org", 80, opts)
- if not sock1 then
- ngx.say(err)
- return
- end
- end
-
- local th = ngx.thread.spawn(resolve)
- local ok, err = ngx.thread.kill(th)
- if not ok then
- ngx.log(ngx.ALERT, "kill thread failed: ", err)
- return
- end
-
- local sock2, err = ngx.socket.connect("127.0.0.1", port, opts)
- if not sock2 then
- ngx.log(ngx.ALERT, "resume connect failed: ", err)
- return
- end
-
- ngx.log(ngx.INFO, "resume success")
- }
- }
---- request
-GET /t
---- no_error_log
-[alert]
---- error_log
-resume success
-
-
-
-=== TEST 50: conn queuing: increase the counter for connections created before creating the pool with setkeepalive()
---- config
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- location /t {
- content_by_lua_block {
- local function connect()
- local sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port)
- if not sock then
- error("connect failed: " .. err)
- end
-
- return sock
- end
-
- local sock1 = connect()
- local sock2 = connect()
- assert(sock1:setkeepalive())
- assert(sock2:setkeepalive())
-
- local sock1 = connect()
- local sock2 = connect()
- assert(sock1:close())
- assert(sock2:close())
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- no_error_log
-[error]
---- response_body
-ok
-
-
-
-=== TEST 51: conn queuing: only decrease the counter for connections which were counted by the pool
---- config
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- location /t {
- content_by_lua_block {
- local function connect()
- local sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port)
- if not sock then
- error("connect failed: " .. err)
- end
-
- return sock
- end
-
- local sock1 = connect()
- local sock2 = connect()
- assert(sock1:setkeepalive(1000, 1))
- assert(sock2:setkeepalive(1000, 1))
-
- local sock1 = connect()
- local sock2 = connect()
- assert(sock1:close())
- assert(sock2:close())
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- no_error_log
-[error]
---- response_body
-ok
-
-
-
-=== TEST 52: conn queuing: clean up pending connect operations which are in queue
---- config
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- location /sub {
- content_by_lua_block {
- local opts = {pool = "test", pool_size = 1, backlog = 1}
- local sock, err = ngx.socket.connect("127.0.0.1", ngx.var.port, opts)
- if not sock then
- ngx.say("connect failed: " .. err)
- return
- end
-
- local function f()
- assert(ngx.socket.connect("127.0.0.1", ngx.var.port, opts))
- end
-
- local th = ngx.thread.spawn(f)
- local ok, err = ngx.thread.kill(th)
- if not ok then
- ngx.log(ngx.ERR, "kill thread failed: ", err)
- return
- end
-
- sock:close()
- }
- }
-
- location /t {
- content_by_lua_block {
- ngx.location.capture("/sub")
- -- let pending connect operation resumes first
- ngx.sleep(0)
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- no_error_log
-[error]
---- error_log
-lua tcp socket abort queueing
---- response_body
-ok
-
-
-
-=== TEST 53: custom pools in third parameters for unix domain socket
---- http_config eval
-"
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
- server {
- listen unix:$::HtmlDir/nginx.sock;
- default_type 'text/plain';
-
- server_tokens off;
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
- }
-"
---- config
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
- content_by_lua '
- local test = require "test"
- local path = "$TEST_NGINX_HTML_DIR/nginx.sock";
- test.go(path, "A")
- test.go(path, "B")
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-function go(path, pool)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("unix:" .. path, nil, {pool = pool})
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-end
---- request
-GET /t
---- response_body
-connected: 1, reused: 0
-connected: 1, reused: 0
---- no_error_log eval
-["[error]",
-"lua tcp socket keepalive: free connection pool for ",
-"lua tcp socket get keepalive peer: using connection"
-]
---- error_log
-lua tcp socket keepalive create connection pool for key "A"
-lua tcp socket keepalive create connection pool for key "B"
-
-
-
-=== TEST 54: wrong first argument for setkeepalive
---- quic_max_idle_timeout: 1.2
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keepalive\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\r\n0\r\n\r\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ok, err = sock:setkeepalive("not a number", "not a number")
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
- }
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- error_code:
---- response_body
---- error_log eval
-qr/\Qbad argument #1 to 'setkeepalive' (number expected, got string)\E/
---- no_error_log
-[crit]
---- timeout: 4
---- curl_error eval
-qr{HTTP/3 stream 0 reset by server}
-
-
-
-=== TEST 55: wrong second argument for setkeepalive
---- quic_max_idle_timeout: 1.2
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- keepalive_timeout 60s;
-
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keepalive\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("\r\n0\r\n\r\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response of ", #data, " bytes")
-
- ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ok, err = sock:setkeepalive(10, "not a number")
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
- }
- }
-
- location /foo {
- echo foo;
- }
-
- location /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
---- error_code:
---- response_body
---- error_log eval
-qr/\Qbad argument #2 to 'setkeepalive' (number expected, got string)\E/
---- no_error_log
-[crit]
---- timeout: 4
---- curl_error eval
-qr{HTTP/3 stream 0 reset by server}
diff --git a/src/deps/src/lua-nginx-module/t/069-null.t b/src/deps/src/lua-nginx-module/t/069-null.t
deleted file mode 100644
index e4c26afb9..000000000
--- a/src/deps/src/lua-nginx-module/t/069-null.t
+++ /dev/null
@@ -1,95 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-#master_on();
-#workers(1);
-#log_level('debug');
-#log_level('warn');
-#worker_connections(1024);
-
-plan tests => repeat_each() * (blocks() * 3 + 1);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
-
-our $LuaCpath = $ENV{LUA_CPATH} ||
- '/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;';
-
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: compare ngx.null with cjson.null
---- http_config eval
- "lua_package_cpath '$::LuaCpath';";
---- config
- location /lua {
- content_by_lua '
- local cjson = require "cjson"
- ngx.say(cjson.null == ngx.null)
- ngx.say(cjson.encode(ngx.null))
- ';
- }
---- request
-GET /lua
---- response_body
-true
-null
---- no_error_log
-[error]
-
-
-
-=== TEST 2: output ngx.null
---- config
- location /lua {
- content_by_lua '
- ngx.say("ngx.null: ", ngx.null)
- ';
- }
---- request
-GET /lua
---- response_body
-ngx.null: null
---- no_error_log
-[error]
-
-
-
-=== TEST 3: output ngx.null in a table
---- config
- location /lua {
- content_by_lua '
- ngx.say({"ngx.null: ", ngx.null})
- ';
- }
---- request
-GET /lua
---- response_body
-ngx.null: null
---- no_error_log
-[error]
-
-
-
-=== TEST 4: log ngx.null
---- config
- location /lua {
- content_by_lua '
- print("ngx.null: ", ngx.null)
- ngx.say("done")
- ';
- }
---- request
-GET /lua
---- response_body
-done
---- error_log
-ngx.null: null
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/070-sha1.t b/src/deps/src/lua-nginx-module/t/070-sha1.t
deleted file mode 100644
index 62823a925..000000000
--- a/src/deps/src/lua-nginx-module/t/070-sha1.t
+++ /dev/null
@@ -1,70 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: set sha1 hello
---- config
- location = /sha1 {
- content_by_lua 'ngx.say(ngx.encode_base64(ngx.sha1_bin("hello")))';
- }
---- request
-GET /sha1
---- response_body
-qvTGHdzF6KLavt4PO0gs2a6pQ00=
---- no_error_log
-[error]
-
-
-
-=== TEST 2: set sha1 ""
---- config
- location = /sha1 {
- content_by_lua 'ngx.say(ngx.encode_base64(ngx.sha1_bin("")))';
- }
---- request
-GET /sha1
---- response_body
-2jmj7l5rSw0yVb/vlWAYkK/YBwk=
---- no_error_log
-[error]
-
-
-
-=== TEST 3: set sha1 nil
---- config
- location = /sha1 {
- content_by_lua 'ngx.say(ngx.encode_base64(ngx.sha1_bin(nil)))';
- }
---- request
-GET /sha1
---- response_body
-2jmj7l5rSw0yVb/vlWAYkK/YBwk=
---- no_error_log
-[error]
-
-
-
-=== TEST 4: set sha1 number
---- config
- location = /sha1 {
- content_by_lua 'ngx.say(ngx.encode_base64(ngx.sha1_bin(512)))';
- }
---- request
-GET /sha1
---- response_body
-zgmxJ9SPg4aKRWReJG07UvS97L4=
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/071-idle-socket.t b/src/deps/src/lua-nginx-module/t/071-idle-socket.t
deleted file mode 100644
index 49d45a1b5..000000000
--- a/src/deps/src/lua-nginx-module/t/071-idle-socket.t
+++ /dev/null
@@ -1,433 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-no_long_string();
-#no_diff();
-#log_level 'warn';
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: read events come when socket is idle
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("foofoo\\r\\n")
- local line, err, part = reader()
- if line then
- ngx.print("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
-
- ngx.location.capture("/sleep")
-
- local data, err, part = sock:receive("*a")
- if not data then
- ngx.say("failed to read the 2nd part: ", err)
- else
- ngx.say("2nd part: [", data, "]")
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /sleep {
- echo_sleep 0.5;
- more_clear_headers Date;
- }
-
- location /foo {
- echo -n foofoo;
- echo_flush;
- echo_sleep 0.3;
- echo -n barbar;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: HTTP/1.1 200 OK\r
-Server: nginx\r
-Content-Type: text/plain\r
-Transfer-Encoding: chunked\r
-Connection: close\r
-\r
-6\r
-2nd part: [6\r
-barbar\r
-0\r
-\r
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 2: read timer cleared in time
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- sock:settimeout(400)
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- end
-
- ngx.location.capture("/sleep")
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent again: ", bytes)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /sleep {
- echo_sleep 0.5;
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 11
-received: OK
-request sent again: 11
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 3: connect timer cleared in time
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- sock:settimeout(300)
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- ngx.location.capture("/sleep")
-
- local req = "flush_all\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /sleep {
- echo_sleep 0.5;
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 11
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 4: send timer cleared in time
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- sock:settimeout(300)
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- ngx.location.capture("/sleep")
-
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- return
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /sleep {
- echo_sleep 0.5;
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 11
-received: OK
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 5: set keepalive when system socket recv buffer has unread data
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local reader = sock:receiveuntil("foofoo\\r\\n")
- local line, err, part = reader()
- if line then
- ngx.print("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
-
- ngx.location.capture("/sleep")
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set keepalive: ", err)
- end
- ';
- }
-
- location /sleep {
- echo_sleep 0.5;
- more_clear_headers Date;
- }
-
- location /foo {
- echo -n foofoo;
- echo_flush;
- echo_sleep 0.3;
- echo -n barbar;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body_like eval
-qr{connected: 1
-request sent: 57
-read: HTTP/1\.1 200 OK\r
-Server: nginx\r
-Content-Type: text/plain\r
-Transfer-Encoding: chunked\r
-Connection: close\r
-\r
-6\r
-failed to set keepalive: (?:unread data in buffer|closed|connection in dubious state)
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 6: set keepalive when cosocket recv buffer has unread data
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- local data, err = sock:receive(1)
- if not data then
- ngx.say("failed to read the 1st byte: ", err)
- return
- end
-
- ngx.say("read: ", data)
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set keepalive: ", err)
- end
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 11
-read: O
-failed to set keepalive: unread data in buffer
-}
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/072-conditional-get.t b/src/deps/src/lua-nginx-module/t/072-conditional-get.t
deleted file mode 100644
index 7cf2dcd22..000000000
--- a/src/deps/src/lua-nginx-module/t/072-conditional-get.t
+++ /dev/null
@@ -1,90 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: If-Modified-Since true
---- config
- location /lua {
- content_by_lua '
- ngx.header.last_modified = "Thu, 10 May 2012 07:50:59 GMT"
- ngx.say("hello")
- ';
- }
---- request
-GET /lua
---- more_headers
-If-Modified-Since: Thu, 10 May 2012 07:50:59 GMT
---- response_body
---- error_code: 304
---- no_error_log
-[error]
-
-
-
-=== TEST 2: If-Modified-Since true
---- config
- location /lua {
- if_modified_since before;
- content_by_lua '
- ngx.header.last_modified = "Thu, 10 May 2012 07:50:48 GMT"
- ngx.say("hello")
- ';
- }
---- request
-GET /lua
---- more_headers
-If-Modified-Since: Thu, 10 May 2012 07:50:59 GMT
---- response_body
---- error_code: 304
---- no_error_log
-[error]
-
-
-
-=== TEST 3: If-Unmodified-Since false
---- config
- location /lua {
- #if_modified_since before;
- content_by_lua '
- ngx.header.last_modified = "Thu, 10 May 2012 07:50:48 GMT"
- local ok, err = ngx.say("hello")
- if not ok then
- ngx.log(ngx.WARN, "say failed: ", err)
- end
- ';
- }
---- request
-GET /lua
---- more_headers
-If-Unmodified-Since: Thu, 10 May 2012 07:50:47 GMT
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-
---- response_body_like: 412 Precondition Failed
---- error_code: 412
---- error_log
-say failed: nginx output filter error
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/073-backtrace.t b/src/deps/src/lua-nginx-module/t/073-backtrace.t
deleted file mode 100644
index 663c3afec..000000000
--- a/src/deps/src/lua-nginx-module/t/073-backtrace.t
+++ /dev/null
@@ -1,189 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * 51;
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /lua {
- content_by_lua
- ' local function bar()
- return lua_concat(3)
- end
- local function foo()
- bar()
- end
- foo()
- ';
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-attempt to call global 'lua_concat'
-: in function 'bar'
-:5: in function 'foo'
-:7: in main chunk
-
-
-
-=== TEST 2: error(nil)
---- config
- location /lua {
- content_by_lua
- ' local function bar()
- error(nil)
- end
- local function foo()
- bar()
- end
- foo()
- ';
- }
---- request
-GET /lua
---- ignore_response
---- error_log eval
-[
-'lua entry thread aborted: runtime error: unknown reason',
-'stack traceback:',
-" in function 'error'",
-": in function 'bar'",
-":5: in function 'foo'",
-qr/:7: in main chunk/,
-]
-
-
-
-=== TEST 3: deep backtrace in a single coroutine (more than 15)
---- config eval
-my $s = "
- location /lua {
- content_by_lua '
-";
-my $prev;
-for my $i (1..18) {
- if (!defined $prev) {
- $s .= "
- local function func$i()
- return error([[blah]])
- end";
- } else {
- $s .= "
- local function func$i()
- local v = func$prev()
- return v
- end";
- }
- $prev = $i;
-}
-$s .= "
- func$prev()
- ';
- }
-";
---- request
-GET /lua
---- stap2
-probe process("$LIBLUA_PATH").function("lua_concat") {
- println("lua concat")
- //print_ubacktrace()
-}
---- stap_out2
---- ignore_response
---- error_log
-: blah
-: in function 'func1'
-:7: in function 'func2'
-:11: in function 'func3'
-:15: in function 'func4'
-:19: in function 'func5'
-:23: in function 'func6'
-:27: in function 'func7'
-:31: in function 'func8'
-:35: in function 'func9'
-:39: in function 'func10'
-:43: in function 'func11'
-:47: in function 'func12'
-:51: in function 'func13'
-:55: in function 'func14'
-:59: in function 'func15'
-:63: in function 'func16'
-:67: in function 'func17'
-:71: in function 'func18'
-:74: in main chunk
-
-
-
-=== TEST 4: deep backtrace in a single coroutine (more than 22)
---- config eval
-my $s = "
- location /lua {
- content_by_lua '
-";
-my $prev;
-for my $i (1..23) {
- if (!defined $prev) {
- $s .= "
- local function func$i()
- return error([[blah]])
- end";
- } else {
- $s .= "
- local function func$i()
- local v = func$prev()
- return v
- end";
- }
- $prev = $i;
-}
-$s .= "
- func$prev()
- ';
- }
-";
---- request
-GET /lua
---- stap2
-probe process("$LIBLUA_PATH").function("lua_concat") {
- println("lua concat")
- //print_ubacktrace()
-}
---- stap_out2
---- ignore_response
---- error_log
-: blah
-: in function 'func1'
-:7: in function 'func2'
-:11: in function 'func3'
-:15: in function 'func4'
-:19: in function 'func5'
-:23: in function 'func6'
-:27: in function 'func7'
-:31: in function 'func8'
-:35: in function 'func9'
-:39: in function 'func10'
-:43: in function 'func11'
-:47: in function 'func12'
-:59: in function 'func15'
-:63: in function 'func16'
-:67: in function 'func17'
-:71: in function 'func18'
-:75: in function 'func19'
-:79: in function 'func20'
-:83: in function 'func21'
-...
diff --git a/src/deps/src/lua-nginx-module/t/074-prefix-var.t b/src/deps/src/lua-nginx-module/t/074-prefix-var.t
deleted file mode 100644
index c116d8465..000000000
--- a/src/deps/src/lua-nginx-module/t/074-prefix-var.t
+++ /dev/null
@@ -1,66 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: $prefix
---- http_config: lua_package_path "$prefix/html/?.lua;;";
---- config
- location /t {
- content_by_lua '
- local foo = require "foo"
- foo.go()
- ';
- }
---- user_files
->>> foo.lua
-module("foo", package.seeall)
-
-function go()
- ngx.say("Greetings from module foo.")
-end
---- request
-GET /t
---- response_body
-Greetings from module foo.
---- no_error_log
-[error]
-
-
-
-=== TEST 2: ${prefix}
---- http_config: lua_package_path "${prefix}html/?.lua;;";
---- config
- location /t {
- content_by_lua '
- local foo = require "foo"
- foo.go()
- ';
- }
---- user_files
->>> foo.lua
-module("foo", package.seeall)
-
-function go()
- ngx.say("Greetings from module foo.")
-end
---- request
-GET /t
---- response_body
-Greetings from module foo.
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/075-logby.t b/src/deps/src/lua-nginx-module/t/075-logby.t
deleted file mode 100644
index 3e9743584..000000000
--- a/src/deps/src/lua-nginx-module/t/075-logby.t
+++ /dev/null
@@ -1,595 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 10);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: log_by_lua
---- config
- location /lua {
- echo hello;
- log_by_lua 'ngx.log(ngx.ERR, "Hello from log_by_lua: ", ngx.var.uri)';
- }
---- request
-GET /lua
---- response_body
-hello
---- error_log
-Hello from log_by_lua: /lua
-
-
-
-=== TEST 2: log_by_lua_file
---- config
- location /lua {
- echo hello;
- log_by_lua_file html/a.lua;
- }
---- user_files
->>> a.lua
-ngx.log(ngx.ERR, "Hello from log_by_lua: ", ngx.var.uri)
---- request
-GET /lua
---- response_body
-hello
---- error_log
-Hello from log_by_lua: /lua
-
-
-
-=== TEST 3: log_by_lua_file & content_by_lua
---- config
- location /lua {
- set $counter 3;
- content_by_lua 'ngx.var.counter = ngx.var.counter + 1 ngx.say(ngx.var.counter)';
- log_by_lua_file html/a.lua;
- }
---- user_files
->>> a.lua
-ngx.log(ngx.ERR, "Hello from log_by_lua: ", ngx.var.counter * 2)
---- request
-GET /lua
---- response_body
-4
---- error_log
-Hello from log_by_lua: 8
-
-
-
-=== TEST 4: ngx.ctx available in log_by_lua (already defined)
---- config
- location /lua {
- content_by_lua 'ngx.ctx.counter = 3 ngx.say(ngx.ctx.counter)';
- log_by_lua 'ngx.log(ngx.ERR, "ngx.ctx.counter: ", ngx.ctx.counter)';
- }
---- request
-GET /lua
---- response_body
-3
---- error_log
-ngx.ctx.counter: 3
-lua release ngx.ctx
-
-
-
-=== TEST 5: ngx.ctx available in log_by_lua (not defined yet)
---- config
- location /lua {
- echo hello;
- log_by_lua '
- ngx.log(ngx.ERR, "ngx.ctx.counter: ", ngx.ctx.counter)
- ngx.ctx.counter = "hello world"
- ';
- }
---- request
-GET /lua
---- response_body
-hello
---- error_log
-ngx.ctx.counter: nil
-lua release ngx.ctx
-
-
-
-=== TEST 6: log_by_lua + shared dict
---- http_config
- lua_shared_dict foo 100k;
---- config
- location /lua {
- echo hello;
- log_by_lua '
- local foo = ngx.shared.foo
- local key = ngx.var.uri .. ngx.status
- local newval, err = foo:incr(key, 1)
- if not newval then
- if err == "not found" then
- foo:add(key, 0)
- newval, err = foo:incr(key, 1)
- if not newval then
- ngx.log(ngx.ERR, "failed to incr ", key, ": ", err)
- return
- end
- else
- ngx.log(ngx.ERR, "failed to incr ", key, ": ", err)
- return
- end
- end
- print(key, ": ", foo:get(key))
- ';
- }
---- request
-GET /lua
---- response_body
-hello
---- error_log eval
-qr{/lua200: [12]}
---- no_error_log
-[error]
-
-
-
-=== TEST 7: ngx.ctx used in different locations and different ctx (1)
---- config
- location /t {
- echo hello;
- log_by_lua '
- ngx.log(ngx.ERR, "ngx.ctx.counter: ", ngx.ctx.counter)
- ';
- }
-
- location /t2 {
- content_by_lua '
- ngx.ctx.counter = 32
- ngx.say("hello")
- ';
- }
---- request
-GET /t
---- response_body
-hello
---- error_log
-ngx.ctx.counter: nil
-lua release ngx.ctx
-
-
-
-=== TEST 8: ngx.ctx used in different locations and different ctx (2)
---- config
- location /t {
- echo hello;
- log_by_lua '
- ngx.log(ngx.ERR, "ngx.ctx.counter: ", ngx.ctx.counter)
- ';
- }
-
- location /t2 {
- content_by_lua '
- ngx.ctx.counter = 32
- ngx.say(ngx.ctx.counter)
- ';
- }
---- request
-GET /t2
---- response_body
-32
---- error_log
-lua release ngx.ctx
-
-
-
-=== TEST 9: lua error (string)
---- config
- location /lua {
- log_by_lua 'error("Bad")';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log eval
-qr/failed to run log_by_lua\*: log_by_lua\(nginx\.conf:\d+\):1: Bad/
-
-
-
-=== TEST 10: lua error (nil)
---- config
- location /lua {
- log_by_lua 'error(nil)';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-failed to run log_by_lua*: unknown reason
-
-
-
-=== TEST 11: globals sharing
---- config
- location /lua {
- echo ok;
- log_by_lua '
- if not foo then
- foo = 1
- else
- ngx.log(ngx.INFO, "old foo: ", foo)
- foo = foo + 1
- end
- ngx.log(ngx.WARN, "foo = ", foo)
- ';
- }
---- request
-GET /lua
---- response_body
-ok
---- grep_error_log eval: qr/old foo: \d+/
---- grep_error_log_out eval
-["", "old foo: 1\n"]
-
-
-
-=== TEST 12: no ngx.print
---- config
- location /lua {
- log_by_lua "ngx.print(32) return 1";
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 13: no ngx.say
---- config
- location /lua {
- log_by_lua "ngx.say(32) return 1";
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 14: no ngx.flush
---- config
- location /lua {
- log_by_lua "ngx.flush()";
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 15: no ngx.eof
---- config
- location /lua {
- log_by_lua "ngx.eof()";
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 16: no ngx.send_headers
---- config
- location /lua {
- log_by_lua "ngx.send_headers()";
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 17: no ngx.location.capture
---- config
- location /lua {
- log_by_lua 'ngx.location.capture("/sub")';
- echo ok;
- }
-
- location /sub {
- echo sub;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 18: no ngx.location.capture_multi
---- config
- location /lua {
- log_by_lua 'ngx.location.capture_multi{{"/sub"}}';
- echo ok;
- }
-
- location /sub {
- echo sub;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 19: no ngx.exit
---- config
- location /lua {
- log_by_lua 'ngx.exit(0)';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 20: no ngx.redirect
---- config
- location /lua {
- log_by_lua 'ngx.redirect("/blah")';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 21: no ngx.exec
---- config
- location /lua {
- log_by_lua 'ngx.exec("/blah")';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 22: no ngx.req.set_uri(uri, true)
---- config
- location /lua {
- log_by_lua 'ngx.req.set_uri("/blah", true)';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 23: ngx.req.set_uri(uri) exists
---- config
- location /lua {
- log_by_lua 'ngx.req.set_uri("/blah") print("log_by_lua: uri: ", ngx.var.uri)';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-log_by_lua: uri: /blah
-
-
-
-=== TEST 24: no ngx.req.read_body()
---- config
- location /lua {
- log_by_lua 'ngx.req.read_body()';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 25: no ngx.req.socket()
---- config
- location /lua {
- log_by_lua 'return ngx.req.socket()';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log eval
-my $err_log;
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $err_log = "http v3 not supported yet";
-} else {
- $err_log = "API disabled in the context of log_by_lua*";
-}
-
-$err_log;
-
-
-
-=== TEST 26: no ngx.socket.tcp()
---- config
- location /lua {
- log_by_lua 'return ngx.socket.tcp()';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 27: no ngx.socket.connect()
---- config
- location /lua {
- log_by_lua 'return ngx.socket.connect("127.0.0.1", 80)';
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 28: backtrace
---- config
- location /t {
- echo ok;
- log_by_lua '
- local bar
- local function foo()
- bar()
- end
-
- function bar()
- error("something bad happened")
- end
-
- foo()
- ';
- }
---- request
- GET /t
---- response_body
-ok
---- error_log
-something bad happened
-stack traceback:
-in function 'error'
-in function 'bar'
-in function 'foo'
-
-
-
-=== TEST 29: Lua file does not exist
---- config
- location /lua {
- echo ok;
- log_by_lua_file html/test2.lua;
- }
---- user_files
->>> test.lua
-v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- response_body
-ok
---- error_log eval
-qr/failed to load external Lua file ".*?test2\.lua": cannot open .*? No such file or directory/
-
-
-
-=== TEST 30: log_by_lua runs before access logging (github issue #254)
---- config
- location /lua {
- echo ok;
- access_log logs/foo.log;
- log_by_lua 'print("hello")';
- }
---- request
-GET /lua
---- stap
-F(ngx_http_log_handler) {
- println("log handler")
-}
-F(ngx_http_lua_log_handler) {
- println("lua log handler")
-}
---- stap_out
-lua log handler
-log handler
-
---- response_body
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 31: reading ngx.header.HEADER in log_by_lua
---- config
- location /lua {
- echo ok;
- log_by_lua 'ngx.log(ngx.WARN, "content-type: ", ngx.header.content_type)';
- }
---- request
-GET /lua
-
---- response_body
-ok
---- error_log eval
-qr{log_by_lua\(nginx\.conf:\d+\):1: content-type: text/plain}
-
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/076-no-postpone.t b/src/deps/src/lua-nginx-module/t/076-no-postpone.t
deleted file mode 100644
index 94da63a52..000000000
--- a/src/deps/src/lua-nginx-module/t/076-no-postpone.t
+++ /dev/null
@@ -1,146 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3 + 1);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: rewrite no postpone on
---- http_config
- rewrite_by_lua_no_postpone on;
---- config
- set $foo '';
- location /t {
- rewrite_by_lua '
- ngx.var.foo = 1
- ';
- if ($foo = 1) {
- echo "foo: $foo";
- }
- echo "no foo: $foo";
- }
---- request
-GET /t
---- response_body
-foo: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 2: rewrite no postpone explicitly off
---- http_config
- rewrite_by_lua_no_postpone off;
---- config
- set $foo '';
- location /t {
- rewrite_by_lua '
- ngx.var.foo = 1
- ';
- if ($foo = 1) {
- echo "foo: $foo";
- }
- echo "no foo: $foo";
- }
---- request
-GET /t
---- response_body
-no foo: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 3: rewrite no postpone off by default
---- config
- set $foo '';
- location /t {
- rewrite_by_lua '
- ngx.var.foo = 1
- ';
- if ($foo = 1) {
- echo "foo: $foo";
- }
- echo "no foo: $foo";
- }
---- request
-GET /t
---- response_body
-no foo: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 4: access no postpone on
---- http_config
- access_by_lua_no_postpone on;
---- config
- location /t {
- access_by_lua '
- ngx.redirect("http://www.taobao.com/foo")
- ngx.say("hi")
- ';
- content_by_lua 'return';
- deny all;
- }
---- request
-GET /t
---- response_headers
-Location: http://www.taobao.com/foo
---- response_body_like: 302 Found
---- error_code: 302
---- no_error_log
-[error]
-
-
-
-=== TEST 5: access no postpone explicitly off
---- http_config
- access_by_lua_no_postpone off;
---- config
- location /t {
- access_by_lua '
- ngx.redirect("http://www.taobao.com/foo")
- ngx.say("hi")
- ';
- content_by_lua 'return';
- deny all;
- }
---- request
-GET /t
---- response_body_like: 403 Forbidden
---- error_code: 403
---- error_log
-access forbidden by rule
-
-
-
-=== TEST 6: access no postpone off by default
---- config
- location /t {
- access_by_lua '
- ngx.redirect("http://www.taobao.com/foo")
- ngx.say("hi")
- ';
- content_by_lua 'return';
- deny all;
- }
---- request
-GET /t
---- response_body_like: 403 Forbidden
---- error_code: 403
---- error_log
-access forbidden by rule
diff --git a/src/deps/src/lua-nginx-module/t/077-sleep.t b/src/deps/src/lua-nginx-module/t/077-sleep.t
deleted file mode 100644
index 4867b9ca7..000000000
--- a/src/deps/src/lua-nginx-module/t/077-sleep.t
+++ /dev/null
@@ -1,505 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * 71;
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sleep 0.5 - content
---- config
- location /test {
- content_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.sleep(0.5)
- local now = ngx.now()
- ngx.say(now - before)
- ';
- }
---- request
-GET /test
---- response_body_like chop
-^0\.(?:4[5-9]\d*|5[0-5]\d*|5)$
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
-lua sleep timer expired: "/test?"
-
-
-
-=== TEST 2: sleep a - content
---- config
- location /test {
- content_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.sleep("a")
- local now = ngx.now()
- ngx.say(now - before)
- ';
- }
---- request
-GET /test
---- error_code: 500
---- response_body_like: 500 Internal Server Error
---- error_log
-bad argument #1 to 'sleep'
-
-
-
-=== TEST 3: sleep 0.5 in subrequest - content
---- config
- location /test {
- content_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.location.capture("/sleep")
- local now = ngx.now()
- local delay = now - before
- ngx.say(delay)
- ';
- }
- location /sleep {
- content_by_lua 'ngx.sleep(0.5)';
- }
---- request
-GET /test
---- response_body_like chop
-^0\.(?:4[5-9]\d*|5[0-9]\d*|5)$
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/sleep?"
---- no_error_log
-[error]
-
-
-
-=== TEST 4: sleep a in subrequest with bad argument
---- config
- location /test {
- content_by_lua '
- local res = ngx.location.capture("/sleep");
- ';
- }
- location /sleep {
- content_by_lua 'ngx.sleep("a")';
- }
---- request
-GET /test
---- response_body_like:
---- error_log
-bad argument #1 to 'sleep'
-
-
-
-=== TEST 5: sleep 0.33 - multi-times in content
---- quic_max_idle_timeout: 1.1
---- config
- location /test {
- content_by_lua '
- ngx.update_time()
- local start = ngx.now()
- ngx.sleep(0.33)
- ngx.sleep(0.33)
- ngx.sleep(0.33)
- ngx.say(ngx.now() - start)
- ';
- }
---- request
-GET /test
---- response_body_like chop
-^(?:0\.9\d*|1\.[0-2]\d*|1)$
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 6: sleep 0.5 - interleaved by ngx.say() - ended by ngx.sleep
---- quic_max_idle_timeout: 2.2
---- config
- location /test {
- content_by_lua '
- ngx.send_headers()
- -- ngx.location.capture("/sleep")
- ngx.sleep(1)
- ngx.say("blah")
- ngx.sleep(1)
- -- ngx.location.capture("/sleep")
- ';
- }
- location = /sleep {
- echo_sleep 0.1;
- }
---- request
-GET /test
---- response_body
-blah
---- error_log
-lua ready to sleep
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 7: sleep 0.5 - interleaved by ngx.say() - not ended by ngx.sleep
---- quic_max_idle_timeout: 0.9
---- config
- location /test {
- content_by_lua '
- ngx.send_headers()
- -- ngx.location.capture("/sleep")
- ngx.sleep(0.3)
- ngx.say("blah")
- ngx.sleep(0.5)
- -- ngx.location.capture("/sleep")
- ngx.say("hiya")
- ';
- }
- location = /sleep {
- echo_sleep 0.1;
- }
---- request
-GET /test
---- response_body
-blah
-hiya
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 8: ngx.location.capture before and after ngx.sleep
---- config
- location /test {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
-
- ngx.sleep(0.1)
-
- res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ';
- }
- location = /hello {
- echo hello world;
- }
- location = /sub {
- proxy_pass http://127.0.0.1:$server_port/hello;
- }
---- request
-GET /test
---- response_body
-hello world
-hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 9: sleep 0
---- config
- location /test {
- content_by_lua '
- ngx.update_time()
- local before = ngx.now()
- ngx.sleep(0)
- local now = ngx.now()
- ngx.say("elapsed: ", now - before)
- ';
- }
---- request
-GET /test
---- response_body_like chop
-elapsed: 0
---- error_log
-lua ready to sleep for
-lua sleep timer expired: "/test?"
-lua sleep timer expired: "/test?"
---- no_error_log
-[error]
-
-
-
-=== TEST 10: ngx.sleep unavailable in log_by_lua
---- config
- location /t {
- echo hello;
- log_by_lua '
- ngx.sleep(0.1)
- ';
- }
---- request
-GET /t
---- response_body
-hello
---- wait: 0.1
---- error_log
-API disabled in the context of log_by_lua*
-
-
-
-=== TEST 11: ngx.sleep() fails to yield (xpcall err handler)
---- config
- location = /t {
- content_by_lua '
- local function f()
- return error(1)
- end
- local function err()
- ngx.sleep(0.001)
- end
- xpcall(f, err)
- ngx.say("ok")
- ';
- }
---- request
- GET /t
---- response_body
-ok
---- error_log
-lua clean up the timer for pending ngx.sleep
---- no_error_log
-[error]
-
-
-
-=== TEST 12: ngx.sleep() fails to yield (require)
---- http_config
- lua_package_path "$prefix/html/?.lua;;";
---- config
- location = /t {
- content_by_lua '
- package.loaded["foosleep"] = nil
- require "foosleep";
- ';
- }
---- request
- GET /t
---- user_files
->>> foosleep.lua
-ngx.sleep(0.001)
-
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- wait: 0.2
---- error_log eval
-[
-"lua clean up the timer for pending ngx.sleep",
-qr{runtime error: attempt to yield across (?:metamethod/)?C-call boundary},
-]
-
-
-
-=== TEST 13: sleep coctx handler did not get called in ngx.exit().
---- config
- location /t {
- content_by_lua "
- local function sleep(t)
- --- nginx return reply to client without waiting
- ngx.sleep(t)
- end
-
- local function wait()
- --- worker would crash afterwards
- xpcall(function () error(1) end, function() return sleep(0.001) end)
- --- ngx.exit was required to crash worker
- ngx.exit(200)
- end
-
- wait()
- ";
- }
---- request
- GET /t
-
---- wait: 0.1
---- response_body
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 14: sleep coctx handler did not get called in ngx.exec().
---- config
- location /t {
- content_by_lua '
- local function sleep(t)
- --- nginx return reply to client without waiting
- ngx.sleep(t)
- end
-
- local function wait()
- --- worker would crash afterwards
- xpcall(function () error(1) end, function() return sleep(0.001) end)
- --- ngx.exit was required to crash worker
- ngx.exec("/dummy")
- end
-
- wait()
- ';
- }
-
- location /dummy {
- echo ok;
- }
---- request
- GET /t
-
---- wait: 0.1
---- response_body
-ok
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 15: sleep coctx handler did not get called in ngx.req.set_uri(uri, true).
---- config
- location /t {
- rewrite_by_lua '
- local function sleep(t)
- --- nginx return reply to client without waiting
- ngx.sleep(t)
- end
-
- local function wait()
- --- worker would crash afterwards
- xpcall(function () error(1) end, function() return sleep(0.001) end)
- --- ngx.exit was required to crash worker
- ngx.req.set_uri("/dummy", true)
- end
-
- wait()
- ';
- }
-
- location /dummy {
- echo ok;
- }
---- request
- GET /t
-
---- wait: 0.1
---- response_body
-ok
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 16: sleep 0
---- config
- location /t {
- content_by_lua_block {
- local function f (n)
- print("f begin ", n)
- ngx.sleep(0)
- print("f middle ", n)
- ngx.sleep(0)
- print("f end ", n)
- ngx.sleep(0)
- end
-
- for i = 1, 3 do
- assert(ngx.thread.spawn(f, i))
- end
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/\bf (?:begin|middle|end)\b|\bworker cycle$|\be?poll timer: \d+$/
---- grep_error_log_out eval
-qr/f begin
-f begin
-f begin
-worker cycle
-e?poll timer: 0
-f middle
-f middle
-f middle
-worker cycle
-e?poll timer: 0
-f end
-f end
-f end
-worker cycle
-e?poll timer: 0
-/
-
-
-
-=== TEST 17: sleep short times less than 1ms
---- config
- location /t {
- content_by_lua_block {
- local delay = 0.0005
-
- local function f (n)
- print("f begin ", n)
- ngx.sleep(delay)
- print("f middle ", n)
- ngx.sleep(delay)
- print("f end ", n)
- ngx.sleep(delay)
- end
-
- for i = 1, 3 do
- assert(ngx.thread.spawn(f, i))
- end
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/\bf (?:begin|middle|end)\b|\bworker cycle$|\be?poll timer: \d+$/
---- grep_error_log_out eval
-qr/f begin
-f begin
-f begin
-worker cycle
-e?poll timer: 0
-f middle
-f middle
-f middle
-worker cycle
-e?poll timer: 0
-f end
-f end
-f end
-worker cycle
-e?poll timer: 0
-/
diff --git a/src/deps/src/lua-nginx-module/t/078-hup-vars.t b/src/deps/src/lua-nginx-module/t/078-hup-vars.t
deleted file mode 100644
index 5072c4d29..000000000
--- a/src/deps/src/lua-nginx-module/t/078-hup-vars.t
+++ /dev/null
@@ -1,64 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_CHECK_LEAK}) {
- $SkipReason = "unavailable for the hup tests";
-
- } else {
- $ENV{TEST_NGINX_USE_HUP} = 1;
- undef $ENV{TEST_NGINX_USE_STAP};
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (3 * blocks());
-
-#no_diff();
-#no_long_string();
-no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: nginx variable hup bug (step 1)
-http://mailman.nginx.org/pipermail/nginx-devel/2012-May/002223.html
---- config
- location /t {
- set $vv $http_host;
- set_by_lua $i 'return ngx.var.http_host';
- echo $i;
- }
---- request
-GET /t
---- response_body
-localhost
---- no_error_log
-[error]
-
-
-
-=== TEST 2: nginx variable hup bug (step 2)
-http://mailman.nginx.org/pipermail/nginx-devel/2012-May/002223.html
---- config
- location /t {
- #set $vv $http_host;
- set_by_lua $i 'return ngx.var.http_host';
- echo $i;
- }
---- request
-GET /t
---- response_body
-localhost
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/079-unused-directives.t b/src/deps/src/lua-nginx-module/t/079-unused-directives.t
deleted file mode 100644
index aacd0d31d..000000000
--- a/src/deps/src/lua-nginx-module/t/079-unused-directives.t
+++ /dev/null
@@ -1,342 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * 110;
-
-#no_diff();
-#no_long_string();
-#no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: rewrite_by_lua unused
---- config
- location /t {
- set_by_lua $i 'return 32';
- #rewrite_by_lua return;
- echo $i;
- }
---- request
-GET /t
---- response_body
-32
---- no_error_log
-lua capture header filter, uri "/t"
-lua capture body filter, uri "/t"
-lua rewrite handler, uri:"/t"
-lua access handler, uri:"/t"
-lua content handler, uri:"/t"
-lua header filter for user lua code, uri "/t"
-lua body filter for user lua code, uri "/t"
-lua log handler, uri:"/t"
-[error]
-
-
-
-=== TEST 2: rewrite_by_lua used
---- config
- location /t {
- rewrite_by_lua return;
- echo hello;
- }
---- request
-GET /t
---- response_body
-hello
---- error_log
-lua rewrite handler, uri:"/t"
-lua capture header filter, uri "/t"
-lua capture body filter, uri "/t"
---- no_error_log
-lua access handler, uri:"/t"
-lua content handler, uri:"/t"
-lua header filter for user lua code, uri "/t"
-lua body filter for user lua code, uri "/t"
-lua log handler, uri:"/t"
-[error]
---- log_level: debug
-
-
-
-=== TEST 3: access_by_lua used
---- config
- location /t {
- access_by_lua return;
- echo hello;
- }
---- request
-GET /t
---- response_body
-hello
---- error_log
-lua access handler, uri:"/t" c:1
-lua capture body filter, uri "/t"
-lua capture header filter, uri "/t"
---- no_error_log
-lua rewrite handler, uri:"/t"
-lua content handler, uri:"/t"
-lua header filter for user lua code, uri "/t"
-lua body filter for user lua code, uri "/t"
-lua log handler, uri:"/t"
-[error]
-
-
-
-=== TEST 4: content_by_lua used
---- config
- location /t {
- content_by_lua 'ngx.say("hello")';
- }
---- request
-GET /t
---- response_body
-hello
---- error_log
-lua content handler, uri:"/t" c:1
-lua capture body filter, uri "/t"
-lua capture header filter, uri "/t"
---- no_error_log
-lua access handler, uri:"/t"
-lua rewrite handler, uri:"/t"
-lua header filter for user lua code, uri "/t"
-lua body filter for user lua code, uri "/t"
-lua log handler, uri:"/t"
-[error]
-
-
-
-=== TEST 5: header_filter_by_lua
---- config
- location /t {
- echo hello;
- header_filter_by_lua return;
- }
---- request
-GET /t
---- response_body
-hello
---- error_log
-lua header filter for user lua code, uri "/t"
---- no_error_log
-lua capture header filter, uri "/t"
-lua content handler, uri:"/t"
-lua access handler, uri:"/t"
-lua rewrite handler, uri:"/t"
-lua capture body filter, uri "/t"
-lua log handler, uri:"/t"
-lua body filter for user lua code, uri "/t"
-[error]
-
-
-
-=== TEST 6: log_by_lua
---- config
- location /t {
- echo hello;
- log_by_lua return;
- }
---- request
-GET /t
---- response_body
-hello
---- error_log
-lua log handler, uri:"/t"
---- no_error_log
-lua header filter for user lua code, uri "/t"
-lua capture header filter, uri "/t"
-lua content handler, uri:"/t"
-lua access handler, uri:"/t"
-lua rewrite handler, uri:"/t"
-lua capture body filter, uri "/t"
-lua body filter for user lua code, uri "/t"
-[error]
-
-
-
-=== TEST 7: body_filter_by_lua
---- config
- location /t {
- echo hello;
- body_filter_by_lua return;
- }
---- request
-GET /t
---- response_body
-hello
---- error_log
-lua header filter for user lua code, uri "/t"
-lua body filter for user lua code, uri "/t"
---- no_error_log
-lua capture header filter, uri "/t"
-lua content handler, uri:"/t"
-lua access handler, uri:"/t"
-lua rewrite handler, uri:"/t"
-lua capture body filter, uri "/t"
-lua log handler, uri:"/t"
-[error]
-
-
-
-=== TEST 8: header_filter_by_lua_file
---- config
- location /t {
- echo hello;
- header_filter_by_lua_file html/a.lua;
- }
---- user_files
->>> a.lua
-return
---- request
-GET /t
---- response_body
-hello
---- error_log
-lua header filter for user lua code, uri "/t"
---- no_error_log
-lua capture header filter, uri "/t"
-lua content handler, uri:"/t"
-lua access handler, uri:"/t"
-lua rewrite handler, uri:"/t"
-lua capture body filter, uri "/t"
-lua log handler, uri:"/t"
-lua body filter for user lua code, uri "/t"
-[error]
-
-
-
-=== TEST 9: log_by_lua
---- config
- location /t {
- echo hello;
- log_by_lua return;
- }
---- request
-GET /t
---- response_body
-hello
---- error_log
-lua log handler, uri:"/t"
---- no_error_log
-lua header filter for user lua code, uri "/t"
-lua capture header filter, uri "/t"
-lua content handler, uri:"/t"
-lua access handler, uri:"/t"
-lua rewrite handler, uri:"/t"
-lua capture body filter, uri "/t"
-lua body filter for user lua code, uri "/t"
-[error]
-
-
-
-=== TEST 10: body_filter_by_lua
---- config
- location /t {
- echo hello;
- body_filter_by_lua return;
- }
---- request
-GET /t
---- response_body
-hello
---- error_log
-lua header filter for user lua code, uri "/t"
-lua body filter for user lua code, uri "/t"
---- no_error_log
-lua capture header filter, uri "/t"
-lua content handler, uri:"/t"
-lua access handler, uri:"/t"
-lua rewrite handler, uri:"/t"
-lua capture body filter, uri "/t"
-lua log handler, uri:"/t"
-[error]
-
-
-
-=== TEST 11: header_filter_by_lua with multiple http blocks (github issue #294)
-This test case won't run with nginx 1.9.3+ since duplicate http {} blocks
-have been prohibited since then.
---- SKIP
---- config
- location = /t {
- echo ok;
- header_filter_by_lua '
- ngx.status = 201
- ngx.header.Foo = "foo"
- ';
-
- }
---- post_main_config
- http {
- }
---- request
-GET /t
---- response_headers
-Foo: foo
---- response_body
-ok
---- error_code: 201
---- no_error_log
-[error]
-
-
-
-=== TEST 12: body_filter_by_lua in multiple http blocks (github issue #294)
-This test case won't run with nginx 1.9.3+ since duplicate http {} blocks
-have been prohibited since then.
---- SKIP
---- config
- location = /t {
- echo -n ok;
- body_filter_by_lua '
- if ngx.arg[2] then
- ngx.arg[1] = ngx.arg[1] .. "ay\\n"
- end
- ';
-
- }
---- post_main_config
- http {
- }
---- request
-GET /t
---- response_body
-okay
---- no_error_log
-[error]
-
-
-
-=== TEST 13: capture filter with multiple http blocks (github issue #294)
-This test case won't run with nginx 1.9.3+ since duplicate http {} blocks
-have been prohibited since then.
---- SKIP
---- config
- location = /t {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.say("sub: ", res.body)
- ';
- }
-
- location = /sub {
- echo -n sub;
- }
---- post_main_config
- http {
- }
---- request
-GET /t
---- response_body
-sub: sub
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/080-hup-shdict.t b/src/deps/src/lua-nginx-module/t/080-hup-shdict.t
deleted file mode 100644
index c7625568c..000000000
--- a/src/deps/src/lua-nginx-module/t/080-hup-shdict.t
+++ /dev/null
@@ -1,84 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_CHECK_LEAK}) {
- $SkipReason = "unavailable for the hup tests";
-
- } else {
- $ENV{TEST_NGINX_USE_HUP} = 1;
- undef $ENV{TEST_NGINX_USE_STAP};
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: initialize the fields in shdict
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- dogs:set("bah", 10502)
- local val = dogs:get("foo")
- ngx.say(val, " ", type(val))
- val = dogs:get("bah")
- ngx.say(val, " ", type(val))
- ';
- }
---- request
-GET /test
---- response_body
-32 number
-10502 number
---- no_error_log
-[error]
-
-
-
-=== TEST 2: retrieve the fields in shdict after HUP reload
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- -- dogs:set("foo", 32)
- -- dogs:set("bah", 10502)
-
- local val = dogs:get("foo")
- ngx.say(val, " ", type(val))
- val = dogs:get("bah")
- ngx.say(val, " ", type(val))
- ';
- }
---- request
-GET /test
---- response_body
-32 number
-10502 number
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/081-bytecode.t b/src/deps/src/lua-nginx-module/t/081-bytecode.t
deleted file mode 100644
index 92383bcb9..000000000
--- a/src/deps/src/lua-nginx-module/t/081-bytecode.t
+++ /dev/null
@@ -1,376 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: bytecode ("ngx.say('hello');")
---- config
- root html;
- location /save_call {
- content_by_lua '
- ngx.req.read_body();
- local b = ngx.req.get_body_data();
- local f = io.open(ngx.var.realpath_root.."/test.lua", "w");
- -- luajit bytecode: sub(149,-1), lua bytecode: sub(1,147)
- if jit then
- if not string.find(jit.version, "LuaJIT 2.0") then
- ngx.say("test skipped")
- return
- end
- f:write(string.sub(b, 149));
- else
- f:write(string.sub(b, 1, 147));
- end
- f:close();
- local res = ngx.location.capture("/call");
- ngx.print(res.body)
- ';
- }
- location /call {
- content_by_lua_file $realpath_root/test.lua;
- }
---- request eval
-"POST /save_call
-\x1b\x4c\x75\x61\x51\x00\x01\x04\x08\x04\x08\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x40\x74\x65\x73\x74\x2e\x6c\x75\x61\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x02\x05\x00\x00\x00\x05\x00\x00\x00\x06\x40\x40\x00\x41\x80\x00\x00\x1c\x40\x00\x01\x1e\x00\x80\x00\x03\x00\x00\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x6e\x67\x78\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x73\x61\x79\x00\x04\x06\x00\x00\x00\x00\x00\x00\x00\x68\x65\x6c\x6c\x6f\x00\x00\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
-\x1b\x4c\x4a\x01\x02\x29\x02\x00\x02\x00\x03\x00\x05\x34\x00\x00\x00\x37\x00\x01\x00\x25\x01\x02\x00\x3e\x00\x02\x01\x47\x00\x01\x00\x0a\x68\x65\x6c\x6c\x6f\x08\x73\x61\x79\x08\x6e\x67\x78\x00"
---- response_body_like chop
-^(?:hello|test skipped)$
---- no_error_log
-[error]
-
-
-
-=== TEST 2: luajit load lua bytecode or lua load luajit bytecode
---- config
- root html;
- location /save_call {
- content_by_lua '
- ngx.req.read_body();
- local b = ngx.req.get_body_data();
- local f = io.open(ngx.var.realpath_root.."/test.lua", "w");
- -- luajit bytecode: sub(149,-1), lua bytecode: sub(1,147)
- if not package.loaded["jit"] then
- f:write(string.sub(b, 149));
- else
- f:write(string.sub(b, 1, 147));
- end
- f:close();
- local res = ngx.location.capture("/call");
- if res.status == 200 then
- ngx.print(res.body)
- else
- ngx.say("error")
- end
- ';
- }
- location /call {
- content_by_lua_file $realpath_root/test.lua;
- }
---- request eval
-"POST /save_call
-\x1b\x4c\x75\x61\x51\x00\x01\x04\x08\x04\x08\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x40\x74\x65\x73\x74\x2e\x6c\x75\x61\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x02\x05\x00\x00\x00\x05\x00\x00\x00\x06\x40\x40\x00\x41\x80\x00\x00\x1c\x40\x00\x01\x1e\x00\x80\x00\x03\x00\x00\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x6e\x67\x78\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x73\x61\x79\x00\x04\x06\x00\x00\x00\x00\x00\x00\x00\x68\x65\x6c\x6c\x6f\x00\x00\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
-\x1b\x4c\x4a\x01\x02\x29\x02\x00\x02\x00\x03\x00\x05\x34\x00\x00\x00\x37\x00\x01\x00\x25\x01\x02\x00\x3e\x00\x02\x01\x47\x00\x01\x00\x0a\x68\x65\x6c\x6c\x6f\x08\x73\x61\x79\x08\x6e\x67\x78\x00"
---- response_body
-error
---- error_log eval
-qr/failed to load external Lua file ".*?test\.lua": .* cannot load incompatible bytecode/
-
-
-
-=== TEST 3: unknown bytecode version
---- config
- root html;
- location /save_call {
- content_by_lua '
- ngx.req.read_body();
- local b = ngx.req.get_body_data();
- local f = io.open(ngx.var.realpath_root.."/test.lua", "w");
- -- luajit bytecode: sub(149,-1), lua bytecode: sub(1,147)
- if package.loaded["jit"] then
- f:write(string.sub(b, 149));
- else
- f:write(string.sub(b, 1, 147));
- end
- f:close();
- local res = ngx.location.capture("/call");
- if res.status == 200 then
- ngx.print(res.body)
- else
- ngx.say("error")
- end
- ';
- }
- location /call {
- content_by_lua_file $realpath_root/test.lua;
- }
---- request eval
-"POST /save_call
-\x1b\x4c\x75\x61\x52\x00\x01\x04\x08\x04\x08\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x40\x74\x65\x73\x74\x2e\x6c\x75\x61\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x02\x05\x00\x00\x00\x05\x00\x00\x00\x06\x40\x40\x00\x41\x80\x00\x00\x1c\x40\x00\x01\x1e\x00\x80\x00\x03\x00\x00\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x6e\x67\x78\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x73\x61\x79\x00\x04\x06\x00\x00\x00\x00\x00\x00\x00\x68\x65\x6c\x6c\x6f\x00\x00\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
-\x1b\x4c\x4a\x80\x02\x29\x02\x00\x02\x00\x03\x00\x05\x34\x00\x00\x00\x37\x00\x01\x00\x25\x01\x02\x00\x3e\x00\x02\x01\x47\x00\x01\x00\x0a\x68\x65\x6c\x6c\x6f\x08\x73\x61\x79\x08\x6e\x67\x78\x00"
---- response_body
-error
---- error_log
-cannot load incompatible bytecode
-
-
-
-=== TEST 4: bytecode (big endian)
---- config
- root html;
- location /save_call {
- content_by_lua '
- ngx.req.read_body();
- local b = ngx.req.get_body_data();
- local f = io.open(ngx.var.realpath_root.."/test.lua", "w");
- -- luajit bytecode: sub(149,-1), lua bytecode: sub(1,147)
- local do_jit
- if jit then
- if not string.find(jit.version, "LuaJIT 2.0") then
- ngx.say("test skipped")
- return
- end
-
- do_jit = true; f:write(string.sub(b, 149));
- else
- f:write(string.sub(b, 1, 147));
- end
- f:close(); res = ngx.location.capture("/call");
- if do_jit and res.status == 200 then
- ngx.say("ok")
- elseif not do_jit and res.status == 500 then
- ngx.say("ok")
- else
- ngx.say("error")
- end
- ';
- }
- location /call {
- content_by_lua_file $realpath_root/test.lua;
- }
---- request eval
-"POST /save_call
-\x1b\x4c\x75\x61\x51\x00\x00\x04\x08\x04\x08\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x40\x74\x65\x73\x74\x2e\x6c\x75\x61\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x02\x05\x00\x00\x00\x05\x00\x00\x00\x06\x40\x40\x00\x41\x80\x00\x00\x1c\x40\x00\x01\x1e\x00\x80\x00\x03\x00\x00\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x6e\x67\x78\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x73\x61\x79\x00\x04\x06\x00\x00\x00\x00\x00\x00\x00\x68\x65\x6c\x6c\x6f\x00\x00\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
-\x1b\x4c\x4a\x01\x03\x29\x02\x00\x02\x00\x03\x00\x05\x00\x00\x00\x34\x00\x01\x00\x37\x00\x02\x01\x25\x01\x02\x00\x3e\x00\x01\x00\x47\x0a\x68\x65\x6c\x6c\x6f\x08\x73\x61\x79\x08\x6e\x67\x78\x00"
---- response_body_like chop
-^(?:ok|test skipped)$
---- no_error_log
-[error]
-
-
-
-=== TEST 5: good header but bad body
---- config
- root html;
- location /save_call {
- content_by_lua '
- ngx.req.read_body();
- local b = ngx.req.get_body_data();
- local f = io.open(ngx.var.realpath_root.."/test.lua", "w");
- -- luajit bytecode: sub(149,-1), lua bytecode: sub(1,147)
- local jit;
- if package.loaded["jit"] then
- jit = true;
- f:write(string.sub(b, 149));
- else
- f:write(string.sub(b, 1, 147));
- end
- if not jit then
- f:close(); res = ngx.location.capture("/call");
- if res.status == 200 then
- ngx.print("ok")
- else
- ngx.say("error")
- end
- else
- -- luajit will get a segmentation fault with bad bytecode,
- -- so here just skip this case for luajit
- ngx.say("error")
- end
- ';
- }
- location /call {
- content_by_lua_file $realpath_root/test.lua;
- }
---- request eval
-"POST /save_call
-\x1b\x4c\x75\x61\x51\x00\x01\x04\x08\x04\x08\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x40\x74\x65\x73\x74\x2e\x6c\x75\x61\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x02\x05\x00\x00\x00\xff\xff\xff\xff\x06\x40\x40\x00\x41\x80\x00\x00\x1c\x40\x00\x01\x1e\x00\x80\x00\x03\x00\x00\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x6e\x67\x78\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x73\x61\x79\x00\x04\x06\x00\x00\x00\x00\x00\x00\x00\x68\x65\x6c\x6c\x6f\x00\x00\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
-\x1b\x4c\x4a\x01\x02\x29\x02\x00\x02\x00\x03\x00\x05\xff\xff\xff\xff\x37\x00\x01\x00\x25\x01\x02\x00\x3e\x00\x02\x01\x47\x00\x01\x00\x0a\x68\x65\x6c\x6c\x6f\x08\x73\x61\x79\x08\x6e\x67\x78\x00"
---- response_body
-error
---- no_error_log
-[error]
-
-
-
-=== TEST 6: stripped(lua) & no stripped(luajit)
---- config
- root html;
- location /save_call {
- content_by_lua '
- ngx.req.read_body();
- local b = ngx.req.get_body_data();
- local f = io.open(ngx.var.realpath_root.."/test.lua", "w");
- -- luajit bytecode: sub(149,-1), lua bytecode: sub(1,147)
- if jit then
- if not string.find(jit.version, "LuaJIT 2.0") then
- ngx.say("test skipped")
- return
- end
-
- f:write(string.sub(b, 119));
- else
- f:write(string.sub(b, 1, 117));
- end
- f:close(); res = ngx.location.capture("/call");
- ngx.print(res.body)
- ';
- }
- location /call {
- content_by_lua_file $realpath_root/test.lua;
- }
---- request eval
-"POST /save_call
-\x1b\x4c\x75\x61\x51\x00\x01\x04\x08\x04\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x02\x05\x00\x00\x00\x05\x00\x00\x00\x06\x40\x40\x00\x41\x80\x00\x00\x1c\x40\x00\x01\x1e\x00\x80\x00\x03\x00\x00\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x6e\x67\x78\x00\x04\x04\x00\x00\x00\x00\x00\x00\x00\x73\x61\x79\x00\x04\x06\x00\x00\x00\x00\x00\x00\x00\x68\x65\x6c\x6c\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
-\x1b\x4c\x4a\x01\x00\x09\x40\x74\x65\x73\x74\x2e\x6c\x75\x61\x32\x02\x00\x02\x00\x03\x00\x05\x06\x00\x02\x34\x00\x00\x00\x37\x00\x01\x00\x25\x01\x02\x00\x3e\x00\x02\x01\x47\x00\x01\x00\x0a\x68\x65\x6c\x6c\x6f\x08\x73\x61\x79\x08\x6e\x67\x78\x01\x01\x01\x01\x01\x00\x00"
---- response_body_like chop
-^(?:hello|test skipped)$
---- no_error_log
-[error]
-
-
-
-=== TEST 7: generate & load bytecode for LuaJIT (stripped)
---- config
- location = /t {
- content_by_lua '
- local bcsave = require "jit.bcsave"
- if jit then
- local prefix = "$TEST_NGINX_SERVER_ROOT"
- local infile = prefix .. "/html/a.lua"
- local outfile = prefix .. "/html/a.luac"
- bcsave.start("-s", infile, outfile)
- return ngx.exec("/call")
- end
-
- ngx.say("test skipped!")
- ';
- }
- location = /call {
- content_by_lua_file html/a.luac;
- }
---- request
- GET /t
-
---- user_files
->>> a.lua
-ngx.status = 201 ngx.say("hello from Lua!")
---- response_body_like chop
-^(?:hello from Lua!|test skipped!)$
---- no_error_log
-[error]
---- error_code: 201
-
-
-
-=== TEST 8: generate & load bytecode for LuaJIT (not stripped)
---- config
- location = /t {
- content_by_lua '
- local bcsave = require "jit.bcsave"
- if jit then
- local prefix = "$TEST_NGINX_SERVER_ROOT"
- local infile = prefix .. "/html/a.lua"
- local outfile = prefix .. "/html/a.luac"
- bcsave.start("-g", infile, outfile)
- return ngx.exec("/call")
- end
-
- ngx.say("test skipped!")
- ';
- }
- location = /call {
- content_by_lua_file html/a.luac;
- }
---- request
- GET /t
-
---- user_files
->>> a.lua
-ngx.status = 201 ngx.say("hello from Lua!")
---- response_body_like chop
-^(?:hello from Lua!|test skipped!)$
---- no_error_log
-[error]
---- error_code: 201
-
-
-
-=== TEST 9: bytecode (not stripped)
---- config
- location = /t {
- content_by_lua_block {
- local f = assert(loadstring("local a = 1 ngx.say('a = ', a)", "=code"))
- local bc = string.dump(f)
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/a.luac", "w"))
- f:write(bc)
- f:close()
- }
- }
-
- location = /t2 {
- content_by_lua_file html/a.luac;
- }
-
- location = /main {
- echo_location /t;
- echo_location /t2;
- }
---- request
-GET /main
---- response_body
-a = 1
---- no_error_log
-[error]
-
-
-
-=== TEST 10: bytecode (stripped)
---- config
- location = /t {
- content_by_lua_block {
- local f = assert(loadstring("local a = 1 ngx.say('a = ', a)", "=code"))
- local bc = string.dump(f, true)
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/a.luac", "w"))
- f:write(bc)
- f:close()
- }
- }
-
- location = /t2 {
- content_by_lua_file html/a.luac;
- }
-
- location = /main {
- echo_location /t;
- echo_location /t2;
- }
---- request
-GET /main
---- response_body
-a = 1
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/082-body-filter-2.t b/src/deps/src/lua-nginx-module/t/082-body-filter-2.t
deleted file mode 100644
index 3c9b9797d..000000000
--- a/src/deps/src/lua-nginx-module/t/082-body-filter-2.t
+++ /dev/null
@@ -1,271 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_EVENT_TYPE} && $ENV{TEST_NGINX_EVENT_TYPE} ne 'poll') {
- $SkipReason = "unavailable for the event type '$ENV{TEST_NGINX_EVENT_TYPE}'";
-
- } elsif ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "http3 does not support mockeagain";
-
- } elsif ($ENV{TEST_NGINX_USE_HTTP2}) {
- $SkipReason = "http2 does not support mockeagain";
-
- } else {
- if ($ENV{LD_PRELOAD} && $ENV{LD_PRELOAD} =~ /\bmockeagain\.so\b/) {
- $ENV{TEST_NGINX_POSTPONE_OUTPUT} = 1;
- $ENV{TEST_NGINX_EVENT_TYPE} = 'poll';
- $ENV{MOCKEAGAIN}='w'
- } else {
- $SkipReason = "'mockeagain.so' does not appear to be preloaded "
- . "with 'LD_PRELOAD'";
- }
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 5);
-
-#no_diff();
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: check ctx->busy_bufs
---- config
- location /t {
- postpone_output 1;
- content_by_lua_block {
- for i = 1, 5 do
- ngx.say(i, ": Hello World!")
- end
- }
-
- body_filter_by_lua_block {
- ngx.arg[1] = ngx.arg[1]
- }
- }
---- request
-GET /t
---- response_body
-1: Hello World!
-2: Hello World!
-3: Hello World!
-4: Hello World!
-5: Hello World!
-
---- error_log
-waiting body filter busy buffer to be sent
-lua say response has busy bufs
---- no_error_log
-[error]
-
-
-
-=== TEST 2: arg[1] not change and say long string
---- config
- location /t {
- header_filter_by_lua_block {ngx.header.content_length = nil}
- body_filter_by_lua_block {
- local function anyting_not_change_arg1()
- return
- end
- anyting_not_change_arg1()
- }
- content_by_lua_block {
- for i = 1, 100 do
- ngx.say("12345678901234567890")
- end
- }
- }
---- request
-GET /t
---- response_body eval
-("12345678901234567890\n" x 100)
---- no_error_log
-[error]
-[alert]
-[crit]
-
-
-
-=== TEST 3: arg[1] not change and chunked_transfer_encoding off
---- config
- location /t {
- header_filter_by_lua_block {ngx.header.content_length = nil}
- body_filter_by_lua_block {
- local function anyting_not_change_arg1()
- return
- end
- anyting_not_change_arg1()
- }
- chunked_transfer_encoding off;
- content_by_lua_block {
- for i = 1, 100 do
- ngx.say("12345678901234567890123456789012345678901234567890".."_"..tostring(i/3))
- end
- }
- }
---- request
-GET /t
---- response_body
-12345678901234567890123456789012345678901234567890_0.33333333333333
-12345678901234567890123456789012345678901234567890_0.66666666666667
-12345678901234567890123456789012345678901234567890_1
-12345678901234567890123456789012345678901234567890_1.3333333333333
-12345678901234567890123456789012345678901234567890_1.6666666666667
-12345678901234567890123456789012345678901234567890_2
-12345678901234567890123456789012345678901234567890_2.3333333333333
-12345678901234567890123456789012345678901234567890_2.6666666666667
-12345678901234567890123456789012345678901234567890_3
-12345678901234567890123456789012345678901234567890_3.3333333333333
-12345678901234567890123456789012345678901234567890_3.6666666666667
-12345678901234567890123456789012345678901234567890_4
-12345678901234567890123456789012345678901234567890_4.3333333333333
-12345678901234567890123456789012345678901234567890_4.6666666666667
-12345678901234567890123456789012345678901234567890_5
-12345678901234567890123456789012345678901234567890_5.3333333333333
-12345678901234567890123456789012345678901234567890_5.6666666666667
-12345678901234567890123456789012345678901234567890_6
-12345678901234567890123456789012345678901234567890_6.3333333333333
-12345678901234567890123456789012345678901234567890_6.6666666666667
-12345678901234567890123456789012345678901234567890_7
-12345678901234567890123456789012345678901234567890_7.3333333333333
-12345678901234567890123456789012345678901234567890_7.6666666666667
-12345678901234567890123456789012345678901234567890_8
-12345678901234567890123456789012345678901234567890_8.3333333333333
-12345678901234567890123456789012345678901234567890_8.6666666666667
-12345678901234567890123456789012345678901234567890_9
-12345678901234567890123456789012345678901234567890_9.3333333333333
-12345678901234567890123456789012345678901234567890_9.6666666666667
-12345678901234567890123456789012345678901234567890_10
-12345678901234567890123456789012345678901234567890_10.333333333333
-12345678901234567890123456789012345678901234567890_10.666666666667
-12345678901234567890123456789012345678901234567890_11
-12345678901234567890123456789012345678901234567890_11.333333333333
-12345678901234567890123456789012345678901234567890_11.666666666667
-12345678901234567890123456789012345678901234567890_12
-12345678901234567890123456789012345678901234567890_12.333333333333
-12345678901234567890123456789012345678901234567890_12.666666666667
-12345678901234567890123456789012345678901234567890_13
-12345678901234567890123456789012345678901234567890_13.333333333333
-12345678901234567890123456789012345678901234567890_13.666666666667
-12345678901234567890123456789012345678901234567890_14
-12345678901234567890123456789012345678901234567890_14.333333333333
-12345678901234567890123456789012345678901234567890_14.666666666667
-12345678901234567890123456789012345678901234567890_15
-12345678901234567890123456789012345678901234567890_15.333333333333
-12345678901234567890123456789012345678901234567890_15.666666666667
-12345678901234567890123456789012345678901234567890_16
-12345678901234567890123456789012345678901234567890_16.333333333333
-12345678901234567890123456789012345678901234567890_16.666666666667
-12345678901234567890123456789012345678901234567890_17
-12345678901234567890123456789012345678901234567890_17.333333333333
-12345678901234567890123456789012345678901234567890_17.666666666667
-12345678901234567890123456789012345678901234567890_18
-12345678901234567890123456789012345678901234567890_18.333333333333
-12345678901234567890123456789012345678901234567890_18.666666666667
-12345678901234567890123456789012345678901234567890_19
-12345678901234567890123456789012345678901234567890_19.333333333333
-12345678901234567890123456789012345678901234567890_19.666666666667
-12345678901234567890123456789012345678901234567890_20
-12345678901234567890123456789012345678901234567890_20.333333333333
-12345678901234567890123456789012345678901234567890_20.666666666667
-12345678901234567890123456789012345678901234567890_21
-12345678901234567890123456789012345678901234567890_21.333333333333
-12345678901234567890123456789012345678901234567890_21.666666666667
-12345678901234567890123456789012345678901234567890_22
-12345678901234567890123456789012345678901234567890_22.333333333333
-12345678901234567890123456789012345678901234567890_22.666666666667
-12345678901234567890123456789012345678901234567890_23
-12345678901234567890123456789012345678901234567890_23.333333333333
-12345678901234567890123456789012345678901234567890_23.666666666667
-12345678901234567890123456789012345678901234567890_24
-12345678901234567890123456789012345678901234567890_24.333333333333
-12345678901234567890123456789012345678901234567890_24.666666666667
-12345678901234567890123456789012345678901234567890_25
-12345678901234567890123456789012345678901234567890_25.333333333333
-12345678901234567890123456789012345678901234567890_25.666666666667
-12345678901234567890123456789012345678901234567890_26
-12345678901234567890123456789012345678901234567890_26.333333333333
-12345678901234567890123456789012345678901234567890_26.666666666667
-12345678901234567890123456789012345678901234567890_27
-12345678901234567890123456789012345678901234567890_27.333333333333
-12345678901234567890123456789012345678901234567890_27.666666666667
-12345678901234567890123456789012345678901234567890_28
-12345678901234567890123456789012345678901234567890_28.333333333333
-12345678901234567890123456789012345678901234567890_28.666666666667
-12345678901234567890123456789012345678901234567890_29
-12345678901234567890123456789012345678901234567890_29.333333333333
-12345678901234567890123456789012345678901234567890_29.666666666667
-12345678901234567890123456789012345678901234567890_30
-12345678901234567890123456789012345678901234567890_30.333333333333
-12345678901234567890123456789012345678901234567890_30.666666666667
-12345678901234567890123456789012345678901234567890_31
-12345678901234567890123456789012345678901234567890_31.333333333333
-12345678901234567890123456789012345678901234567890_31.666666666667
-12345678901234567890123456789012345678901234567890_32
-12345678901234567890123456789012345678901234567890_32.333333333333
-12345678901234567890123456789012345678901234567890_32.666666666667
-12345678901234567890123456789012345678901234567890_33
-12345678901234567890123456789012345678901234567890_33.333333333333
---- no_error_log
-[error]
-[alert]
-[crit]
-
-
-
-=== TEST 4: set resp body nil with ngx.arg[1] first
---- config
- location /t {
- content_by_lua_block {
- ngx.say("Hello World!")
- }
-
- body_filter_by_lua_block {
- ngx.arg[1] = ""
- ngx.arg[2] = true
- }
- }
---- request
-GET /t
---- response_body
---- no_error_log
-[error]
-[alert]
-[crit]
-
-
-
-=== TEST 5: set resp body nil with ngx.arg[2] first
---- config
- location /t {
- content_by_lua_block {
- ngx.say("Hello World!")
- }
-
- body_filter_by_lua_block {
- ngx.arg[2] = true
- ngx.arg[1] = ""
- }
- }
---- request
-GET /t
---- response_body
---- no_error_log
-[error]
-[alert]
-[crit]
diff --git a/src/deps/src/lua-nginx-module/t/082-body-filter.t b/src/deps/src/lua-nginx-module/t/082-body-filter.t
deleted file mode 100644
index 4033bac8c..000000000
--- a/src/deps/src/lua-nginx-module/t/082-body-filter.t
+++ /dev/null
@@ -1,902 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 11);
-
-#no_diff();
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: read chunks (inline)
---- config
- location /read {
- echo -n hello world;
- echo -n hiya globe;
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- print("chunk: [", chunk, "], eof: ", eof)
- ';
- }
---- request
-GET /read
---- response_body chop
-hello worldhiya globe
---- error_log
-chunk: [hello world], eof: false
-chunk: [hiya globe], eof: false
-chunk: [], eof: true
---- no_error_log
-[error]
-
-
-
-=== TEST 2: read chunks (file)
---- config
- location /read {
- echo -n hello world;
- echo -n hiya globe;
-
- body_filter_by_lua_file html/a.lua;
- }
---- user_files
->>> a.lua
-local chunk, eof = ngx.arg[1], ngx.arg[2]
-print("chunk: [", chunk, "], eof: ", eof)
---- request
-GET /read
---- response_body chop
-hello worldhiya globe
---- error_log
-chunk: [hello world], eof: false
-chunk: [hiya globe], eof: false
-chunk: [], eof: true
---- no_error_log
-[error]
-
-
-
-=== TEST 3: read chunks (user module)
---- http_config
- lua_package_path "$prefix/html/?.lua;;";
---- config
- location /read {
- echo -n hello world;
- echo -n hiya globe;
-
- body_filter_by_lua '
- local foo = require "foo"
- foo.go()
- ';
- }
---- user_files
->>> foo.lua
-module("foo", package.seeall)
-
-function go()
- -- ngx.say("Hello")
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- print("chunk: [", chunk, "], eof: ", eof)
-end
---- request
-GET /read
---- response_body chop
-hello worldhiya globe
---- error_log
-chunk: [hello world], eof: false
-chunk: [hiya globe], eof: false
-chunk: [], eof: true
---- no_error_log
-[error]
-
-
-
-=== TEST 4: rewrite chunks (upper all)
---- config
- location /t {
- echo hello world;
- echo hiya globe;
-
- body_filter_by_lua '
- ngx.arg[1] = string.upper(ngx.arg[1])
- ';
- }
---- request
-GET /t
---- response_body
-HELLO WORLD
-HIYA GLOBE
---- no_error_log
-[error]
-
-
-
-=== TEST 5: rewrite chunks (truncate data)
---- config
- location /t {
- echo hello world;
- echo hiya globe;
-
- body_filter_by_lua '
- local chunk = ngx.arg[1]
- if string.match(chunk, "hello") then
- ngx.arg[1] = string.upper(chunk)
- ngx.arg[2] = true
- return
- end
-
- ngx.arg[1] = nil
- ';
- }
---- request
-GET /t
---- response_body
-HELLO WORLD
---- no_error_log
-[error]
-
-
-
-=== TEST 6: set eof back and forth
---- config
- location /t {
- echo hello world;
- echo hiya globe;
-
- body_filter_by_lua '
- local chunk = ngx.arg[1]
- if string.match(chunk, "hello") then
- ngx.arg[1] = string.upper(chunk)
- ngx.arg[2] = true
- ngx.arg[2] = false
- ngx.arg[2] = true
- return
- end
-
- ngx.arg[1] = nil
- ngx.arg[2] = true
- ngx.arg[2] = false
- ';
- }
---- request
-GET /t
---- response_body
-HELLO WORLD
---- no_error_log
-[error]
-
-
-
-=== TEST 7: set eof to original
---- config
- location /t {
- echo hello world;
- echo hiya globe;
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- ngx.arg[2] = eof
- ';
- }
---- request
-GET /t
---- response_body
-hello world
-hiya globe
---- no_error_log
-[error]
-
-
-
-=== TEST 8: set eof to original
---- config
- location /t {
- echo hello world;
- echo hiya globe;
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- ngx.arg[2] = eof
- ';
- }
---- request
-GET /t
---- response_body
-hello world
-hiya globe
---- no_error_log
-[error]
-
-
-
-=== TEST 9: fully buffered output (string scalar)
---- config
- location /t {
- echo hello world;
- echo hiya globe;
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- local buf = ngx.ctx.buf
-
- if eof then
- if buf then
- ngx.arg[1] = "[" .. buf .. chunk .. "]"
- return
- end
-
- return
- end
-
- if buf then
- ngx.ctx.buf = buf .. chunk
- else
- ngx.ctx.buf = chunk
- end
-
- ngx.arg[1] = nil
- ';
- }
---- request
-GET /t
---- response_body chop
-[hello world
-hiya globe
-]
---- no_error_log
-[error]
-
-
-
-=== TEST 10: fully buffered output (string table)
---- config
- location /t {
- echo hello world;
- echo hiya globe;
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- local buf = ngx.ctx.buf
-
- if eof then
- if buf then
- ngx.arg[1] = {"[", buf, chunk, "]"}
- return
- end
-
- return
- end
-
- if buf then
- ngx.ctx.buf = {buf, chunk}
- else
- ngx.ctx.buf = chunk
- end
-
- ngx.arg[1] = nil
- ';
- }
---- request
-GET /t
---- response_body chop
-[hello world
-hiya globe
-]
---- no_error_log
-[error]
-
-
-
-=== TEST 11: abort via user error (string)
---- config
- location /t {
- echo hello world;
- echo_flush;
- echo hiya globe;
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- if eof then
- error("something bad happened!")
- end
- ';
- }
---- request
-GET /t
---- ignore_response
---- error_log
-failed to run body_filter_by_lua*: body_filter_by_lua(nginx.conf:49):4: something bad happened!
-
-
-
-=== TEST 12: abort via user error (nil)
---- config
- location /t {
- echo hello world;
- echo_flush;
- echo hiya globe;
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- if eof then
- error(nil)
- end
- ';
- }
---- request
-GET /t
---- ignore_response
---- error_log
-failed to run body_filter_by_lua*: unknown reason
-
-
-
-=== TEST 13: abort via return NGX_ERROR
---- config
- location /t {
- echo hello world;
- echo_flush;
- echo hiya globe;
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- if eof then
- return ngx.ERROR
- end
- ';
- }
---- request
-GET /t
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 14: using body_filter_by_lua and header_filter_by_lua at the same time
---- config
- location /t {
- content_by_lua '
- ngx.header.content_length = 12
- ngx.say("Hello World")
- ';
-
- header_filter_by_lua 'ngx.header.content_length = nil';
-
- body_filter_by_lua '
- ngx.arg[1] = ngx.arg[1] .. "aaa"
- ';
- }
---- request
-GET /t
---- response_body chop
-Hello World
-aaaaaa
---- response_headers
-!content-length
---- no_error_log
-[error]
-
-
-
-=== TEST 15: table arguments to ngx.arg[1] (github issue #54)
---- config
- location /t {
- echo -n hello;
-
- body_filter_by_lua '
- if ngx.arg[1] ~= "" then
- ngx.arg[1] = {{ngx.arg[1]}, "!", "\\n"}
- end
- ';
- }
---- request
-GET /t
---- response_body
-hello!
---- no_error_log
-[error]
-
-
-
-=== TEST 16: fully buffered output (string scalar, buffering to disk by ngx_proxy)
---- config
- location /t {
- proxy_pass http://127.0.0.1:$server_port/stub;
- proxy_buffers 2 256;
- proxy_busy_buffers_size 256;
- proxy_buffer_size 256;
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- local buf = ngx.ctx.buf
-
- if eof then
- if buf then
- ngx.arg[1] = "[" .. buf .. chunk .. "]"
- return
- end
-
- return
- end
-
- if buf then
- ngx.ctx.buf = buf .. chunk
- else
- ngx.ctx.buf = chunk
- end
-
- ngx.arg[1] = nil
- ';
- }
-
- location = /stub {
- echo_duplicate 512 "a";
- echo_duplicate 512 "b";
- }
---- request
-GET /t
---- response_body eval
-"[" . ("a" x 512) . ("b" x 512) . "]";
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 17: backtrace
---- config
- location /t {
- body_filter_by_lua '
- local bar
- local function foo()
- bar()
- end
-
- function bar()
- error("something bad happened")
- end
-
- foo()
- ';
- echo ok;
- }
---- request
- GET /t
---- ignore_response
---- error_log
-something bad happened
-stack traceback:
-in function 'error'
-in function 'bar'
-in function 'foo'
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP\/3 stream 0 reset by server#
-
-
-
-=== TEST 18: setting "eof" in subrequests
---- config
- location /t {
- echo_location /read;
- echo_location /read;
- }
-
- location /read {
- echo -n hello world;
- echo -n hiya globe;
-
- body_filter_by_lua '
- ngx.arg[2] = 1
- ';
- }
---- request
-GET /t
---- response_body chop
-hello worldhello world
---- no_error_log
-[error]
-
-
-
-=== TEST 19: Lua file does not exist
---- config
- location /lua {
- echo ok;
- body_filter_by_lua_file html/test2.lua;
- }
---- user_files
->>> test.lua
-v = ngx.var["request_uri"]
-ngx.print("request_uri: ", v, "\n")
---- request
-GET /lua?a=1&b=2
---- ignore_response
---- error_log eval
-qr/failed to load external Lua file ".*?test2\.lua": cannot open .*? No such file or directory/
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP\/3 stream 0 reset by server#
-
-
-
-=== TEST 20: overwrite eof
---- config
- location /read {
- return 200 "hello world";
-
- body_filter_by_lua '
- local chunk, eof = ngx.arg[1], ngx.arg[2]
- if eof then
- ngx.arg[2] = false
- end
- ';
- }
-
- location = /t {
- content_by_lua '
- local res = ngx.location.capture("/read")
- ngx.say("truncated: ", res.truncated)
- ';
- }
---- request
-GET /t
---- response_body
-truncated: true
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 21: zero-size bufs
---- config
- location = /t {
- echo hello;
- echo world;
-
- body_filter_by_lua '
- ngx.arg[1] = ""
- ';
- }
---- request
-GET /t
---- response_body
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 22: body filter + ngx.say() (github issue #386)
---- config
- postpone_output 1;
- location = /t {
- header_filter_by_lua 'ngx.header.content_length = nil';
-
- body_filter_by_lua '
- -- do return end
- if not ngx.ctx.chunks then
- ngx.ctx.chunks = {}
- end
-
- table.insert(ngx.ctx.chunks, ngx.arg[1])
- print("got chunk ", ngx.arg[1])
- ngx.arg[1] = nil
-
- if ngx.arg[2] then
- print("seen eof: ", string.upper(table.concat(ngx.ctx.chunks)))
- ngx.arg[1] = string.upper(table.concat(ngx.ctx.chunks))
- end
- ';
-
- content_by_lua '
- for i = 1, 10 do
- assert(ngx.say("hello world"))
- end
- ';
- }
---- request
-GET /t
---- response_body eval
-"HELLO WORLD\n" x 10
-
---- stap2
-global active = 1
-F(ngx_http_lua_body_filter_by_chunk) {
- printf("body filter by lua: %p: %s\n", $in, ngx_chain_dump($in))
-}
-
-F(ngx_http_write_filter) {
- printf("write filter: %p: %s\n", $in, ngx_chain_dump($in))
-}
-
-
-F(ngx_output_chain) {
- #printf("ctx->in: %s\n", ngx_chain_dump($ctx->in))
- #printf("ctx->busy: %s\n", ngx_chain_dump($ctx->busy))
- printf("output chain %p: %s\n", $in, ngx_chain_dump($in))
-}
-F(ngx_linux_sendfile_chain) {
- printf("linux sendfile chain: %s\n", ngx_chain_dump($in))
-}
-F(ngx_chain_writer) {
- printf("chain writer ctx out: %p\n", $data)
- printf("nginx chain writer: %s\n", ngx_chain_dump($in))
-}
-probe syscall.writev {
- if (active && pid() == target()) {
- printf("writev(%s)", ngx_iovec_dump($vec, $vlen))
- /*
- for (i = 0; i < $vlen; i++) {
- printf(" %p [%s]", $vec[i]->iov_base, text_str(user_string_n($vec[i]->iov_base, $vec[i]->iov_len)))
- }
- */
- }
-}
-probe syscall.writev.return {
- if (active && pid() == target()) {
- printf(" = %s\n", retstr)
- }
-}
-
---- stap_out2
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 23: body filter + ngx.say() (github issue #386), with flush
---- config
- location = /t {
- header_filter_by_lua 'ngx.header.content_length = nil';
-
- body_filter_by_lua '
- -- do return end
- if not ngx.ctx.chunks then
- ngx.ctx.chunks = {}
- end
-
- table.insert(ngx.ctx.chunks, ngx.arg[1])
- print("got chunk ", ngx.arg[1])
- ngx.arg[1] = nil
-
- if ngx.arg[2] then
- print("seen eof: ", string.upper(table.concat(ngx.ctx.chunks)))
- ngx.arg[1] = string.upper(table.concat(ngx.ctx.chunks))
- end
- ';
-
- content_by_lua '
- for i = 1, 10 do
- assert(ngx.say("hello world"))
- ngx.flush(true)
- end
- ';
- }
---- request
-GET /t
---- response_body eval
-"HELLO WORLD\n" x 10
-
---- stap
-F(ngx_http_write_filter) {
- for (cl = $in; cl; cl = @cast(cl, "ngx_chain_t")->next) {
- if (@cast(cl, "ngx_chain_t")->buf->flush) {
- printf("seen flush buf.\n")
- }
-
- if (@cast(cl, "ngx_chain_t")->buf->last_buf) {
- printf("seen last buf.\n")
- }
- }
-}
-
---- stap_out_like eval
-qr/^(?:seen flush buf\.
-){10,}seen last buf\.
-$/
-
---- stap2
-global active = 1
-F(ngx_http_lua_body_filter_by_chunk) {
- printf("body filter by lua: %p: %s\n", $in, ngx_chain_dump($in))
-}
-
-F(ngx_http_write_filter) {
- printf("write filter: %p: %s\n", $in, ngx_chain_dump($in))
-}
-
-F(ngx_http_charset_body_filter) {
- printf("charset body filter: %p: %s\n", $in, ngx_chain_dump($in))
-}
-
-F(ngx_output_chain) {
- #printf("ctx->in: %s\n", ngx_chain_dump($ctx->in))
- #printf("ctx->busy: %s\n", ngx_chain_dump($ctx->busy))
- printf("output chain %p: %s\n", $in, ngx_chain_dump($in))
-}
-
-F(ngx_linux_sendfile_chain) {
- printf("linux sendfile chain: %s\n", ngx_chain_dump($in))
-}
-
-F(ngx_chain_writer) {
- printf("chain writer ctx out: %p\n", $data)
- printf("nginx chain writer: %s\n", ngx_chain_dump($in))
-}
-
-probe syscall.writev {
- if (active && pid() == target()) {
- printf("writev(%s)", ngx_iovec_dump($vec, $vlen))
- /*
- for (i = 0; i < $vlen; i++) {
- printf(" %p [%s]", $vec[i]->iov_base, text_str(user_string_n($vec[i]->iov_base, $vec[i]->iov_len)))
- }
- */
- }
-}
-
-probe syscall.writev.return {
- if (active && pid() == target()) {
- printf(" = %s\n", retstr)
- }
-}
-
---- stap_out2
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 24: clear ngx.arg[1] and then read it
---- config
- location /t {
- echo hello;
- echo world;
-
- body_filter_by_lua '
- ngx.arg[1] = nil
- local data = ngx.arg[1]
- print([[data chunk: "]], data, [["]])
-
- ngx.arg[1] = ""
- data = ngx.arg[1]
- print([[data chunk 2: "]], data, [["]])
- ';
- }
---- request
-GET /t
---- response_body
---- log_level: info
---- grep_error_log eval: qr/data chunk(?: \d+)?: [^,]+/
---- grep_error_log_out
-data chunk: ""
-data chunk 2: ""
-data chunk: ""
-data chunk 2: ""
-data chunk: ""
-data chunk 2: ""
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 25: clear ngx.arg[1] and then read ngx.arg[2]
---- config
- location /t {
- echo hello;
- echo world;
-
- body_filter_by_lua '
- ngx.arg[1] = nil
- local eof = ngx.arg[2]
- print([[eof: ]], eof)
-
- ngx.arg[1] = ""
- eof = ngx.arg[2]
- print([[eof 2: ]], eof)
- ';
- }
---- request
-GET /t
---- response_body
---- log_level: info
---- grep_error_log eval: qr/eof(?: \d+)?: [^,]+/
---- grep_error_log_out
-eof: false
-eof 2: false
-eof: false
-eof 2: false
-eof: true
-eof 2: true
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 26: no ngx.print
---- config
- location /lua {
- echo ok;
- body_filter_by_lua "ngx.print(32) return 1";
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of body_filter_by_lua*
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP\/3 stream 0 reset by server#
-
-
-
-=== TEST 27: syntax error in body_filter_by_lua_block
---- config
- location /lua {
-
- body_filter_by_lua_block {
- 'for end';
- }
- content_by_lua_block {
- ngx.say("Hello world")
- }
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-failed to load inlined Lua code: body_filter_by_lua(nginx.conf:41):2: unexpected symbol near ''for end''
---- no_error_log
-no_such_error1
-no_such_error2
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP\/3 stream 0 reset by server#
-
-
-
-=== TEST 28: syntax error in second body_by_lua_block
---- config
- location /foo {
- body_filter_by_lua_block {
- 'for end';
- }
- content_by_lua_block {
- ngx.say("Hello world")
- }
- }
-
- location /lua {
- body_filter_by_lua_block {
- 'for end';
- }
- content_by_lua_block {
- ngx.say("Hello world")
- }
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-failed to load inlined Lua code: body_filter_by_lua(nginx.conf:49):2: unexpected symbol near ''for end''
---- no_error_log
-no_such_error1
-no_such_error2
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP\/3 stream 0 reset by server#
diff --git a/src/deps/src/lua-nginx-module/t/083-bad-sock-self.t b/src/deps/src/lua-nginx-module/t/083-bad-sock-self.t
deleted file mode 100644
index 206de8b99..000000000
--- a/src/deps/src/lua-nginx-module/t/083-bad-sock-self.t
+++ /dev/null
@@ -1,140 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-
-#$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-no_long_string();
-#no_diff();
-#log_level 'warn';
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: receive
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
- sock.receive("l")
- ';
- }
---- request
- POST /t
---- more_headers: Content-Length: 1024
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad argument #1 to 'receive' (table expected, got string)
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 2: receiveuntil
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.req.socket()
- sock.receiveuntil(32, "ab")
- ';
- }
---- request
- POST /t
---- more_headers: Content-Length: 1024
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad argument #1 to 'receiveuntil' (table expected, got number)
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 3: send (bad arg number)
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.socket.tcp()
- sock.send("hello")
- ';
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-expecting 2 arguments (including the object), but got 1
-
-
-
-=== TEST 4: send (bad self)
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.socket.tcp()
- sock.send("hello", 32)
- ';
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad argument #1 to 'send' (table expected, got string)
-
-
-
-=== TEST 5: getreusedtimes (bad self)
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.socket.tcp()
- sock.getreusedtimes(2)
- ';
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad argument #1 to 'getreusedtimes' (table expected, got number)
-
-
-
-=== TEST 6: close (bad self)
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.socket.tcp()
- sock.close(2)
- ';
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad argument #1 to 'close' (table expected, got number)
-
-
-
-=== TEST 7: setkeepalive (bad self)
---- config
- location /t {
- content_by_lua '
- local sock, err = ngx.socket.tcp()
- sock.setkeepalive(2)
- ';
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-bad argument #1 to 'setkeepalive' (table expected, got number)
diff --git a/src/deps/src/lua-nginx-module/t/084-inclusive-receiveuntil.t b/src/deps/src/lua-nginx-module/t/084-inclusive-receiveuntil.t
deleted file mode 100644
index 60f8363f9..000000000
--- a/src/deps/src/lua-nginx-module/t/084-inclusive-receiveuntil.t
+++ /dev/null
@@ -1,758 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-no_long_string();
-#no_diff();
-#log_level 'warn';
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: ambiguous boundary patterns (abcabd) - inclusive mode
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("abcabd", { inclusive = true })
-
- for i = 1, 3 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabcabdabcabd;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abcabcabd
-read: abcabd
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 2: ambiguous boundary patterns (abcabdabcabe 4) - inclusive mode
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("abcabdabcabe", { inclusive = true })
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo ababcabdabcabe;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: ababcabdabcabe
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 3: ambiguous boundary patterns (abcabd) - inclusive mode - small buffers
---- no_http2
---- config
- server_tokens off;
- lua_socket_buffer_size 1;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("abcabd", { inclusive = true })
-
- for i = 1, 3 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabcabdabcabd;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abcabcabd
-read: abcabd
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 4: inclusive option value nil
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aa", { inclusive = nil })
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabcaad;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abcabc
-failed to read a line: closed [d
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 5: inclusive option value false
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aa", { inclusive = false })
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabcaad;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abcabc
-failed to read a line: closed [d
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 6: inclusive option value true (aa)
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aa", { inclusive = true })
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabcaad;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: abcabcaa
-failed to read a line: closed [d
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 7: bad inclusive option value type
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aa", { inclusive = "true" })
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabcaad;
- more_clear_headers Date;
- }
---- request
-GET /t
---- ignore_response
---- error_log
-bad "inclusive" option value type: string
---- no_error_log
-[alert]
-[warn]
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP\/3 stream 0 reset by server#
-
-
-
-=== TEST 8: bad option table
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("aa", { inclusive = "true" })
-
- for i = 1, 2 do
- local line, err, part = reader()
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo abcabcaad;
- more_clear_headers Date;
- }
---- request
-GET /t
---- ignore_response
---- error_log
-bad "inclusive" option value type: string
---- no_error_log
-[alert]
-[warn]
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP\/3 stream 0 reset by server#
-
-
-
-=== TEST 9: ambiguous boundary patterns (--abc), small buffer
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- lua_socket_buffer_size 1;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("--abc", { inclusive = true })
-
- for i = 1, 6 do
- local line, err, part = reader(4)
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a line: ", err, " [", part, "]")
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo "hello, world ----abc";
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: hell
-read: o, w
-read: orld
-read: ----abc
-failed to read a line: nil [nil]
-failed to read a line: closed [
-]
-close: 1 nil
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 10: ambiguous boundary patterns (--abc), small buffer, mixed by other reading calls
---- no_http2
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- lua_socket_buffer_size 1;
-
- content_by_lua '
- -- collectgarbage("collect")
-
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", bytes)
-
- local read_headers = sock:receiveuntil("\\r\\n\\r\\n")
- local headers, err, part = read_headers()
- if not headers then
- ngx.say("failed to read headers: ", err, " [", part, "]")
- end
-
- local reader = sock:receiveuntil("--abc", { inclusive = true })
-
- for i = 1, 7 do
- local line, err, part = reader(4)
- if line then
- ngx.say("read: ", line)
-
- else
- ngx.say("failed to read a chunk: ", err, " [", part, "]")
- end
-
- local data, err, part = sock:receive(1)
- if not data then
- ngx.say("failed to read a byte: ", err, " [", part, "]")
- break
- else
- ngx.say("read one byte: ", data)
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo "hello, world ----abc";
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-qq{connected: 1
-request sent: 57
-read: hell
-read one byte: o
-read: , wo
-read one byte: r
-read: ld -
-read one byte: -
-read: --abc
-read one byte:
-
-failed to read a chunk: nil [nil]
-failed to read a byte: closed []
-close: 1 nil
-}
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/085-if.t b/src/deps/src/lua-nginx-module/t/085-if.t
deleted file mode 100644
index 33f57caf7..000000000
--- a/src/deps/src/lua-nginx-module/t/085-if.t
+++ /dev/null
@@ -1,200 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3 + 2);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: set_by_lua (if fails)
---- config
- location /t {
- set $true $arg_a;
- if ($true) {
- set_by_lua $true 'return tonumber(ngx.var["true"]) + 1';
- break;
- }
- set $true "empty";
-
- echo "[$true]";
- }
---- request
-GET /t
---- response_body
-[empty]
---- no_error_log
-[error]
-
-
-
-=== TEST 2: set_by_lua (if true)
---- config
- location /t {
- set $true $arg_a;
- if ($true) {
- set_by_lua $true 'return tonumber(ngx.var["true"]) + 1';
- break;
- }
- set $true "blah";
-
- echo "[$true]";
- }
---- request
-GET /t?a=2
---- response_body
-[3]
---- no_error_log
-[error]
-
-
-
-=== TEST 3: content_by_lua inherited by location if
---- config
- location /t {
- set $true 1;
- if ($true) {
- # nothing
- }
-
- content_by_lua 'ngx.say("hello world")';
- }
---- request
-GET /t
---- response_body
-hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 4: rewrite_by_lua inherited by location if
---- config
- location /t {
- set $true 1;
- if ($true) {
- # nothing
- }
-
- rewrite_by_lua 'ngx.say("hello world") ngx.exit(200)';
- }
---- request
-GET /t
---- response_body
-hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 5: access_by_lua inherited by location if
---- config
- location /t {
- set $true 1;
- if ($true) {
- # nothing
- }
-
- access_by_lua 'ngx.say("hello world") ngx.exit(200)';
- }
---- request
-GET /t
---- response_body
-hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 6: log_by_lua inherited by location if
---- config
- location /t {
- set $true 1;
- if ($true) {
- # nothing
- }
-
- log_by_lua 'ngx.log(ngx.WARN, "from log by lua")';
- echo hello world;
- }
---- request
-GET /t
---- response_body
-hello world
---- no_error_log
-[error]
---- error_log
-from log by lua
-
-
-
-=== TEST 7: header_filter_by_lua inherited by location if
---- config
- location /t {
- set $true 1;
- if ($true) {
- # nothing
- }
-
- header_filter_by_lua 'ngx.header.Foo = "bah"';
- echo hello world;
- }
---- request
-GET /t
---- response_body
-hello world
---- response_headers
-Foo: bah
---- no_error_log
-[error]
-
-
-
-=== TEST 8: body_filter_by_lua inherited by location if
---- config
- location /t {
- set $true 1;
- if ($true) {
- # nothing
- }
-
- body_filter_by_lua 'ngx.arg[1] = string.upper(ngx.arg[1])';
- echo hello world;
- }
---- request
-GET /t
---- response_body
-HELLO WORLD
---- no_error_log
-[error]
-
-
-
-=== TEST 9: if is evil for ngx_proxy
-This test case requires the following patch for the nginx core:
-http://mailman.nginx.org/pipermail/nginx-devel/2012-June/002374.html
---- config
- location /proxy-pass-uri {
- proxy_pass http://127.0.0.1:$TEST_NGINX_SERVER_PORT/;
-
- set $true 1;
-
- if ($true) {
- # nothing
- }
- }
---- request
-GET /proxy-pass-uri
---- response_body_like: It works!
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/086-init-by.t b/src/deps/src/lua-nginx-module/t/086-init-by.t
deleted file mode 100644
index 04f8160eb..000000000
--- a/src/deps/src/lua-nginx-module/t/086-init-by.t
+++ /dev/null
@@ -1,367 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 2);
-
-#no_diff();
-#no_long_string();
-no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity (inline)
---- http_config
- init_by_lua 'foo = "hello, FOO"';
---- config
- location /lua {
- content_by_lua 'ngx.say(foo)';
- }
---- request
-GET /lua
---- response_body
-hello, FOO
---- no_error_log
-[error]
-
-
-
-=== TEST 2: sanity (file)
---- http_config
- init_by_lua_file html/init.lua;
---- config
- location /lua {
- content_by_lua 'ngx.say(foo)';
- }
---- user_files
->>> init.lua
-foo = "hello, FOO"
---- request
-GET /lua
---- response_body
-hello, FOO
---- no_error_log
-[error]
-
-
-
-=== TEST 3: require
---- http_config
- lua_package_path "$prefix/html/?.lua;;";
- init_by_lua 'require "blah"';
---- config
- location /lua {
- content_by_lua '
- blah.go()
- ';
- }
---- user_files
->>> blah.lua
-module(..., package.seeall)
-
-function go()
- ngx.say("hello, blah")
-end
---- request
-GET /lua
---- response_body
-hello, blah
---- no_error_log
-[error]
-
-
-
-=== TEST 4: shdict (single)
---- http_config
- lua_shared_dict dogs 1m;
- init_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 6)
- dogs:get("Jim")
- ';
---- config
- location /lua {
- content_by_lua '
- local dogs = ngx.shared.dogs
- ngx.say("Jim: ", dogs:get("Jim"))
- ';
- }
---- request
-GET /lua
---- response_body
-Jim: 6
---- no_error_log
-[error]
-
-
-
-=== TEST 5: shdict (multi)
---- http_config
- lua_shared_dict dogs 1m;
- lua_shared_dict cats 1m;
- init_by_lua '
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 6)
- dogs:get("Jim")
- local cats = ngx.shared.cats
- cats:set("Tom", 2)
- dogs:get("Tom")
- ';
---- config
- location /lua {
- content_by_lua '
- local dogs = ngx.shared.dogs
- ngx.say("Jim: ", dogs:get("Jim"))
- ';
- }
---- request
-GET /lua
---- response_body
-Jim: 6
---- no_error_log
-[error]
-
-
-
-=== TEST 6: print
---- http_config
- lua_shared_dict dogs 1m;
- lua_shared_dict cats 1m;
- init_by_lua '
- print("log from init_by_lua")
- ';
---- config
- location /lua {
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- grep_error_log chop
-log from init_by_lua
---- grep_error_log_out eval
-["log from init_by_lua\n", ""]
-
-
-
-=== TEST 7: ngx.log
---- http_config
- lua_shared_dict dogs 1m;
- lua_shared_dict cats 1m;
- init_by_lua '
- ngx.log(ngx.NOTICE, "log from init_by_lua")
- ';
---- config
- location /lua {
- echo ok;
- }
---- request
-GET /lua
---- response_body
-ok
---- grep_error_log chop
-log from init_by_lua
---- grep_error_log_out eval
-["log from init_by_lua\n", ""]
-
-
-
-=== TEST 8: require (with shm defined)
---- http_config
- lua_package_path "$prefix/html/?.lua;;";
- lua_shared_dict dogs 1m;
- init_by_lua 'require "blah"';
---- config
- location /lua {
- content_by_lua '
- blah.go()
- ';
- }
---- user_files
->>> blah.lua
-module(..., package.seeall)
-
-function go()
- ngx.say("hello, blah")
-end
---- request
-GET /lua
---- response_body
-hello, blah
---- no_error_log
-[error]
-
-
-
-=== TEST 9: coroutine API (inlined init_by_lua)
---- http_config
- init_by_lua '
- local function f()
- foo = 32
- coroutine.yield(78)
- bar = coroutine.status(coroutine.running())
- end
- local co = coroutine.create(f)
- local ok, err = coroutine.resume(co)
- if not ok then
- print("Failed to resume our co: ", err)
- return
- end
- baz = err
- coroutine.resume(co)
- ';
---- config
- location /lua {
- content_by_lua '
- ngx.say("foo = ", foo)
- ngx.say("bar = ", bar)
- ngx.say("baz = ", baz)
- ';
- }
---- request
-GET /lua
---- response_body
-foo = 32
-bar = running
-baz = 78
---- no_error_log
-[error]
-Failed to resume our co:
-
-
-
-=== TEST 10: coroutine API (init_by_lua_file)
---- http_config
- init_by_lua_file html/init.lua;
-
---- config
- location /lua {
- content_by_lua '
- ngx.say("foo = ", foo)
- ngx.say("bar = ", bar)
- ngx.say("baz = ", baz)
- ';
- }
---- request
-GET /lua
---- user_files
->>> init.lua
-local function f()
- foo = 32
- coroutine.yield(78)
- bar = coroutine.status(coroutine.running())
-end
-local co = coroutine.create(f)
-local ok, err = coroutine.resume(co)
-if not ok then
- print("Failed to resume our co: ", err)
- return
-end
-baz = err
-coroutine.resume(co)
-
---- response_body
-foo = 32
-bar = running
-baz = 78
---- no_error_log
-[error]
-Failed to resume our co:
-
-
-
-=== TEST 11: access a field in the ngx. table
---- http_config
- init_by_lua '
- print("INIT 1: foo = ", ngx.foo)
- ngx.foo = 3
- print("INIT 2: foo = ", ngx.foo)
- ';
---- config
- location /t {
- echo ok;
- }
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/INIT \d+: foo = \S+/
---- grep_error_log_out eval
-[
-"INIT 1: foo = nil
-INIT 2: foo = 3
-",
-"",
-]
-
-
-
-=== TEST 12: error in init
---- http_config
- init_by_lua_block {
- error("failed to init")
- }
---- config
- location /t {
- echo ok;
- }
---- must_die
---- error_log
-failed to init
---- error_log
-[error]
-
-
-
-=== TEST 13: syntax error in init_by_lua_block
---- http_config
- init_by_lua_block {
- ngx.log(ngx.debug, "pass")
- error("failed to init"
- ngx.log(ngx.debug, "unreachable")
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("hello world")
- }
- }
---- must_die
---- error_log
-init_by_lua error: init_by_lua(nginx.conf:25):4: ')' expected (to close '(' at line 3) near 'ngx'
---- no_error_log
-no_such_error_log
-
-
-
-=== TEST 14: syntax error in init_by_lua_file
---- http_config
- init_by_lua_file html/init.lua;
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("hello world")
- }
- }
---- user_files
->>> init.lua
- ngx.log(ngx.debug, "pass")
- error("failed to init"
- ngx.log(ngx.debug, "unreachable")
-
---- must_die
---- error_log eval
-qr|init_by_lua_file error: .*?/t/servroot\w*?/html/init.lua:3: '\)' expected \(to close '\(' at line 2\) near 'ngx'|
---- no_error_log
-no_such_error_log
diff --git a/src/deps/src/lua-nginx-module/t/087-udp-socket.t b/src/deps/src/lua-nginx-module/t/087-udp-socket.t
deleted file mode 100644
index d1bc65436..000000000
--- a/src/deps/src/lua-nginx-module/t/087-udp-socket.t
+++ /dev/null
@@ -1,1334 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (3 * blocks() + 16);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-log_level 'warn';
-
-no_long_string();
-#no_diff();
-#no_shuffle();
-check_accum_error_log();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
- #set $port 1234;
-
- content_by_lua '
- local socket = ngx.socket
- -- local socket = require "socket"
-
- local udp = socket.udp()
-
- local port = ngx.var.port
- udp:settimeout(1000) -- 1 sec
-
- local ok, err = udp:setpeername("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected")
-
- local req = "\\0\\1\\0\\0\\0\\1\\0\\0flush_all\\r\\n"
- local ok, err = udp:send(req)
- if not ok then
- ngx.say("failed to send: ", err)
- return
- end
-
- local data, err = udp:receive()
- if not data then
- ngx.say("failed to receive data: ", err)
- return
- end
- ngx.print("received ", #data, " bytes: ", data)
- ';
- }
---- request
-GET /t
---- response_body eval
-"connected\nreceived 12 bytes: \x{00}\x{01}\x{00}\x{00}\x{00}\x{01}\x{00}\x{00}OK\x{0d}\x{0a}"
---- no_error_log
-[error]
---- log_level: debug
---- error_log
-lua udp socket receive buffer size: 65536
-
-
-
-=== TEST 2: multiple parallel queries
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
- #set $port 1234;
-
- content_by_lua '
- local socket = ngx.socket
- -- local socket = require "socket"
-
- local udp = socket.udp()
-
- local port = ngx.var.port
- udp:settimeout(1000) -- 1 sec
-
- local ok, err = udp:setpeername("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected")
-
- local req = "\\0\\1\\0\\0\\0\\1\\0\\0flush_all\\r\\n"
- local ok, err = udp:send(req)
- if not ok then
- ngx.say("failed to send: ", err)
- return
- end
-
- req = "\\0\\2\\0\\0\\0\\1\\0\\0flush_all\\r\\n"
- ok, err = udp:send(req)
- if not ok then
- ngx.say("failed to send: ", err)
- return
- end
-
- ngx.sleep(0.05)
-
- local data, err = udp:receive()
- if not data then
- ngx.say("failed to receive data: ", err)
- return
- end
- ngx.print("1: received ", #data, " bytes: ", data)
-
- data, err = udp:receive()
- if not data then
- ngx.say("failed to receive data: ", err)
- return
- end
- ngx.print("2: received ", #data, " bytes: ", data)
- ';
- }
---- request
-GET /t
---- response_body_like eval
-"^connected\n"
-."1: received 12 bytes: "
-."\x{00}[\1\2]\x{00}\x{00}\x{00}\x{01}\x{00}\x{00}OK\x{0d}\x{0a}"
-."2: received 12 bytes: "
-."\x{00}[\1\2]\x{00}\x{00}\x{00}\x{01}\x{00}\x{00}OK\x{0d}\x{0a}\$"
---- no_error_log
-[error]
-
-
-
-=== TEST 3: access a TCP interface
-test-nginx use the same port for tcp(http) and udp(http3)
-so need to change to a port that is not listen by any app.
-default port range:
-net.ipv4.ip_local_port_range = 32768 60999
-choose a port greater than 61000 should be less race.
---- config
- server_tokens off;
- location /t {
- set $port 65432;
-
- content_by_lua '
- local socket = ngx.socket
- -- local socket = require "socket"
-
- local udp = socket.udp()
-
- local port = ngx.var.port
- udp:settimeout(1000) -- 1 sec
-
- local ok, err = udp:setpeername("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected")
-
- local req = "\\0\\1\\0\\0\\0\\1\\0\\0flush_all\\r\\n"
- local ok, err = udp:send(req)
- if not ok then
- ngx.say("failed to send: ", err)
- return
- end
-
- local data, err = udp:receive()
- if not data then
- ngx.say("failed to receive data: ", err)
- return
- end
- ngx.print("received ", #data, " bytes: ", data)
- ';
- }
---- request
-GET /t
---- response_body
-connected
-failed to receive data: connection refused
---- error_log eval
-qr/recv\(\) failed \(\d+: Connection refused\)/
-
-
-
-=== TEST 4: access conflicts of connect() on shared udp objects
---- http_config
- lua_package_path '$prefix/html/?.lua;;';
---- config
- server_tokens off;
- location /main {
- content_by_lua '
- local reqs = {}
- for i = 1, 170 do
- table.insert(reqs, {"/t"})
- end
- local resps = {ngx.location.capture_multi(reqs)}
- for i = 1, 170 do
- ngx.say(resps[i].status)
- end
- ';
- }
-
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
- #set $port 1234;
-
- content_by_lua '
- local port = ngx.var.port
- local foo = require "foo"
- local udp = foo.get_udp()
-
- udp:settimeout(100) -- 100 ms
-
- local ok, err = udp:setpeername("127.0.0.1", port)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return ngx.exit(500)
- end
-
- ngx.say("connected")
-
- local data, err = udp:receive()
- if not data then
- ngx.say("failed to receive data: ", err)
- return
- end
- ngx.print("received ", #data, " bytes: ", data)
- ';
- }
---- user_files
->>> foo.lua
-module("foo", package.seeall)
-
-local udp
-
-function get_udp()
- if not udp then
- udp = ngx.socket.udp()
- end
-
- return udp
-end
-
---- stap2
-M(http-lua-info) {
- printf("udp resume: %p\n", $coctx)
- print_ubacktrace()
-}
-
---- request
-GET /main
---- response_body_like: \b500\b
---- error_log eval
-qr/content_by_lua\(nginx\.conf:\d+\):8: bad request/
-
-
-
-=== TEST 5: access conflicts of receive() on shared udp objects
---- http_config
- lua_package_path '$prefix/html/?.lua;;';
---- config
- server_tokens off;
- location /main {
- content_by_lua '
- local reqs = {}
- for i = 1, 170 do
- table.insert(reqs, {"/t"})
- end
- local resps = {ngx.location.capture_multi(reqs)}
- for i = 1, 170 do
- ngx.say(resps[i].status)
- end
- ';
- }
-
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
- #set $port 1234;
-
- content_by_lua '
- local port = ngx.var.port
- local foo = require "foo"
- local udp = foo.get_udp(port)
-
- local data, err = udp:receive()
- if not data then
- ngx.log(ngx.ERR, "failed to receive data: ", err)
- return ngx.exit(500)
- end
- ngx.print("received ", #data, " bytes: ", data)
- ';
- }
---- user_files
->>> foo.lua
-module("foo", package.seeall)
-
-local udp
-
-function get_udp(port)
- if not udp then
- udp = ngx.socket.udp()
-
- udp:settimeout(100) -- 100ms
-
- local ok, err = udp:setpeername("127.0.0.1", port)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return ngx.exit(500)
- end
- end
-
- return udp
-end
---- request
-GET /main
---- response_body_like: \b500\b
---- error_log eval
-qr/content_by_lua\(nginx\.conf:\d+\):6: bad request/
-
-
-
-=== TEST 6: connect again immediately
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.udp()
- local port = ngx.var.port
-
- local ok, err = sock:setpeername("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- ok, err = sock:setpeername("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected again: ", ok)
-
- local req = "\\0\\1\\0\\0\\0\\1\\0\\0flush_all\\r\\n"
- local ok, err = sock:send(req)
- if not ok then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.say("request sent: ", ok)
-
- local line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive: ", err)
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body eval
-"connected: 1
-connected again: 1
-request sent: 1
-received: \0\1\0\0\0\1\0\0OK\r\n
-close: 1 nil
-"
---- no_error_log
-[error]
---- error_log eval
-["lua reuse socket upstream", "lua udp socket reconnect without shutting down"]
---- log_level: debug
-
-
-
-=== TEST 7: recv timeout
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local port = ngx.var.port
-
- local sock = ngx.socket.udp()
- sock:settimeout(100) -- 100 ms
-
- local ok, err = sock:setpeername("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local line, err = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive: ", err)
- end
-
- -- ok, err = sock:close()
- -- ngx.say("close: ", ok, " ", err)
- ';
- }
-
- location /foo {
- echo foo;
- more_clear_headers Date;
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: timeout
---- error_log
-lua udp socket read timed out
-
-
-
-=== TEST 8: with an explicit receive buffer size argument
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
- #set $port 1234;
-
- content_by_lua '
- local socket = ngx.socket
- -- local socket = require "socket"
-
- local udp = socket.udp()
-
- local port = ngx.var.port
- udp:settimeout(1000) -- 1 sec
-
- local ok, err = udp:setpeername("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected")
-
- local req = "\\0\\1\\0\\0\\0\\1\\0\\0flush_all\\r\\n"
- local ok, err = udp:send(req)
- if not ok then
- ngx.say("failed to send: ", err)
- return
- end
-
- local data, err = udp:receive(1400)
- if not data then
- ngx.say("failed to receive data: ", err)
- return
- end
- ngx.print("received ", #data, " bytes: ", data)
- ';
- }
---- request
-GET /t
---- response_body eval
-"connected\nreceived 12 bytes: \x{00}\x{01}\x{00}\x{00}\x{00}\x{01}\x{00}\x{00}OK\x{0d}\x{0a}"
---- no_error_log
-[error]
---- log_level: debug
---- error_log
-lua udp socket receive buffer size: 1400
-
-
-
-=== TEST 9: read timeout and re-receive
---- config
- location = /t {
- content_by_lua '
- local udp = ngx.socket.udp()
- udp:settimeout(30)
- local ok, err = udp:setpeername("127.0.0.1", 19232)
- if not ok then
- ngx.say("failed to setpeername: ", err)
- return
- end
- local ok, err = udp:send("blah")
- if not ok then
- ngx.say("failed to send: ", err)
- return
- end
- for i = 1, 2 do
- local data, err = udp:receive()
- if err == "timeout" then
- -- continue
- else
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
- ngx.say("received: ", data)
- return
- end
- end
-
- ngx.say("timed out")
- ';
- }
---- udp_listen: 19232
---- udp_reply: hello world
---- udp_reply_delay: 45ms
---- request
-GET /t
---- response_body
-received: hello world
---- error_log
-lua udp socket read timed out
-
-
-
-=== TEST 10: access the google DNS server (using IP addr)
---- config
- server_tokens off;
- location /t {
- content_by_lua '
- local socket = ngx.socket
- -- local socket = require "socket"
-
- local udp = socket.udp()
-
- udp:settimeout(5000) -- 5 sec
-
- local ok, err = udp:setpeername("$TEST_NGINX_RESOLVER", 53)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "\\0}\\1\\0\\0\\1\\0\\0\\0\\0\\0\\0\\3www\\6google\\3com\\0\\0\\1\\0\\1"
-
- -- ngx.print(req)
- -- do return end
-
- local ok, err = udp:send(req)
- if not ok then
- ngx.say("failed to send: ", err)
- return
- end
-
- local data, err = udp:receive()
- if not data then
- ngx.say("failed to receive data: ", err)
- return
- end
-
- if string.match(data, "\\3www\\6google\\3com") then
- ngx.say("received a good response.")
- else
- ngx.say("received a bad response: ", #data, " bytes: ", data)
- end
- ';
- }
---- request
-GET /t
---- response_body
-received a good response.
---- no_error_log
-[error]
---- log_level: debug
---- error_log
-lua udp socket receive buffer size: 65536
---- no_check_leak
-
-
-
-=== TEST 11: access the google DNS server (using domain names)
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- -- avoid flushing google in "check leak" testing mode:
- local counter = package.loaded.counter
- if not counter then
- counter = 1
- elseif counter >= 2 then
- return ngx.exit(503)
- else
- counter = counter + 1
- end
- package.loaded.counter = counter
-
- local socket = ngx.socket
- -- local socket = require "socket"
-
- local udp = socket.udp()
-
- udp:settimeout(2000) -- 2 sec
-
- local ok, err = udp:setpeername("google-public-dns-a.google.com", 53)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "\\0}\\1\\0\\0\\1\\0\\0\\0\\0\\0\\0\\3www\\6google\\3com\\0\\0\\1\\0\\1"
-
- -- ngx.print(req)
- -- do return end
-
- local ok, err = udp:send(req)
- if not ok then
- ngx.say("failed to send: ", err)
- return
- end
-
- local data, err = udp:receive()
- if not data then
- ngx.say("failed to receive data: ", err)
- return
- end
-
- if string.match(data, "\\3www\\6google\\3com") then
- ngx.say("received a good response.")
- else
- ngx.say("received a bad response: ", #data, " bytes: ", data)
- end
- ';
- }
---- request
-GET /t
---- response_body
-received a good response.
---- no_error_log
-[error]
---- log_level: debug
---- error_log
-lua udp socket receive buffer size: 65536
---- no_check_leak
-
-
-
-=== TEST 12: github issue #215: Handle the posted requests in lua cosocket api (failed to resolve)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 5s;
-
- location = /sub {
- content_by_lua '
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername("xxx", 80)
- if not ok then
- ngx.say("failed to connect to xxx: ", err)
- return
- end
- ngx.say("successfully connected to xxx!")
- sock:close()
- ';
- }
-
- location = /lua {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ';
- }
---- request
-GET /sub
-
---- stap
-F(ngx_resolve_name_done) {
- println("resolve name done")
-}
-
---- stap_out
-resolve name done
-
---- response_body_like chop
-^failed to connect to xxx: xxx could not be resolved.*?Host not found
-
---- no_error_log
-[error]
---- timeout: 10
-
-
-
-=== TEST 13: github issue #215: Handle the posted requests in lua cosocket api (successfully resolved)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 5s;
-
- location = /sub {
- content_by_lua '
- if not package.i then
- package.i = 1
- end
-
- local servers = {"openresty.org", "agentzh.org", "sregex.org"}
- local server = servers[package.i]
- package.i = package.i + 1
-
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername(server, 80)
- if not ok then
- ngx.say("failed to connect to ", server, ": ", err)
- return
- end
- ngx.say("successfully connected to xxx!")
- sock:close()
- ';
- }
-
- location = /lua {
- content_by_lua '
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- ';
- }
---- request
-GET /lua
---- response_body
-successfully connected to xxx!
-
---- no_error_log
-[error]
---- timeout: 10
-
-
-
-=== TEST 14: datagram unix domain socket
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
- #set $port 1234;
-
- content_by_lua '
- local socket = ngx.socket
- -- local socket = require "socket"
-
- local udp = socket.udp()
-
- local port = ngx.var.port
- udp:settimeout(1000) -- 1 sec
-
- local ok, err = udp:setpeername("unix:a.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected")
-
- local req = "hello,\\nserver"
- local ok, err = udp:send(req)
- if not ok then
- ngx.say("failed to send: ", err)
- return
- end
-
- local data, err = udp:receive()
- if not data then
- ngx.say("failed to receive data: ", err)
- return
- end
- ngx.print("received ", #data, " bytes: ", data)
- ';
- }
---- request
-GET /t
-
---- udp_listen: a.sock
---- udp_reply
-hello,
-client
-
---- response_body
-connected
-received 14 bytes: hello,
-client
-
---- stap2
-probe syscall.socket, syscall.connect {
- print(name, "(", argstr, ")")
-}
-
-probe syscall.socket.return, syscall.connect.return {
- println(" = ", retstr)
-}
---- no_error_log
-[error]
-[crit]
---- skip_eval: 3: $^O ne 'linux'
-
-
-
-=== TEST 15: bad request tries to setpeer
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location = /main {
- echo_location /t?reset=1;
- echo_location /t;
- }
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local test = require "test"
- if ngx.var.arg_reset then
- local sock = test.new_sock()
- local ok, err = sock:setpeername("127.0.0.1", ngx.var.port)
- if not ok then
- ngx.say("failed to set peer: ", err)
- else
- ngx.say("peer set")
- end
- return
- end
- local sock = test.get_sock()
- sock:setpeername("127.0.0.1", ngx.var.port)
- ';
- }
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.udp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^peer set
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.udp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^peer set
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.udp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^peer set
->> test.lua
-module("test", package.seeall)
-
-local sock
-
-function new_sock()
- sock = ngx.socket.udp()
- return sock
-end
-
-function get_sock()
- return sock
-end
---- request
-GET /main
---- response_body_like eval
-qr/^peer set
- repeat_each() * (blocks() * 3);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: get method name in main request
---- config
- location /t {
- content_by_lua '
- ngx.say("method: [", ngx.req.get_method(), "]")
- ';
- }
---- request
- GET /t
---- response_body
-method: [GET]
---- no_error_log
-[error]
-
-
-
-=== TEST 2: get method name in subrequest
---- config
- location /t {
- echo_subrequest POST /sub;
- }
-
- location /sub {
- content_by_lua '
- ngx.say("method: [", ngx.req.get_method(), "]")
- ';
- }
---- request
- GET /t
---- response_body
-method: [POST]
---- no_error_log
-[error]
-
-
-
-=== TEST 3: set GET to POST
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_method(ngx.HTTP_POST)
- ';
-
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
-
- location /echo {
- echo $request_method;
- }
---- request
-GET /t
---- response_body
-POST
---- no_error_log
-[error]
-
-
-
-=== TEST 4: set POST to GET
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_method(ngx.HTTP_GET)
- ';
-
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
-
- location /echo {
- echo $request_method;
- }
---- request
-POST /t
-hello world
---- response_body
-GET
---- no_error_log
-[error]
-
-
-
-=== TEST 5: set POST to DELETE
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_method(ngx.HTTP_DELETE)
- ';
-
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
-
- location /echo {
- echo $request_method;
- }
---- request
-POST /t
-hello world
---- response_body
-DELETE
---- no_error_log
-[error]
-
-
-
-=== TEST 6: set POST to PUT
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_method(ngx.HTTP_PUT)
- ';
-
- proxy_pass http://127.0.0.1:$server_port/echo;
- }
-
- location /echo {
- echo $request_method;
- }
---- request
-POST /t
-hello world
---- response_body
-PUT
---- no_error_log
-[error]
-
-
-
-=== TEST 7: set POST to PUT (using $requeset_method)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_method(ngx.HTTP_PUT)
- ';
-
- echo $request_method;
- }
---- request
-POST /t
-hello world
---- response_body
-PUT
---- no_error_log
-[error]
-
-
-
-=== TEST 8: set GET to HEAD
---- no_http2
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_method(ngx.HTTP_HEAD)
- ';
-
- proxy_pass http://127.0.0.1:$server_port/echo;
- #proxy_pass http://127.0.0.1:8888/;
- }
-
- location /echo {
- echo $request_method;
- }
---- request
-GET /t
---- response_body
---- no_error_log
-[error]
-
-
-
-=== TEST 9: set method name in subrequest
---- config
- location /t {
- echo_subrequest POST /sub;
- echo "main: $echo_request_method";
- }
-
- location /sub {
- content_by_lua '
- ngx.req.set_method(ngx.HTTP_PUT)
- ngx.say("sub: ", ngx.var.echo_request_method)
- ';
- }
---- request
- GET /t
---- response_body
-sub: PUT
-main: GET
---- no_error_log
-[error]
-
-
-
-=== TEST 10: set HEAD to GET
-XXX: does http3 do not support set HEAD to GET??
---- no_http2
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_method(ngx.HTTP_GET)
- ';
-
- echo "method: $echo_request_method";
- }
---- request
- HEAD /t
---- response_body
-method: GET
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 11: set GET to WebDAV methods
-XXX: does http3 do not support change HEAD method?
---- no_http2
---- config
- location /t {
- content_by_lua '
- local methods = {
- ngx.HTTP_MKCOL,
- ngx.HTTP_COPY,
- ngx.HTTP_MOVE,
- ngx.HTTP_PROPFIND,
- ngx.HTTP_PROPPATCH,
- ngx.HTTP_LOCK,
- ngx.HTTP_UNLOCK,
- ngx.HTTP_PATCH,
- ngx.HTTP_TRACE,
- }
-
- for i, method in ipairs(methods) do
- ngx.req.set_method(method)
- ngx.say("method: ", ngx.var.echo_request_method)
- end
- ';
- }
---- request
- HEAD /t
---- response_body
-method: MKCOL
-method: COPY
-method: MOVE
-method: PROPFIND
-method: PROPPATCH
-method: LOCK
-method: UNLOCK
-method: PATCH
-method: TRACE
---- no_error_log
-[error]
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
diff --git a/src/deps/src/lua-nginx-module/t/089-phase.t b/src/deps/src/lua-nginx-module/t/089-phase.t
deleted file mode 100644
index 028c400c7..000000000
--- a/src/deps/src/lua-nginx-module/t/089-phase.t
+++ /dev/null
@@ -1,223 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 2) + 2;
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: get_phase in init_by_lua
---- http_config
- init_by_lua 'phase = ngx.get_phase()';
---- config
- location /lua {
- content_by_lua '
- ngx.say(phase)
- ';
- }
---- request
-GET /lua
---- response_body
-init
-
-
-
-=== TEST 2: get_phase in set_by_lua
---- config
- set_by_lua $phase 'return ngx.get_phase()';
- location /lua {
- content_by_lua '
- ngx.say(ngx.var.phase)
- ';
- }
---- request
-GET /lua
---- response_body
-set
-
-
-
-=== TEST 3: get_phase in rewrite_by_lua
---- config
- location /lua {
- rewrite_by_lua '
- ngx.say(ngx.get_phase())
- ngx.exit(200)
- ';
- }
---- request
-GET /lua
---- response_body
-rewrite
-
-
-
-=== TEST 4: get_phase in access_by_lua
---- config
- location /lua {
- access_by_lua '
- ngx.say(ngx.get_phase())
- ngx.exit(200)
- ';
- }
---- request
-GET /lua
---- response_body
-access
-
-
-
-=== TEST 5: get_phase in content_by_lua
---- config
- location /lua {
- content_by_lua '
- ngx.say(ngx.get_phase())
- ';
- }
---- request
-GET /lua
---- response_body
-content
-
-
-
-=== TEST 6: get_phase in header_filter_by_lua
---- config
- location /lua {
- echo "OK";
- header_filter_by_lua '
- ngx.header.Phase = ngx.get_phase()
- ';
- }
---- request
-GET /lua
---- response_header
-Phase: header_filter
-
-
-
-=== TEST 7: get_phase in body_filter_by_lua
---- config
- location /lua {
- content_by_lua '
- ngx.exit(200)
- ';
- body_filter_by_lua '
- ngx.arg[1] = ngx.get_phase()
- ';
- }
---- request
-GET /lua
---- response_body chop
-body_filter
-
-
-
-=== TEST 8: get_phase in log_by_lua
---- config
- location /lua {
- echo "OK";
- log_by_lua '
- ngx.log(ngx.ERR, ngx.get_phase())
- ';
- }
---- request
-GET /lua
---- error_log
-log
-
-
-
-=== TEST 9: get_phase in ngx.timer callback
---- config
- location /lua {
- echo "OK";
- log_by_lua '
- local function f()
- ngx.log(ngx.WARN, "current phase: ", ngx.get_phase())
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to add timer: ", err)
- end
- ';
- }
---- request
-GET /lua
---- no_error_log
-[error]
---- error_log
-current phase: timer
-
-
-
-=== TEST 10: get_phase in init_worker_by_lua
---- http_config
- init_worker_by_lua 'phase = ngx.get_phase()';
---- config
- location /lua {
- content_by_lua '
- ngx.say(phase)
- ';
- }
---- request
-GET /lua
---- response_body
-init_worker
---- no_error_log
-[error]
-
-
-
-=== TEST 11: get_phase in exit_worker_by_lua
---- http_config
- exit_worker_by_lua_block {
- local phase = ngx.get_phase()
- ngx.log(ngx.ERR, phase)
- ngx.log(ngx.ERR, "exiting now")
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("ok")
- }
- }
---- request
-GET /lua
---- response_body
-ok
---- shutdown_error_log eval
-[
-qr/exit_worker_by_lua\(nginx\.conf:\d+\):\d+: exit_worker/,
-qr/exiting now$/,
-]
-
-
-
-=== TEST 12: server_rewrite_by_lua_block in http
---- http_config
- server_rewrite_by_lua_block {
- ngx.ctx.phase = ngx.get_phase()
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.ctx.phase)
- }
- }
---- request
-GET /lua
---- response_body
-server_rewrite
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/090-log-socket-errors.t b/src/deps/src/lua-nginx-module/t/090-log-socket-errors.t
deleted file mode 100644
index f5a9f80b7..000000000
--- a/src/deps/src/lua-nginx-module/t/090-log-socket-errors.t
+++ /dev/null
@@ -1,108 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: log socket errors off (tcp)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
-
- location /t {
- lua_socket_connect_timeout 1ms;
- lua_socket_log_errors off;
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.2", 12345)
- ngx.say(err)
- ';
- }
---- request
-GET /t
---- response_body
-timeout
---- no_error_log
-[error]
-
-
-
-=== TEST 2: log socket errors on (tcp)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
-
- location /t {
- lua_socket_connect_timeout 1ms;
- lua_socket_log_errors on;
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.2", 12345)
- ngx.say(err)
- ';
- }
---- request
-GET /t
---- response_body
-timeout
---- error_log
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
-
-
-
-=== TEST 3: log socket errors on (udp)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
-
- location /t {
- lua_socket_log_errors on;
- lua_socket_read_timeout 1ms;
- content_by_lua '
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername("127.0.0.2", 12345)
- ok, err = sock:receive()
- ngx.say(err)
- ';
- }
---- request
-GET /t
---- response_body
-timeout
---- error_log
-lua udp socket read timed out
-
-
-
-=== TEST 4: log socket errors off (udp)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
-
- location /t {
- lua_socket_log_errors off;
- lua_socket_read_timeout 1ms;
- content_by_lua '
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername("127.0.0.2", 12345)
- ok, err = sock:receive()
- ngx.say(err)
- ';
- }
---- request
-GET /t
---- response_body
-timeout
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/091-coroutine.t b/src/deps/src/lua-nginx-module/t/091-coroutine.t
deleted file mode 100644
index bfbdb3893..000000000
--- a/src/deps/src/lua-nginx-module/t/091-coroutine.t
+++ /dev/null
@@ -1,1750 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 14);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-our $StapScript = <<'_EOC_';
-global ids, cur
-
-function gen_id(k) {
- if (ids[k]) return ids[k]
- ids[k] = ++cur
- return cur
-}
-
-F(ngx_http_handler) {
- delete ids
- cur = 0
-}
-
-/*
-F(ngx_http_lua_run_thread) {
- id = gen_id($ctx->cur_co)
- printf("run thread %d\n", id)
-}
-
-probe process("/usr/local/openresty-debug/luajit/lib/libluajit-5.1.so.2").function("lua_resume") {
- id = gen_id($L)
- printf("lua resume %d\n", id)
-}
-*/
-
-M(http-lua-user-coroutine-resume) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("resume %x in %x\n", c, p)
-}
-
-M(http-lua-thread-yield) {
- println("thread yield")
-}
-
-/*
-F(ngx_http_lua_coroutine_yield) {
- printf("yield %x\n", gen_id($L))
-}
-*/
-
-M(http-lua-user-coroutine-yield) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("yield %x in %x\n", c, p)
-}
-
-F(ngx_http_lua_atpanic) {
- printf("lua atpanic(%d):", gen_id($L))
- print_ubacktrace();
-}
-
-M(http-lua-user-coroutine-create) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("create %x in %x\n", c, p)
-}
-
-F(ngx_http_lua_ngx_exec) { println("exec") }
-
-F(ngx_http_lua_ngx_exit) { println("exit") }
-F(ngx_http_lua_ffi_exit) { println("exit") }
-_EOC_
-
-no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: basic coroutine print
---- config
- location /lua {
- content_by_lua '
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
-
- local function f()
- local cnt = 0
- for i = 1, 20 do
- ngx.say("Hello, ", cnt)
- cy()
- cnt = cnt + 1
- end
- end
-
- local c = cc(f)
- for i=1,3 do
- cr(c)
- ngx.say("***")
- end
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- response_body
-Hello, 0
-***
-Hello, 1
-***
-Hello, 2
-***
---- no_error_log
-[error]
-
-
-
-=== TEST 2: basic coroutine2
---- config
- location /lua {
- content_by_lua '
- local function f(fid)
- local cnt = 0
- while true do
- ngx.say("cc", fid, ": ", cnt)
- coroutine.yield()
- cnt = cnt + 1
- end
- end
-
- local ccs = {}
- for i=1,3 do
- ccs[#ccs+1] = coroutine.create(function() f(i) end)
- end
-
- for i=1,9 do
- local cc = table.remove(ccs, 1)
- coroutine.resume(cc)
- ccs[#ccs+1] = cc
- end
- ';
- }
---- request
-GET /lua
---- response_body
-cc1: 0
-cc2: 0
-cc3: 0
-cc1: 1
-cc2: 1
-cc3: 1
-cc1: 2
-cc2: 2
-cc3: 2
---- no_error_log
-[error]
-
-
-
-=== TEST 3: basic coroutine and cosocket
-access the public network is unstable, need a bigger timeout
---- quic_max_idle_timeout: 4
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /lua {
- content_by_lua '
- local function worker(url)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect(url, 80)
- coroutine.yield()
- if not ok then
- ngx.say("failed to connect to: ", url, " error: ", err)
- return
- end
- coroutine.yield()
- ngx.say("successfully connected to: ", url)
- sock:close()
- end
-
- local urls = {
- "agentzh.org",
- "openresty.com",
- "openresty.org"
- }
-
- local ccs = {}
- for i, url in ipairs(urls) do
- local cc = coroutine.create(function() worker(url) end)
- ccs[#ccs+1] = cc
- end
-
- while true do
- if #ccs == 0 then break end
- local cc = table.remove(ccs, 1)
- local ok = coroutine.resume(cc)
- if ok then
- ccs[#ccs+1] = cc
- end
- end
-
- ngx.say("*** All Done ***")
- ';
- }
---- request
-GET /lua
---- response_body
-successfully connected to: agentzh.org
-successfully connected to: openresty.com
-successfully connected to: openresty.org
-*** All Done ***
---- no_error_log
-[error]
---- timeout: 10
-
-
-
-=== TEST 4: coroutine.wrap(generate prime numbers)
---- config
- location /lua {
- content_by_lua '
- -- generate all the numbers from 2 to n
- local function gen (n)
- return coroutine.wrap(function ()
- for i=2,n do coroutine.yield(i) end
- end)
- end
-
- -- filter the numbers generated by g, removing multiples of p
- local function filter (p, g)
- return coroutine.wrap(function ()
- while 1 do
- local n = g()
- if n == nil then return end
- if math.fmod(n, p) ~= 0 then coroutine.yield(n) end
- end
- end)
- end
-
- local N = 10
- local x = gen(N) -- generate primes up to N
- while 1 do
- local n = x() -- pick a number until done
- if n == nil then break end
- ngx.say(n) -- must be a prime number
- x = filter(n, x) -- now remove its multiples
- end
- ';
- }
---- request
-GET /lua
---- response_body
-2
-3
-5
-7
---- no_error_log
-[error]
-
-
-
-=== TEST 5: coroutine.wrap(generate prime numbers,reset create and resume)
---- config
- location /lua {
- content_by_lua '
- coroutine.create = nil
- coroutine.resume = nil
- -- generate all the numbers from 2 to n
- local function gen (n)
- return coroutine.wrap(function ()
- for i=2,n do coroutine.yield(i) end
- end)
- end
-
- -- filter the numbers generated by g, removing multiples of p
- local function filter (p, g)
- return coroutine.wrap(function ()
- while 1 do
- local n = g()
- if n == nil then return end
- if math.fmod(n, p) ~= 0 then coroutine.yield(n) end
- end
- end)
- end
-
- local N = 10
- local x = gen(N) -- generate primes up to N
- while 1 do
- local n = x() -- pick a number until done
- if n == nil then break end
- ngx.say(n) -- must be a prime number
- x = filter(n, x) -- now remove its multiples
- end
- ';
- }
---- request
-GET /lua
---- response_body
-2
-3
-5
-7
---- no_error_log
-[error]
-
-
-
-=== TEST 6: coroutine.wrap(generate fib)
---- config
- location /lua {
- content_by_lua '
- local function generatefib (n)
- return coroutine.wrap(function ()
- local a,b = 1, 1
- while a <= n do
- coroutine.yield(a)
- a, b = b, a+b
- end
- end)
- end
-
- -- In lua, because OP_TFORLOOP uses luaD_call to execute the iterator function,
- -- and luaD_call is a C function, so we can not yield in the iterator function.
- -- So the following case(using for loop) will be failed.
- -- Luajit is OK.
- if package.loaded["jit"] then
- for i in generatefib(1000) do ngx.say(i) end
- else
- local gen = generatefib(1000)
- while true do
- local i = gen()
- if not i then break end
- ngx.say(i)
- end
- end
- ';
- }
---- request
-GET /lua
---- response_body
-1
-1
-2
-3
-5
-8
-13
-21
-34
-55
-89
-144
-233
-377
-610
-987
---- no_error_log
-[error]
-
-
-
-=== TEST 7: coroutine wrap and cosocket
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /lua {
- content_by_lua '
- local function worker(url)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect(url, 80)
- coroutine.yield()
- if not ok then
- ngx.say("failed to connect to: ", url, " error: ", err)
- return
- end
- coroutine.yield()
- ngx.say("successfully connected to: ", url)
- sock:close()
- end
-
- local urls = {
- "agentzh.org",
- "openresty.com",
- "openresty.org"
- }
-
- local cfs = {}
- for i, url in ipairs(urls) do
- local cf = coroutine.wrap(function() worker(url) end)
- cfs[#cfs+1] = cf
- end
-
- for i=1,3 do cfs[i]() end
- for i=1,3 do cfs[i]() end
- for i=1,3 do cfs[i]() end
-
- ngx.say("*** All Done ***")
- ';
- }
---- request
-GET /lua
---- response_body
-successfully connected to: agentzh.org
-successfully connected to: openresty.com
-successfully connected to: openresty.org
-*** All Done ***
---- no_error_log
-[error]
---- timeout: 10
-
-
-
-=== TEST 8: coroutine status, running
---- config
- location /lua {
- content_by_lua '
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
- local st, rn = coroutine.status, coroutine.running
-
- local function f(self)
- local cnt = 0
- if rn() ~= self then ngx.say("error"); return end
- ngx.say("running: ", st(self)) --running
- cy()
- local c = cc(function(father)
- ngx.say("normal: ", st(father))
- end) -- normal
- cr(c, self)
- end
-
- local c = cc(f)
- ngx.say("suspended: ", st(c)) -- suspended
- cr(c, c)
- ngx.say("suspended: ", st(c)) -- suspended
- cr(c, c)
- ngx.say("dead: ", st(c)) -- dead
- ';
- }
---- request
-GET /lua
---- response_body
-suspended: suspended
-running: running
-suspended: suspended
-normal: normal
-dead: dead
---- no_error_log
-[error]
-
-
-
-=== TEST 9: entry coroutine yielded will be resumed immediately
---- config
- location /lua {
- content_by_lua '
- ngx.say("[", {coroutine.yield()}, "]")
- ngx.say("[", {coroutine.yield(1, "a")}, "]")
- ngx.say("done")
- ';
- }
---- request
-GET /lua
---- response_body
-[]
-[]
-done
---- no_error_log
-[error]
-
-
-
-=== TEST 10: thread traceback (multi-thread)
-Note: only coroutine.wrap propagates errors to the parent coroutine
-(and thus produces a traceback)
---- config
- location /lua {
- content_by_lua_block {
- local f = function(cr) coroutine.resume(cr) end
- -- emit a error
- local g = function() unknown.unknown = 1 end
- local l1 = coroutine.wrap(f)
- local l2 = coroutine.wrap(g)
- local l3 = coroutine.wrap(function() l1(l2) end)
- l3()
- ngx.say("hello")
- }
- }
---- request
-GET /lua
---- error_code: 500
---- response_body_unlike
-hello
---- error_log eval
-["stack traceback:", "coroutine 0:", "coroutine 1:", "coroutine 2:"]
-
-
-
-=== TEST 11: thread traceback (only the entry thread)
---- config
- location /lua {
- content_by_lua '
- -- emit a error
- unknown.unknown = 1
- ngx.say("hello")
- ';
- }
---- request
-GET /lua
---- error_code: 500
---- error_log eval
-["stack traceback:", "coroutine 0:"]
-
-
-
-=== TEST 12: bug: resume dead coroutine with args
---- config
- location /lua {
- content_by_lua '
- local function print(...)
- local args = {...}
- local is_first = true
- for i,v in ipairs(args) do
- if is_first then
- is_first = false
- else
- ngx.print(" ")
- end
- ngx.print(v)
- end
- ngx.print("\\\n")
- end
-
- local function foo (a)
- print("foo", a)
- return coroutine.yield(2*a)
- end
-
- local co = coroutine.create(function (a,b)
- print("co-body", a, b)
- local r = foo(a+1)
- print("co-body", r)
- local r, s = coroutine.yield(a+b, a-b)
- print("co-body", r, s)
- return b, "end"
- end)
-
- print("main", coroutine.resume(co, 1, 10))
- print("main", coroutine.resume(co, "r"))
- print("main", coroutine.resume(co, "x", "y"))
- print("main", coroutine.resume(co, "x", "y"))
- ';
- }
---- request
-GET /lua
---- response_body
-co-body 1 10
-foo 2
-main true 4
-co-body r
-main true 11 -9
-co-body x y
-main true 10 end
-main false cannot resume dead coroutine
---- no_error_log
-[error]
-
-
-
-=== TEST 13: deeply nested coroutines
---- config
- location /lua {
- content_by_lua '
- local create = coroutine.create
- local resume = coroutine.resume
- local yield = coroutine.yield
- local g
- local function f()
- ngx.say("f begin")
- yield()
- local c2 = create(g)
- ngx.say("1: resuming c2")
- resume(c2)
- ngx.say("2: resuming c2")
- resume(c2)
- yield()
- ngx.say("3: resuming c2")
- resume(c2)
- ngx.say("f done")
- end
-
- function g()
- ngx.say("g begin")
- yield()
- ngx.say("g going")
- yield()
- ngx.say("g done")
- end
-
- local c1 = create(f)
- ngx.say("1: resuming c1")
- resume(c1)
- ngx.say("2: resuming c1")
- resume(c1)
- ngx.say("3: resuming c1")
- resume(c1)
- ngx.say("main done")
- ';
- }
---- request
-GET /lua
---- response_body
-1: resuming c1
-f begin
-2: resuming c1
-1: resuming c2
-g begin
-2: resuming c2
-g going
-3: resuming c1
-3: resuming c2
-g done
-f done
-main done
---- no_error_log
-[error]
-
-
-
-=== TEST 14: using ngx.exit in user coroutines
---- config
- location /lua {
- content_by_lua '
- local create = coroutine.create
- local resume = coroutine.resume
- local yield = coroutine.yield
-
- local code = 400
- local g
-
- local function f()
- local c2 = create(g)
- yield()
- code = code + 1
- resume(c2)
- yield()
- resume(c2)
- end
-
- function g()
- code = code + 1
- yield()
- code = code + 1
- ngx.exit(code)
- end
-
- local c1 = create(f)
- resume(c1)
- resume(c1)
- resume(c1)
- ngx.say("done")
- ';
- }
---- request
-GET /lua
---- stap eval: $::StapScript
---- stap_out
-create 2 in 1
-resume 2 in 1
-create 3 in 2
-yield 2 in 1
-resume 2 in 1
-resume 3 in 2
-yield 3 in 2
-yield 2 in 1
-resume 2 in 1
-resume 3 in 2
-exit
-
---- response_body_like: 403 Forbidden
---- error_code: 403
---- no_error_log
-[error]
-
-
-
-=== TEST 15: using ngx.exec in user coroutines
---- config
- location /lua {
- content_by_lua '
- local create = coroutine.create
- local resume = coroutine.resume
- local yield = coroutine.yield
-
- local code = 0
- local g
-
- local function f()
- local c2 = create(g)
- yield()
- code = code + 1
- resume(c2)
- yield()
- resume(c2)
- end
-
- function g()
- code = code + 1
- yield()
- code = code + 1
- ngx.exec("/n/" .. code)
- end
-
- local c1 = create(f)
- resume(c1)
- resume(c1)
- resume(c1)
- ngx.say("done")
- ';
- }
-
- location ~ '^/n/(\d+)' {
- echo "num: $1";
- }
-
---- stap eval: $::StapScript
---- stap_out
-create 2 in 1
-resume 2 in 1
-create 3 in 2
-yield 2 in 1
-resume 2 in 1
-resume 3 in 2
-yield 3 in 2
-yield 2 in 1
-resume 2 in 1
-resume 3 in 2
-exec
-
---- request
-GET /lua
---- response_body
-num: 3
---- no_error_log
-[error]
-
-
-
-=== TEST 16: coroutine.create in header_filter_by_lua
---- config
- location /lua {
- echo hello;
- header_filter_by_lua '
- local function f()
- yield()
- end
-
- local c1 = coroutine.create(f)
- ngx.say("done")
- ';
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-API disabled in the context of header_filter_by_lua*
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 17: resume coroutines from within another one that is not its parent
---- config
- location /t {
- content_by_lua '
- local print = ngx.say
-
- local c1, c2
-
- local function f()
- print("f 1")
- print(coroutine.resume(c2))
- print("f 2")
- end
-
- local function g()
- print("g 1")
- -- print(coroutine.resume(c1))
- print("g 2")
- end
-
- c1 = coroutine.create(f)
- c2 = coroutine.create(g)
-
- coroutine.resume(c1)
- ';
- }
---- request
-GET /t
---- response_body
-f 1
-g 1
-g 2
-true
-f 2
---- no_error_log
-[error]
-
-
-
-=== TEST 18: infinite recursive calls of coroutine.resume
---- config
- location /t {
- content_by_lua '
- local print = ngx.say
-
- local c1, c2
-
- local function f()
- print("f 1")
- print(coroutine.resume(c2))
- print("f 2")
- end
-
- local function g()
- print("g 1")
- print(coroutine.resume(c1))
- print("g 2")
- end
-
- c1 = coroutine.create(f)
- c2 = coroutine.create(g)
-
- coroutine.resume(c1)
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- response_body
-f 1
-g 1
-falsecannot resume normal coroutine
-g 2
-true
-f 2
---- no_error_log
-[error]
-
-
-
-=== TEST 19: resume running (entry) coroutines
---- config
- location /t {
- content_by_lua '
- ngx.say(coroutine.status(coroutine.running()))
- ngx.say(coroutine.resume(coroutine.running()))
- ';
- }
---- request
-GET /t
---- response_body
-running
-falsecannot resume running coroutine
---- no_error_log
-[error]
-
-
-
-=== TEST 20: resume running (user) coroutines
---- config
- location /t {
- content_by_lua '
- local co
- local function f()
- ngx.say("f: ", coroutine.status(co))
- ngx.say("f: ", coroutine.resume(co))
- end
- co = coroutine.create(f)
- ngx.say("chunk: ", coroutine.status(co))
- ngx.say("chunk: ", coroutine.resume(co))
- ';
- }
---- request
-GET /t
---- response_body
-chunk: suspended
-f: running
-f: falsecannot resume running coroutine
-chunk: true
---- no_error_log
-[error]
-
-
-
-=== TEST 21: user coroutine end with errors, and the parent coroutine gets the right status
---- config
- location /t {
- content_by_lua '
- local co
- local function f()
- error("bad")
- end
- co = coroutine.create(f)
- ngx.say("child: resume: ", coroutine.resume(co))
- ngx.say("child: status: ", coroutine.status(co))
- ngx.say("parent: status: ", coroutine.status(coroutine.running()))
- ';
- }
---- request
-GET /t
---- response_body eval
-qr/^child: resume: falsecontent_by_lua\(nginx\.conf:\d+\):4: bad
-child: status: dead
-parent: status: running
-$/s
---- no_error_log
-[error]
-
-
-
-=== TEST 22: entry coroutine is yielded by hand and still gets the right status
---- config
- location /t {
- content_by_lua '
- local co = coroutine.running()
- ngx.say("status: ", coroutine.status(co))
- coroutine.yield(co)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /t
---- response_body
-status: running
-status: running
---- no_error_log
-[error]
-
-
-
-=== TEST 23: github issue #208: coroutine as iterator doesn't work
---- config
- location = /t {
- content_by_lua '
- local say = ngx.say
- local wrap, yield = coroutine.wrap, coroutine.yield
-
- local function it(it_state)
- for i = 1, it_state.i do
- yield(it_state.path, tostring(i))
- end
- return nil
- end
-
- local function it_factory(path)
- local it_state = { i = 10, path = path }
- return wrap(it), it_state
- end
-
- --[[
- for path, value in it_factory("test") do
- say(path, value)
- end
- ]]
-
- do
- local f, s, var = it_factory("test")
- while true do
- local path, value = f(s, var)
- var = path
- if var == nil then break end
- say(path, value)
- end
- end
- ';
- }
---- request
- GET /t
---- more_headers
-Cookie: abc=32
---- stap2 eval: $::StapScript
---- response_body
-test1
-test2
-test3
-test4
-test5
-test6
-test7
-test8
-test9
-test10
---- no_error_log
-[error]
-
-
-
-=== TEST 24: init_by_lua + our own coroutines in content_by_lua
---- http_config
- init_by_lua 'return';
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /lua {
- content_by_lua '
- local function worker(url)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect(url, 80)
- coroutine.yield()
- if not ok then
- ngx.say("failed to connect to: ", url, " error: ", err)
- return
- end
- coroutine.yield()
- ngx.say("successfully connected to: ", url)
- sock:close()
- end
-
- local urls = {
- "agentzh.org",
- }
-
- local ccs = {}
- for i, url in ipairs(urls) do
- local cc = coroutine.create(function() worker(url) end)
- ccs[#ccs+1] = cc
- end
-
- while true do
- if #ccs == 0 then break end
- local cc = table.remove(ccs, 1)
- local ok = coroutine.resume(cc)
- if ok then
- ccs[#ccs+1] = cc
- end
- end
-
- ngx.say("*** All Done ***")
- ';
- }
---- request
-GET /lua
---- response_body
-successfully connected to: agentzh.org
-*** All Done ***
---- no_error_log
-[error]
---- timeout: 10
-
-
-
-=== TEST 25: init_by_lua_file + our own coroutines in content_by_lua
---- http_config
- init_by_lua_file html/init.lua;
-
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /lua {
- content_by_lua '
- local function worker(url)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect(url, 80)
- coroutine.yield()
- if not ok then
- ngx.say("failed to connect to: ", url, " error: ", err)
- return
- end
- coroutine.yield()
- ngx.say("successfully connected to: ", url)
- sock:close()
- end
-
- local urls = {
- "agentzh.org"
- }
-
- local ccs = {}
- for i, url in ipairs(urls) do
- local cc = coroutine.create(function() worker(url) end)
- ccs[#ccs+1] = cc
- end
-
- while true do
- if #ccs == 0 then break end
- local cc = table.remove(ccs, 1)
- local ok = coroutine.resume(cc)
- if ok then
- ccs[#ccs+1] = cc
- end
- end
-
- ngx.say("*** All Done ***")
- ';
- }
---- user_files
->>> init.lua
-return
-
---- request
-GET /lua
---- response_body
-successfully connected to: agentzh.org
-*** All Done ***
---- no_error_log
-[error]
---- timeout: 10
-
-
-
-=== TEST 26: mixing coroutine.* API between init_by_lua and other contexts (github #304) - init_by_lua
---- http_config
- init_by_lua '
- co_wrap = coroutine.wrap
- co_yield = coroutine.yield
- ';
-
---- config
- location /cotest {
- content_by_lua '
- local function generator()
- return co_wrap(function()
- co_yield("data")
- end)
- end
-
- local co = generator()
- local data = co()
- ngx.say(data)
- ';
- }
-
---- request
-GET /cotest
---- stap2 eval: $::StapScript
---- response_body
-data
---- no_error_log
-[error]
-
-
-
-=== TEST 27: mixing coroutine.* API between init_by_lua and other contexts (github #304) - init_by_lua_file
---- http_config
- init_by_lua_file html/init.lua;
-
---- config
- location /cotest {
- content_by_lua '
- local function generator()
- return co_wrap(function()
- co_yield("data")
- end)
- end
-
- local co = generator()
- local data = co()
- ngx.say(data)
- ';
- }
-
---- user_files
->>> init.lua
-co_wrap = coroutine.wrap
-co_yield = coroutine.yield
-
---- request
-GET /cotest
---- stap2 eval: $::StapScript
---- response_body
-data
---- no_error_log
-[error]
-
-
-
-=== TEST 28: coroutine context collicisions
---- config
- location /lua {
- content_by_lua '
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
-
- local function f()
- return 3
- end
-
- for i = 1, 10 do
- collectgarbage()
- local c = cc(f)
- if coroutine.status(c) == "dead" then
- ngx.say("found a dead coroutine")
- return
- end
- cr(c)
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- response_body
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 29: require "coroutine"
---- config
- location /lua {
- content_by_lua '
- local coroutine = require "coroutine"
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
-
- local function f()
- local cnt = 0
- for i = 1, 20 do
- ngx.say("Hello, ", cnt)
- ngx.sleep(0.001)
- cy()
- cnt = cnt + 1
- end
- end
-
- local c = cc(f)
- for i=1,3 do
- cr(c)
- ngx.say("***")
- end
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- response_body
-Hello, 0
-***
-Hello, 1
-***
-Hello, 2
-***
---- no_error_log
-[error]
-
-
-
-=== TEST 30: basic coroutine in header_filter_by_lua
---- config
- location = /t {
- echo ok;
- header_filter_by_lua '
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
-
- local function f()
- local cnt = 0
- for i = 1, 20 do
- print("co yield: ", cnt)
- cy()
- cnt = cnt + 1
- end
- end
-
- local c = cc(f)
- for i = 1, 3 do
- print("co resume.")
- cr(c)
- end
- ';
- }
---- request
-GET /t
---- response_body
-ok
---- grep_error_log eval: qr/co (?:yield: \d+|resume\.)/
---- grep_error_log_out
-co resume.
-co yield: 0
-co resume.
-co yield: 1
-co resume.
-co yield: 2
---- no_error_log
-[error]
-
-
-
-=== TEST 31: basic coroutine in body_filter_by_lua
---- config
- location = /t {
- echo ok;
- body_filter_by_lua '
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
-
- local function f()
- local cnt = 0
- for i = 1, 20 do
- print("co yield: ", cnt)
- cy()
- cnt = cnt + 1
- end
- end
-
- local c = cc(f)
- for i = 1, 3 do
- print("co resume.")
- cr(c)
- end
- ';
- }
---- request
-GET /t
---- response_body
-ok
---- grep_error_log eval: qr/co (?:yield: \d+|resume\.)/
---- grep_error_log_out
-co resume.
-co yield: 0
-co resume.
-co yield: 1
-co resume.
-co yield: 2
-co resume.
-co yield: 0
-co resume.
-co yield: 1
-co resume.
-co yield: 2
-
---- no_error_log
-[error]
-
-
-
-=== TEST 32: coroutine.wrap propagates errors to parent coroutine
---- config
- location = /t {
- content_by_lua_block {
- local co = coroutine.wrap(function()
- print("in wrapped coroutine")
- error("something went wrong")
- end)
-
- co()
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- error_code: 500
---- response_body_unlike
-ok
---- error_log eval
-[
- qr/\[notice\] .*? in wrapped coroutine/,
- qr/\[error\] .*? lua entry thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):\d+: something went wrong/,
- "stack traceback:",
- "coroutine 0:",
- "coroutine 1:"
-]
-
-
-
-=== TEST 33: coroutine.wrap propagates nested errors to parent coroutine
-Note: in this case, both the error message and the traceback are constructed
-from co1's stack level.
---- config
- location = /t {
- content_by_lua_block {
- local co1 = coroutine.wrap(function()
- error("something went wrong in co1")
- end)
-
- local co2 = coroutine.wrap(function()
- co1()
- end)
-
- co2()
- }
- }
---- request
-GET /t
---- error_code: 500
---- ignore_response
---- error_log eval
-[
- qr/\[error\] .*? lua entry thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):\d+: something went wrong in co1/,
- "stack traceback:",
- "coroutine 0:",
- "coroutine 1:",
- "coroutine 2:"
-]
-
-
-
-=== TEST 34: coroutine.wrap propagates nested errors with stack level to parent coroutine
-Note: in this case, the error message is constructed at the entry thread stack
-level, and the traceback is constructed from co1's stack level.
---- config
- location = /t {
- content_by_lua_block {
- local co1 = coroutine.wrap(function()
- error("something went wrong in co1", 2)
- end)
-
- local co2 = coroutine.wrap(function()
- co1()
- end)
-
- co2()
- }
- }
---- request
-GET /t
---- error_code: 500
---- error_log eval
-[
- qr/\[error\] .*? lua entry thread aborted: runtime error: something went wrong in co1/,
- "stack traceback:",
- "coroutine 0:",
- "coroutine 1:",
- "coroutine 2:"
-]
-
-
-
-=== TEST 35: coroutine.wrap runtime errors do not log errors
---- config
- location = /t {
- content_by_lua_block {
- local co = coroutine.wrap(function()
- print("in wrapped coroutine")
- error("something went wrong")
- end)
-
- co()
- }
- }
---- request
-GET /t
---- error_code: 500
---- ignore_response
---- no_error_log eval
-[
- qr/\[error\] .*? lua coroutine: runtime error:/,
- "[crit]",
- "[emerg]",
- "[warn]",
-]
-
-
-
-=== TEST 36: coroutine.wrap does not return status boolean on yield
---- config
- location = /t {
- content_by_lua_block {
- local co = coroutine.wrap(function()
- coroutine.yield("ok", "err")
- end)
-
- local ret1, ret2 = co()
-
- ngx.say(ret1, ", ", ret2)
- }
- }
---- request
-GET /t
---- response_body
-ok, err
---- no_error_log
-[error]
-
-
-
-=== TEST 37: coroutine.wrap does not return status boolean on done
---- config
- location = /t {
- content_by_lua_block {
- local co = coroutine.wrap(function() end)
-
- local ret1 = co()
-
- ngx.say(ret1)
- }
- }
---- request
-GET /t
---- response_body
-nil
---- no_error_log
-[error]g
-
-
-
-=== TEST 38: coroutine.wrap does not return status boolean on error
---- SKIP: not supported
---- config
- location = /t {
- content_by_lua_block {
- local co = coroutine.wrap(function()
- error("something went wrong")
- end)
-
- local ret1, ret2 = pcall(co)
-
- ngx.say(ret1, ", ", ret2)
- }
- }
---- request
-GET /t
---- response_body
-false, something went wrong
---- no_error_log
-[error]
-
-
-
-=== TEST 39: coroutine.wrap creates different function refs
---- config
- location = /t {
- content_by_lua_block {
- local f = function() end
- local co = coroutine.wrap(f)
- local co2 = coroutine.wrap(f)
-
- ngx.say("co == co2: ", co == co2)
- }
- }
---- request
-GET /t
---- response_body
-co == co2: false
---- no_error_log
-[error]
-
-
-
-=== TEST 40: coroutine.wrap supports yielding and resuming
---- config
- location = /t {
- content_by_lua_block {
- local function f()
- local cnt = 0
- for i = 1, 20 do
- ngx.say("co yield: ", cnt)
- coroutine.yield()
- cnt = cnt + 1
- end
- end
-
- local f = coroutine.wrap(f)
- for i = 1, 3 do
- ngx.say("co resume")
- f()
- end
- }
- }
---- request
-GET /t
---- response_body
-co resume
-co yield: 0
-co resume
-co yield: 1
-co resume
-co yield: 2
---- no_error_log
-[error]
-
-
-
-=== TEST 41: coroutine.wrap return values
---- config
- location = /t {
- content_by_lua_block {
- local function f()
- local cnt = 0
- for i = 1, 20 do
- coroutine.yield(cnt, cnt + 1)
- cnt = cnt + 1
- end
- end
-
- local f = coroutine.wrap(f)
- for i = 1, 3 do
- ngx.say("co resume")
- local ret1, ret2 = f()
- ngx.say("co yield: ", ret1, ", ", ret2)
- end
- }
- }
---- request
-GET /t
---- response_body
-co resume
-co yield: 0, 1
-co resume
-co yield: 1, 2
-co resume
-co yield: 2, 3
---- no_error_log
-[error]
-
-
-
-=== TEST 42: coroutine.wrap arguments
---- config
- location = /t {
- content_by_lua_block {
- local function f(step)
- local cnt = 0
- for i = 1, 20 do
- ngx.say("co yield: ", cnt)
- coroutine.yield()
- cnt = cnt + step
- end
- end
-
- local f = coroutine.wrap(f)
- for i = 1, 3 do
- ngx.say("co resume")
- f(i)
- end
- }
- }
---- request
-GET /t
---- response_body
-co resume
-co yield: 0
-co resume
-co yield: 1
-co resume
-co yield: 2
---- no_error_log
-[error]
-
-
-
-=== TEST 43: coroutine.wrap in header_filter_by_lua (orig coroutine.wrap)
---- config
- location = /t {
- return 200;
-
- header_filter_by_lua_block {
- local function f()
- local cnt = 0
- for i = 1, 20 do
- print("co yield: ", cnt)
- coroutine.yield()
- cnt = cnt + 1
- end
- end
-
- local f = coroutine.wrap(f)
- for i = 1, 3 do
- print("co resume.")
- f()
- end
- }
- }
---- request
-GET /t
---- ignore_response
---- grep_error_log eval: qr/co (?:yield: \d+|resume\.)/
---- grep_error_log_out
-co resume.
-co yield: 0
-co resume.
-co yield: 1
-co resume.
-co yield: 2
---- no_error_log
-[error]
-
-
-
-=== TEST 44: coroutine.wrap in header_filter_by_lua propagates errors (orig coroutine.wrap)
---- config
- location = /t {
- return 200;
-
- header_filter_by_lua_block {
- local co = coroutine.wrap(function()
- print("in wrapped coroutine")
- error("something went wrong")
- end)
-
- local err = co()
-
- ngx.log(ngx.CRIT, "err: ", err)
- }
- }
---- request
-GET /t
---- ignore_response
---- error_log eval
-[
- qr/\[notice\] .*? in wrapped coroutine/,
- qr/\[error\] .*? failed to run header_filter_by_lua\*: header_filter_by_lua\(nginx.conf:\d+\):\d+: header_filter_by_lua\(nginx.conf:\d+\):\d+: something went wrong/,
- "stack traceback:",
- "in function 'co'"
-]
---- curl_error eval
-qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
-
-
-
-=== TEST 45: coroutine.wrap in init_by_lua propagates errors (orig coroutine.wrap)
---- http_config
- init_by_lua_block {
- local co = coroutine.wrap(function()
- print("in wrapped coroutine")
- error("something went wrong")
- end)
-
- local err = co()
-
- ngx.log(ngx.CRIT, "err: ", err)
- }
---- config
-
---- must_die
---- grep_error_log eval: qr/init_by_lua\(nginx.conf:25\).*? something went wrong/
---- grep_error_log_out
-init_by_lua(nginx.conf:25):7: init_by_lua(nginx.conf:25):4: something went wrong
-
-
-
-=== TEST 46: coroutine.resume runtime errors do not log errors
---- config
- location = /t {
- content_by_lua_block {
- local function f()
- error("something went wrong")
- end
-
- local ret1, ret2 = coroutine.resume(coroutine.create(f))
- ngx.say(ret1)
- ngx.say(ret2)
- }
- }
---- request
-GET /t
---- response_body_like
-false
-content_by_lua\(nginx.conf:\d+\):\d+: something went wrong
---- no_error_log eval
-[
- qr/\[error\] .*? lua coroutine: runtime error:",
- "stack traceback:",
-]
diff --git a/src/deps/src/lua-nginx-module/t/092-eof.t b/src/deps/src/lua-nginx-module/t/092-eof.t
deleted file mode 100644
index 86778dedb..000000000
--- a/src/deps/src/lua-nginx-module/t/092-eof.t
+++ /dev/null
@@ -1,82 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 6);
-
-master_on();
-workers(2);
-no_root_location();
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: 404 parallel subrequests after ngx.eof()
---- config
- location = /lua {
- content_by_lua '
- ngx.say(1)
- ngx.eof()
- local res1, res2 = ngx.location.capture_multi{
- { "/bad1" },
- { "/bad2" }
- }
- ngx.log(ngx.WARN, "res1: ", res1.status)
- ngx.log(ngx.WARN, "res2: ", res2.status)
- ';
- }
---- request
-GET /lua
---- response_body
-1
---- no_error_log
-[alert]
---- error_log
-res1: 404
-res2: 404
-No such file or directory
-
-
-
-=== TEST 2: parallel normal subrequests after ngx.eof()
---- config
- location = /t {
- content_by_lua '
- ngx.say(1)
- ngx.eof()
- local r1, r2 = ngx.location.capture_multi{
- { "/proxy/tom" },
- { "/proxy/jim" }
- }
- ngx.log(ngx.WARN, r1.body)
- ngx.log(ngx.WARN, r2.body)
- ';
- }
-
- location ~ '^/proxy/(\w+)' {
- proxy_pass http://127.0.0.1:$server_port/hello?a=$1;
- }
-
- location = /hello {
- echo_sleep 0.5;
- echo -n "hello, $arg_a";
- }
---- request
-GET /t
---- response_body
-1
---- no_error_log
-[alert]
-[error]
---- error_log
-hello, tom
-hello, jim
diff --git a/src/deps/src/lua-nginx-module/t/093-uthread-spawn.t b/src/deps/src/lua-nginx-module/t/093-uthread-spawn.t
deleted file mode 100644
index 99750d3c0..000000000
--- a/src/deps/src/lua-nginx-module/t/093-uthread-spawn.t
+++ /dev/null
@@ -1,1680 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-
-#no_shuffle();
-worker_connections(256);
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple user thread without I/O
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 2: two simple user threads without I/O
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("in thread 1")
- end
-
- local function g()
- ngx.say("in thread 2")
- end
-
- ngx.say("before 1")
- ngx.thread.spawn(f)
- ngx.say("after 1")
-
- ngx.say("before 2")
- ngx.thread.spawn(g)
- ngx.say("after 2")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: ok
-terminate 1: ok
-delete thread 2
-delete thread 3
-delete thread 1
-
---- response_body
-before 1
-in thread 1
-after 1
-before 2
-in thread 2
-after 2
---- no_error_log
-[error]
-
-
-
-=== TEST 3: simple user thread with sleep
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("before sleep")
- ngx.sleep(0.1)
- ngx.say("after sleep")
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before thread create
-before sleep
-after thread create
-after sleep
---- no_error_log
-[error]
-
-
-
-=== TEST 4: two simple user threads with sleep
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("1: before sleep")
- ngx.sleep(0.2)
- ngx.say("1: after sleep")
- end
-
- local function g()
- ngx.say("2: before sleep")
- ngx.sleep(0.1)
- ngx.say("2: after sleep")
- end
-
- ngx.say("1: before thread create")
- ngx.thread.spawn(f)
- ngx.say("1: after thread create")
-
- ngx.say("2: before thread create")
- ngx.thread.spawn(g)
- ngx.say("2: after thread create")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2
-
---- wait: 0.1
---- response_body
-1: before thread create
-1: before sleep
-1: after thread create
-2: before thread create
-2: before sleep
-2: after thread create
-2: after sleep
-1: after sleep
---- no_error_log
-[error]
-
-
-
-=== TEST 5: error in user thread
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.blah()
- end
-
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: fail
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-after
---- error_log eval
-qr/lua user thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):3: attempt to call field 'blah' \(a nil value\)/
-
-
-
-=== TEST 6: simple user threads doing a single subrequest (entry quits early)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("before capture")
- local res = ngx.location.capture("/proxy")
- ngx.say("after capture: ", res.body)
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/foo;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello world;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before thread create
-before capture
-after thread create
-after capture: hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 7: simple user threads doing a single subrequest (entry also does a subrequest and quits early)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("before capture")
- local res = ngx.location.capture("/proxy?foo")
- ngx.say("after capture: ", res.body)
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- local res = ngx.location.capture("/proxy?bar")
- ngx.say("capture: ", res.body)
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/$args;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello foo;
- }
-
- location /bar {
- echo -n hello bar;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before thread create
-before capture
-after thread create
-capture: hello bar
-after capture: hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 8: simple user threads doing a single subrequest (entry also does a subrequest and quits late)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("before capture")
- local res = ngx.location.capture("/proxy?foo")
- ngx.say("after capture: ", res.body)
- end
-
- ngx.say("before thread create")
- ngx.thread.spawn(f)
- ngx.say("after thread create")
- local res = ngx.location.capture("/proxy?bar")
- ngx.say("capture: ", res.body)
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/$args;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello foo;
- }
-
- location /bar {
- echo_sleep 0.2;
- echo -n hello bar;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before thread create
-before capture
-after thread create
-after capture: hello foo
-capture: hello bar
---- no_error_log
-[error]
-
-
-
-=== TEST 9: two simple user threads doing single subrequests (entry also does a subrequest and quits between)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("f: before capture")
- local res = ngx.location.capture("/proxy?foo")
- ngx.say("f: after capture: ", res.body)
- end
-
- local function g()
- ngx.say("g: before capture")
- local res = ngx.location.capture("/proxy?bah")
- ngx.say("g: after capture: ", res.body)
- end
-
- ngx.say("before thread 1 create")
- ngx.thread.spawn(f)
- ngx.say("after thread 1 create")
-
- ngx.say("before thread 2 create")
- ngx.thread.spawn(g)
- ngx.say("after thread 2 create")
-
- local res = ngx.location.capture("/proxy?bar")
- ngx.say("capture: ", res.body)
- ';
- }
-
- location /proxy {
- proxy_pass http://127.0.0.1:$server_port/$args;
- }
-
- location /foo {
- echo_sleep 0.1;
- echo -n hello foo;
- }
-
- location /bar {
- echo_sleep 0.2;
- echo -n hello bar;
- }
-
- location /bah {
- echo_sleep 0.3;
- echo -n hello bah;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-terminate 3: ok
-delete thread 3
-
---- response_body
-before thread 1 create
-f: before capture
-after thread 1 create
-before thread 2 create
-g: before capture
-after thread 2 create
-f: after capture: hello foo
-capture: hello bar
-g: after capture: hello bah
---- no_error_log
-[error]
-
-
-
-=== TEST 10: nested user threads
---- config
- location /lua {
- content_by_lua '
- local g
- local function f()
- ngx.say("before g")
- ngx.thread.spawn(g)
- ngx.say("after g")
- end
-
- function g()
- ngx.say("hello in g()")
- end
-
- ngx.say("before f")
- ngx.thread.spawn(f)
- ngx.say("after f")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 3
-delete thread 2
-
---- response_body
-before f
-before g
-hello in g()
-after f
-after g
---- no_error_log
-[error]
-
-
-
-=== TEST 11: nested user threads (with I/O)
---- config
- location /lua {
- content_by_lua '
- local g
- local function f()
- ngx.say("before g")
- ngx.thread.spawn(g)
- ngx.say("after g")
- end
-
- function g()
- ngx.sleep(0.1)
- ngx.say("hello in g()")
- end
-
- ngx.say("before f")
- ngx.thread.spawn(f)
- ngx.say("after f")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-before f
-before g
-after f
-after g
-hello in g()
---- no_error_log
-[error]
-
-
-
-=== TEST 12: coroutine status of a running user thread
---- config
- location /lua {
- content_by_lua '
- local co
- local function f()
- co = coroutine.running()
- ngx.sleep(0.1)
- end
-
- ngx.thread.spawn(f)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-status: running
---- no_error_log
-[error]
-
-
-
-=== TEST 13: coroutine status of a dead user thread
---- config
- location /lua {
- content_by_lua '
- local co
- local function f()
- co = coroutine.running()
- end
-
- ngx.thread.spawn(f)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-status: zombie
---- no_error_log
-[error]
-
-
-
-=== TEST 14: coroutine status of a "normal" user thread
---- config
- location /lua {
- content_by_lua '
- local co
- local g
- local function f()
- co = coroutine.running()
- local co2 = coroutine.create(g)
- coroutine.resume(co2)
- end
-
- function g()
- ngx.sleep(0.1)
- end
-
- ngx.thread.spawn(f)
- ngx.say("status: ", coroutine.status(co))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 2
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-terminate 2: ok
-delete thread 2
-
---- response_body
-status: normal
---- no_error_log
-[error]
-
-
-
-=== TEST 15: creating user threads in a user coroutine
---- config
- location /lua {
- content_by_lua '
- local g
- local function f()
- ngx.say("before g")
- ngx.thread.spawn(g)
- ngx.say("after g")
- end
-
- function g()
- ngx.say("hello in g()")
- end
-
- ngx.say("before f")
- local co = coroutine.create(f)
- coroutine.resume(co)
- ngx.say("after f")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-terminate 2: ok
-delete thread 3
-terminate 1: ok
-delete thread 1
-
---- response_body
-before f
-before g
-hello in g()
-after g
-after f
---- no_error_log
-[error]
-
-
-
-=== TEST 16: manual time slicing between a user thread and the entry thread
---- config
- location /lua {
- content_by_lua '
- local yield = coroutine.yield
-
- local function f()
- local self = coroutine.running()
- ngx.say("f 1")
- yield(self)
- ngx.say("f 2")
- yield(self)
- ngx.say("f 3")
- end
-
- local self = coroutine.running()
- ngx.say("0")
- yield(self)
- ngx.say("1")
- ngx.thread.spawn(f)
- ngx.say("2")
- yield(self)
- ngx.say("3")
- yield(self)
- ngx.say("4")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-0
-1
-f 1
-2
-f 2
-3
-f 3
-4
---- no_error_log
-[error]
-
-
-
-=== TEST 17: manual time slicing between two user threads
---- config
- location /lua {
- content_by_lua '
- local yield = coroutine.yield
-
- local function f()
- local self = coroutine.running()
- ngx.say("f 1")
- yield(self)
- ngx.say("f 2")
- yield(self)
- ngx.say("f 3")
- end
-
- local function g()
- local self = coroutine.running()
- ngx.say("g 1")
- yield(self)
- ngx.say("g 2")
- yield(self)
- ngx.say("g 3")
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ngx.say("done")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-f 1
-g 1
-f 2
-done
-g 2
-f 3
-g 3
---- no_error_log
-[error]
-
-
-
-=== TEST 18: entry thread and a user thread flushing at the same time
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- coroutine.yield(coroutine.running)
- ngx.flush(true)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ngx.flush(true)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 19: two user threads flushing at the same time
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello from f")
- ngx.flush(true)
- end
-
- local function g()
- ngx.say("hello from g")
- ngx.flush(true)
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like
-^(?:create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3|create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: ok
-terminate 1: ok
-delete thread 2
-delete thread 3
-delete thread 1)$
-
---- response_body
-hello from f
-hello from g
---- no_error_log
-[error]
-
-
-
-=== TEST 20: user threads + ngx.socket.tcp
---- config
- location /lua {
- content_by_lua '
- local function f()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- local bytes, err = sock:send("flush_all\\r\\n")
- if not bytes then
- ngx.say("failed to send query: ", err)
- return
- end
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("received: ", line)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-before
-after
-received: OK
---- no_error_log
-[error]
-
-
-
-=== TEST 21: user threads + ngx.socket.udp
---- config
- location /lua {
- content_by_lua '
- local function f()
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername("127.0.0.1", $TEST_NGINX_RAND_PORT_1)
- local bytes, err = sock:send("blah")
- if not bytes then
- ngx.say("failed to send query: ", err)
- return
- end
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("received: ", line)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^(?:create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-|create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-)$
-
---- udp_listen: $TEST_NGINX_RAND_PORT_1
---- udp_query: blah
---- udp_reply: hello udp
---- response_body_like chop
-^(?:before
-after
-received: hello udp
-|before
-received: hello udp
-after)$
-
---- no_error_log
-[error]
-
-
-
-=== TEST 22: simple user thread with ngx.req.read_body()
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.req.read_body()
- local body = ngx.req.get_body_data()
- ngx.say("body: ", body)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-POST /lua
-hello world
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^(?:create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1|create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2)$
-
---- response_body_like chop
-^(?:before
-body: hello world
-after|before
-after
-body: hello world)$
-
---- no_error_log
-[error]
-
-
-
-=== TEST 23: simple user thread with ngx.req.socket()
-ngx.req.socket() does not support in http3
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
---- config
- location /lua {
- content_by_lua '
- local function f()
- local sock = ngx.req.socket()
- local body, err = sock:receive(11)
- if not body then
- ngx.say("failed to read body: ", err)
- return
- end
-
- ngx.say("body: ", body)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-POST /lua
-hello world
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^(?:create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1|create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2)$
-
---- response_body_like chop
-^(?:before
-body: hello world
-after|before
-after
-body: hello world)$
-
---- no_error_log
-[error]
-
-
-
-=== TEST 24: simple user thread with args
---- config
- location /lua {
- content_by_lua '
- local function f(a, b)
- ngx.say("hello ", a, " and ", b)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f, "foo", 3.14)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before
-hello foo and 3.14
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 25: multiple user threads + subrequests returning 404 immediately
---- config
- location /t {
- content_by_lua '
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- ngx.say("status: ", res.status)
- end
-
- local threads = {}
- for i = 1, 2 do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- return 404;
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap eval
-"$::GCScript"
-.
-'
-F(ngx_http_finalize_request) {
- printf("finalize request %s: rc:%d c:%d a:%d\n", ngx_http_req_uri($r), $rc, $r->main->count, $r == $r->main);
- #if ($rc == -1) {
- #print_ubacktrace()
- #}
-}
-
-M(http-subrequest-done) {
- printf("subrequest %s done\n", ngx_http_req_uri($r))
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: %s rc=%d, status=%d a=%d\n", ngx_http_req_uri($r), $rc,
- $r->headers_out->status, $r == $r->main)
- #print_ubacktrace()
-}
-'
---- stap_out_like chop
-^create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-finalize request /t: rc:-4 c:4 a:1
-finalize request /proxy/1: rc:404 c:3 a:0
-post subreq: /proxy/1 rc=404, status=0 a=0
-subrequest /proxy/1 done
-terminate 2: ok
-delete thread 2
-finalize request /proxy/2: rc:404 c:2 a:0
-post subreq: /proxy/2 rc=404, status=0 a=0
-subrequest /proxy/2 done
-terminate 3: ok
-delete thread 3
-finalize request /t: rc:0 c:1 a:1
-(?:finalize request /t: rc:0 c:1 a:1)?$
-
---- response_body
-ok
-status: 404
-status: 404
---- no_error_log
-[error]
---- timeout: 3
-
-
-
-=== TEST 26: multiple user threads + subrequests returning 404 remotely (no wait)
---- config
- location /t {
- content_by_lua '
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- ngx.say("status: ", res.status)
- end
-
- local threads = {}
- for i = 1, 5 do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- proxy_pass http://127.0.0.1:$server_port/d/$1;
- }
-
- location /d {
- return 404;
- #echo $uri;
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-create 4 in 1
-spawn user thread 4 in 1
-create 5 in 1
-spawn user thread 5 in 1
-create 6 in 1
-spawn user thread 6 in 1
-terminate 1: ok
-delete thread 1
-(?:terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-terminate 4: ok
-delete thread 4
-terminate 5: ok
-delete thread 5
-terminate 6: ok
-delete thread 6
-|terminate 6: ok
-delete thread 6
-terminate 5: ok
-delete thread 5
-terminate 4: ok
-delete thread 4
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2)$
-
---- response_body
-ok
-status: 404
-status: 404
-status: 404
-status: 404
-status: 404
---- no_error_log
-[error]
---- timeout: 6
-
-
-
-=== TEST 27: multiple user threads + subrequests returning 201 immediately
---- config
- location /t {
- content_by_lua '
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- ngx.say("status: ", res.status)
- end
-
- local threads = {}
- for i = 1, 2 do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- content_by_lua 'ngx.exit(201)';
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap eval
-"$::GCScript"
-.
-'
-F(ngx_http_finalize_request) {
- printf("finalize request %s: rc:%d c:%d a:%d\n", ngx_http_req_uri($r), $rc, $r->main->count, $r == $r->main);
- #if ($rc == -1) {
- #print_ubacktrace()
- #}
-}
-
-M(http-subrequest-done) {
- printf("subrequest %s done\n", ngx_http_req_uri($r))
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: %s rc=%d, status=%d a=%d\n", ngx_http_req_uri($r), $rc,
- $r->headers_out->status, $r == $r->main)
- #print_ubacktrace()
-}
-'
-
---- stap_out_like chop
-^create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-finalize request /t: rc:-4 c:4 a:1
-terminate 4: ok
-delete thread 4
-finalize request /proxy/1: rc:0 c:3 a:0
-post subreq: /proxy/1 rc=0, status=201 a=0
-subrequest /proxy/1 done
-terminate 2: ok
-delete thread 2
-terminate 5: ok
-delete thread 5
-finalize request /proxy/2: rc:0 c:2 a:0
-post subreq: /proxy/2 rc=0, status=201 a=0
-subrequest /proxy/2 done
-terminate 3: ok
-delete thread 3
-finalize request /t: rc:0 c:1 a:1
-(?:finalize request /t: rc:0 c:1 a:1)?$
-
---- response_body
-ok
-status: 201
-status: 201
---- no_error_log
-[error]
---- timeout: 3
-
-
-
-=== TEST 28: multiple user threads + subrequests returning 204 immediately
---- config
- location /t {
- content_by_lua '
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- ngx.say("status: ", res.status)
- end
-
- local threads = {}
- for i = 1, 2 do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- content_by_lua 'ngx.exit(204)';
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap eval
-"$::GCScript"
-.
-'
-F(ngx_http_finalize_request) {
- printf("finalize request %s: rc:%d c:%d a:%d\n", ngx_http_req_uri($r), $rc, $r->main->count, $r == $r->main);
- #if ($rc == -1) {
- #print_ubacktrace()
- #}
-}
-
-M(http-subrequest-done) {
- printf("subrequest %s done\n", ngx_http_req_uri($r))
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: %s rc=%d, status=%d a=%d\n", ngx_http_req_uri($r), $rc,
- $r->headers_out->status, $r == $r->main)
- #print_ubacktrace()
-}
-'
---- stap_out_like chop
-^create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-finalize request /t: rc:-4 c:4 a:1
-terminate 4: ok
-delete thread 4
-finalize request /proxy/1: rc:204 c:3 a:0
-post subreq: /proxy/1 rc=204, status=204 a=0
-subrequest /proxy/1 done
-terminate 2: ok
-delete thread 2
-terminate 5: ok
-delete thread 5
-finalize request /proxy/2: rc:204 c:2 a:0
-post subreq: /proxy/2 rc=204, status=204 a=0
-subrequest /proxy/2 done
-terminate 3: ok
-delete thread 3
-finalize request /t: rc:0 c:1 a:1
-(?:finalize request /t: rc:0 c:1 a:1)?$
-
---- response_body
-ok
-status: 204
-status: 204
---- no_error_log
-[error]
---- timeout: 3
-
-
-
-=== TEST 29: multiple user threads + subrequests returning 404 remotely (wait)
---- config
- location /t {
- content_by_lua '
- local n = 5
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- return res.status
- end
-
- local threads = {}
- for i = 1, n do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- for i = 1, n do
- local ok, res = ngx.thread.wait(threads[i])
- ngx.say(i, ": ", res)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- proxy_pass http://127.0.0.1:$server_port/d/$1;
- }
-
- location /d {
- return 404;
- #echo $uri;
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap3 eval: $::GCScript
---- stap_out3
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-create 4 in 1
-spawn user thread 4 in 1
-create 5 in 1
-spawn user thread 5 in 1
-create 6 in 1
-spawn user thread 6 in 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-terminate 4: ok
-delete thread 4
-terminate 5: ok
-delete thread 5
-terminate 6: ok
-delete thread 6
-terminate 1: ok
-delete thread 1
-
---- response_body
-1: 404
-2: 404
-3: 404
-4: 404
-5: 404
-ok
---- no_error_log
-[error]
---- timeout: 6
-
-
-
-=== TEST 30: multiple user threads + subrequests remotely (wait)
---- config
- location /t {
- content_by_lua '
- local n = 20
- local capture = ngx.location.capture
- local insert = table.insert
-
- local function f(i)
- local res = capture("/proxy/" .. i)
- return res.status
- end
-
- local threads = {}
- for i = 1, n do
- local co = ngx.thread.spawn(f, i)
- insert(threads, co)
- end
-
- for i = 1, n do
- local ok, res = ngx.thread.wait(threads[i])
- ngx.say(i, ": ", res)
- end
-
- ngx.say("ok")
- ';
- }
-
- location ~ ^/proxy/(\d+) {
- proxy_pass http://127.0.0.1:$server_port/d/$1;
- }
-
- location /d {
- echo_sleep 0.001;
- echo $uri;
- }
---- request
- GET /t
---- stap2 eval: $::StapScript
---- stap3 eval: $::GCScript
---- stap_out3
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-create 4 in 1
-spawn user thread 4 in 1
-create 5 in 1
-spawn user thread 5 in 1
-create 6 in 1
-spawn user thread 6 in 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-terminate 4: ok
-delete thread 4
-terminate 5: ok
-delete thread 5
-terminate 6: ok
-delete thread 6
-terminate 1: ok
-delete thread 1
-
---- response_body
-1: 200
-2: 200
-3: 200
-4: 200
-5: 200
-6: 200
-7: 200
-8: 200
-9: 200
-10: 200
-11: 200
-12: 200
-13: 200
-14: 200
-15: 200
-16: 200
-17: 200
-18: 200
-19: 200
-20: 200
-ok
---- no_error_log
-[error]
-[alert]
---- timeout: 10
-
-
-
-=== TEST 31: simple user thread without I/O
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("f")
- end
-
- ngx.thread.spawn(f)
- collectgarbage()
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-f
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/094-uthread-exit.t b/src/deps/src/lua-nginx-module/t/094-uthread-exit.t
deleted file mode 100644
index 0194e44b3..000000000
--- a/src/deps/src/lua-nginx-module/t/094-uthread-exit.t
+++ /dev/null
@@ -1,1660 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: exit in user thread (entry thread is still pending to run)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ngx.sleep(1)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-M(timer-add) {
- if ($arg2 == 1000) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-delete thread 1
-
---- response_body
-before
-hello in thread
---- no_error_log
-[error]
-
-
-
-=== TEST 2: exit in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ngx.sleep(1)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 3: exit in a user thread (another user thread is still pending on ngx.sleep)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("f")
- ngx.exit(0)
- end
-
- local function g()
- ngx.sleep(1)
- ngx.say("g")
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-create 3 in 1
-spawn user thread 3 in 1
-add timer 1000
-terminate 1: ok
-delete thread 1
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 3
-free request
-
---- response_body
-end
-f
---- no_error_log
-[error]
-
-
-
-=== TEST 4: exit in user thread (entry already quits)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("exiting the user thread")
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- wait: 0.1
---- response_body
-before
-after
-exiting the user thread
---- no_error_log
-[error]
-
-
-
-=== TEST 5: exit in user thread (entry thread is still pending on the DNS resolver for ngx.socket.tcp)
---- config
- location /lua {
- resolver 127.0.0.2:12345;
- resolver_timeout 12s;
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.001)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("agentzh.org", 80)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-F(ngx_resolve_name) {
- printf("resolving %s\n", user_string_n($ctx->name->data, $ctx->name->len))
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 1) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 12000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_tcp_resolve_cleanup) {
- println("lua tcp resolve cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 1
-resolving agentzh.org
-add timer 12000
-expire timer 1
-terminate 2: ok
-delete thread 2
-lua tcp resolve cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 6: exit in user thread (entry thread is still pending on the DNS resolver for ngx.socket.udp)
---- config
- location /lua {
- resolver 127.0.0.2:12345;
- resolver_timeout 12s;
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.001)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.udp()
- local ok, err = sock:setpeername("agentzh.org", 80)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-F(ngx_resolve_name) {
- printf("resolving %s\n", user_string_n($ctx->name->data, $ctx->name->len))
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 1) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 12000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 1) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_udp_resolve_cleanup) {
- println("lua udp resolve cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 1
-resolving agentzh.org
-add timer 12000
-expire timer 1
-terminate 2: ok
-delete thread 2
-lua udp resolve cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 7: exit in user thread (entry thread is still pending on tcpsock:connect)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
- sock:settimeout(12000)
- local ok, err = sock:connect("127.0.0.2", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 12000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 8: exit in user thread (entry thread is still pending on tcpsock:receive)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, ok = sock:send("blpop not_exists 2\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local data, err = sock:receive()
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 9: exit in user thread (entry thread is still pending on tcpsock:receiveuntil's iterator)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local bytes, ok = sock:send("blpop not_exists 2\\r\\n")
- if not bytes then
- ngx.say("failed to send: ", err)
- return
- end
-
- local it, err = sock:receiveuntil("\\r\\n")
- if not it then
- ngx.say("failed to receive until: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local data, err = it()
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 10: exit in user thread (entry thread is still pending on udpsock:receive)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.socket.udp()
-
- local ok, err = sock:setpeername("8.8.8.8", 12345)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- sock:settimeout(12000)
-
- local data, err = sock:receive()
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_udp_socket_cleanup) {
- println("lua udp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua udp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
-
-
-
-=== TEST 11: exit in user thread (entry thread is still pending on reqsock:receive)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
- local sock = ngx.req.socket()
-
- sock:settimeout(12000)
-
- local data, err = sock:receive(1024)
- if not data then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("end")
- ';
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
-
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_coctx_cleanup) {
- println("lua tcp socket cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua tcp socket cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 12: exit in user thread (entry thread is still pending on ngx.req.read_body)
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.req.read_body()
-
- ngx.say("end")
- ';
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 12000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 12000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_req_body_cleanup) {
- println("lua req body cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 12000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua req body cleanup
-delete timer 12000
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-before
-hello in thread
-after
---- no_error_log
-[error]
---- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 13: exit(0) in user thread (entry thread is still pending on ngx.location.capture), with pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.location.capture("/sleep")
-
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- ignore_response
---- error_log
-attempt to abort with pending subrequests
---- no_error_log
-[alert]
-[warn]
-
-
-
-=== TEST 14: exit in user thread (entry thread is still pending on ngx.location.capture), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture("/sleep")
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 15: exit in user thread (entry thread is still pending on ngx.location.capture_multi), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture_multi{
- {"/echo"},
- {"/sleep"}
- }
- ngx.say("end")
- ';
- }
-
- location = /echo {
- echo hello;
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-post subreq /echo
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 16: exit in entry thread (user thread is still pending on ngx.location.capture_multi), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.location.capture_multi{
- {"/echo"},
- {"/sleep"}
- }
- ngx.say("end")
- end
-
- ngx.thread.spawn(f)
-
- ngx.sleep(0.1)
- ngx.exit(0)
- ';
- }
-
- location = /echo {
- echo hello;
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-post subreq /echo
-add timer 200
-expire timer 100
-terminate 1: fail
-delete thread 2
-delete thread 1
-delete timer 200
-free request
-
---- wait: 0.1
---- ignore_response
---- error_log
-attempt to abort with pending subrequests
---- no_error_log
-[alert]
-[warn]
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
-
-
-
-=== TEST 17: exit(444) in user thread (entry thread is still pending on ngx.location.capture), with pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(444)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.location.capture("/sleep")
-
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: ok
-delete thread 2
-delete thread 1
-delete timer 200
-free request
-
---- wait: 0.1
---- ignore_response
---- no_error_log
-[alert]
-[error]
-[warn]
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
-
-
-
-=== TEST 18: exit(408) in user thread (entry thread is still pending on ngx.location.capture), with pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(408)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.location.capture("/sleep")
-
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: ok
-delete thread 2
-delete thread 1
-delete timer 200
-free request
-
---- wait: 0.1
---- ignore_response
---- no_error_log
-[alert]
-[error]
-[warn]
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
-
-
-
-=== TEST 19: exit(499) in user thread (entry thread is still pending on ngx.location.capture), with pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(499)
- end
-
- ngx.say("before")
- ngx.thread.spawn(f)
- ngx.say("after")
-
- ngx.location.capture("/sleep")
-
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: ok
-delete thread 2
-delete thread 1
-delete timer 200
-free request
-
---- wait: 0.1
---- ignore_response
---- no_error_log
-[alert]
-[error]
-[warn]
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
diff --git a/src/deps/src/lua-nginx-module/t/095-uthread-exec.t b/src/deps/src/lua-nginx-module/t/095-uthread-exec.t
deleted file mode 100644
index 4cd121da1..000000000
--- a/src/deps/src/lua-nginx-module/t/095-uthread-exec.t
+++ /dev/null
@@ -1,427 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: exec in user thread (entry still pending)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ngx.say("hello")
- ';
- }
-
- location /foo {
- echo i am foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-delete thread 1
-
---- response_body
-i am foo
---- no_error_log
-[error]
-
-
-
-=== TEST 2: exec in user thread (entry already quits)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
- ';
- }
-
- location /foo {
- echo i am foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-i am foo
---- no_error_log
-[error]
-
-
-
-=== TEST 3: exec in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ';
- }
-
- location = /foo {
- echo hello foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- response_body
-hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 4: exec in a user thread (another user thread is still pending on ngx.sleep)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- local function g()
- ngx.sleep(1)
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ';
- }
-
- location = /foo {
- echo hello foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-create 3 in 1
-spawn user thread 3 in 1
-add timer 1000
-terminate 1: ok
-delete thread 1
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 3
-free request
-
---- wait: 0.1
---- response_body
-hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 5: exec in user thread (entry thread is still pending on ngx.location.capture), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.exec("/foo")
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture("/sleep")
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
-
- location = /foo {
- echo hello world;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 6: exec in entry thread (user thread is still pending on ngx.location.capture), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.location.capture("/sleep")
- ngx.say("end")
- end
-
- ngx.thread.spawn(f)
-
- ngx.sleep(0.1)
- ngx.exec("/foo")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
-
- location = /foo {
- echo hello world;
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 1: fail
-delete thread 2
-delete thread 1
-delete timer 200
-free request
-
---- ignore_response
---- error_log
-attempt to abort with pending subrequests
---- no_error_log
-[alert]
-[warn]
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
diff --git a/src/deps/src/lua-nginx-module/t/096-uthread-redirect.t b/src/deps/src/lua-nginx-module/t/096-uthread-redirect.t
deleted file mode 100644
index 62909b944..000000000
--- a/src/deps/src/lua-nginx-module/t/096-uthread-redirect.t
+++ /dev/null
@@ -1,281 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: ngx.redirect() in user thread (entry thread is still pending on ngx.location.capture_multi), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.redirect(301)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture_multi{
- {"/echo"},
- {"/sleep"}
- }
- ngx.say("end")
- ';
- }
-
- location = /echo {
- echo hello;
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-post subreq /echo
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- wait: 0.1
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
-
-
-
-=== TEST 2: redirect in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.redirect(301)
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ngx.say("end")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- response_body_like: 302 Found
---- error_code: 302
---- no_error_log
-[error]
-
-
-
-=== TEST 3: ngx.redirect() in entry thread (user thread is still pending on ngx.location.capture_multi), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- content_by_lua '
- local function f()
- ngx.location.capture_multi{
- {"/echo"},
- {"/sleep"}
- }
- ngx.say("end")
- end
-
- ngx.thread.spawn(f)
-
- ngx.sleep(0.1)
- ngx.redirect(301)
- ';
- }
-
- location = /echo {
- echo hello;
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
---- request
-POST /lua
---- more_headers
-Content-Length: 1024
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-post subreq /echo
-add timer 200
-expire timer 100
-terminate 1: fail
-delete thread 2
-delete thread 1
-delete timer 200
-free request
-
---- ignore_response
---- error_log
-attempt to abort with pending subrequests
---- no_error_log
-[alert]
-[warn]
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
diff --git a/src/deps/src/lua-nginx-module/t/097-uthread-rewrite.t b/src/deps/src/lua-nginx-module/t/097-uthread-rewrite.t
deleted file mode 100644
index 998e25622..000000000
--- a/src/deps/src/lua-nginx-module/t/097-uthread-rewrite.t
+++ /dev/null
@@ -1,347 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: rewrite in user thread (entry still pending)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.req.set_uri("/foo", true)
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ngx.say("hello")
- ';
- }
-
- location /foo {
- echo i am foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-delete thread 1
-
---- response_body
-i am foo
---- no_error_log
-[error]
-
-
-
-=== TEST 2: rewrite in user thread (entry already quits)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.req.set_uri("/foo", true)
- end
-
- ngx.thread.spawn(f)
- ';
- }
-
- location /foo {
- echo i am foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-i am foo
---- no_error_log
-[error]
-
-
-
-=== TEST 3: rewrite in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.req.set_uri("/foo", true)
- end
-
- ngx.thread.spawn(f)
- ngx.sleep(1)
- ';
- }
-
- location = /foo {
- echo hello foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 1000
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 1
-free request
-
---- response_body
-hello foo
---- no_error_log
-[error]
-
-
-
-=== TEST 4: rewrite in a user thread (another user thread is still pending on ngx.sleep)
---- config
- location /lua {
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.req.set_uri("/foo", true)
- end
-
- local function g()
- ngx.sleep(1)
- end
-
- ngx.thread.spawn(f)
- ngx.thread.spawn(g)
- ';
- }
-
- location = /foo {
- echo hello foo;
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-create 3 in 1
-spawn user thread 3 in 1
-add timer 1000
-terminate 1: ok
-delete thread 1
-expire timer 100
-terminate 2: ok
-delete thread 2
-lua sleep cleanup
-delete timer 1000
-delete thread 3
-free request
-
---- response_body
-hello foo
---- no_error_log
-[error]
---- wait: 0.1
-
-
-
-=== TEST 5: rewrite in user thread (entry thread is still pending on ngx.location.capture), without pending output
---- config
- location /lua {
- client_body_timeout 12000ms;
- rewrite_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.req.set_uri("/foo", true)
- end
-
- ngx.thread.spawn(f)
-
- ngx.location.capture("/sleep")
- ngx.say("end")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.2;
- }
-
- location = /foo {
- echo hello world;
- }
---- request
-POST /lua
---- stap2 eval: $::StapScript
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 200 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 200 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq %s\n", ngx_http_req_uri($r))
-}
-
-_EOC_
-
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-add timer 100
-add timer 200
-expire timer 100
-terminate 2: fail
-expire timer 200
-post subreq /sleep
-terminate 1: ok
-delete thread 2
-delete thread 1
-free request
-
---- response_body
-end
---- error_log
-attempt to abort with pending subrequests
diff --git a/src/deps/src/lua-nginx-module/t/098-uthread-wait.t b/src/deps/src/lua-nginx-module/t/098-uthread-wait.t
deleted file mode 100644
index e2818e008..000000000
--- a/src/deps/src/lua-nginx-module/t/098-uthread-wait.t
+++ /dev/null
@@ -1,1342 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple user thread wait without I/O
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- return "done"
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to run thread: ", res)
- return
- end
-
- ngx.say(res)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-hello in thread
-thread created: zombie
-done
---- no_error_log
-[error]
-
-
-
-=== TEST 2: simple user thread wait with I/O
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("hello in thread")
- return "done"
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to wait thread: ", res)
- return
- end
-
- ngx.say(res)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-thread created: running
-hello in thread
-done
---- no_error_log
-[error]
-
-
-
-=== TEST 3: wait on uthreads on the reversed order of their termination
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("f: hello")
- return "done"
- end
-
- local function g()
- ngx.sleep(0.2)
- ngx.say("g: hello")
- return "done"
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("f thread created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("g thread created: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tg)
- if not ok then
- ngx.say("failed to wait g: ", res)
- return
- end
-
- ngx.say("g: ", res)
-
- ngx.say("f thread status: ", coroutine.status(tf))
-
- ok, res = ngx.thread.wait(tf)
- if not ok then
- ngx.say("failed to wait f: ", res)
- return
- end
-
- ngx.say("f: ", res)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 2: ok
-terminate 3: ok
-delete thread 3
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-f thread created: running
-g thread created: running
-f: hello
-g: hello
-g: done
-f thread status: zombie
-f: done
---- no_error_log
-[error]
-
-
-
-=== TEST 4: wait on uthreads on the exact order of their termination
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("f: hello")
- return "done"
- end
-
- local function g()
- ngx.sleep(0.2)
- ngx.say("g: hello")
- return "done"
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("f thread created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("g thread created: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tf)
- if not ok then
- ngx.say("failed to wait f: ", res)
- return
- end
-
- ngx.say("f: ", res)
-
- ngx.say("g thread status: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tg)
- if not ok then
- ngx.say("failed to wait g: ", res)
- return
- end
-
- ngx.say("g: ", res)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-terminate 1: ok
-delete thread 1
-
---- wait: 0.1
---- response_body
-f thread created: running
-g thread created: running
-f: hello
-f: done
-g thread status: running
-g: hello
-g: done
---- no_error_log
-[error]
-
-
-
-=== TEST 5: simple user thread wait without I/O (return multiple values)
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- return "done", 3.14
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res1, res2 = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to run thread: ", res1)
- return
- end
-
- ngx.say("res: ", res1, " ", res2)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-hello in thread
-thread created: zombie
-res: done 3.14
---- no_error_log
-[error]
-
-
-
-=== TEST 6: simple user thread wait with I/O, return multiple values
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("hello in thread")
- return "done", 3.14
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- local ok, res1, res2 = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to wait thread: ", res1)
- return
- end
-
- ngx.say("res: ", res1, " ", res2)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-thread created: running
-hello in thread
-res: done 3.14
---- no_error_log
-[error]
-
-
-
-=== TEST 7: simple user thread wait without I/O, throw errors
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- error("bad bad!")
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to wait thread: ", res)
- return
- end
-
- ngx.say(res)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: fail
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-hello in thread
-thread created: zombie
-failed to wait thread: bad bad!
---- error_log eval
-qr/lua user thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):4: bad bad!/
-
-
-
-=== TEST 8: simple user thread wait with I/O, throw errors
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("hello in thread")
- error("bad bad!")
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to wait thread: ", res)
- return
- end
-
- ngx.say(res)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: fail
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-thread created: running
-hello in thread
-failed to wait thread: bad bad!
---- error_log eval
-qr/lua user thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):5: bad bad!/
-
-
-
-=== TEST 9: simple user thread wait without I/O (in a user coroutine)
---- config
- location /lua {
- content_by_lua '
- local function g()
- ngx.say("hello in thread")
- return "done"
- end
-
- local function f()
- local t, err = ngx.thread.spawn(g)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to run thread: ", res)
- return
- end
-
- ngx.say(res)
- end
-
- local co = coroutine.create(f)
- coroutine.resume(co)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-terminate 1: ok
-delete thread 1
-
---- response_body
-hello in thread
-thread created: zombie
-done
---- no_error_log
-[error]
-
-
-
-=== TEST 10: simple user thread wait with I/O (in a user coroutine)
---- config
- location /lua {
- content_by_lua '
- local function g()
- ngx.sleep(0.1)
- ngx.say("hello in thread")
- return "done"
- end
-
- local function f()
- local t, err = ngx.thread.spawn(g)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to run thread: ", res)
- return
- end
-
- ngx.say(res)
- end
-
- local co = coroutine.create(f)
- coroutine.resume(co)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-terminate 1: ok
-delete thread 1
-
---- response_body
-thread created: running
-hello in thread
-done
---- no_error_log
-[error]
-
-
-
-=== TEST 11: waiting on two simple user threads without I/O
---- config
- location /lua {
- content_by_lua '
- -- local out = function (...) ngx.log(ngx.ERR, ...) end
- local out = ngx.say
-
- local function f()
- out("f: hello")
- return "f done"
- end
-
- local function g()
- out("g: hello")
- return "g done"
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- out("failed to spawn thread f: ", err)
- return
- end
-
- out("thread f created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- out("failed to spawn thread g: ", err)
- return
- end
-
- out("thread g created: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tf, tg)
- if not ok then
- out("failed to wait thread: ", res)
- return
- end
-
- out("res: ", res)
-
- out("f status: ", coroutine.status(tf))
- out("g status: ", coroutine.status(tg))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: ok
-delete thread 2
-terminate 1: ok
-delete thread 3
-delete thread 1
-
---- response_body
-f: hello
-thread f created: zombie
-g: hello
-thread g created: zombie
-res: f done
-f status: dead
-g status: zombie
-
---- no_error_log
-[error]
-
-
-
-=== TEST 12: waiting on two simple user threads with I/O
---- config
- location /lua {
- content_by_lua '
- -- local out = function (...) ngx.log(ngx.ERR, ...) end
- local out = ngx.say
-
- local function f()
- ngx.sleep(0.1)
- out("f: hello")
- return "f done"
- end
-
- local function g()
- ngx.sleep(0.2)
- out("g: hello")
- return "g done"
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- out("failed to spawn thread f: ", err)
- return
- end
-
- out("thread f created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- out("failed to spawn thread g: ", err)
- return
- end
-
- out("thread g created: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tf, tg)
- if not ok then
- out("failed to wait thread: ", res)
- return
- end
-
- out("res: ", res)
-
- out("f status: ", coroutine.status(tf))
- out("g status: ", coroutine.status(tg))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-delete thread 3
-
---- response_body
-thread f created: running
-thread g created: running
-f: hello
-res: f done
-f status: dead
-g status: running
-g: hello
-
---- no_error_log
-[error]
-
-
-
-=== TEST 13: waiting on two simple user threads with I/O (uthreads completed in reversed order)
---- config
- location /lua {
- content_by_lua '
- -- local out = function (...) ngx.log(ngx.ERR, ...) end
- local out = ngx.say
-
- local function f()
- ngx.sleep(0.2)
- out("f: hello")
- return "f done"
- end
-
- local function g()
- ngx.sleep(0.1)
- out("g: hello")
- return "g done"
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- out("failed to spawn thread f: ", err)
- return
- end
-
- out("thread f created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- out("failed to spawn thread g: ", err)
- return
- end
-
- out("thread g created: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tf, tg)
- if not ok then
- out("failed to wait thread: ", res)
- return
- end
-
- out("res: ", res)
-
- out("f status: ", coroutine.status(tf))
- out("g status: ", coroutine.status(tg))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: ok
-delete thread 3
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-thread f created: running
-thread g created: running
-g: hello
-res: g done
-f status: running
-g status: dead
-f: hello
-
---- no_error_log
-[error]
-
-
-
-=== TEST 14: waiting on two simple user threads without I/O, both aborted by errors
---- config
- location /lua {
- content_by_lua '
- -- local out = function (...) ngx.log(ngx.ERR, ...) end
- local out = ngx.say
-
- local function f()
- out("f: hello")
- error("f done")
- end
-
- local function g()
- out("g: hello")
- error("g done")
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- out("failed to spawn thread f: ", err)
- return
- end
-
- out("thread f created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- out("failed to spawn thread g: ", err)
- return
- end
-
- out("thread g created: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tf, tg)
- if not ok then
- out("failed to wait thread: ", res)
- else
- out("res: ", res)
- end
-
- out("f status: ", coroutine.status(tf))
- out("g status: ", coroutine.status(tg))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: fail
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: fail
-delete thread 2
-terminate 1: ok
-delete thread 3
-delete thread 1
-
---- response_body
-f: hello
-thread f created: zombie
-g: hello
-thread g created: zombie
-failed to wait thread: f done
-f status: dead
-g status: zombie
-
---- error_log eval
-qr/lua user thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):7: f done/
-
-
-
-=== TEST 15: waiting on two simple user threads with I/O, both aborted by errors
---- config
- location /lua {
- content_by_lua '
- -- local out = function (...) ngx.log(ngx.ERR, ...) end
- local out = ngx.say
-
- local function f()
- ngx.sleep(0.1)
- out("f: hello")
- error("f done")
- end
-
- local function g()
- ngx.sleep(0.2)
- out("g: hello")
- error("g done")
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- out("failed to spawn thread f: ", err)
- return
- end
-
- out("thread f created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- out("failed to spawn thread g: ", err)
- return
- end
-
- out("thread g created: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tf, tg)
- if not ok then
- out("failed to wait thread: ", res)
- else
- out("res: ", res)
- end
-
- out("f status: ", coroutine.status(tf))
- out("g status: ", coroutine.status(tg))
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 2: fail
-delete thread 2
-terminate 1: ok
-delete thread 1
-terminate 3: fail
-delete thread 3
-
---- response_body
-thread f created: running
-thread g created: running
-f: hello
-failed to wait thread: f done
-f status: dead
-g status: running
-g: hello
-
---- error_log eval
-qr/lua user thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):8: f done/
-
-
-
-=== TEST 16: wait on uthreads on the exact order of their termination, but exit the world early
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- ngx.say("f: hello")
- return "done"
- end
-
- local function g()
- ngx.sleep(0.2)
- ngx.say("g: hello")
- return "done"
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("f thread created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("g thread created: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tf, tg)
- if not ok then
- ngx.say("failed to wait: ", res)
- return
- end
-
- ngx.say("res: ", res)
-
- ngx.exit(200)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 3
-delete thread 1
-
---- response_body
-f thread created: running
-g thread created: running
-f: hello
-res: done
-
---- no_error_log
-[error]
-
-
-
-=== TEST 17: wait on uthreads on the reversed order of their termination, but exit the world early
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.2)
- ngx.say("f: hello")
- return "f done"
- end
-
- local function g()
- ngx.sleep(0.1)
- ngx.say("g: hello")
- return "g done"
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- ngx.say("failed to spawn thread f: ", err)
- return
- end
-
- ngx.say("f thread created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- ngx.say("failed to spawn thread g: ", err)
- return
- end
-
- ngx.say("g thread created: ", coroutine.status(tg))
-
- local ok, res = ngx.thread.wait(tf, tg)
- if not ok then
- ngx.say("failed to wait: ", res)
- return
- end
-
- ngx.say("res: ", res)
-
- ngx.exit(200)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 3: ok
-delete thread 3
-terminate 1: ok
-delete thread 2
-delete thread 1
-
---- response_body
-f thread created: running
-g thread created: running
-g: hello
-res: g done
-
---- no_error_log
-[error]
-
-
-
-=== TEST 18: entry coroutine waiting on a thread not created by itself
---- config
- location /lua {
- content_by_lua '
- local t
-
- local function f()
- ngx.sleep(0.1)
- return "done"
- end
-
- local function g()
- t = ngx.thread.spawn(f)
- end
-
- local co = coroutine.create(g)
- coroutine.resume(co)
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to run thread: ", res)
- return
- end
-
- ngx.say(res)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 2: ok
-terminate 1: fail
-delete thread 3
-delete thread 1
-
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-only the parent coroutine can wait on the thread
-
-
-
-=== TEST 19: entry coroutine waiting on a user coroutine
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- coroutine.yield()
- return "done"
- end
-
- local co = coroutine.create(f)
- coroutine.resume(co)
-
- local ok, res = ngx.thread.wait(co)
- if not ok then
- ngx.say("failed to run thread: ", res)
- return
- end
-
- ngx.say(res)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: fail
-delete thread 1
-
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/lua entry thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):11: attempt to wait on a coroutine that is not a user thread/
-
-
-
-=== TEST 20: lua backtrace dumper may access dead parent coroutines
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.sleep(0.1)
- collectgarbage()
- error("f done")
- end
-
- ngx.thread.spawn(f)
- ngx.say("ok")
-
- collectgarbage()
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: fail
-delete thread 2
-
---- response_body
-ok
-
---- error_log eval
-qr/lua user thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):5: f done/
-
-
-
-=== TEST 21: waiting on a dead coroutine
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello in thread")
- return "done"
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to run thread: ", res)
- return
- end
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to run thread: ", res)
- return
- end
-
- ngx.say(res)
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-hello in thread
-thread created: zombie
-failed to run thread: already waited or killed
---- no_error_log
-[error]
-
-
-
-=== TEST 22: spawn and wait uthreads for many times
---- config
- location /lua {
- content_by_lua '
- local function f()
- -- ngx.say("hello in thread")
- return "done"
- end
-
- for i = 1, 100 do
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- break
- end
-
- -- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to run thread: ", res)
- break
- end
-
- ngx.say(i, ": ", res)
- end
- ';
- }
---- request
-GET /lua
---- response_body eval
-my $s = '';
-for my $i (1..100) {
- $s .= "$i: done\n";
-}
-$s;
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 23: no parameters for ngx.thread.wait
---- config
- location /lua {
- content_by_lua_block {
- ngx.thread.wait()
- ngx.say("ok")
- }
- }
---- request
-GET /lua
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-at least one coroutine should be specified
---- no_error_log
-[crit]
diff --git a/src/deps/src/lua-nginx-module/t/099-c-api.t b/src/deps/src/lua-nginx-module/t/099-c-api.t
deleted file mode 100644
index 50334626b..000000000
--- a/src/deps/src/lua-nginx-module/t/099-c-api.t
+++ /dev/null
@@ -1,397 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(3);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: find zone
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local ffi = require "ffi"
-
- ffi.cdef[[
- void *ngx_http_lua_find_zone(char *data, size_t len);
- ]]
-
- local buf = ffi.new("char[?]", 4)
- ffi.copy(buf, "foo", 3)
- local zone = ffi.C.ngx_http_lua_find_zone(buf, 3)
- ngx.say("foo zone: ", tonumber(ffi.cast("long", zone)) ~= 0 and "defined" or "undef")
-
- ffi.copy(buf, "dogs", 4)
- zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
- ngx.say("dogs zone: ", tonumber(ffi.cast("long", zone)) ~= 0 and "defined" or "undef")
- ';
- }
---- request
-GET /test
---- response_body
-foo zone: undef
-dogs zone: defined
---- no_error_log
-[error]
-
-
-
-=== TEST 2: number typed value
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local ffi = require "ffi"
-
- ffi.cdef[[
- typedef struct {
- size_t len;
- char *data;
- } ngx_str_t;
-
- typedef struct {
- uint8_t type;
-
- union {
- int b; /* boolean */
- double n; /* number */
- ngx_str_t s; /* string */
- } value;
-
- } ngx_http_lua_value_t;
-
- void *ngx_http_lua_find_zone(char *data, size_t len);
- intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
- ]]
-
- local dogs = ngx.shared.dogs
- dogs:set("foo", 1234567)
- dogs:set("bar", 3.14159)
-
- local buf = ffi.new("char[?]", 4)
-
- ffi.copy(buf, "dogs", 4)
- local zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
-
- local val = ffi.new("ngx_http_lua_value_t[?]", 1)
-
- ffi.copy(buf, "foo", 3)
- local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
- ngx.say("foo: rc=", tonumber(rc),
- ", type=", val[0].type,
- ", val=", tonumber(val[0].value.n))
-
- ffi.copy(buf, "bar", 3)
- local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
- ngx.say("bar: rc=", tonumber(rc),
- ", type=", val[0].type,
- ", val=", tonumber(val[0].value.n))
- ';
- }
---- request
-GET /test
---- response_body
-foo: rc=0, type=3, val=1234567
-bar: rc=0, type=3, val=3.14159
---- no_error_log
-[error]
-
-
-
-=== TEST 3: boolean typed value
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local ffi = require "ffi"
-
- ffi.cdef[[
- typedef struct {
- size_t len;
- char *data;
- } ngx_str_t;
-
- typedef struct {
- uint8_t type;
-
- union {
- int b; /* boolean */
- double n; /* number */
- ngx_str_t s; /* string */
- } value;
-
- } ngx_http_lua_value_t;
-
- void *ngx_http_lua_find_zone(char *data, size_t len);
- intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
- ]]
-
- local dogs = ngx.shared.dogs
- dogs:set("foo", true)
- dogs:set("bar", false)
-
- local buf = ffi.new("char[?]", 4)
-
- ffi.copy(buf, "dogs", 4)
- local zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
-
- local val = ffi.new("ngx_http_lua_value_t[?]", 1)
-
- ffi.copy(buf, "foo", 3)
- local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
- ngx.say("foo: rc=", tonumber(rc),
- ", type=", tonumber(val[0].type),
- ", val=", tonumber(val[0].value.b))
-
- local val = ffi.new("ngx_http_lua_value_t[?]", 1)
- ffi.copy(buf, "bar", 3)
- local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
- ngx.say("bar: rc=", tonumber(rc),
- ", type=", tonumber(val[0].type),
- ", val=", tonumber(val[0].value.b))
- ';
- }
---- request
-GET /test
---- response_body
-foo: rc=0, type=1, val=1
-bar: rc=0, type=1, val=0
---- no_error_log
-[error]
-
-
-
-=== TEST 4: key not found
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local ffi = require "ffi"
-
- ffi.cdef[[
- typedef struct {
- size_t len;
- char *data;
- } ngx_str_t;
-
- typedef struct {
- uint8_t type;
-
- union {
- int b; /* boolean */
- double n; /* number */
- ngx_str_t s; /* string */
- } value;
-
- } ngx_http_lua_value_t;
-
- void *ngx_http_lua_find_zone(char *data, size_t len);
- intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
- ]]
-
- local dogs = ngx.shared.dogs
- dogs:flush_all()
-
- local buf = ffi.new("char[?]", 4)
-
- ffi.copy(buf, "dogs", 4)
- local zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
-
- local val = ffi.new("ngx_http_lua_value_t[?]", 1)
-
- ffi.copy(buf, "foo", 3)
- local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
- ngx.say("foo: rc=", tonumber(rc))
-
- local val = ffi.new("ngx_http_lua_value_t[?]", 1)
- ffi.copy(buf, "bar", 3)
- local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
- ngx.say("bar: rc=", tonumber(rc))
- ';
- }
---- request
-GET /test
---- response_body
-foo: rc=-5
-bar: rc=-5
---- no_error_log
-[error]
-
-
-
-=== TEST 5: string typed value
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local ffi = require "ffi"
-
- ffi.cdef[[
- typedef struct {
- size_t len;
- char *data;
- } ngx_str_t;
-
- typedef struct {
- uint8_t type;
-
- union {
- int b; /* boolean */
- double n; /* number */
- ngx_str_t s; /* string */
- } value;
-
- } ngx_http_lua_value_t;
-
- void *ngx_http_lua_find_zone(char *data, size_t len);
- intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
- ]]
-
- local dogs = ngx.shared.dogs
- dogs:set("foo", "hello world")
- dogs:set("bar", "")
-
- local buf = ffi.new("char[?]", 4)
-
- ffi.copy(buf, "dogs", 4)
- local zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
-
- local s = ffi.new("char[?]", 20)
-
- local val = ffi.new("ngx_http_lua_value_t[?]", 1)
- val[0].value.s.len = 20
- val[0].value.s.data = s
-
- ffi.copy(buf, "foo", 3)
- local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
- ngx.say("foo: rc=", tonumber(rc),
- ", type=", tonumber(val[0].type),
- ", val=", ffi.string(val[0].value.s.data, val[0].value.s.len),
- ", len=", tonumber(val[0].value.s.len))
-
- local val = ffi.new("ngx_http_lua_value_t[?]", 1)
- val[0].value.s.len = 20
- val[0].value.s.data = s
-
- ffi.copy(buf, "bar", 3)
- local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
- ngx.say("bar: rc=", tonumber(rc),
- ", type=", tonumber(val[0].type),
- ", val=", ffi.string(val[0].value.s.data, val[0].value.s.len),
- ", len=", tonumber(val[0].value.s.len))
- ';
- }
---- request
-GET /test
---- response_body
-foo: rc=0, type=4, val=hello world, len=11
-bar: rc=0, type=4, val=, len=0
---- no_error_log
-[error]
-
-
-
-=== TEST 6: nil typed value
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua '
- local ffi = require "ffi"
-
- ffi.cdef[[
- typedef struct {
- size_t len;
- char *data;
- } ngx_str_t;
-
- typedef struct {
- uint8_t type;
-
- union {
- int b; /* boolean */
- double n; /* number */
- ngx_str_t s; /* string */
- } value;
-
- } ngx_http_lua_value_t;
-
- void *ngx_http_lua_find_zone(char *data, size_t len);
- intptr_t ngx_http_lua_shared_dict_get(void *zone, char *kdata, size_t klen, ngx_http_lua_value_t *val);
- ]]
-
- local dogs = ngx.shared.dogs
- dogs:set("foo", nil)
-
- local buf = ffi.new("char[?]", 4)
-
- ffi.copy(buf, "dogs", 4)
- local zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
-
- local val = ffi.new("ngx_http_lua_value_t[?]", 1)
-
- ffi.copy(buf, "foo", 3)
- local rc = ffi.C.ngx_http_lua_shared_dict_get(zone, buf, 3, val)
- ngx.say("foo: rc=", tonumber(rc))
- ';
- }
---- request
-GET /test
---- response_body
-foo: rc=-5
---- no_error_log
-[error]
-
-
-
-=== TEST 7: find zone (multiple zones)
---- http_config
- lua_shared_dict dogs 1m;
- lua_shared_dict cats 1m;
---- config
- location = /test {
- content_by_lua '
- local ffi = require "ffi"
-
- ffi.cdef[[
- void *ngx_http_lua_find_zone(char *data, size_t len);
- ]]
-
- local buf = ffi.new("char[?]", 4)
- ffi.copy(buf, "cats", 4)
- local zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
- local cats = tostring(zone)
-
- ffi.copy(buf, "dogs", 4)
- zone = ffi.C.ngx_http_lua_find_zone(buf, 4)
- local dogs = tostring(zone)
-
- ngx.say("dogs == cats ? ", dogs == cats)
- -- ngx.say("dogs: ", dogs)
- -- ngx.say("cats ", cats)
- ';
- }
---- request
-GET /test
---- response_body
-dogs == cats ? false
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/100-client-abort.t b/src/deps/src/lua-nginx-module/t/100-client-abort.t
deleted file mode 100644
index 39d3244b1..000000000
--- a/src/deps/src/lua-nginx-module/t/100-client-abort.t
+++ /dev/null
@@ -1,1074 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-BEGIN {
- if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "client abort detect does not support in http3";
- } elsif ($ENV{TEST_NGINX_USE_HTTP2}) {
- $SkipReason = "client abort detect does not support in http2";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-use t::StapThread;
-
-our $GCScript = <<_EOC_;
-$t::StapThread::GCScript
-
-F(ngx_http_lua_check_broken_connection) {
- println("lua check broken conn")
-}
-
-F(ngx_http_lua_request_cleanup) {
- println("lua req cleanup")
-}
-_EOC_
-
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 1);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 2: sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.sleep(1)
- ';
- log_by_lua '
- ngx.log(ngx.NOTICE, "here in log by lua")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-here in log by lua
-
-
-
-=== TEST 3: sleep + ignore
---- config
- location /t {
- lua_check_client_abort off;
- content_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-lua req cleanup
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 4: subrequest + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location /sub {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 5: subrequest + ignore
---- config
- location /t {
- lua_check_client_abort off;
- content_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location /sub {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: fail
-lua req cleanup
-delete thread 1
-
---- wait: 1.1
---- timeout: 0.2
---- abort
---- ignore_response
---- error_log
-bad things happen
-
-
-
-=== TEST 6: subrequest + stop (proxy, ignore client abort)
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location = /sub {
- proxy_ignore_client_abort on;
- proxy_pass http://127.0.0.2:12345/;
- }
-
- location = /sleep {
- lua_check_client_abort on;
- content_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 7: subrequest + stop (proxy, check client abort)
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.location.capture("/sub")
- error("bad things happen")
- ';
- }
-
- location = /sub {
- proxy_ignore_client_abort off;
- proxy_pass http://127.0.0.2:12345/;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 8: need body on + sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- lua_need_request_body on;
- content_by_lua '
- ngx.sleep(1)
- ';
- log_by_lua '
- ngx.log(ngx.NOTICE, "here in log by lua")
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-here in log by lua
-
-
-
-=== TEST 9: ngx.req.read_body + sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.req.read_body()
- ngx.sleep(1)
- ';
- log_by_lua '
- ngx.log(ngx.NOTICE, "here in log by lua")
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 0.1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-here in log by lua
-
-
-
-=== TEST 10: ngx.req.socket + receive() + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local sock = ngx.req.socket()
- sock:receive()
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 11: ngx.req.socket + receive(N) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local sock = ngx.req.socket()
- sock:receive(5)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 0.1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 12: ngx.req.socket + receive(n) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local sock = ngx.req.socket()
- sock:receive(2)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like
-^(?:lua check broken conn
-terminate 1: ok
-delete thread 1
-lua req cleanup|lua check broken conn
-lua req cleanup
-delete thread 1)$
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 13: ngx.req.socket + m * receive(n) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local sock = ngx.req.socket()
- sock:receive(2)
- sock:receive(2)
- sock:receive(1)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 14: ngx.req.socket + receiveuntil + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local sock = ngx.req.socket()
- local it = sock:receiveuntil("\\n")
- it()
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 15: ngx.req.socket + receiveuntil + it(n) + sleep + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local sock = ngx.req.socket()
- local it = sock:receiveuntil("\\n")
- it(2)
- it(3)
- ngx.sleep(1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- timeout: 0.2
---- wait: 0.1
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 16: cosocket + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.req.discard_body()
-
- local sock, err = ngx.socket.tcp()
- if not sock then
- ngx.log(ngx.ERR, "failed to get socket: ", err)
- return
- end
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect: ", err)
- return
- end
-
- local bytes, err = sock:send("blpop nonexist 2\\r\\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send query: ", err)
- return
- end
-
- -- ngx.log(ngx.ERR, "about to receive")
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive query: ", err)
- return
- end
-
- ngx.log(ngx.ERR, "res: ", res)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 17: ngx.req.socket + receive n < content-length + ignore
---- config
- location /t {
- lua_check_client_abort off;
- content_by_lua '
- local sock = ngx.req.socket()
- local res, err, part = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err, ": ", part)
- return
- end
- error("bad")
- ';
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 100\r
-\r
-hello"
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-failed to receive: client aborted: hello
-
-
-
-=== TEST 18: ngx.req.socket + receive n < content-length + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local sock = ngx.req.socket()
- local res, err, part = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err, ": ", part)
- return
- end
- error("bad")
- ';
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 100\r
-\r
-hello"
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-failed to receive: client aborted: hello
-
-
-
-=== TEST 19: ngx.req.socket + receive n == content-length + stop
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local sock = ngx.req.socket()
- local res, err = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err)
- return
- end
- ngx.sleep(0.1)
- error("bad")
- ';
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 5\r
-\r
-hello"
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like
-^(?:lua check broken conn
-terminate 1: ok
-delete thread 1
-lua req cleanup|lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1)$
-
---- shutdown
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-
-
-
-=== TEST 20: ngx.req.socket + receive n == content-length + ignore
---- config
- location /t {
- content_by_lua '
- local sock = ngx.req.socket()
- local res, err = sock:receive("*a")
- if not res then
- ngx.log(ngx.NOTICE, "failed to receive: ", err)
- return
- end
- ngx.say("done")
- ';
- }
---- raw_request eval
-"POST /t HTTP/1.0\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 5\r
-\r
-hello"
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-lua req cleanup
-
---- shutdown: 1
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 21: ngx.req.read_body + sleep + stop (log handler still gets called)
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.req.read_body()
- ngx.sleep(0.1)
- ';
- }
---- request
-POST /t
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- shutdown: 1
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
---- SKIP
-
-
-
-=== TEST 22: exec to lua + ignore
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.exec("/t2")
- ';
- }
-
- location = /t2 {
- lua_check_client_abort off;
- content_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-lua req cleanup
-delete thread 1
-terminate 2: ok
-delete thread 2
-lua req cleanup
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-
-
-
-=== TEST 23: exec to proxy + ignore
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.exec("/t2")
- ';
- }
-
- location = /t2 {
- proxy_ignore_client_abort on;
- proxy_pass http://127.0.0.1:$server_port/sleep;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 24: exec (named location) to proxy + ignore
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.exec("@t2")
- ';
- }
-
- location @t2 {
- proxy_ignore_client_abort on;
- proxy_pass http://127.0.0.1:$server_port/sleep;
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 25: bug in ngx_http_upstream_test_connect for kqueue
---- config
- location /t {
- proxy_pass http://127.0.0.1:1234/;
- }
---- request
-GET /t
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-qr{connect\(\) failed \(\d+: Connection refused\) while connecting to upstream}
---- no_error_log
-[alert]
-
-
-
-=== TEST 26: sleep (default off)
---- config
- location /t {
- content_by_lua '
- ngx.sleep(1)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-lua req cleanup
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 27: ngx.say
---- config
- location /t {
- postpone_output 1;
- content_by_lua '
- ngx.sleep(0.2)
- local ok, err = ngx.say("hello")
- if not ok then
- ngx.log(ngx.WARN, "say failed: ", err)
- return
- end
- ';
- }
---- request
-GET /t
-
---- wait: 0.2
---- timeout: 0.1
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
---- error_log
-say failed: nginx output filter error
-
-
-
-=== TEST 28: ngx.print
---- config
- location /t {
- postpone_output 1;
- content_by_lua '
- ngx.sleep(0.2)
- local ok, err = ngx.print("hello")
- if not ok then
- ngx.log(ngx.WARN, "print failed: ", err)
- return
- end
- ';
- }
---- request
-GET /t
-
---- wait: 0.2
---- timeout: 0.1
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
---- error_log
-print failed: nginx output filter error
-
-
-
-=== TEST 29: ngx.send_headers
---- config
- location /t {
- postpone_output 1;
- content_by_lua '
- ngx.sleep(0.2)
- local ok, err = ngx.send_headers()
- if not ok then
- ngx.log(ngx.WARN, "send headers failed: ", err)
- return
- end
- ngx.log(ngx.WARN, "send headers succeeded")
- ';
- }
---- request
-GET /t
-
---- wait: 0.2
---- timeout: 0.1
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
---- error_log
-send headers succeeded
-
-
-
-=== TEST 30: ngx.flush
---- config
- location /t {
- #postpone_output 1;
- content_by_lua '
- ngx.say("hello")
- ngx.sleep(0.2)
- local ok, err = ngx.flush()
- if not ok then
- ngx.log(ngx.WARN, "flush failed: ", err)
- return
- end
- ngx.log(ngx.WARN, "flush succeeded")
- ';
- }
---- request
-GET /t
-
---- wait: 0.2
---- timeout: 0.1
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
---- error_log
-flush succeeded
-
-
-
-=== TEST 31: ngx.eof
---- config
- location /t {
- postpone_output 1;
- content_by_lua '
- ngx.sleep(0.2)
- local ok, err = ngx.eof()
- if not ok then
- ngx.log(ngx.WARN, "eof failed: ", err)
- return
- end
- ngx.log(ngx.WARN, "eof succeeded")
- ';
- }
---- request
-GET /t
-
---- wait: 0.2
---- timeout: 0.1
---- abort
---- ignore_response
---- no_error_log
-[error]
-[alert]
-eof succeeded
---- error_log
-eof failed: nginx output filter error
diff --git a/src/deps/src/lua-nginx-module/t/101-on-abort.t b/src/deps/src/lua-nginx-module/t/101-on-abort.t
deleted file mode 100644
index 784f244e0..000000000
--- a/src/deps/src/lua-nginx-module/t/101-on-abort.t
+++ /dev/null
@@ -1,856 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-BEGIN {
- if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "client abort detect does not support in http3";
- } elsif ($ENV{TEST_NGINX_USE_HTTP2}) {
- $SkipReason = "client abort detect does not support in http2";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-use t::StapThread;
-
-our $GCScript = <<_EOC_;
-$t::StapThread::GCScript
-
-F(ngx_http_lua_check_broken_connection) {
- println("lua check broken conn")
-}
-
-F(ngx_http_lua_request_cleanup) {
- println("lua req cleanup")
-}
-_EOC_
-
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 19);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-$ENV{TEST_NGINX_REDIS_PORT} ||= '6379';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: ignore the client abort event in the user callback
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out_like chop
-^create 2 in 1
-lua check broken conn
-terminate 2: ok
-(?:lua check broken conn
-)?terminate 1: ok
-delete thread 2
-delete thread 1
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- wait: 0.7
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 2: abort in the user callback
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(444)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- wait: 0.1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 3: ngx.exit(499) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(499)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ';
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 4: ngx.exit(408) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(408)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ';
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- wait: 0.1
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 5: ngx.exit(-1) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(-1)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ';
- }
-
- location = /sleep {
- echo_sleep 1;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 6: ngx.exit(0) with pending subrequest
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(0)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.location.capture("/sleep")
- ngx.log(ngx.ERR, "main handler done")
- ';
- }
-
- location = /sleep {
- echo_sleep 0.7;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: fail
-terminate 1: ok
-delete thread 2
-delete thread 1
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- wait: 0.7
---- ignore_response
---- error_log eval
-[
-'client prematurely closed connection',
-'on abort called',
-qr/lua user thread aborted: runtime error: content_by_lua\(nginx\.conf:\d+\):4: attempt to abort with pending subrequests/,
-'main handler done',
-]
-
-
-
-=== TEST 7: accessing cosocket in callback
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to redis: ", err)
- ngx.exit(499)
- end
- local bytes, err = sock:send("flushall\\r\\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send query: ", err)
- ngx.exit(499)
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive: ", err)
- ngx.exit(499)
- end
- ngx.log(ngx.NOTICE, "callback done: ", res)
- ngx.exit(499)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- wait: 0.5
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-callback done: +OK
-
-
-
-=== TEST 8: ignore the client abort event in the user callback (no check)
---- config
- location /t {
- lua_check_client_abort off;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- ngx.say("cannot set on_abort: ", err)
- return
- end
-
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-terminate 1: ok
-delete thread 1
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- response_body
-cannot set on_abort: lua_check_client_abort is off
---- no_error_log
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 9: register on_abort callback but no client abortion
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.say("done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-lua req cleanup
-delete thread 2
-
---- response_body
-done
---- no_error_log
-[error]
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 10: ignore the client abort event in the user callback (uthread)
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- end)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-lua check broken conn
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-lua req cleanup
-
---- timeout: 0.2
---- abort
---- wait: 0.7
---- ignore_response
---- no_error_log
-[error]
---- error_log
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 11: abort in the user callback (uthread)
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(444)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- end)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 3
-
---- timeout: 0.2
---- wait: 0.1
---- abort
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 12: register on_abort callback but no client abortion (uthread)
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.1)
- ngx.say("done")
- end)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-delete thread 3
-lua req cleanup
-delete thread 2
-
---- response_body
-done
---- no_error_log
-[error]
-client prematurely closed connection
-on abort called
-main handler done
-
-
-
-=== TEST 13: register on_abort callback multiple times
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- ngx.say("1: cannot set on_abort: " .. err)
- return
- end
-
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- ngx.say("2: cannot set on_abort: " .. err)
- return
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.1)
- ngx.say("done")
- end)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-lua req cleanup
-delete thread 2
-
---- response_body
-2: cannot set on_abort: duplicate call
-
---- no_error_log
-[error]
-
-
-
-=== TEST 14: abort with 499 in the user callback, but the header is already sent
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(499)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.send_headers()
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 15: abort with 444 in the user callback, but the header is already sent
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(444)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.send_headers()
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 16: abort with 408 in the user callback, but the header is already sent
---- config
- location /t {
- lua_check_client_abort on;
- content_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- ngx.exit(408)
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.send_headers()
- ngx.sleep(0.7)
- ngx.log(ngx.NOTICE, "main handler done")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-lua check broken conn
-terminate 2: ok
-lua req cleanup
-delete thread 2
-delete thread 1
-
---- timeout: 0.2
---- wait: 0.1
---- abort
---- ignore_response
---- no_error_log
-[error]
-main handler done
---- error_log
-client prematurely closed connection
-on abort called
-
-
-
-=== TEST 17: GC issue with the on_abort thread object
---- config
- location = /t {
- lua_check_client_abort on;
- content_by_lua '
- ngx.on_abort(function () end)
- collectgarbage()
- ngx.sleep(60)
- ';
- }
---- request
- GET /t
---- abort
---- timeout: 0.2
---- ignore_response
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 18: register on_abort callback but no client abortion (2 uthreads and 1 pending)
---- config
- location /t {
- lua_check_client_abort on;
- rewrite_by_lua '
- local ok, err = ngx.on_abort(function ()
- ngx.log(ngx.NOTICE, "on abort called")
- end)
-
- if not ok then
- error("cannot set on_abort: " .. err)
- end
-
- ngx.thread.spawn(function ()
- ngx.sleep(0.1)
- ngx.say("done")
- ngx.exit(200)
- end)
-
- ngx.thread.spawn(function ()
- ngx.sleep(100)
- end)
- ';
- content_by_lua return;
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-spawn user thread 3 in 1
-create 4 in 1
-spawn user thread 4 in 1
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-lua req cleanup
-delete thread 2
-delete thread 3
-delete thread 4
-
---- wait: 0.5
---- response_body
-done
---- no_error_log
-[error]
-client prematurely closed connection
-on abort called
-main handler done
diff --git a/src/deps/src/lua-nginx-module/t/102-req-start-time.t b/src/deps/src/lua-nginx-module/t/102-req-start-time.t
deleted file mode 100644
index d54b19941..000000000
--- a/src/deps/src/lua-nginx-module/t/102-req-start-time.t
+++ /dev/null
@@ -1,115 +0,0 @@
-# -*- mode: conf -*-
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: start time
---- config
- location = /start {
- content_by_lua 'ngx.say(ngx.req.start_time())';
- }
---- request
-GET /start
---- response_body_like: ^\d{10,}(\.\d+)?$
---- no_error_log
-[error]
-
-
-
-=== TEST 2: start time in set_by_lua
---- config
- location = /start {
- set_by_lua $a 'return ngx.req.start_time()';
- echo $a;
- }
---- request
-GET /start
---- response_body_like: ^\d{10,}(\.\d+)?$
---- no_error_log
-[error]
-
-
-
-=== TEST 3: request time
---- config
- location = /req_time {
- content_by_lua '
- ngx.sleep(0.1)
-
- local req_time = ngx.now() - ngx.req.start_time()
-
- ngx.say(req_time)
- ngx.say(ngx.req.start_time() < ngx.now())
- ';
- }
---- request
-GET /req_time
---- response_body_like chop
-^(?:0\.[12]|0\.099|0\.098)\d*
-true$
---- no_error_log
-[error]
-
-
-
-=== TEST 4: request time update
---- config
- location = /req_time {
- content_by_lua '
- ngx.sleep(0.1)
-
- local req_time = ngx.now() - ngx.req.start_time()
-
- ngx.sleep(0.1)
-
- ngx.update_time()
-
- local req_time_updated = ngx.now() - ngx.req.start_time()
-
- ngx.say(req_time)
- ngx.say(req_time_updated)
- ngx.say(req_time_updated > req_time)
- ';
- }
---- request
-GET /req_time
---- response_body_like chomp
-^(?:0\.[12]|0\.099|0\.098)\d*
-0\.\d+
-true$
---- no_error_log
-[error]
-
-
-
-=== TEST 5: init_by_lua
---- http_config
- init_by_lua '
- time = ngx.req.start_time()
- ';
---- config
- location = /t {
- content_by_lua '
- ngx.say(time)
- ';
- }
---- request
- GET /t
---- response_body
---- no_error_log
-[error]
---- SKIP
diff --git a/src/deps/src/lua-nginx-module/t/103-req-http-ver.t b/src/deps/src/lua-nginx-module/t/103-req-http-ver.t
deleted file mode 100644
index 73ecccae2..000000000
--- a/src/deps/src/lua-nginx-module/t/103-req-http-ver.t
+++ /dev/null
@@ -1,57 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: HTTP 1.1
---- config
- location /t {
- content_by_lua '
- ngx.say(ngx.req.http_version())
- ';
- }
---- request
-GET /t
---- response_body eval
-my $body;
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- $body="3\n";
-} elsif (defined $ENV{TEST_NGINX_USE_HTTP2}) {
- $body="2\n";
-} else {
- $body="1.1\n";
-}
-
-$body;
---- no_error_log
-[error]
-
-
-
-=== TEST 2: HTTP 1.0
---- config
- location /t {
- content_by_lua '
- ngx.say(ngx.req.http_version())
- ';
- }
---- request
-GET /t HTTP/1.0
---- response_body
-1
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/104-req-raw-header.t b/src/deps/src/lua-nginx-module/t/104-req-raw-header.t
deleted file mode 100644
index 459d190ac..000000000
--- a/src/deps/src/lua-nginx-module/t/104-req-raw-header.t
+++ /dev/null
@@ -1,1061 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "http3 does not support ngx.req.raw_header()";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 15);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: small header
---- config
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- request
-GET /t
---- response_body eval
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-\r
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 2: large header
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 561;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- request
-GET /t
---- more_headers eval
-CORE::join "\n", map { "Header$_: value-$_" } 1..512
-
---- response_body eval
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 3: large header (no request line)
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 561;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header(true))
- ';
- }
---- request
-GET /t
---- more_headers eval
-CORE::join "\n", map { "Header$_: value-$_" } 1..512
-
---- response_body eval
-qq{Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 4: small header (no request line)
---- config
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header(true))
- ';
- }
---- request
-GET /t
---- response_body eval
-qq{Host: localhost\r
-Connection: close\r
-\r
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 5: small header (no request line, with leading CRLF)
---- config
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header(true))
- ';
- }
---- raw_request eval
-"\r\nGET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-\r
-"
---- response_body eval
-qq{Host: localhost\r
-Connection: close\r
-\r
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 6: small header, with leading CRLF
---- config
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- raw_request eval
-"\r\nGET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-\r
-"
---- response_body eval
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-\r
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 7: large header, with leading CRLF
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 561;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
-
---- raw_request eval
-"\r\nGET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-".
-(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\n\r\n"
-
---- response_body eval
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 8: large header, with leading CRLF, excluding request line
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 561;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header(true))
- ';
- }
-
---- raw_request eval
-"\r\nGET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-".
-(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\n\r\n"
-
---- response_body eval
-qq{Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 9: large header, with lots of leading CRLF, excluding request line
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 561;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header(true))
- ';
- }
-
---- raw_request eval
-("\r\n" x 534) . "GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-".
-(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\n\r\n"
-
---- response_body eval
-qq{Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 10: small header, pipelined
---- config
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- pipelined_requests eval
-["GET /t", "GET /th"]
-
---- more_headers
-Foo: bar
-
---- response_body eval
-[qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: keep-alive\r
-Foo: bar\r
-\r
-}, qq{GET /th HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-Foo: bar\r
-\r
-}]
---- no_error_log
-[error]
-
-
-
-=== TEST 11: large header, pipelined
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 561;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- pipelined_requests eval
-["GET /t", "GET /t"]
-
---- more_headers eval
-CORE::join "\n", map { "Header$_: value-$_" } 1..512
-
---- response_body eval
-my $headers = (CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\n\r\n";
-
-[qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: keep-alive\r
-$headers},
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-$headers}]
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 12: small header, multi-line header
---- config
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-Foo: bar baz\r
- blah\r
-\r
-"
---- response_body eval
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-Foo: bar baz\r
- blah\r
-\r
-}
---- no_error_log
-[error]
---- skip_nginx
-3: >= 1.21.1
-
-
-
-=== TEST 13: large header, multi-line header
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 50 567;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
-
---- raw_request eval
-my $headers = (CORE::join "\r\n", map { "Header$_: value-$_\r\n hello $_ world blah blah" } 1..512) . "\r\n\r\n";
-
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-$headers}
-
---- response_body eval
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_\r\n hello $_ world blah blah" } 1..512) . "\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
---- skip_nginx
-3: >= 1.21.1
-
-
-
-=== TEST 14: small header (POST body)
---- config
- location /t {
- content_by_lua '
- ngx.req.read_body()
- ngx.print(ngx.req.raw_header())
- ';
- }
---- request
-POST /t
-hello
---- response_body eval
-qq{POST /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 5\r
-\r
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 15: small header (POST body) - in subrequests
---- config
- location /t {
- content_by_lua '
- ngx.req.read_body()
- ngx.print(ngx.req.raw_header())
- ';
- }
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/t")
- ngx.print(res.body)
- ';
- }
-
---- request
-POST /main
-hello
---- response_body eval
-qq{POST /main HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-Content-Length: 5\r
-\r
-}
---- no_error_log
-[error]
-
-
-
-=== TEST 16: large header (POST body)
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 561;
- location /t {
- content_by_lua '
- ngx.req.read_body()
- ngx.print(ngx.req.raw_header())
- ';
- }
---- request
-POST /t
-hello
---- more_headers eval
-CORE::join"\n", map { "Header$_: value-$_" } 1..512
-
---- response_body eval
-qq{POST /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\nContent-Length: 5\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 17: large header (POST body) - in subrequests
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 561;
- location /t {
- content_by_lua '
- ngx.req.read_body()
- ngx.print(ngx.req.raw_header())
- ';
- }
-
- location /main {
- content_by_lua '
- local res = ngx.location.capture("/t")
- ngx.print(res.body)
- ';
- }
---- request
-POST /main
-hello
---- more_headers eval
-CORE::join"\n", map { "Header$_: value-$_" } 1..512
-
---- response_body eval
-qq{POST /main HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..512) . "\r\nContent-Length: 5\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 18: large header (POST body) - r->header_end is outside r->header_in
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 564;
- location /t {
- content_by_lua '
- -- ngx.req.read_body()
- ngx.print(ngx.req.raw_header())
- ';
- }
---- request
-POST /t
-hello
---- more_headers eval
-CORE::join("\n", map { "Header$_: value-$_" } 1..80) . "\nA: abcdefghijklmnopqrs\n"
-
---- response_body eval
-qq{POST /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..80)
-. "\r\nA: abcdefghijklmnopqrs\r\nContent-Length: 5\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 19: large header (POST body) - r->header_end is outside r->header_in (2)
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 30 564;
- location /t {
- content_by_lua '
- -- ngx.req.read_body()
- ngx.print(ngx.req.raw_header())
- ';
- }
---- request
-POST /t
-hello
---- more_headers eval
-CORE::join("\n", map { "Header$_: value-$_" } 1..52) . "\nA: abcdefghijklmnopqrs\n"
-
---- response_body eval
-qq{POST /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..52)
-. "\r\nA: abcdefghijklmnopqrs\r\nContent-Length: 5\r\n\r\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 20: raw_header (the default header buffer can hold the request line, but not the header entries) - without request line)
---- config
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header(true))
- ';
- }
---- request
-GET /t
---- more_headers eval
-my $s = "User-Agent: curl\nBah: bah\n";
-$s .= "Accept: */*\n";
-$s .= "Cookie: " . "C" x 1200 . "\n";
-$s
---- response_body eval
-"Host: localhost\r
-Connection: close\r
-User-Agent: curl\r
-Bah: bah\r
-Accept: */*\r
-Cookie: " . ("C" x 1200) . "\r\n\r\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 21: raw_header (the default header buffer can hold the request line, but not the header entries) - with request line)
---- config
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- request
-GET /t
---- more_headers eval
-my $s = "User-Agent: curl\nBah: bah\n";
-$s .= "Accept: */*\n";
-$s .= "Cookie: " . "C" x 1200 . "\n";
-$s
---- response_body eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-User-Agent: curl\r
-Bah: bah\r
-Accept: */*\r
-Cookie: " . ("C" x 1200) . "\r\n\r\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 22: ngx_proxy/ngx_fastcgi/etc change r->header_end to point to their own buffers
---- config
- location = /t {
- proxy_buffering off;
- proxy_pass http://127.0.0.1:$server_port/bad;
- proxy_intercept_errors on;
- error_page 500 = /500;
- }
-
- location = /bad {
- return 500;
- }
-
- location = /500 {
- internal;
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- request
-GET /t
---- response_body eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-\r
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 23: ngx_proxy/ngx_fastcgi/etc change r->header_end to point to their own buffers (exclusive LF in the request data)
---- config
- location = /t {
- proxy_buffering off;
- proxy_pass http://127.0.0.1:$server_port/bad;
- proxy_intercept_errors on;
- error_page 500 = /500;
- }
-
- location = /bad {
- return 500;
- }
-
- location = /500 {
- internal;
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- raw_request eval
-"GET /t HTTP/1.1
-Host: localhost
-Connection: close
-Content-Length: 5
-
-hello"
---- response_body eval
-"GET /t HTTP/1.1
-Host: localhost
-Connection: close
-Content-Length: 5
-
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 24: ngx_proxy/ngx_fastcgi/etc change r->header_end to point to their own buffers (exclusive LF in the request data, and no status line)
---- config
- location = /t {
- proxy_buffering off;
- proxy_pass http://127.0.0.1:$server_port/bad;
- proxy_intercept_errors on;
- error_page 500 = /500;
- }
-
- location = /bad {
- return 500;
- }
-
- location = /500 {
- internal;
- content_by_lua '
- ngx.print(ngx.req.raw_header(true))
- ';
- }
---- raw_request eval
-"GET /t HTTP/1.1
-Host: localhost
-Connection: close
-Content-Length: 5
-
-hello"
---- response_body eval
-"Host: localhost
-Connection: close
-Content-Length: 5
-
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 25: ngx_proxy/ngx_fastcgi/etc change r->header_end to point to their own buffers (mixed LF and CRLF in the request data, and no status line)
---- config
- location = /t {
- proxy_buffering off;
- proxy_pass http://127.0.0.1:$server_port/bad;
- proxy_intercept_errors on;
- error_page 500 = /500;
- }
-
- location = /bad {
- return 500;
- }
-
- location = /500 {
- internal;
- content_by_lua '
- ngx.print(ngx.req.raw_header(true))
- ';
- }
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost
-Connection: close\r
-Content-Length: 5\r
-
-hello"
---- response_body eval
-"Host: localhost
-Connection: close\r
-Content-Length: 5\r
-
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 26: ngx_proxy/ngx_fastcgi/etc change r->header_end to point to their own buffers (another way of mixing LF and CRLF in the request data, and no status line)
---- config
- location = /t {
- proxy_buffering off;
- proxy_pass http://127.0.0.1:$server_port/bad;
- proxy_intercept_errors on;
- error_page 500 = /500;
- }
-
- location = /bad {
- return 500;
- }
-
- location = /500 {
- internal;
- content_by_lua '
- ngx.print(ngx.req.raw_header(true))
- ';
- }
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost
-Connection: close\r
-Content-Length: 5
-\r
-hello"
---- response_body eval
-"Host: localhost
-Connection: close\r
-Content-Length: 5
-\r
-"
---- no_error_log
-[error]
-
-
-
-=== TEST 27: two pipelined requests with large headers
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 3 5610;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- pipelined_requests eval
-["GET /t", "GET /t"]
---- more_headers eval
-CORE::join "\n", map { "Header$_: value-$_" } 1..585
-
---- response_body eval
-[qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: keep-alive\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..585) . "\r\n\r\n",
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..585) . "\r\n\r\n",
-,
-]
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 28: a request with large header and a smaller pipelined request following
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 2 1921;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- pipelined_requests eval
-["GET /t", "GET /t"]
---- more_headers eval
-[CORE::join("\n", map { "Header$_: value-$_" } 1..170), "Foo: bar\n"]
-
---- response_body eval
-[qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: keep-alive\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..170) . "\r\n\r\n",
-qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-Foo: bar\r
-\r
-},
-]
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 29: a request with large header and a smaller pipelined request following
---- config
- client_header_buffer_size 10;
- large_client_header_buffers 2 1921;
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- pipelined_requests eval
-["GET /t", "GET /t" . ("a" x 512)]
---- more_headers eval
-[CORE::join("\n", map { "Header$_: value-$_" } 1..170), "Foo: bar\n"]
-
---- response_body eval
-[qq{GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: keep-alive\r
-}
-.(CORE::join "\r\n", map { "Header$_: value-$_" } 1..170) . "\r\n\r\n",
-qq{GET /t} . ("a" x 512) . qq{ HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-Foo: bar\r
-\r
-},
-]
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 30: large headers (using single LF as line break)
---- config
- location /t {
- content_by_lua_block {
- ngx.print(ngx.req.raw_header())
- }
- }
-
---- raw_request eval
-"GET /t HTTP/1.1
-Host: localhost
-Connection: close
-".
-(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
-
---- response_body eval
-qq{GET /t HTTP/1.1
-Host: localhost
-Connection: close
-}
-.(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 31: large headers without request line (using single LF as line break)
---- config
- location /t {
- content_by_lua_block {
- ngx.print(ngx.req.raw_header(true))
- }
- }
-
---- raw_request eval
-"GET /t HTTP/1.1
-Host: localhost
-Connection: close
-".
-(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
-
---- response_body eval
-qq{Host: localhost
-Connection: close
-}
-.(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 32: large headers with leading CRLF (using single LF as line break)
---- config
- location /t {
- content_by_lua_block {
- ngx.print(ngx.req.raw_header())
- }
- }
-
---- raw_request eval
-"\r
-GET /t HTTP/1.1
-Host: localhost
-Connection: close
-".
-(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
-
---- response_body eval
-qq{GET /t HTTP/1.1
-Host: localhost
-Connection: close
-}
-.(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 33: large headers without request line but contains leading CRLF (using single LF as line break)
---- config
- location /t {
- content_by_lua_block {
- ngx.print(ngx.req.raw_header(true))
- }
- }
-
---- raw_request eval
-"\r
-GET /t HTTP/1.1
-Host: localhost
-Connection: close
-".
-(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
-
---- response_body eval
-qq{Host: localhost
-Connection: close
-}
-.(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
-
---- no_error_log
-[error]
---- timeout: 5
-
-
-
-=== TEST 34: multi-line header is invalid (nginx >= 1.21.1)
---- config
- location /t {
- content_by_lua '
- ngx.print(ngx.req.raw_header())
- ';
- }
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Connection: close\r
-Foo: bar baz\r
- blah\r
-\r
-"
---- error_code: 400
---- error_log
-client sent invalid header line: "\x20..." while reading client request headers
---- no_error_log
-[error]
---- skip_nginx
-3: < 1.21.1
-
-
-
-=== TEST 35: bugfix: invalid http request
---- log_level: error
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;;";
---- config
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to memc: ", err)
- return
- end
- sock:send("\n")
- sock:close()
-
- ngx.say("OK")
- }
- }
-
- log_by_lua_block {
- local h = ngx.req.raw_header()
- }
-
---- request
-GET /t
---- response_body
-OK
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/105-pressure.t b/src/deps/src/lua-nginx-module/t/105-pressure.t
deleted file mode 100644
index 2fc130d09..000000000
--- a/src/deps/src/lua-nginx-module/t/105-pressure.t
+++ /dev/null
@@ -1,55 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-worker_connections(1014);
-#master_on();
-#log_level('debug');
-
-repeat_each(20);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-#warn $html_dir;
-
-our $Id;
-
-#no_diff();
-#no_long_string();
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#no_shuffle();
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: memory issue in the "args" string option for ngx.location.capture
-the default worker_connections is 64, HTTP3 will keep the connection when curl
-request finished. So need to change the worker_connection.
---- config
- location /test1 {
- content_by_lua '
- local res = ngx.location.capture("/test2/auth", {args = ngx.var.args})
- ngx.print(res.body)
- ';
- }
- location /test2 {
- content_by_lua '
- collectgarbage()
- ngx.say(ngx.var.args)
- ';
- }
-
---- request eval
-$::Id = int rand 10000;
-"GET /test1?parent=$::Id&name=2013031816214284300707&footprint=dsfasfwefklds"
-
---- response_body eval
-"parent=$::Id&name=2013031816214284300707&footprint=dsfasfwefklds\n"
-
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/106-timer.t b/src/deps/src/lua-nginx-module/t/106-timer.t
deleted file mode 100644
index 513e1e5b4..000000000
--- a/src/deps/src/lua-nginx-module/t/106-timer.t
+++ /dev/null
@@ -1,2399 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 8 + 61);
-
-#no_diff();
-no_long_string();
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_HTML_DIR} = $HtmlDir;
-
-worker_connections(1024);
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple at
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local function f(premature)
- print("elapsed: ", ngx.now() - begin)
- print("timer prematurely expired: ", premature)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-timer prematurely expired: true
-
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.0(?:4[4-9]|5[0-6])\d*, context: ngx\.timer, client: \d+\.\d+\.\d+\.\d+, server: 0\.0\.0\.0:\d+/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"timer prematurely expired: false",
-]
---- grep_error_log eval: qr/lua caching unused lua thread|lua reusing cached lua thread/
---- grep_error_log_out eval
-[
- "lua caching unused lua thread
-lua caching unused lua thread
-",
- "lua reusing cached lua thread
-lua reusing cached lua thread
-lua caching unused lua thread
-lua caching unused lua thread
-",
-]
-
-
-
-=== TEST 2: globals are shared
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local function f()
- foo = 3
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.06)
- ngx.say("foo = ", foo)
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-foo = 3
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.0(?:4[4-9]|5[0-6])/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 3: lua variable sharing via upvalue
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local foo
- local function f()
- foo = 3
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.06)
- ngx.say("foo = ", foo)
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-foo = 3
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.0(?:4[4-9]|5[0-6])/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 4: simple at (sleep in the timer callback)
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
- ngx.sleep(0.2)
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.3
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] .*? my lua timer handler/,
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.(?:1[4-9]|2[0-6]?)/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 5: tcp cosocket in timer handler (short connections)
---- no_http2
---- config
- server_tokens off;
-
- location = /gc {
- content_by_lua_block {
- local c = collectgarbage("count")
- ngx.say("before: ", c)
- collectgarbage("collect")
- c = collectgarbage("count")
- ngx.say("after: ", c)
- }
- }
-
- location = /t {
- content_by_lua '
- collectgarbage()
- -- ngx.say("gc size: ", collectgarbage("count"))
- local begin = ngx.now()
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
- local function f()
- print("my lua timer handler")
- local sock = ngx.socket.tcp()
- local port = $TEST_NGINX_SERVER_PORT
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
-
- print("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- if err == "closed" then
- break
- end
- fail("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- print("close: ", ok, " ", err)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- -- ngx.sleep(0.1)
- ngx.say("registered timer")
- ';
- }
-
- location = /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"connected: 1",
-"request sent: 57",
-"received: HTTP/1.1 200 OK",
-qr/received: Server: \S+/,
-"received: Content-Type: text/plain",
-"received: Content-Length: 4",
-"received: Connection: close",
-"received: foo",
-"close: 1 nil",
-]
-
-
-
-=== TEST 6: tcp cosocket in timer handler (keep-alive connections)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- content_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set reusable: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 7: 0 timer
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local function f()
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0(?:[^.]|\.00)/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 8: udp cosocket in timer handler
---- config
- location = /t {
- content_by_lua '
- local begin = ngx.now()
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
- local function f()
- print("my lua timer handler")
- local socket = ngx.socket
- -- local socket = require "socket"
-
- local udp = socket.udp()
-
- local port = $TEST_NGINX_MEMCACHED_PORT
- udp:settimeout(1000) -- 1 sec
-
- local ok, err = udp:setpeername("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok)
-
- local req = "\\0\\1\\0\\0\\0\\1\\0\\0flush_all\\r\\n"
- local ok, err = udp:send(req)
- if not ok then
- fail("failed to send: ", err)
- return
- end
-
- local data, err = udp:receive()
- if not data then
- fail("failed to receive data: ", err)
- return
- end
- print("received ", #data, " bytes: ", data)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
-
- location = /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"connected: 1",
-"received 12 bytes: \x{00}\x{01}\x{00}\x{00}\x{00}\x{01}\x{00}\x{00}OK\x{0d}\x{0a}"
-]
-
-
-
-=== TEST 9: simple at (sleep in the timer callback) - log_by_lua
---- config
- location /t {
- echo hello world;
- log_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
- ngx.sleep(0.02)
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-hello world
-
---- wait: 0.3
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-qr/\[lua\] log_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.0(?:6[4-9]|7[0-9]|8[1-3])/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 10: tcp cosocket in timer handler (keep-alive connections) - log_by_lua
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- echo hello;
- log_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- ';
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set reusable: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-hello
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 11: tcp cosocket in timer handler (keep-alive connections) - header_filter_by_lua
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- echo hello;
- header_filter_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- ';
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set reusable: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap3
-global count = 0
-F(ngx_http_lua_header_filter) {
- if (count++ == 10) {
- println("header filter")
- print_ubacktrace()
- }
-}
-
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-hello
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 12: tcp cosocket in timer handler (keep-alive connections) - body_filter_by_lua
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- echo hello;
- body_filter_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- ';
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set keep alive: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap3
-global count = 0
-F(ngx_http_lua_header_filter) {
- if (count++ == 10) {
- println("header filter")
- print_ubacktrace()
- }
-}
-
---- stap eval: $::GCScript
---- stap_out_like chop
-create 2 in 1
-create 3 in 1
-(?:terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-|terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2)$
-
---- response_body
-hello
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 13: tcp cosocket in timer handler (keep-alive connections) - set_by_lua
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- set_by_lua $a '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- return 32
- ';
- echo $a;
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set reusable: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap3
-global count = 0
-F(ngx_http_lua_header_filter) {
- if (count++ == 10) {
- println("header filter")
- print_ubacktrace()
- }
-}
-
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-32
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 14: coroutine API
---- config
- location /t {
- content_by_lua '
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
- local function f()
- local function f()
- local cnt = 0
- for i = 1, 20 do
- print("cnt = ", cnt)
- cy()
- cnt = cnt + 1
- end
- end
-
- local c = cc(f)
- for i=1,3 do
- cr(c)
- print("after resume, i = ", i)
- end
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-create 3 in 2
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"cnt = 0",
-"after resume, i = 1",
-"cnt = 1",
-"after resume, i = 2",
-"cnt = 2",
-"after resume, i = 3",
-]
-
-
-
-=== TEST 15: ngx.thread API
---- config
- location /t {
- content_by_lua '
- local function fail (...)
- ngx.log(ngx.ERR, ...)
- end
- local function handle()
- local function f()
- print("hello in thread")
- return "done"
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- fail("failed to spawn thread: ", err)
- return
- end
-
- print("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- fail("failed to run thread: ", res)
- return
- end
-
- print("wait result: ", res)
- end
- local ok, err = ngx.timer.at(0.01, handle)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"hello in thread",
-"thread created: zombie",
-"wait result: done",
-]
-
-
-
-=== TEST 16: shared dict
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location /t {
- content_by_lua '
- local function f()
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- dogs:set("bah", 10502)
- local val = dogs:get("foo")
- print("get foo: ", val, " ", type(val))
- val = dogs:get("bah")
- print("get bah: ", val, " ", type(val))
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"get foo: 32 number",
-"get bah: 10502 number",
-]
-
-
-
-=== TEST 17: ngx.exit(0)
---- config
- location /t {
- content_by_lua '
- local function f()
- local function g()
- print("BEFORE ngx.exit")
- ngx.exit(0)
- end
- g()
- print("CANNOT REACH HERE")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"BEFORE ngx.exit",
-]
---- no_error_log
-CANNOT REACH HERE
-API disabled
-
-
-
-=== TEST 18: ngx.exit(403)
---- config
- location /t {
- content_by_lua '
- local function f()
- local function g()
- print("BEFORE ngx.exit")
- ngx.exit(403)
- end
- g()
- print("CANNOT REACH HERE")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-CANNOT REACH HERE
-API disabled
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"BEFORE ngx.exit",
-]
-
-
-
-=== TEST 19: exit in user thread (entry thread is still pending on ngx.sleep)
---- quic_max_idle_timeout: 1.3
---- config
- location /t {
- content_by_lua '
- local function handle()
- local function f()
- print("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- print("BEFORE thread spawn")
- ngx.thread.spawn(f)
- print("AFTER thread spawn")
- ngx.sleep(1)
- print("entry thread END")
- end
- local ok, err = ngx.timer.at(0.05, handle)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out_like chop
-(?:create 2 in 1
-terminate 1: ok
-delete thread 1
-free request
-create 3 in 2
-spawn user thread 3 in 2
-add timer 100
-add timer 1000
-expire timer 100
-terminate 3: ok
-delete thread 3
-lua sleep cleanup
-delete timer 1000
-delete thread 2|create 2 in 1
-terminate 1: ok
-delete thread 1
-create 3 in 2
-spawn user thread 3 in 2
-add timer 100
-add timer 1000
-free request
-expire timer 100
-terminate 3: ok
-delete thread 3
-lua sleep cleanup
-delete timer 1000
-delete thread 2)$
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-API disabled
-entry thread END
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"BEFORE thread spawn",
-"hello in thread",
-"AFTER thread spawn",
-]
-
-
-
-=== TEST 20: chained timers (0 delay)
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- local ok, err = ngx.timer.at(0, g)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-create 3 in 2
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-'lua ngx.timer expired',
-'http lua close fake http connection',
-qr/trace: \[m\]\[f\]\[g\], context: ngx\.timer, client: \d+\.\d+\.\d+\.\d+, server: 0\.0\.0\.0:\d+/,
-]
-
-
-
-=== TEST 21: chained timers (non-zero delay)
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- local ok, err = ngx.timer.at(0.01, g)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-create 3 in 2
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log
-lua ngx.timer expired
-http lua close fake http connection
-trace: [m][f][g]
-
-
-
-=== TEST 22: multiple parallel timers
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- local ok, err = ngx.timer.at(0.01, g)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log
-lua ngx.timer expired
-http lua close fake http connection
-trace: [m][f][g]
-
-
-
-=== TEST 23: lua_max_pending_timers
---- http_config
- lua_max_pending_timers 1;
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer f: ", err)
- return
- end
- local ok, err = ngx.timer.at(0.01, g)
- if not ok then
- ngx.say("failed to set timer g: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-failed to set timer g: too many pending timers
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-[error]
-
---- error_log
-lua ngx.timer expired
-http lua close fake http connection
-
-
-
-=== TEST 24: lua_max_pending_timers (just not exceeding)
---- http_config
- lua_max_pending_timers 2;
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer f: ", err)
- return
- end
- local ok, err = ngx.timer.at(0.01, g)
- if not ok then
- ngx.say("failed to set timer g: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-[error]
-
---- error_log
-lua ngx.timer expired
-http lua close fake http connection
-trace: [m][f][g]
-
-
-
-=== TEST 25: lua_max_pending_timers - chained timers (non-zero delay) - not exceeding
---- http_config
- lua_max_pending_timers 1;
-
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- local ok, err = ngx.timer.at(0.01, g)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-create 3 in 2
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log
-lua ngx.timer expired
-http lua close fake http connection
-trace: [m][f][g]
-
-
-
-=== TEST 26: lua_max_pending_timers - chained timers (zero delay) - not exceeding
---- http_config
- lua_max_pending_timers 1;
-
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- local ok, err = ngx.timer.at(0, g)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-create 3 in 2
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log
-lua ngx.timer expired
-http lua close fake http connection
-trace: [m][f][g]
-
-
-
-=== TEST 27: lua_max_running_timers (just not enough)
---- http_config
- lua_max_running_timers 1;
---- config
- location /t {
- content_by_lua '
- collectgarbage()
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local f, g
-
- g = function ()
- ngx.sleep(0.01)
- end
-
- f = function ()
- ngx.sleep(0.01)
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer f: ", err)
- return
- end
- local ok, err = ngx.timer.at(0, g)
- if not ok then
- ngx.say("failed to set timer g: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[crit]
-[error]
-
---- error_log eval
-[
-qr/\[alert\] .*? lua failed to run timer with function defined at =content_by_lua\(nginx.conf:\d+\):11: 1 lua_max_running_timers are not enough/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-]
-
-
-
-=== TEST 28: lua_max_running_timers (just enough)
---- http_config
- lua_max_running_timers 2;
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local f, g
-
- g = function ()
- ngx.sleep(0.01)
- end
-
- f = function ()
- ngx.sleep(0.01)
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer f: ", err)
- return
- end
- local ok, err = ngx.timer.at(0, g)
- if not ok then
- ngx.say("failed to set timer g: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-[error]
-
---- error_log
-lua ngx.timer expired
-http lua close fake http connection
-
-
-
-=== TEST 29: lua_max_running_timers (just enough) - 2
---- http_config
- lua_max_running_timers 2;
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local f, g
-
- g = function ()
- ngx.timer.at(0.02, f)
- ngx.sleep(0.01)
- end
-
- f = function ()
- ngx.sleep(0.01)
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer f: ", err)
- return
- end
- local ok, err = ngx.timer.at(0, g)
- if not ok then
- ngx.say("failed to set timer g: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 1
-terminate 1: ok
-delete thread 1
-create 4 in 3
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-terminate 4: ok
-delete thread 4
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-[error]
-
---- error_log
-lua ngx.timer expired
-http lua close fake http connection
-
-
-
-=== TEST 30: user args
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local function f(premature, a, b, c)
- print("elapsed: ", ngx.now() - begin)
- print("timer prematurely expired: ", premature)
- print("timer user args: ", a, " ", b, " ", c)
- end
- local ok, err = ngx.timer.at(0.05, f, 1, "hello", true)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-timer prematurely expired: true
-
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.0(?:4[4-9]|5[0-6])\d*, context: ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"timer prematurely expired: false",
-"timer user args: 1 hello true",
-]
-
-
-
-=== TEST 31: use of ngx.ctx
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local function f(premature)
- ngx.ctx.s = "hello"
- print("elapsed: ", ngx.now() - begin)
- print("timer prematurely expired: ", premature)
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-timer prematurely expired: true
-
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: .*?, context: ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"timer prematurely expired: false",
-"lua release ngx.ctx at ref ",
-]
-
-
-
-=== TEST 32: syslog error log
---- http_config
- #error_log syslog:server=127.0.0.1:12345 error;
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.log(ngx.ERR, "Bad bad bad")
- end
- ngx.timer.at(0, f)
- ngx.sleep(0.001)
- ngx.say("ok")
- ';
- }
---- log_level: error
---- error_log_file: syslog:server=127.0.0.1:$TEST_NGINX_RAND_PORT_1
---- udp_listen: $TEST_NGINX_RAND_PORT_1
---- udp_query eval: qr/Bad bad bad/
---- udp_reply: hello
---- wait: 0.1
---- request
- GET /t
---- response_body
-ok
---- error_log
-Bad bad bad
---- skip_nginx: 4: < 1.7.1
-
-
-
-=== TEST 33: log function location when failed to run a timer
---- http_config
- lua_max_running_timers 1;
---- config
- location /t {
- content_by_lua_block {
- local function g()
- ngx.sleep(0.01)
- end
-
- local function f()
- ngx.sleep(0.01)
- end
-
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to create timer f: ", err)
- return
- end
-
- local ok, err = ngx.timer.at(0, g)
- if not ok then
- ngx.say("failed to create timer g: ", err)
- return
- end
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- wait: 0.1
---- error_log eval
-qr/\[alert\] .*? lua failed to run timer with function defined at =content_by_lua\(nginx.conf:\d+\):2: 1 lua_max_running_timers are not enough/
---- no_error_log
-[crit]
-[error]
-
-
-
-=== TEST 34: log function location when failed to run a timer (anonymous function)
---- http_config
- lua_max_running_timers 1;
---- config
- location /t {
- content_by_lua_block {
- local function f()
- ngx.sleep(0.01)
- end
-
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer f: ", err)
- return
- end
-
- local ok, err = ngx.timer.at(0, function()
- ngx.sleep(0.01)
- end)
-
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- wait: 0.1
---- error_log eval
-qr/\[alert\] .*? lua failed to run timer with function defined at =content_by_lua\(nginx.conf:\d+\):12: 1 lua_max_running_timers are not enough/
---- no_error_log
-[crit]
-[error]
-
-
-
-=== TEST 35: log function location when failed to run a timer (lua file)
---- user_files
->>> test.lua
-local _M = {}
-
-function _M.run()
- ngx.sleep(0.01)
-end
-
-return _M
---- http_config
- lua_package_path '$TEST_NGINX_HTML_DIR/?.lua;./?.lua;;';
- lua_max_running_timers 1;
---- config
- location /t {
- content_by_lua_block {
- local test = require "test"
-
- local ok, err = ngx.timer.at(0, test.run)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
-
- local ok, err = ngx.timer.at(0, test.run)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- wait: 0.1
---- no_error_log
-[crit]
-[error]
---- error_log eval
-qr/\[alert\] .*? lua failed to run timer with function defined at @.+\/test.lua:3: 1 lua_max_running_timers are not enough/
-
-
-
-=== TEST 36: log function location when failed to run a timer with args (lua file)
---- user_files
->>> test.lua
-local _M = {}
-
-function _M.run(premature, arg)
- ngx.sleep(0.01)
-end
-
-return _M
---- http_config
- lua_package_path '$TEST_NGINX_HTML_DIR/?.lua;./?.lua;;';
- lua_max_running_timers 1;
---- config
- location /t {
- content_by_lua_block {
- local test = require "test"
-
- local ok, err = ngx.timer.at(0, test.run, "arg")
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
-
- local ok, err = ngx.timer.at(0, test.run, "arg")
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- wait: 0.1
---- no_error_log
-[crit]
-[error]
---- error_log eval
-qr/\[alert\] .*? lua failed to run timer with function defined at @.+\/test.lua:3: 1 lua_max_running_timers are not enough/
diff --git a/src/deps/src/lua-nginx-module/t/107-timer-errors.t b/src/deps/src/lua-nginx-module/t/107-timer-errors.t
deleted file mode 100644
index 32016125c..000000000
--- a/src/deps/src/lua-nginx-module/t/107-timer-errors.t
+++ /dev/null
@@ -1,1422 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 7);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: accessing nginx variables
---- config
- location /t {
- content_by_lua '
- local function f()
- print("uri: ", ngx.var.uri)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 2: reading ngx.status
---- config
- location /t {
- content_by_lua '
- local function f()
- print("uri: ", ngx.status)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 3: writing ngx.status
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.status = 200
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 4: ngx.req.raw_header
---- config
- location /t {
- content_by_lua '
- local function f()
- print("raw header: ", ngx.req.raw_header())
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 5: ngx.req.get_headers
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.get_headers()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 6: ngx.req.set_header
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.set_header("Foo", 32)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 7: ngx.req.clear_header
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.clear_header("Foo")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 8: ngx.req.set_uri
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.set_uri("/foo")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 9: ngx.req.set_uri_args
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.set_uri_args("foo")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 10: ngx.redirect()
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.redirect("/foo")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 11: ngx.exec()
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.exec("/foo")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 12: ngx.say()
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.say("hello")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 13: ngx.print()
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.print("hello")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 14: ngx.flush()
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.flush()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 15: ngx.send_headers()
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.send_headers()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 16: ngx.req.get_uri_args()
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.get_uri_args()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 17: ngx.req.read_body
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.read_body()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 18: ngx.req.discard_body
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.discard_body()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 19: ngx.req.init_body
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.init_body()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 20: ngx.header
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.header.Foo = 3
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 21: ngx.on_abort
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.on_abort(f)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 22: ngx.location.capture
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.location.capture("/")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 23: ngx.location.capture_multi
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.location.capture_multi{{"/"}}
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 24: ngx.req.get_method
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.get_method()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 25: ngx.req.set_method
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.set_method(ngx.HTTP_POST)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 26: ngx.req.http_version
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.http_version()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 27: ngx.req.get_post_args
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.get_post_args()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 28: ngx.req.get_body_data
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.get_body_data()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 29: ngx.req.get_body_file
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.get_body_file()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 30: ngx.req.set_body_data
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.set_body_data("hello")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 31: ngx.req.set_body_file
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.set_body_file("hello")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 32: ngx.req.append_body
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.append_body("hello")
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 33: ngx.req.finish_body
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.req.finish_body()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 34: ngx.headers_sent
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.headers_sent()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the current context/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 35: ngx.eof
---- config
- location /t {
- content_by_lua '
- local function f()
- ngx.eof()
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 36: ngx.req.socket
---- config
- location /t {
- content_by_lua '
- local function f()
- local sock, err = ngx.req.socket()
- if not sock then
- ngx.log(ngx.ERR, "failed to get req sock: ", err)
- end
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[error\] .*? runtime error: content_by_lua\(nginx\.conf:\d+\):3: API disabled in the context of ngx\.timer/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
diff --git a/src/deps/src/lua-nginx-module/t/108-timer-safe.t b/src/deps/src/lua-nginx-module/t/108-timer-safe.t
deleted file mode 100644
index a23634cd3..000000000
--- a/src/deps/src/lua-nginx-module/t/108-timer-safe.t
+++ /dev/null
@@ -1,1398 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 8 + 60);
-
-#no_diff();
-no_long_string();
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_HTML_DIR} = $HtmlDir;
-
-worker_connections(1024);
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple at
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local function f()
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.05)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.0(?:4[4-9]|5[0-6])/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 2: simple at (sleep in the timer callback)
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
- ngx.sleep(0.2)
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0.5, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.5)
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.5
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] .*? my lua timer handler/,
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.(?:6[4-9]|7[0-6])/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 3: tcp cosocket in timer handler (short connections)
---- no_http2
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- local begin = ngx.now()
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
- local function f()
- print("my lua timer handler")
- local sock = ngx.socket.tcp()
- local port = $TEST_NGINX_SERVER_PORT
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
-
- print("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- if err == "closed" then
- break
- end
- fail("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- print("close: ", ok, " ", err)
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.02)
- ';
- }
-
- location = /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap3 eval: $::GCScript
---- stap_out2
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"connected: 1",
-"request sent: 57",
-"received: HTTP/1.1 200 OK",
-qr/received: Server: \S+/,
-"received: Content-Type: text/plain",
-"received: Content-Length: 4",
-"received: Connection: close",
-"received: foo",
-"close: 1 nil",
-]
-
-
-
-=== TEST 4: tcp cosocket in timer handler (keep-alive connections)
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- content_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.02)
- ';
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set reusable: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap3 eval: $::GCScript
---- stap_out2
-create 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 5: 0 timer
---- config
- location /t {
- content_by_lua '
- local begin = ngx.now()
- local function f()
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 1: ok
-delete thread 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-registered timer
-
---- wait: 0.02
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0(?:[^.]|\.00)/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 6: udp cosocket in timer handler
---- config
- location = /t {
- content_by_lua '
- local begin = ngx.now()
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
- local function f()
- print("my lua timer handler")
- local socket = ngx.socket
- -- local socket = require "socket"
-
- local udp = socket.udp()
-
- local port = $TEST_NGINX_MEMCACHED_PORT
- udp:settimeout(1000) -- 1 sec
-
- local ok, err = udp:setpeername("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok)
-
- local req = "\\0\\1\\0\\0\\0\\1\\0\\0flush_all\\r\\n"
- local ok, err = udp:send(req)
- if not ok then
- fail("failed to send: ", err)
- return
- end
-
- local data, err = udp:receive()
- if not data then
- fail("failed to receive data: ", err)
- return
- end
- print("received ", #data, " bytes: ", data)
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.05)
- ';
- }
-
- location = /foo {
- content_by_lua 'ngx.say("foo")';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"connected: 1",
-"received 12 bytes: \x{00}\x{01}\x{00}\x{00}\x{00}\x{01}\x{00}\x{00}OK\x{0d}\x{0a}"
-]
-
-
-
-=== TEST 7: simple at (sleep in the timer callback) - log_by_lua
---- config
- location /t {
- echo hello world;
- echo_sleep 0.07;
- log_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
- ngx.sleep(0.02)
- print("elapsed: ", ngx.now() - begin)
- end
- local ok, err = ngx.timer.at(0.05, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-hello world
-
---- wait: 0.15
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-qr/\[lua\] log_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.0(?:6[4-9]|7[0-9]|8[0-6])/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 8: tcp cosocket in timer handler (keep-alive connections) - log_by_lua
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- echo hello;
- echo_sleep 0.01;
- log_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- ';
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set reusable: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-hello
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 9: tcp cosocket in timer handler (keep-alive connections) - header_filter_by_lua
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- echo hello;
- echo_sleep 0.01;
- header_filter_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- ';
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set reusable: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap3
-global count = 0
-F(ngx_http_lua_header_filter) {
- if (count++ == 10) {
- println("header filter")
- print_ubacktrace()
- }
-}
-
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-hello
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 10: tcp cosocket in timer handler (keep-alive connections) - body_filter_by_lua
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- echo_sleep 0.01;
- echo hello;
- body_filter_by_lua '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- ';
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set reusable: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap3
-global count = 0
-F(ngx_http_lua_header_filter) {
- if (count++ == 10) {
- println("header filter")
- print_ubacktrace()
- }
-}
-
---- stap eval: $::GCScript
---- stap_out_like chop
-create 2 in 1
-create 3 in 1
-(?:terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-|terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2)$
-
---- response_body
-hello
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 11: tcp cosocket in timer handler (keep-alive connections) - set_by_lua
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
-
---- config
- location = /t {
- set_by_lua $a '
- local begin = ngx.now()
- local function f()
- print("my lua timer handler")
-
- local test = require "test"
- local port = $TEST_NGINX_MEMCACHED_PORT
- test.go(port)
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to set timer: ", err)
- return
- end
- print("registered timer")
- return 32
- ';
- echo $a;
- echo_sleep 0.01;
- }
-
---- user_files
->>> test.lua
-module("test", package.seeall)
-
-local function fail(...)
- ngx.log(ngx.ERR, ...)
-end
-
-function go(port)
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- fail("failed to connect: ", err)
- return
- end
-
- print("connected: ", ok, ", reused: ", sock:getreusedtimes())
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- fail("failed to send request: ", err)
- return
- end
- print("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- print("received: ", line)
-
- else
- fail("failed to receive a line: ", err, " [", part, "]")
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- fail("failed to set reusable: ", err)
- end
-end
-
---- request
-GET /t
---- stap2 eval: $::StapScript
---- stap3
-global count = 0
-F(ngx_http_lua_header_filter) {
- if (count++ == 10) {
- println("header filter")
- print_ubacktrace()
- }
-}
-
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-
---- response_body
-32
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"registered timer",
-qr/\[lua\] .*? my lua timer handler/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-qr/go\(\): connected: 1, reused: \d+/,
-"go(): request sent: 11",
-"go(): received: OK",
-]
-
-
-
-=== TEST 12: coroutine API
---- config
- location /t {
- content_by_lua '
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
- local function f()
- function f()
- local cnt = 0
- for i = 1, 20 do
- print("cnt = ", cnt)
- cy()
- cnt = cnt + 1
- end
- end
-
- local c = cc(f)
- for i=1,3 do
- cr(c)
- print("after resume, i = ", i)
- end
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.01)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 2
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"cnt = 0",
-"after resume, i = 1",
-"cnt = 1",
-"after resume, i = 2",
-"cnt = 2",
-"after resume, i = 3",
-]
-
-
-
-=== TEST 13: ngx.thread API
---- config
- location /t {
- content_by_lua '
- local function fail (...)
- ngx.log(ngx.ERR, ...)
- end
- local function handle()
- local function f()
- print("hello in thread")
- return "done"
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- fail("failed to spawn thread: ", err)
- return
- end
-
- print("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- fail("failed to run thread: ", res)
- return
- end
-
- print("wait result: ", res)
- end
- local ok, err = ngx.timer.at(0.01, handle)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.02)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-terminate 3: ok
-delete thread 3
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"hello in thread",
-"thread created: zombie",
-"wait result: done",
-]
-
-
-
-=== TEST 14: shared dict
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location /t {
- content_by_lua '
- local function f()
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- dogs:set("bah", 10502)
- local val = dogs:get("foo")
- print("get foo: ", val, " ", type(val))
- val = dogs:get("bah")
- print("get bah: ", val, " ", type(val))
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.02)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"get foo: 32 number",
-"get bah: 10502 number",
-]
-
-
-
-=== TEST 15: ngx.exit(0)
---- config
- location /t {
- content_by_lua '
- local function f()
- local function g()
- print("BEFORE ngx.exit")
- ngx.exit(0)
- end
- g()
- print("CANNOT REACH HERE")
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.01)
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[alert]
-[crit]
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"BEFORE ngx.exit",
-]
---- no_error_log
-CANNOT REACH HERE
-API disabled
-
-
-
-=== TEST 16: ngx.exit(403)
---- config
- location /t {
- content_by_lua '
- local function f()
- local function g()
- print("BEFORE ngx.exit")
- ngx.exit(403)
- end
- g()
- print("CANNOT REACH HERE")
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.01)
- ';
- }
---- request
-GET /t
---- stap2
-F(ngx_http_lua_timer_handler) {
- println("lua timer handler")
-}
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-CANNOT REACH HERE
-API disabled
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"BEFORE ngx.exit",
-]
-
-
-
-=== TEST 17: exit in user thread (entry thread is still pending on ngx.sleep)
---- config
- location /t {
- content_by_lua '
- local function handle()
- local function f()
- print("hello in thread")
- ngx.sleep(0.1)
- ngx.exit(0)
- end
-
- print("BEFORE thread spawn")
- ngx.thread.spawn(f)
- print("AFTER thread spawn")
- ngx.sleep(1)
- print("entry thread END")
- end
- local ok, err = ngx.timer.at(0.01, handle)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.12)
- ';
- }
---- request
-GET /t
---- stap eval
-<<'_EOC_' . $::GCScript;
-
-global timers
-
-F(ngx_http_free_request) {
- println("free request")
-}
-
-M(timer-add) {
- if ($arg2 == 1000 || $arg2 == 100) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
- }
-}
-
-M(timer-del) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("delete timer %d\n", tm)
- delete timers[$arg1]
- }
- /*
- if (tm == 1000) {
- print_ubacktrace()
- }
- */
-}
-
-M(timer-expire) {
- tm = timers[$arg1]
- if (tm == 1000 || tm == 100) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
- }
-}
-
-F(ngx_http_lua_sleep_cleanup) {
- println("lua sleep cleanup")
-}
-_EOC_
-
---- stap_out
-create 2 in 1
-create 3 in 2
-spawn user thread 3 in 2
-add timer 100
-add timer 1000
-expire timer 100
-terminate 3: ok
-delete thread 3
-lua sleep cleanup
-delete timer 1000
-delete thread 2
-terminate 1: ok
-delete thread 1
-free request
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-API disabled
-entry thread END
-
---- error_log eval
-[
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"BEFORE thread spawn",
-"hello in thread",
-"AFTER thread spawn",
-]
-
-
-
-=== TEST 18: chained timers (non-zero delay)
---- config
- location /t {
- content_by_lua '
- local s = ""
-
- local function fail(...)
- ngx.log(ngx.ERR, ...)
- end
-
- local function g()
- s = s .. "[g]"
- print("trace: ", s)
- end
-
- local function f()
- local ok, err = ngx.timer.at(0.01, g)
- if not ok then
- fail("failed to set timer: ", err)
- return
- end
- s = s .. "[f]"
- end
- local ok, err = ngx.timer.at(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- s = "[m]"
- ngx.sleep(0.03)
- ';
- }
---- request
-GET /t
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-create 3 in 2
-terminate 2: ok
-delete thread 2
-terminate 3: ok
-delete thread 3
-terminate 1: ok
-delete thread 1
-
---- response_body
-registered timer
-
---- wait: 0.1
---- no_error_log
-[error]
-[alert]
-[crit]
-
---- error_log
-lua ngx.timer expired
-http lua close fake http connection
-trace: [m][f][g]
diff --git a/src/deps/src/lua-nginx-module/t/109-timer-hup.t b/src/deps/src/lua-nginx-module/t/109-timer-hup.t
deleted file mode 100644
index 551dd486c..000000000
--- a/src/deps/src/lua-nginx-module/t/109-timer-hup.t
+++ /dev/null
@@ -1,506 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_CHECK_LEAK}) {
- $SkipReason = "unavailable for the hup tests";
-
- } elsif (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- #os.execute("kill -HUP " .. pid)
- $SkipReason = "send HUP relaod signal by self make two workers with same id";
-
- } else {
- $ENV{TEST_NGINX_USE_HUP} = 1;
- undef $ENV{TEST_NGINX_USE_STAP};
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * 81;
-
-#no_diff();
-no_long_string();
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_HTML_DIR} = $HtmlDir;
-
-worker_connections(1024);
-run_tests();
-
-__DATA__
-
-=== TEST 1: single timer
---- config
- location /t {
- content_by_lua '
- local f, err = io.open("$TEST_NGINX_SERVER_ROOT/logs/nginx.pid", "r")
- if not f then
- ngx.say("failed to open nginx.pid: ", err)
- return
- end
-
- local pid = f:read()
- -- ngx.say("master pid: [", pid, "]")
-
- f:close()
-
- local i = 0
- local function f(premature)
- i = i + 1
- print("timer prematurely expired: ", premature)
- print("in callback: hello, ", i)
- end
- local ok, err = ngx.timer.at(3, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- os.execute("kill -HUP " .. pid)
- ';
- }
---- request
-GET /t
-
---- response_body
-registered timer
-
---- wait: 0.3
---- no_error_log
-[error]
-[alert]
-[crit]
-in callback: hello, 2
-timer prematurely expired: false
-
---- error_log
-lua abort pending timers
-lua ngx.timer expired
-http lua close fake http connection
-in callback: hello, 1
-timer prematurely expired: true
-
-
-
-=== TEST 2: multiple timers
---- config
- location /t {
- content_by_lua '
- local f, err = io.open("$TEST_NGINX_SERVER_ROOT/logs/nginx.pid", "r")
- if not f then
- ngx.say("failed to open nginx.pid: ", err)
- return
- end
-
- local pid = f:read()
- -- ngx.say("master pid: [", pid, "]")
-
- f:close()
-
- local i = 0
- local function f(premature)
- i = i + 1
- print("timer prematurely expired: ", premature)
- print("in callback: hello, ", i, "!")
- end
- for i = 1, 10 do
- local ok, err = ngx.timer.at(3, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- end
- ngx.say("registered timers")
- os.execute("kill -HUP " .. pid)
- ';
- }
---- request
-GET /t
-
---- response_body
-registered timers
-
---- wait: 0.3
---- no_error_log
-[error]
-[alert]
-[crit]
-in callback: hello, 11!
-timer prematurely expired: false
-
---- error_log
-lua abort pending timers
-lua ngx.timer expired
-http lua close fake http connection
-in callback: hello, 1!
-in callback: hello, 2!
-in callback: hello, 3!
-in callback: hello, 4!
-in callback: hello, 5!
-in callback: hello, 6!
-in callback: hello, 7!
-in callback: hello, 8!
-in callback: hello, 9!
-in callback: hello, 10!
-timer prematurely expired: true
-
-
-
-=== TEST 3: trying to add new timer after HUP reload
---- config
- location /t {
- content_by_lua '
- local f, err = io.open("$TEST_NGINX_SERVER_ROOT/logs/nginx.pid", "r")
- if not f then
- ngx.say("failed to open nginx.pid: ", err)
- return
- end
-
- local pid = f:read()
- -- ngx.say("master pid: [", pid, "]")
-
- f:close()
-
- local function f(premature)
- print("timer prematurely expired: ", premature)
- local ok, err = ngx.timer.at(3, f)
- if not ok then
- print("failed to register a new timer after reload: ", err)
- else
- print("registered a new timer after reload")
- end
- end
- local ok, err = ngx.timer.at(3, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- os.execute("kill -HUP " .. pid)
- ';
- }
---- request
-GET /t
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-in callback: hello, 2
-timer prematurely expired: false
-
---- error_log
-lua abort pending timers
-lua ngx.timer expired
-http lua close fake http connection
-timer prematurely expired: true
-failed to register a new timer after reload: process exiting, context: ngx.timer
-
-
-
-=== TEST 4: trying to add new timer after HUP reload
---- config
- location /t {
- content_by_lua '
- local f, err = io.open("$TEST_NGINX_SERVER_ROOT/logs/nginx.pid", "r")
- if not f then
- ngx.say("failed to open nginx.pid: ", err)
- return
- end
-
- local pid = f:read()
- -- ngx.say("master pid: [", pid, "]")
-
- f:close()
-
- local function g(premature)
- print("g: timer prematurely expired: ", premature)
- print("g: exiting=", ngx.worker.exiting())
- end
-
- local function f(premature)
- print("f: timer prematurely expired: ", premature)
- print("f: exiting=", ngx.worker.exiting())
- local ok, err = ngx.timer.at(0, g)
- if not ok then
- print("f: failed to register a new timer after reload: ", err)
- else
- print("f: registered a new timer after reload")
- end
- end
- local ok, err = ngx.timer.at(3, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- os.execute("kill -HUP " .. pid)
- ';
- }
---- request
-GET /t
-
---- response_body
-registered timer
-
---- wait: 0.2
---- no_error_log
-[error]
-[alert]
-[crit]
-in callback: hello, 2
-failed to register a new timer after reload
-
---- error_log
-lua abort pending timers
-lua ngx.timer expired
-http lua close fake http connection
-f: timer prematurely expired: true
-f: registered a new timer after reload
-f: exiting=true
-g: timer prematurely expired: false
-g: exiting=true
-
-
-
-=== TEST 5: HUP reload should abort pending timers
---- config
- location /t {
- content_by_lua '
- local f, err = io.open("$TEST_NGINX_SERVER_ROOT/logs/nginx.pid", "r")
- if not f then
- ngx.say("failed to open nginx.pid: ", err)
- return
- end
-
- local pid = f:read()
- -- ngx.say("master pid: [", pid, "]")
-
- f:close()
-
- local function f(premature)
- print("f: timer prematurely expired: ", premature)
- print("f: exiting=", ngx.worker.exiting())
- end
-
- for i = 1, 100 do
- local ok, err = ngx.timer.at(3 + i, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- end
- ngx.say("ok")
- os.execute("kill -HUP " .. pid)
- ';
- }
---- request
-GET /t
-
---- response_body
-ok
-
---- wait: 0.5
---- no_error_log
-[error]
-[alert]
-[crit]
-in callback: hello, 2
-failed to register a new timer after reload
-
---- grep_error_log eval: qr/lua found \d+ pending timers/
---- grep_error_log_out
-lua found 100 pending timers
-
-
-
-=== TEST 6: HUP reload should abort pending timers (coroutine + cosocket)
---- http_config
- lua_shared_dict test_dict 1m;
-
- server {
- listen $TEST_NGINX_RAND_PORT_1;
- location = /foo {
- echo 'foo';
- }
- }
-
---- config
- location /t {
- content_by_lua '
- local http_req = {"GET /foo HTTP/1.1", "Host: localhost:1234", "", ""}
- http_req = table.concat(http_req, "\\r\\n")
-
- -- Connect the socket
- local sock = ngx.socket.tcp()
- local ok,err = sock:connect("127.0.0.1", $TEST_NGINX_RAND_PORT_1)
- if not ok then
- ngx.log(ngx.ERR, err)
- end
-
- -- Send the request
- local ok,err = sock:send(http_req)
-
- -- Get Headers
- repeat
- local line, err = sock:receive("*l")
- until not line or string.find(line, "^%s*$")
-
- local function foo()
- repeat
- -- Get and read chunk
- local line, err = sock:receive("*l")
- local len = tonumber(line)
- if len > 0 then
- local chunk, err = sock:receive(len)
- coroutine.yield(chunk)
- sock:receive(2)
- else
- -- Read last newline
- sock:receive(2)
- end
- until len == 0
- end
-
- local co = coroutine.create(foo)
- repeat
- local chunk = select(2,coroutine.resume(co))
- until chunk == nil
-
- -- Breaks the timer
- sock:setkeepalive()
- ngx.say("ok")
- ';
-
- log_by_lua '
- local background_thread
- background_thread = function(premature)
- ngx.log(ngx.DEBUG, premature)
- if premature then
- ngx.shared["test_dict"]:delete("background_flag")
- return
- end
- local ok, err = ngx.timer.at(1, background_thread)
-
- local f, err = io.open("$TEST_NGINX_SERVER_ROOT/logs/nginx.pid", "r")
- if not f then
- ngx.say("failed to open nginx.pid: ", err)
- return
- end
- local pid = f:read()
- -- ngx.say("master pid: [", pid, "]")
- f:close()
-
- os.execute("kill -HUP " .. pid)
- end
- local dict = ngx.shared["test_dict"]
-
- if dict:get("background_flag") == nil then
- local ok, err = ngx.timer.at(0, background_thread)
- if ok then
- dict:set("test_dict", 1)
- end
- end
- ';
- }
---- request
-GET /t
-
---- response_body
-ok
-
---- wait: 0.3
---- no_error_log
-[error]
-[alert]
-[crit]
-in callback: hello, 2
-failed to register a new timer after reload
-
---- grep_error_log eval: qr/lua found \d+ pending timers/
---- grep_error_log_out
-lua found 1 pending timers
-
-
-
-=== TEST 7: HUP reload should abort pending timers (fuzz test)
---- http_config
- lua_max_pending_timers 8192;
-
---- config
- location /t {
- content_by_lua '
- local job = function(premature, kill)
- if premature then
- return
- end
-
- if kill then
- local f, err = io.open("$TEST_NGINX_SERVER_ROOT/logs/nginx.pid", "r")
- if not f then
- ngx.log(ngx.ERR, "failed to open nginx.pid: ", err)
- return
- end
- local pid = f:read()
- -- ngx.say("master pid: [", pid, "]")
- f:close()
-
- os.execute("kill -HUP " .. pid)
- end
- end
-
- math.randomseed(ngx.time())
- local rand = math.random
- local newtimer = ngx.timer.at
- for i = 1, 8191 do
- local delay = rand(4096)
- local ok, err = newtimer(delay, job, false)
- if not ok then
- ngx.say("failed to create timer at ", delay, ": ", err)
- return
- end
- end
- local ok, err = newtimer(0, job, true)
- if not ok then
- ngx.say("failed to create the killer timer: ", err)
- return
- end
- ngx.say("ok")
- ';
- }
---- request
-GET /t
-
---- response_body
-ok
-
---- wait: 0.3
---- no_error_log
-[error]
-[alert]
-
---- grep_error_log eval: qr/lua found \d+ pending timers/
---- grep_error_log_out
-lua found 8191 pending timers
---- timeout: 20
diff --git a/src/deps/src/lua-nginx-module/t/110-etag.t b/src/deps/src/lua-nginx-module/t/110-etag.t
deleted file mode 100644
index 0a94d3d4f..000000000
--- a/src/deps/src/lua-nginx-module/t/110-etag.t
+++ /dev/null
@@ -1,83 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: If-None-Match true
---- config
- location /t {
- content_by_lua '
- ngx.header["ETag"] = "123456789"
- ngx.header.last_modified = "Thu, 10 May 2012 07:50:59 GMT"
- ngx.say(ngx.var.http_if_none_match)
- ';
- }
---- request
-GET /t
---- more_headers
-If-None-Match: 123456789
-If-Modified-Since: Thu, 10 May 2012 07:50:59 GMT
---- response_body
---- error_code: 304
---- no_error_log
-[error]
-
-
-
-=== TEST 2: If-None-Match false
---- config
- location /t {
- etag on;
- content_by_lua '
- ngx.header["ETag"] = "123456789"
- ngx.header.last_modified = "Thu, 10 May 2012 07:50:59 GMT"
- ngx.say(ngx.var.http_if_none_match)
- ';
- }
---- request
-GET /t
---- more_headers
-If-None-Match: 123456780
-If-Modified-Since: Thu, 10 May 2012 07:50:59 GMT
---- response_body
-123456780
---- no_error_log
-[error]
---- skip_nginx: 3: < 1.3.3
-
-
-
-=== TEST 3: Etag clear
---- config
- location /t {
- etag on;
- content_by_lua '
- ngx.header["ETag"] = "123456789"
- ngx.header.last_modified = "Thu, 10 May 2012 07:50:59 GMT"
- ngx.header["ETag"] = nil
- ngx.say(ngx.var.http_if_none_match)
- ';
- }
---- request
-GET /t
---- more_headers
-If-None-Match: 123456789
-If-Modified-Since: Thu, 10 May 2012 07:50:59 GMT
---- response_body
-123456789
---- no_error_log
-[error]
---- skip_nginx: 3: < 1.3.3
diff --git a/src/deps/src/lua-nginx-module/t/111-req-header-ua.t b/src/deps/src/lua-nginx-module/t/111-req-header-ua.t
deleted file mode 100644
index 9e501e3c0..000000000
--- a/src/deps/src/lua-nginx-module/t/111-req-header-ua.t
+++ /dev/null
@@ -1,675 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (4 * blocks());
-
-#no_diff();
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: clear Opera user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", nil)
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- more_headers
-User-Agent: Opera/9.80 (Macintosh; Intel Mac OS X 10.7.4; U; en) Presto/2.10.229 Version/11.62
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: opera: %d\n", $r->headers_in->opera)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: opera: %d\n", $r->headers_in->opera)
-}
-
---- stap_out
-rewrite: opera: 1
-content: opera: 0
-
---- response_body
-User-Agent:
---- no_error_log
-[error]
-
-
-
-=== TEST 2: clear MSIE 4 user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", nil)
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- more_headers
-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT 5.0)
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
---- stap_out
-rewrite: msie=1 msie6=1
-content: msie=0 msie6=0
-
---- response_body
-User-Agent:
---- no_error_log
-[error]
-
-
-
-=== TEST 3: set custom MSIE 4 user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "Mozilla/4.0 (compatible; MSIE 4.01; Windows NT 5.0)")
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
---- stap_out
-rewrite: msie=0 msie6=0
-content: msie=1 msie6=1
-
---- response_body
-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT 5.0)
---- no_error_log
-[error]
-
-
-
-=== TEST 4: clear MSIE 5 user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", nil)
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- more_headers
-User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95; MSIECrawler)
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
---- stap_out
-rewrite: msie=1 msie6=1
-content: msie=0 msie6=0
-
---- response_body
-User-Agent:
---- no_error_log
-[error]
-
-
-
-=== TEST 5: set custom MSIE 5 user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.01; Windows 95; MSIECrawler)")
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
---- stap_out
-rewrite: msie=0 msie6=0
-content: msie=1 msie6=1
-
---- response_body
-User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95; MSIECrawler)
---- no_error_log
-[error]
-
-
-
-=== TEST 6: clear MSIE 6 (without SV1) user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", nil)
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- more_headers
-User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Google Wireless Transcoder;)
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
---- stap_out
-rewrite: msie=1 msie6=1
-content: msie=0 msie6=0
-
---- response_body
-User-Agent:
---- no_error_log
-[error]
-
-
-
-=== TEST 7: set custom MSIE 6 (without SV1) user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Google Wireless Transcoder;)")
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
---- stap_out
-rewrite: msie=0 msie6=0
-content: msie=1 msie6=1
-
---- response_body
-User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Google Wireless Transcoder;)
---- no_error_log
-[error]
-
-
-
-=== TEST 8: clear MSIE 6 (with SV1) user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", nil)
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- more_headers
-User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1)
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
---- stap_out
-rewrite: msie=1 msie6=0
-content: msie=0 msie6=0
-
---- response_body
-User-Agent:
---- no_error_log
-[error]
-
-
-
-=== TEST 9: set custom MSIE 6 (with SV1) user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1)")
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
---- stap_out
-rewrite: msie=0 msie6=0
-content: msie=1 msie6=0
-
---- response_body
-User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1)
---- no_error_log
-[error]
-
-
-
-=== TEST 10: set custom MSIE 7 user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; winfx; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Zune 2.0)")
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: msie=%d msie6=%d\n",
- $r->headers_in->msie,
- $r->headers_in->msie6)
-}
-
---- stap_out
-rewrite: msie=0 msie6=0
-content: msie=1 msie6=0
-
---- response_body
-User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; winfx; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Zune 2.0)
---- no_error_log
-[error]
-
-
-
-=== TEST 11: clear Gecko user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", nil)
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- more_headers
-User-Agent: Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: gecko: %d\n", $r->headers_in->gecko)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: gecko: %d\n", $r->headers_in->gecko)
-}
-
---- stap_out
-rewrite: gecko: 1
-content: gecko: 0
-
---- response_body
-User-Agent:
---- no_error_log
-[error]
-
-
-
-=== TEST 12: set custom Gecko user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0")
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: gecko: %d\n", $r->headers_in->gecko)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: gecko: %d\n", $r->headers_in->gecko)
-}
-
---- stap_out
-rewrite: gecko: 0
-content: gecko: 1
-
---- response_body
-User-Agent: Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0
---- no_error_log
-[error]
-
-
-
-=== TEST 13: clear Chrome user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", nil)
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- more_headers
-User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.151 Safari/535.19
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: chrome: %d\n", $r->headers_in->chrome)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: chrome: %d\n", $r->headers_in->chrome)
-}
-
---- stap_out
-rewrite: chrome: 1
-content: chrome: 0
-
---- response_body
-User-Agent:
---- no_error_log
-[error]
-
-
-
-=== TEST 14: set custom Chrome user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.151 Safari/535.19")
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: chrome: %d\n", $r->headers_in->chrome)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: chrome: %d\n", $r->headers_in->chrome)
-}
-
---- stap_out
-rewrite: chrome: 0
-content: chrome: 1
-
---- response_body
-User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.151 Safari/535.19
---- no_error_log
-[error]
-
-
-
-=== TEST 15: clear Safari (Mac OS X) user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", nil)
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- more_headers
-User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.8
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: safari: %d\n", $r->headers_in->safari)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: safari: %d\n", $r->headers_in->safari)
-}
-
---- stap_out
-rewrite: safari: 1
-content: safari: 0
-
---- response_body
-User-Agent:
---- no_error_log
-[error]
-
-
-
-=== TEST 16: set custom Safari user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.8")
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: safari: %d\n", $r->headers_in->safari)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: safari: %d\n", $r->headers_in->safari)
-}
-
---- stap_out
-rewrite: safari: 0
-content: safari: 1
-
---- response_body
-User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.8
---- no_error_log
-[error]
-
-
-
-=== TEST 17: clear Konqueror user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", nil)
-
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- more_headers
-User-Agent: Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.10 (like Gecko) (Kubuntu)
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: konqueror: %d\n", $r->headers_in->konqueror)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: konqueror: %d\n", $r->headers_in->konqueror)
-}
-
---- stap_out
-rewrite: konqueror: 1
-content: konqueror: 0
-
---- response_body
-User-Agent:
---- no_error_log
-[error]
-
-
-
-=== TEST 18: set custom Konqueror user-agent
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("User-Agent", "Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.10 (like Gecko) (Kubuntu)")
- ';
- echo "User-Agent: $http_user_agent";
- }
-
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: konqueror: %d\n", $r->headers_in->konqueror)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: konqueror: %d\n", $r->headers_in->konqueror)
-}
-
---- stap_out
-rewrite: konqueror: 0
-content: konqueror: 1
-
---- response_body
-User-Agent: Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.10 (like Gecko) (Kubuntu)
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/112-req-header-conn.t b/src/deps/src/lua-nginx-module/t/112-req-header-conn.t
deleted file mode 100644
index 51bc8a431..000000000
--- a/src/deps/src/lua-nginx-module/t/112-req-header-conn.t
+++ /dev/null
@@ -1,148 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (4 * blocks());
-
-#no_diff();
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: clear the Connection req header
---- config
- location /req-header {
- rewrite_by_lua '
- ngx.req.set_header("Connection", nil);
- ';
-
- echo "connection: $http_connection";
- }
---- request
-GET /req-header
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: conn type: %d\n", $r->headers_in->connection_type)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: conn type: %d\n", $r->headers_in->connection_type)
-}
-
---- stap_out
-rewrite: conn type: 1
-content: conn type: 0
-
---- response_body
-connection:
---- no_error_log
-[error]
-
-
-
-=== TEST 2: set custom Connection req header (close)
---- config
- location /req-header {
- rewrite_by_lua '
- ngx.req.set_header("Connection", "CLOSE");
- ';
-
- echo "connection: $http_connection";
- }
---- request
-GET /req-header
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: conn type: %d\n", $r->headers_in->connection_type)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: conn type: %d\n", $r->headers_in->connection_type)
-}
-
---- stap_out
-rewrite: conn type: 1
-content: conn type: 1
-
---- response_body
-connection: CLOSE
---- no_error_log
-[error]
-
-
-
-=== TEST 3: set custom Connection req header (keep-alive)
---- config
- location /req-header {
- rewrite_by_lua '
- ngx.req.set_header("Connection", "keep-alive");
- ';
-
- echo "connection: $http_connection";
- }
---- request
-GET /req-header
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: conn type: %d\n", $r->headers_in->connection_type)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: conn type: %d\n", $r->headers_in->connection_type)
-}
-
---- stap_out
-rewrite: conn type: 1
-content: conn type: 2
-
---- response_body
-connection: keep-alive
---- no_error_log
-[error]
-
-
-
-=== TEST 4: set custom Connection req header (bad)
---- config
- location /req-header {
- rewrite_by_lua '
- ngx.req.set_header("Connection", "bad");
- ';
-
- echo "connection: $http_connection";
- }
---- request
-GET /req-header
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: conn type: %d\n", $r->headers_in->connection_type)
-}
-
-
-F(ngx_http_core_content_phase) {
- printf("content: conn type: %d\n", $r->headers_in->connection_type)
-}
-
---- stap_out
-rewrite: conn type: 1
-content: conn type: 0
-
---- response_body
-connection: bad
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/113-req-header-cookie.t b/src/deps/src/lua-nginx-module/t/113-req-header-cookie.t
deleted file mode 100644
index 944549cd7..000000000
--- a/src/deps/src/lua-nginx-module/t/113-req-header-cookie.t
+++ /dev/null
@@ -1,272 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (3 * blocks() + 6);
-
-#no_diff();
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: clear cookie (with existing cookies)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("Cookie", nil)
- ';
- echo "Cookie foo: $cookie_foo";
- echo "Cookie baz: $cookie_baz";
- echo "Cookie: $http_cookie";
- }
---- request
-GET /t
---- more_headers
-Cookie: foo=bar
-Cookie: baz=blah
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
---- stap_out
-rewrite: cookies: 2
-content: cookies: 0
-
---- response_body
-Cookie foo:
-Cookie baz:
-Cookie:
-
---- no_error_log
-[error]
-
-
-
-=== TEST 2: clear cookie (without existing cookies)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("Cookie", nil)
- ';
- echo "Cookie foo: $cookie_foo";
- echo "Cookie baz: $cookie_baz";
- echo "Cookie: $http_cookie";
- }
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
---- stap_out
-rewrite: cookies: 0
-content: cookies: 0
-
---- response_body
-Cookie foo:
-Cookie baz:
-Cookie:
-
---- no_error_log
-[error]
-
-
-
-=== TEST 3: set one custom cookie (with existing cookies)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("Cookie", "boo=123")
- ';
- echo "Cookie foo: $cookie_foo";
- echo "Cookie baz: $cookie_baz";
- echo "Cookie boo: $cookie_boo";
- echo "Cookie: $http_cookie";
- }
---- request
-GET /t
---- more_headers
-Cookie: foo=bar
-Cookie: baz=blah
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
---- stap_out
-rewrite: cookies: 2
-content: cookies: 1
-
---- response_body
-Cookie foo:
-Cookie baz:
-Cookie boo: 123
-Cookie: boo=123
-
---- no_error_log
-[error]
-
-
-
-=== TEST 4: set one custom cookie (without existing cookies)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("Cookie", "boo=123")
- ';
- echo "Cookie foo: $cookie_foo";
- echo "Cookie baz: $cookie_baz";
- echo "Cookie boo: $cookie_boo";
- echo "Cookie: $http_cookie";
- }
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
---- stap_out
-rewrite: cookies: 0
-content: cookies: 1
-
---- response_body
-Cookie foo:
-Cookie baz:
-Cookie boo: 123
-Cookie: boo=123
-
---- no_error_log
-[error]
-
-
-
-=== TEST 5: set multiple custom cookies (with existing cookies)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("Cookie", {"boo=123","foo=78"})
- ';
- echo "Cookie foo: $cookie_foo";
- echo "Cookie baz: $cookie_baz";
- echo "Cookie boo: $cookie_boo";
- echo "Cookie: $http_cookie";
- }
---- request
-GET /t
---- more_headers
-Cookie: foo=bar
-Cookie: baz=blah
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
---- stap_out
-rewrite: cookies: 2
-content: cookies: 2
-
---- response_body
-Cookie foo: 78
-Cookie baz:
-Cookie boo: 123
-Cookie: boo=123; foo=78
-
---- no_error_log
-[error]
-
-
-
-=== TEST 6: set multiple custom cookies (without existing cookies)
---- config
- location /t {
- rewrite_by_lua '
- ngx.req.set_header("Cookie", {"boo=123", "foo=bar"})
- ';
- echo "Cookie foo: $cookie_foo";
- echo "Cookie baz: $cookie_baz";
- echo "Cookie boo: $cookie_boo";
- echo "Cookie: $http_cookie";
- }
---- request
-GET /t
-
---- stap
-F(ngx_http_lua_rewrite_by_chunk) {
- printf("rewrite: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
-F(ngx_http_core_content_phase) {
- printf("content: cookies: %d\n", $r->headers_in->cookies->nelts)
-}
-
---- stap_out
-rewrite: cookies: 0
-content: cookies: 2
-
---- response_body
-Cookie foo: bar
-Cookie baz:
-Cookie boo: 123
-Cookie: boo=123; foo=bar
-
---- no_error_log
-[error]
-
-
-
-=== TEST 7: set multiple custom cookies with unsafe values (with '\n' and 'r')
---- config
- location /t {
- rewrite_by_lua_block {
- ngx.req.set_header("Cookie", {"boo=123\nfoo", "foo=bar\rbar"})
- }
- echo "Cookie foo: $cookie_foo";
- echo "Cookie baz: $cookie_baz";
- echo "Cookie boo: $cookie_boo";
- echo "Cookie: $http_cookie";
- }
---- request
-GET /t
---- response_body
-Cookie foo: bar%0Dbar
-Cookie baz:
-Cookie boo: 123%0Afoo
-Cookie: boo=123%0Afoo; foo=bar%0Dbar
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/114-config.t b/src/deps/src/lua-nginx-module/t/114-config.t
deleted file mode 100644
index 46d98de2f..000000000
--- a/src/deps/src/lua-nginx-module/t/114-config.t
+++ /dev/null
@@ -1,48 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: ngx.config.debug
---- config
- location /t {
- content_by_lua '
- ngx.say("debug: ", ngx.config.debug)
- ';
- }
---- request
-GET /t
---- response_body_like chop
-^debug: (?:true|false)$
---- no_error_log
-[error]
-
-
-
-=== TEST 2: ngx.config.subsystem
---- config
- location /t {
- content_by_lua '
- ngx.say("subsystem: ", ngx.config.subsystem)
- ';
- }
---- request
-GET /t
---- response_body
-subsystem: http
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/115-quote-sql-str.t b/src/deps/src/lua-nginx-module/t/115-quote-sql-str.t
deleted file mode 100644
index 66553b134..000000000
--- a/src/deps/src/lua-nginx-module/t/115-quote-sql-str.t
+++ /dev/null
@@ -1,76 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#log_level("warn");
-no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: \0
---- config
- location = /set {
- content_by_lua '
- ngx.say(ngx.quote_sql_str("a\\0b\\0"))
- ';
- }
---- request
-GET /set
---- response_body
-'a\0b\0'
---- no_error_log
-[error]
-
-
-
-=== TEST 2: \t
---- config
- location = /set {
- content_by_lua '
- ngx.say(ngx.quote_sql_str("a\\tb\\t"))
- ';
- }
---- request
-GET /set
---- response_body
-'a\tb\t'
---- no_error_log
-[error]
-
-
-
-=== TEST 3: \b
---- config
- location = /set {
- content_by_lua '
- ngx.say(ngx.quote_sql_str("a\\bb\\b"))
- ';
- }
---- request
-GET /set
---- response_body
-'a\bb\b'
---- no_error_log
-[error]
-
-
-
-=== TEST 4: \Z
---- config
- location = /set {
- content_by_lua '
- ngx.say(ngx.quote_sql_str("a\\026b\\026"))
- ';
- }
---- request
-GET /set
---- response_body
-'a\Zb\Z'
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/116-raw-req-socket.t b/src/deps/src/lua-nginx-module/t/116-raw-req-socket.t
deleted file mode 100644
index 6704a9208..000000000
--- a/src/deps/src/lua-nginx-module/t/116-raw-req-socket.t
+++ /dev/null
@@ -1,979 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "http3 does not support ngx.req.socket(true)";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-repeat_each(2);
-
-plan tests => repeat_each() * 43;
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-#log_level 'warn';
-log_level 'debug';
-
-#no_long_string();
-#no_diff();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- server_tokens off;
- location = /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET /mysock HTTP/1.1\\r\\nUpgrade: mysock\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\nhello"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local data, err, partial = reader()
- if not data then
- ngx.say("no response header found")
- return
- end
-
- local msg, err = sock:receive()
- if not msg then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("msg: ", msg)
-
- ok, err = sock:close()
- if not ok then
- ngx.say("failed to close socket: ", err)
- return
- end
- ';
- }
-
- location = /mysock {
- content_by_lua '
- ngx.status = 101
- ngx.send_headers()
- ngx.flush(true)
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
-
- local data, err = sock:receive(5)
- if not data then
- ngx.log(ngx.ERR, "server: failed to receive: ", err)
- return
- end
-
- local bytes, err = sock:send("1: received: " .. data .. "\\n")
- if not bytes then
- ngx.log(ngx.ERR, "server: failed to send: ", err)
- return
- end
- ';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-msg: 1: received: hello
---- grep_error_log: lua socket tcp_nodelay
---- grep_error_log_out
-lua socket tcp_nodelay
-lua socket tcp_nodelay
---- no_error_log
-[error]
-
-
-
-=== TEST 2: header not sent yet
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- ngx.status = 101
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
- local ok, err = sock:send("HTTP/1.1 200 OK\\r\\nContent-Length: 5\\r\\n\\r\\nhello")
- if not ok then
- ngx.log(ngx.ERR, "failed to send: ", err)
- return
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.0\r
-Host: localhost\r
-Content-Length: 5\r
-\r
-hello"
---- response_headers
-Content-Length: 5
---- response_body chop
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 3: http 1.0 buffering
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- ngx.say("hello")
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return ngx.exit(500)
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.0\r
-Host: localhost\r
-Upgrade: mysocket\r
-\r
-hello"
---- stap2
-F(ngx_http_header_filter) {
- println("header filter")
-}
-F(ngx_http_lua_req_socket) {
- println("lua req socket")
-}
---- ignore_response
---- error_log
-server: failed to get raw req socket: http 1.0 buffering
-
-
-
-=== TEST 4: multiple raw req sockets
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- ngx.say("hello")
- ngx.flush(true)
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
- local sock2, err = ngx.req.socket(true)
- if not sock2 then
- ngx.log(ngx.ERR, "server: failed to get raw req socket2: ", err)
- return
- end
-
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Upgrade: mysocket\r
-\r
-hello"
---- stap2
-F(ngx_http_header_filter) {
- println("header filter")
-}
-F(ngx_http_lua_req_socket) {
- println("lua req socket")
-}
---- ignore_response
---- error_log
-server: failed to get raw req socket2: duplicate call
-
-
-
-=== TEST 5: ngx.say after ngx.req.socket(true)
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- ngx.send_headers()
- ngx.flush(true)
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
- local ok, err = ngx.say("ok")
- if not ok then
- ngx.log(ngx.ERR, "failed to say: ", err)
- return
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Upgrade: mysocket\r
-\r
-hello"
---- ignore_response
---- error_log
-failed to say: raw request socket acquired
-
-
-
-=== TEST 6: ngx.print after ngx.req.socket(true)
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- ngx.send_headers()
- ngx.flush(true)
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
- local ok, err = ngx.print("ok")
- if not ok then
- ngx.log(ngx.ERR, "failed to print: ", err)
- return
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Upgrade: mysocket\r
-\r
-hello"
---- ignore_response
---- error_log
-failed to print: raw request socket acquired
-
-
-
-=== TEST 7: ngx.eof after ngx.req.socket(true)
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- ngx.send_headers()
- ngx.flush(true)
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
- local ok, err = ngx.eof()
- if not ok then
- ngx.log(ngx.ERR, "failed to eof: ", err)
- return
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Upgrade: mysocket\r
-\r
-hello"
---- ignore_response
---- error_log
-failed to eof: raw request socket acquired
-
-
-
-=== TEST 8: ngx.flush after ngx.req.socket(true)
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- ngx.send_headers()
- ngx.flush(true)
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
- local ok, err = ngx.flush()
- if not ok then
- ngx.log(ngx.ERR, "failed to flush: ", err)
- return
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Upgrade: mysocket\r
-\r
-hello"
---- ignore_response
---- error_log
-failed to flush: raw request socket acquired
-
-
-
-=== TEST 9: receive timeout
---- config
- server_tokens off;
- postpone_output 1;
- location = /t {
- content_by_lua '
- ngx.send_headers()
- ngx.req.read_body()
- ngx.flush(true)
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
-
- sock:settimeout(100)
-
- local data, err, partial = sock:receive(10)
- if not data then
- ngx.log(ngx.ERR, "server: 1: failed to receive: ", err, ", received: ", partial)
- end
-
- data, err, partial = sock:receive(10)
- if not data then
- ngx.log(ngx.ERR, "server: 2: failed to receive: ", err, ", received: ", partial)
- end
-
- ngx.exit(444)
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Upgrade: mysocket\r
-Connection: close\r
-\r
-ab"
---- ignore_response
---- wait: 0.1
---- error_log
-lua tcp socket read timed out
-server: 1: failed to receive: timeout, received: ab,
-server: 2: failed to receive: timeout, received: ,
---- no_error_log
-[alert]
-
-
-
-=== TEST 10: on_abort called during ngx.sleep()
---- config
- server_tokens off;
- lua_check_client_abort on;
- location = /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET /mysock HTTP/1.1\\r\\nUpgrade: mysock\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\nhello"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local data, err, partial = reader()
- if not data then
- ngx.say("no response header found")
- return
- end
-
- local msg, err = sock:receive()
- if not msg then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("msg: ", msg)
-
- ngx.sleep(0.1)
-
- ok, err = sock:close()
- if not ok then
- ngx.say("failed to close socket: ", err)
- return
- end
- ';
- }
-
- location = /mysock {
- content_by_lua '
- ngx.status = 101
- ngx.send_headers()
- ngx.flush(true)
-
- local ok, err = ngx.on_abort(function (premature) ngx.log(ngx.WARN, "mysock handler aborted") end)
- if not ok then
- ngx.log(ngx.ERR, "failed to set on_abort handler: ", err)
- return
- end
-
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
-
- local data, err = sock:receive(5)
- if not data then
- ngx.log(ngx.ERR, "server: failed to receive: ", err)
- return
- end
-
- local bytes, err = sock:send("1: received: " .. data .. "\\n")
- if not bytes then
- ngx.log(ngx.ERR, "server: failed to send: ", err)
- return
- end
-
- ngx.sleep(1)
- ';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-msg: 1: received: hello
---- error_log
-mysock handler aborted
---- no_error_log
-[error]
---- wait: 1.1
-
-
-
-=== TEST 11: on_abort called during sock:receive()
---- config
- server_tokens off;
- lua_check_client_abort on;
- location = /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET /mysock HTTP/1.1\\r\\nUpgrade: mysock\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\nhello"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local data, err, partial = reader()
- if not data then
- ngx.say("no response header found")
- return
- end
-
- local msg, err = sock:receive()
- if not msg then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("msg: ", msg)
-
- ngx.sleep(0.1)
-
- ok, err = sock:close()
- if not ok then
- ngx.say("failed to close socket: ", err)
- return
- end
- ';
- }
-
- location = /mysock {
- content_by_lua '
- ngx.status = 101
- ngx.send_headers()
- ngx.flush(true)
-
- local ok, err = ngx.on_abort(function (premature) ngx.log(ngx.WARN, "mysock handler aborted") end)
- if not ok then
- ngx.log(ngx.ERR, "failed to set on_abort handler: ", err)
- return
- end
-
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
-
- local data, err = sock:receive(5)
- if not data then
- ngx.log(ngx.ERR, "server: failed to receive: ", err)
- return
- end
-
- local bytes, err = sock:send("1: received: " .. data .. "\\n")
- if not bytes then
- ngx.log(ngx.ERR, "server: failed to send: ", err)
- return
- end
-
- local data, err = sock:receive()
- if not data then
- ngx.log(ngx.WARN, "failed to receive a line: ", err)
- return
- end
- ';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-msg: 1: received: hello
---- error_log
-failed to receive a line: client aborted
---- no_error_log
-[error]
---- wait: 0.1
-
-
-
-=== TEST 12: receiveuntil
---- config
- server_tokens off;
- location = /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET /mysock HTTP/1.1\\r\\nUpgrade: mysock\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\nhello"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- local bytes, err = sock:send(", ")
- if not bytes then
- ngx.say("failed to send packet 1: ", err)
- return
- end
-
- local bytes, err = sock:send("world")
- if not bytes then
- ngx.say("failed to send packet 2: ", err)
- return
- end
-
- local reader = sock:receiveuntil("\\r\\n\\r\\n")
- local data, err, partial = reader()
- if not data then
- ngx.say("no response header found")
- return
- end
-
- local msg, err = sock:receive()
- if not msg then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("msg: ", msg)
-
- ok, err = sock:close()
- if not ok then
- ngx.say("failed to close socket: ", err)
- return
- end
- ';
- }
-
- location = /mysock {
- content_by_lua '
- ngx.status = 101
- ngx.send_headers()
- ngx.flush(true)
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
-
- local reader = sock:receiveuntil("rld")
- local data, err = reader()
- if not data then
- ngx.log(ngx.ERR, "server: failed to receive: ", err)
- return
- end
-
- local bytes, err = sock:send("1: received: " .. data .. "\\n")
- if not bytes then
- ngx.log(ngx.ERR, "server: failed to send: ", err)
- return
- end
- ';
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-msg: 1: received: hello, wo
---- no_error_log
-[error]
-
-
-
-=== TEST 13: request body not read yet
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
-
- local data, err = sock:receive(5)
- if not data then
- ngx.log(ngx.ERR, "failed to receive: ", err)
- return
- end
-
- local ok, err = sock:send("HTTP/1.1 200 OK\\r\\nContent-Length: 5\\r\\n\\r\\n" .. data)
- if not ok then
- ngx.log(ngx.ERR, "failed to send: ", err)
- return
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.0\r
-Host: localhost\r
-Content-Length: 5\r
-\r
-hello"
---- response_headers
-Content-Length: 5
---- response_body chop
-hello
---- no_error_log
-[error]
-
-
-
-=== TEST 14: pending request body reading
---- config
- server_tokens off;
- location = /t {
- content_by_lua '
- ngx.thread.spawn(function ()
- ngx.req.read_body()
- end)
-
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.WARN, "server: failed to get raw req socket: ", err)
- return ngx.exit(444)
- end
-
- local data, err = sock:receive(5)
- if not data then
- ngx.log(ngx.ERR, "failed to receive: ", err)
- return
- end
-
- local ok, err = sock:send("HTTP/1.1 200 OK\\r\\nContent-Length: 5\\r\\n\\r\\n" .. data)
- if not ok then
- ngx.log(ngx.ERR, "failed to send: ", err)
- return
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.0\r
-Host: localhost\r
-Content-Length: 5\r
-\r
-hell"
---- ignore_response
---- no_error_log
-[error]
-[alert]
---- error_log
-server: failed to get raw req socket: pending request body reading in some other thread
-
-
-
-=== TEST 15: read chunked request body with raw req socket
---- config
- location = /t {
- content_by_lua '
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "failed to new: ", err)
- return
- end
- local function err(...)
- ngx.log(ngx.ERR, ...)
- return ngx.exit(400)
- end
- local num = tonumber
- local MAX_CHUNKS = 1000
- local eof = false
- local chunks = {}
- for i = 1, MAX_CHUNKS do
- local line, err = sock:receive()
- if not line then
- err("failed to receive chunk size: ", err)
- end
-
- local size = num(line, 16)
- if not size then
- err("bad chunk size: ", line)
- end
-
- if size == 0 then -- last chunk
- -- receive the last line
- line, err = sock:receive()
- if not line then
- err("failed to receive last chunk: ", err)
- end
-
- if line ~= "" then
- err("bad last chunk: ", line)
- end
-
- eof = true
- break
- end
-
- local chunk, err = sock:receive(size)
- if not chunk then
- err("failed to receive chunk of size ", size, ": ", err)
- end
-
- local data, err = sock:receive(2)
- if not data then
- err("failed to receive chunk terminator: ", err)
- end
-
- if data ~= "\\r\\n" then
- err("bad chunk terminator: ", data)
- end
-
- chunks[i] = chunk
- end
-
- if not eof then
- err("too many chunks (more than ", MAX_CHUNKS, ")")
- end
-
- local concat = table.concat
- local body = concat{"got ", #chunks, " chunks.\\nrequest body: "}
- .. concat(chunks) .. "\\n"
- local ok, err = sock:send("HTTP/1.1 200 OK\\r\\nConnection: close\\r\\nContent-Length: "
- .. #body .. "\\r\\n\\r\\n" .. body)
- if not ok then
- err("failed to send response: ", err)
- end
- ';
- }
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Transfer-Encoding: chunked\r
-Connection: close\r
-\r
-5\r
-hey, \r
-b\r
-hello world\r
-0\r
-\r
-"
---- response_body
-got 2 chunks.
-request body: hey, hello world
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 16: receiveany
---- config
- server_tokens off;
- location = /t {
- #set $port 5000;
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET /mysock HTTP/1.1\r\nUpgrade: mysock\r\nHost: localhost\r\nConnection: close\r\n\r\nhello"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- -- Will return to I/O loop, causing receiveany() in /mysock location to be called
- ngx.sleep(1)
-
- local bytes, err = sock:send(", world")
- if not bytes then
- ngx.say("failed to send packet 1: ", err)
- return
- end
-
- local reader = sock:receiveuntil("\r\n\r\n")
- local data, err, partial = reader()
- if not data then
- ngx.say("no response header found")
- return
- end
-
- local msg, err = sock:receive()
- if not msg then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ngx.say("msg: ", msg)
-
- ok, err = sock:close()
- if not ok then
- ngx.say("failed to close socket: ", err)
- return
- end
- }
- }
-
- location = /mysock {
- content_by_lua_block {
- ngx.status = 101
- ngx.send_headers()
- ngx.flush(true)
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
-
- local data, err = sock:receiveany(1024)
- if not data then
- ngx.log(ngx.ERR, "server: failed to receive: ", err)
- return
- end
-
- local bytes, err = sock:send("1: received: " .. data .. "\n")
- if not bytes then
- ngx.log(ngx.ERR, "server: failed to send: ", err)
- return
- end
- }
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-msg: 1: received: hello
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/117-raw-req-socket-timeout.t b/src/deps/src/lua-nginx-module/t/117-raw-req-socket-timeout.t
deleted file mode 100644
index 07abadcc6..000000000
--- a/src/deps/src/lua-nginx-module/t/117-raw-req-socket-timeout.t
+++ /dev/null
@@ -1,116 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-BEGIN {
- if (!defined $ENV{LD_PRELOAD}) {
- $ENV{LD_PRELOAD} = '';
- }
-
- if ($ENV{LD_PRELOAD} !~ /\bmockeagain\.so\b/) {
- $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}";
- }
-
- if ($ENV{MOCKEAGAIN} eq 'r') {
- $ENV{MOCKEAGAIN} = 'rw';
-
- } else {
- $ENV{MOCKEAGAIN} = 'w';
- }
-
- $ENV{TEST_NGINX_EVENT_TYPE} = 'poll';
- $ENV{MOCKEAGAIN_WRITE_TIMEOUT_PATTERN} = 'hello, world';
- $ENV{TEST_NGINX_POSTPONE_OUTPUT} = 1;
-}
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: pending response header data
---- config
- server_tokens off;
- postpone_output 1;
- location = /t {
- content_by_lua '
- ngx.send_headers()
- ngx.req.read_body()
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Upgrade: mysocket\r
-Connection: close\r
-\r
-"
---- stap2
-F(ngx_http_header_filter) {
- println("header filter")
-}
-F(ngx_http_lua_req_socket) {
- println("lua req socket")
-}
---- response_body
---- error_log
-server: failed to get raw req socket: pending data to write
-
-
-
-=== TEST 2: send timeout
---- config
- server_tokens off;
- postpone_output 1;
- location = /t {
- content_by_lua '
- ngx.send_headers()
- ngx.req.read_body()
- ngx.flush(true)
- local sock, err = ngx.req.socket(true)
- if not sock then
- ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
- return
- end
- sock:settimeout(100)
- local ok, err = sock:send("hello, world!")
- if not ok then
- ngx.log(ngx.ERR, "server: failed to send: ", err)
- end
- ngx.exit(444)
- ';
- }
-
---- raw_request eval
-"GET /t HTTP/1.1\r
-Host: localhost\r
-Upgrade: mysocket\r
-Connection: close\r
-\r
-"
---- ignore_response
---- error_log
-lua tcp socket write timed out
-server: failed to send: timeout
---- no_error_log
-[alert]
diff --git a/src/deps/src/lua-nginx-module/t/118-use-default-type.t b/src/deps/src/lua-nginx-module/t/118-use-default-type.t
deleted file mode 100644
index 6008d6556..000000000
--- a/src/deps/src/lua-nginx-module/t/118-use-default-type.t
+++ /dev/null
@@ -1,140 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-#log_level 'warn';
-log_level 'debug';
-
-#no_long_string();
-#no_diff();
-run_tests();
-
-__DATA__
-
-=== TEST 1: lua_use_default_type default on
---- config
- location /lua {
- default_type text/plain;
- content_by_lua '
- ngx.say("hello")
- ';
- }
---- request
-GET /lua
---- response_body
-hello
---- response_headers
-Content-Type: text/plain
---- no_error_log
-[error]
-
-
-
-=== TEST 2: lua_use_default_type explicitly on
---- config
- lua_use_default_type on;
- location /lua {
- default_type text/plain;
- content_by_lua '
- ngx.say("hello")
- ';
- }
---- request
-GET /lua
---- response_body
-hello
---- response_headers
-Content-Type: text/plain
---- no_error_log
-[error]
-
-
-
-=== TEST 3: lua_use_default_type off
---- config
- lua_use_default_type off;
- location /lua {
- default_type text/plain;
- content_by_lua '
- ngx.say("hello")
- ';
- }
---- request
-GET /lua
---- response_body
-hello
---- response_headers
-!Content-Type
---- no_error_log
-[error]
-
-
-
-=== TEST 4: overriding lua_use_default_type off
---- config
- lua_use_default_type off;
- location /lua {
- lua_use_default_type on;
- default_type text/plain;
- content_by_lua '
- ngx.say("hello")
- ';
- }
---- request
-GET /lua
---- response_body
-hello
---- response_headers
-Content-Type: text/plain
---- no_error_log
-[error]
-
-
-
-=== TEST 5: overriding lua_use_default_type on
---- config
- lua_use_default_type on;
- location /lua {
- lua_use_default_type off;
- default_type text/plain;
- content_by_lua '
- ngx.say("hello")
- ';
- }
---- request
-GET /lua
---- response_body
-hello
---- response_headers
-!Content-Type
---- no_error_log
-[error]
-
-
-
-=== TEST 6: lua_use_default_type on does not set content type on 304
---- config
- lua_use_default_type on;
- location /lua {
- default_type text/plain;
- content_by_lua '
- ngx.status = ngx.HTTP_NOT_MODIFIED
- ';
- }
---- request
-GET /lua
---- response_body
---- response_headers
-!Content-Type
---- no_error_log
-[error]
---- error_code: 304
diff --git a/src/deps/src/lua-nginx-module/t/119-config-prefix.t b/src/deps/src/lua-nginx-module/t/119-config-prefix.t
deleted file mode 100644
index 3f793206e..000000000
--- a/src/deps/src/lua-nginx-module/t/119-config-prefix.t
+++ /dev/null
@@ -1,32 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: content_by_lua
---- config
- location /lua {
- content_by_lua '
- ngx.say("prefix: ", ngx.config.prefix())
- ';
- }
---- request
-GET /lua
---- response_body_like chop
-^prefix: \/\S+$
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/120-re-find.t b/src/deps/src/lua-nginx-module/t/120-re-find.t
deleted file mode 100644
index 43ccece1a..000000000
--- a/src/deps/src/lua-nginx-module/t/120-re-find.t
+++ /dev/null
@@ -1,964 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 1);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "([0-9]+)", "jo")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- end
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 8
-to: 11
-matched: 1234
---- no_error_log
-[error]
-
-
-
-=== TEST 2: empty matched string
---- config
- location /re {
- content_by_lua '
- local s = "hello, world"
- local from, to, err = ngx.re.find(s, "[0-9]*")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- end
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 1
-to: 0
-matched:
---- no_error_log
-[error]
-
-
-
-=== TEST 3: multiple captures (with o)
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "([a-z]+).*?([0-9]{2})[0-9]+", "o")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 1
-to: 11
-matched: hello, 1234
---- no_error_log
-[error]
-
-
-
-=== TEST 4: not matched
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "foo")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched.
---- no_error_log
-[error]
-
-
-
-=== TEST 5: case sensitive by default
---- config
- location /re {
- content_by_lua '
- local from = ngx.re.find("hello, 1234", "HELLO")
- if from then
- ngx.say(from)
- else
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched.
---- no_error_log
-[error]
-
-
-
-=== TEST 6: case insensitive
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "HELLO", "i")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 1
-to: 5
-matched: hello
---- no_error_log
-[error]
-
-
-
-=== TEST 7: UTF-8 mode
---- config
- location /re {
- content_by_lua '
- local s = "helloç« äº¦æ˜¥"
- local from, to, err = ngx.re.find(s, "HELLO.{2}", "iu")
- if not from then
- ngx.say("FAIL: ", err)
- return
- end
-
- ngx.say(string.sub(s, from, to))
- ';
- }
---- request
- GET /re
---- response_body_like chop
-^(?:FAIL: bad argument \#2 to '\?' \(pcre_compile\(\) failed: this version of PCRE is not compiled with PCRE_UTF8 support in "HELLO\.\{2\}" at "HELLO\.\{2\}"\)|helloç« äº¦)$
---- no_error_log
-[error]
-
-
-
-=== TEST 8: multi-line mode (^ at line head)
---- config
- location /re {
- content_by_lua '
- local s = "hello\\nworld"
- local from, to, err = ngx.re.find(s, "^world", "m")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 7
-to: 11
-matched: world
---- no_error_log
-[error]
-
-
-
-=== TEST 9: multi-line mode (. does not match \n)
---- config
- location /re {
- content_by_lua '
- local s = "hello\\nworld"
- local from, to, err = ngx.re.find(s, ".*", "m")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 1
-to: 5
-matched: hello
---- no_error_log
-[error]
-
-
-
-=== TEST 10: single-line mode (^ as normal)
---- config
- location /re {
- content_by_lua '
- local s = "hello\\nworld"
- local from, to, err = ngx.re.find(s, "^world", "s")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched.
---- no_error_log
-[error]
-
-
-
-=== TEST 11: single-line mode (dot all)
---- config
- location /re {
- content_by_lua '
- local s = "hello\\nworld"
- local from, to, err = ngx.re.find(s, ".*", "s")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 1
-to: 11
-matched: hello
-world
---- no_error_log
-[error]
-
-
-
-=== TEST 12: extended mode (ignore whitespaces)
---- config
- location /re {
- content_by_lua '
- local s = "hello\\nworld"
- local from, to, err = ngx.re.find(s, "\\\\w \\\\w", "x")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 1
-to: 2
-matched: he
---- no_error_log
-[error]
-
-
-
-=== TEST 13: bad pattern
---- config
- location /re {
- content_by_lua '
- local s = "hello\\nworld"
- local from, to, err = ngx.re.find(s, "(abc")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- if err then
- ngx.say("error: ", err)
-
- else
- ngx.say("not matched.")
- end
- end
- ';
- }
---- request
- GET /re
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
-:
-"error: pcre_compile() failed: missing ) in \"(abc\"\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 14: bad option
---- config
- location /re {
- content_by_lua '
- local s = "hello\\nworld"
- local from, to, err = ngx.re.find(s, ".*", "H")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- if err then
- ngx.say("error: ", err)
- return
- end
-
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log
-unknown flag "H"
-
-
-
-=== TEST 15: anchored match (failed)
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "([0-9]+)", "a")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- if err then
- ngx.say("error: ", err)
- return
- end
-
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched.
---- no_error_log
-[error]
-
-
-
-=== TEST 16: anchored match (succeeded)
---- config
- location /re {
- content_by_lua '
- local s = "1234, hello"
- local from, to, err = ngx.re.find(s, "([0-9]+)", "a")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- if err then
- ngx.say("error: ", err)
- return
- end
-
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 1
-to: 4
-matched: 1234
---- no_error_log
-[error]
-
-
-
-=== TEST 17: match with ctx but no pos
---- config
- location /re {
- content_by_lua '
- local ctx = {}
- local from, to = ngx.re.find("1234, hello", "([0-9]+)", "", ctx)
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("pos: ", ctx.pos)
- else
- ngx.say("not matched!")
- ngx.say("pos: ", ctx.pos)
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 1
-to: 4
-pos: 5
---- no_error_log
-[error]
-
-
-
-=== TEST 18: match with ctx and a pos
---- config
- location /re {
- content_by_lua '
- local ctx = { pos = 3 }
- local from, to, err = ngx.re.find("1234, hello", "([0-9]+)", "", ctx)
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("pos: ", ctx.pos)
- else
- ngx.say("not matched!")
- ngx.say("pos: ", ctx.pos)
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 3
-to: 4
-pos: 5
---- no_error_log
-[error]
-
-
-
-=== TEST 19: named subpatterns w/ extraction
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "(?[a-z]+), [0-9]+")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- if err then
- ngx.say("error: ", err)
- return
- end
-
- ngx.say("not matched.")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 1
-to: 11
-matched: hello, 1234
---- no_error_log
-[error]
-
-
-
-=== TEST 20: bad UTF-8
---- config
- location = /t {
- content_by_lua '
- local target = "ä½ å¥½"
- local regex = "ä½ å¥½"
-
- local from, to, err = ngx.re.find(string.sub(target, 1, 4), regex, "u")
-
- if err then
- ngx.say("error: ", err)
- return
- end
-
- if m then
- ngx.say("matched: ", from)
- else
- ngx.say("not matched")
- end
- ';
- }
---- request
-GET /t
---- response_body eval
-$Test::Nginx::Util::PcreVersion == 2 ?
-"error: pcre_exec\(\) failed: -4\n"
-:
-"error: pcre_exec\(\) failed: -10\n"
-
---- no_error_log
-[error]
-
-
-
-=== TEST 21: UTF-8 mode without UTF-8 sequence checks
---- config
- location /re {
- content_by_lua '
- local s = "ä½ å¥½"
- local from, to, err = ngx.re.find(s, ".", "U")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
-
- else
- ngx.say("not matched.")
- end
- ';
- }
---- stap
-# TODO: PCRE2 use different option values from PCRE
-probe process("$LIBPCRE_PATH").function("pcre_compile") {
- printf("compile opts: %x\n", $options)
-}
-
-probe process("$LIBPCRE_PATH").function("pcre_exec") {
- printf("exec opts: %x\n", $options)
-}
-
---- stap_out
-compile opts: 800
-exec opts: 2000
-
---- request
- GET /re
---- response_body
-from: 1
-to: 3
-matched: ä½
---- no_error_log
-[error]
-
-
-
-=== TEST 22: just hit match limit
---- http_config
- lua_regex_match_limit 5000;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local from, to, err = ngx.re.find(s, re, "o")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if not from then
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("failed to match.")
- return
-end
-
---- request
- GET /re
---- response_body eval
-# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
-# but PCRE2 replaces this with pcre2_set_match_limit interface,
-# which has different effects.
-$Test::Nginx::Util::PcreVersion == 2 ?
-"failed to match.\n"
-:
-"error: pcre_exec() failed: -8\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 23: just not hit match limit
---- http_config
- lua_regex_match_limit 5100;
---- config
- location /re {
- content_by_lua_file html/a.lua;
- }
-
---- user_files
->>> a.lua
-local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
-
-local s = string.rep([[ABCDEFG]], 10)
-
-local start = ngx.now()
-
-local from, to, err = ngx.re.find(s, re, "o")
-
---[[
-ngx.update_time()
-local elapsed = ngx.now() - start
-ngx.say(elapsed, " sec elapsed.")
-]]
-
-if not from then
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("failed to match")
- return
-end
-
---- request
- GET /re
---- response_body
-failed to match
---- no_error_log
-[error]
-
-
-
-=== TEST 24: specify the group (1)
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "([0-9])([0-9]+)", "jo", nil, 1)
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- end
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 8
-to: 8
-matched: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 25: specify the group (0)
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "([0-9])([0-9]+)", "jo", nil, 0)
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- end
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 8
-to: 11
-matched: 1234
---- no_error_log
-[error]
-
-
-
-=== TEST 26: specify the group (2)
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "([0-9])([0-9]+)", "jo", nil, 2)
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- end
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 9
-to: 11
-matched: 234
---- no_error_log
-[error]
-
-
-
-=== TEST 27: specify the group (3)
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "([0-9])([0-9]+)", "jo", nil, 3)
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: nth out of bound
---- no_error_log
-[error]
-
-
-
-=== TEST 28: specify the group (4)
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "([0-9])([0-9]+)", "jo", nil, 4)
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-error: nth out of bound
---- no_error_log
-[error]
-
-
-
-=== TEST 29: nil submatch (2nd)
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "([0-9])|(hello world)", "jo", nil, 2)
- if from or to then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched!
---- no_error_log
-[error]
-
-
-
-=== TEST 30: nil submatch (1st)
---- config
- location /re {
- content_by_lua '
- local s = "hello, 1234"
- local from, to, err = ngx.re.find(s, "(hello world)|([0-9])", "jo", nil, 1)
- if from or to then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("not matched!")
- end
- ';
- }
---- request
- GET /re
---- response_body
-not matched!
---- no_error_log
-[error]
-
-
-
-=== TEST 31: match with ctx and a pos (anchored by \G)
---- config
- location /re {
- content_by_lua '
- local ctx = { pos = 3 }
- local from, to, err = ngx.re.find("1234, hello", [[(\G[0-9]+)]], "", ctx)
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("pos: ", ctx.pos)
- else
- ngx.say("not matched!")
- ngx.say("pos: ", ctx.pos)
- end
- ';
- }
---- request
- GET /re
---- response_body
-from: 3
-to: 4
-pos: 5
---- no_error_log
-[error]
-
-
-
-=== TEST 32: ignore match limit in DFA mode
---- http_config
- lua_regex_match_limit 1;
---- config
- location /re {
- content_by_lua_block {
- local s = "This is no more"
- local from, to, err = ngx.re.find(s, "<.*>", "d")
- if from then
- ngx.say("from: ", from)
- ngx.say("to: ", to)
- ngx.say("matched: ", string.sub(s, from, to))
- else
- if err then
- ngx.say("error: ", err)
- return
- end
- ngx.say("not matched!")
- end
- }
- }
---- request
- GET /re
---- response_body
-from: 9
-to: 56
-matched:
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/121-version.t b/src/deps/src/lua-nginx-module/t/121-version.t
deleted file mode 100644
index 9000eb370..000000000
--- a/src/deps/src/lua-nginx-module/t/121-version.t
+++ /dev/null
@@ -1,48 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: nginx version
---- config
- location /lua {
- content_by_lua '
- ngx.say("version: ", ngx.config.nginx_version)
- ';
- }
---- request
-GET /lua
---- response_body_like chop
-^version: \d+$
---- no_error_log
-[error]
-
-
-
-=== TEST 2: ngx_lua_version
---- config
- location /lua {
- content_by_lua '
- ngx.say("version: ", ngx.config.ngx_lua_version)
- ';
- }
---- request
-GET /lua
---- response_body_like chop
-^version: \d+$
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/122-worker-2.t b/src/deps/src/lua-nginx-module/t/122-worker-2.t
deleted file mode 100644
index c4ad2aea2..000000000
--- a/src/deps/src/lua-nginx-module/t/122-worker-2.t
+++ /dev/null
@@ -1,49 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-master_on();
-workers(4);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: get worker pids with multiple worker
---- config
- location /lua {
- content_by_lua_block {
- local pids, err = ngx.worker.pids()
- if err ~= nil then
- return
- end
- local pid = ngx.worker.pid()
- ngx.say("worker pid: ", pid)
- local count = ngx.worker.count()
- ngx.say("worker count: ", count)
- ngx.say("worker pids count: ", #pids)
- for i = 1, count do
- if pids[i] == pid then
- ngx.say("worker pid is correct.")
- return
- end
- end
- }
- }
---- request
-GET /lua
---- response_body_like
-worker pid: \d+
-worker count: 4
-worker pids count: 4
-worker pid is correct\.
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/122-worker-3.t b/src/deps/src/lua-nginx-module/t/122-worker-3.t
deleted file mode 100644
index 050486e53..000000000
--- a/src/deps/src/lua-nginx-module/t/122-worker-3.t
+++ /dev/null
@@ -1,58 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_CHECK_LEAK}) {
- $SkipReason = "unavailable for the hup tests";
-
- } else {
- $ENV{TEST_NGINX_USE_HUP} = 1;
- undef $ENV{TEST_NGINX_USE_STAP};
- }
-}
-
-use Test::Nginx::Socket::Lua 'no_plan';
-
-#worker_connections(1014);
-master_on();
-workers(4);
-#log_level('warn');
-
-repeat_each(2);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: get worker pids with multiple worker
---- config
- location /lua {
- content_by_lua_block {
- local pids, err = ngx.worker.pids()
- if err ~= nil then
- return
- end
- local pid = ngx.worker.pid()
- ngx.say("worker pid: ", pid)
- local count = ngx.worker.count()
- ngx.say("worker count: ", count)
- ngx.say("worker pids count: ", #pids)
- for i = 1, count do
- if pids[i] == pid then
- ngx.say("worker pid is correct.")
- return
- end
- end
- }
- }
---- request
-GET /lua
---- response_body_like
-worker pid: \d+
-worker count: 4
-worker pids count: 4
-worker pid is correct\.
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/122-worker.t b/src/deps/src/lua-nginx-module/t/122-worker.t
deleted file mode 100644
index 244c3142d..000000000
--- a/src/deps/src/lua-nginx-module/t/122-worker.t
+++ /dev/null
@@ -1,111 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 - 4);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: content_by_lua + ngx.worker.exiting
---- config
- location /lua {
- content_by_lua '
- ngx.say("worker exiting: ", ngx.worker.exiting())
- ';
- }
---- request
-GET /lua
---- response_body
-worker exiting: false
---- no_error_log
-[error]
-
-
-
-=== TEST 2: content_by_lua + ngx.worker.pid
---- config
- location /lua {
- content_by_lua '
- local pid = ngx.worker.pid()
- ngx.say("worker pid: ", pid)
- if pid ~= tonumber(ngx.var.pid) then
- ngx.say("worker pid is wrong.")
- else
- ngx.say("worker pid is correct.")
- end
- ';
- }
---- request
-GET /lua
---- response_body_like
-worker pid: \d+
-worker pid is correct\.
---- no_error_log
-[error]
-
-
-
-=== TEST 3: init_worker_by_lua + ngx.worker.pid
---- http_config
- init_worker_by_lua '
- my_pid = ngx.worker.pid()
- ';
---- config
- location /lua {
- content_by_lua '
- ngx.say("worker pid: ", my_pid)
- if my_pid ~= tonumber(ngx.var.pid) then
- ngx.say("worker pid is wrong.")
- else
- ngx.say("worker pid is correct.")
- end
- ';
- }
---- request
-GET /lua
---- response_body_like
-worker pid: \d+
-worker pid is correct\.
---- no_error_log
-[error]
-
-
-
-=== TEST 4: content_by_lua + ngx.worker.pids
---- config
- location /lua {
- content_by_lua '
- local pids = ngx.worker.pids()
- local pid = ngx.worker.pid()
- ngx.say("worker pid: ", pid)
- local count = ngx.worker.count()
- if count ~= #pids then
- ngx.say("worker pids is wrong.")
- end
- for i = 1, count do
- if pids[i] == pid then
- ngx.say("worker pid is correct.")
- return
- end
- end
- ngx.say("worker pid is wrong.")
- ';
- }
---- request
-GET /lua
---- response_body_like
-worker pid: \d+
-worker pid is correct\.
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/123-lua-path.t b/src/deps/src/lua-nginx-module/t/123-lua-path.t
deleted file mode 100644
index e30132f3c..000000000
--- a/src/deps/src/lua-nginx-module/t/123-lua-path.t
+++ /dev/null
@@ -1,70 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3 + 1);
-
-$ENV{LUA_PATH} = "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;/foo/bar/baz";
-$ENV{LUA_CPATH} = "/baz/bar/foo";
-#no_diff();
-#no_long_string();
-master_on();
-no_shuffle();
-check_accum_error_log();
-run_tests();
-
-__DATA__
-
-=== TEST 1: LUA_PATH & LUA_CPATH env (code cache on)
---- main_config
-env LUA_PATH;
-env LUA_CPATH;
-
---- config
- location /lua {
- content_by_lua '
- ngx.say(package.path)
- ngx.say(package.cpath)
- ';
- }
---- request
-GET /lua
---- response_body_like
-(?:\.\.\/lua-resty-core\/lib\/\?\.lua;\.\.\/lua-resty-lrucache\/lib\/\?\.lua;){1,2}\/foo\/bar\/baz
-/baz/bar/foo
-
---- no_error_log
-[error]
-
-
-
-=== TEST 2: LUA_PATH & LUA_CPATH env (code cache off)
---- main_config
-env LUA_PATH;
-env LUA_CPATH;
-
---- config
- lua_code_cache off;
- location /lua {
- content_by_lua '
- ngx.say(package.path)
- ngx.say(package.cpath)
- ';
- }
---- request
-GET /lua
---- response_body_like
-(?:\.\.\/lua-resty-core\/lib\/\?\.lua;\.\.\/lua-resty-lrucache\/lib\/\?\.lua;){1,2}\/foo\/bar\/baz
-/baz/bar/foo
-
---- no_error_log
-[error]
---- error_log eval
-qr/\[alert\] .*? lua_code_cache is off/
diff --git a/src/deps/src/lua-nginx-module/t/124-init-worker.t b/src/deps/src/lua-nginx-module/t/124-init-worker.t
deleted file mode 100644
index c68d74bb1..000000000
--- a/src/deps/src/lua-nginx-module/t/124-init-worker.t
+++ /dev/null
@@ -1,1033 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 4 + 4);
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-our $ServerRoot = server_root();
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: set a global lua var
---- http_config
- init_worker_by_lua '
- foo = ngx.md5("hello world")
- ';
---- config
- location /t {
- content_by_lua '
- ngx.say("foo = ", foo)
- ';
- }
---- request
- GET /t
---- response_body
-foo = 5eb63bbbe01eeed093cb22bb8f5acdc3
---- no_error_log
-[error]
-
-
-
-=== TEST 2: no ngx.say()
---- http_config
- init_worker_by_lua '
- ngx.say("hello")
- ';
---- config
- location /t {
- content_by_lua '
- ngx.say("foo = ", foo)
- ';
- }
---- request
- GET /t
---- response_body
-foo = nil
---- error_log
-API disabled in the context of init_worker_by_lua*
-
-
-
-=== TEST 3: timer.at
---- http_config
- init_worker_by_lua '
- _G.my_counter = 0
- local function warn(...)
- ngx.log(ngx.WARN, ...)
- end
- local function handler(premature)
- warn("timer expired (premature: ", premature, "; counter: ",
- _G.my_counter, ")")
- _G.my_counter = _G.my_counter + 1
- end
- local ok, err = ngx.timer.at(0, handler)
- if not ok then
- ngx.log(ngx.ERR, "failed to create timer: ", err)
- end
- warn("created timer: ", ok)
- ';
---- config
- location /t {
- content_by_lua '
- -- ngx.sleep(0.001)
- ngx.say("my_counter = ", _G.my_counter)
- _G.my_counter = _G.my_counter + 1
- ';
- }
---- request
- GET /t
---- response_body
-my_counter = 1
---- grep_error_log eval: qr/warn\(\): [^,]*/
---- grep_error_log_out
-warn(): created timer: 1
-warn(): timer expired (premature: false; counter: 0)
-
---- no_error_log
-[error]
-
-
-
-=== TEST 4: timer.at + cosocket
---- http_config
- init_worker_by_lua '
- _G.done = false
- local function warn(...)
- ngx.log(ngx.WARN, ...)
- end
- local function error(...)
- ngx.log(ngx.ERR, ...)
- end
- local function handler(premature)
- warn("timer expired (premature: ", premature, ")")
-
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- error("failed to connect: ", err)
- _G.done = true
- return
- end
-
- local req = "flush_all\\r\\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- error("failed to send request: ", err)
- _G.done = true
- return
- end
-
- warn("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- warn("received: ", line)
- else
- error("failed to receive a line: ", err, " [", part, "]")
- end
- _G.done = true
- end
-
- local ok, err = ngx.timer.at(0, handler)
- if not ok then
- error("failed to create timer: ", err)
- end
- warn("created timer: ", ok)
- ';
---- config
- location = /t {
- content_by_lua '
- local waited = 0
- local sleep = ngx.sleep
- while not _G.done do
- local delay = 0.001
- sleep(delay)
- waited = waited + delay
- if waited > 1 then
- ngx.say("timed out")
- return
- end
- end
- ngx.say("ok")
- ';
- }
---- request
- GET /t
---- response_body
-ok
---- grep_error_log eval: qr/warn\(\): [^,]*/
---- grep_error_log_out
-warn(): created timer: 1
-warn(): timer expired (premature: false)
-warn(): request sent: 11
-warn(): received: OK
-
---- log_level: debug
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket send timeout: 60000
-lua tcp socket read timeout: 60000
---- no_error_log
-[error]
-
-
-
-=== TEST 5: init_worker_by_lua_file (simple global var)
---- http_config
- init_worker_by_lua_file html/foo.lua;
---- config
- location /t {
- content_by_lua '
- ngx.say("foo = ", foo)
- ';
- }
---- user_files
->>> foo.lua
-foo = ngx.md5("hello world")
---- request
- GET /t
---- response_body
-foo = 5eb63bbbe01eeed093cb22bb8f5acdc3
---- no_error_log
-[error]
-
-
-
-=== TEST 6: timer.at + cosocket (by_lua_file)
---- main_config
-env TEST_NGINX_MEMCACHED_PORT;
---- http_config
- init_worker_by_lua_file html/foo.lua;
---- user_files
->>> foo.lua
-_G.done = false
-local function warn(...)
- ngx.log(ngx.WARN, ...)
-end
-local function error(...)
- ngx.log(ngx.ERR, ...)
-end
-local function handler(premature)
- warn("timer expired (premature: ", premature, ")")
-
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1",
- os.getenv("TEST_NGINX_MEMCACHED_PORT"))
- if not ok then
- error("failed to connect: ", err)
- _G.done = true
- return
- end
-
- local req = "flush_all\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- error("failed to send request: ", err)
- _G.done = true
- return
- end
-
- warn("request sent: ", bytes)
-
- local line, err, part = sock:receive()
- if line then
- warn("received: ", line)
- else
- error("failed to receive a line: ", err, " [", part, "]")
- end
- _G.done = true
-end
-
-local ok, err = ngx.timer.at(0, handler)
-if not ok then
- error("failed to create timer: ", err)
-end
-warn("created timer: ", ok)
-
---- config
- location = /t {
- content_by_lua '
- local waited = 0
- local sleep = ngx.sleep
- while not _G.done do
- local delay = 0.001
- sleep(delay)
- waited = waited + delay
- if waited > 1 then
- ngx.say("timed out")
- return
- end
- end
- ngx.say("ok")
- ';
- }
---- request
- GET /t
---- response_body
-ok
---- grep_error_log eval: qr/warn\(\): [^,]*/
---- grep_error_log_out
-warn(): created timer: 1
-warn(): timer expired (premature: false)
-warn(): request sent: 11
-warn(): received: OK
-
---- log_level: debug
---- error_log
-lua tcp socket connect timeout: 60000
-lua tcp socket send timeout: 60000
-lua tcp socket read timeout: 60000
---- no_error_log
-[error]
-
-
-
-=== TEST 7: ngx.ctx
---- http_config
- init_worker_by_lua '
- ngx.ctx.foo = "hello world"
- local function warn(...)
- ngx.log(ngx.WARN, ...)
- end
- warn("foo = ", ngx.ctx.foo)
- ';
---- config
- location /t {
- echo ok;
- }
---- request
- GET /t
---- response_body
-ok
---- grep_error_log eval: qr/warn\(\): [^,]*/
---- grep_error_log_out
-warn(): foo = hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 8: print
---- http_config
- init_worker_by_lua '
- print("md5 = ", ngx.md5("hello world"))
- ';
---- config
- location /t {
- echo ok;
- }
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- error_log
-md5 = 5eb63bbbe01eeed093cb22bb8f5acdc3
-
-
-
-=== TEST 9: unescape_uri
---- http_config
- init_worker_by_lua '
- local function warn(...)
- ngx.log(ngx.WARN, ...)
- end
-
- warn(ngx.unescape_uri("hello%20world"))
- ';
---- config
- location /t {
- echo ok;
- }
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/warn\(\): [^,]*/
---- grep_error_log_out
-warn(): hello world
-
-
-
-=== TEST 10: escape_uri
---- http_config
- init_worker_by_lua '
- local function warn(...)
- ngx.log(ngx.WARN, ...)
- end
-
- warn(ngx.escape_uri("hello world"))
- ';
---- config
- location /t {
- echo ok;
- }
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/warn\(\): [^,]*/
---- grep_error_log_out
-warn(): hello%20world
-
-
-
-=== TEST 11: ngx.re
---- http_config
- init_worker_by_lua '
- local function warn(...)
- ngx.log(ngx.WARN, ...)
- end
-
- warn((ngx.re.sub("hello world", "world", "XXX", "jo")))
- ';
---- config
- location /t {
- echo ok;
- }
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/warn\(\): [^,]*/
---- grep_error_log_out
-warn(): hello XXX
-
-
-
-=== TEST 12: ngx.http_time
---- http_config
- init_worker_by_lua '
- local function warn(...)
- ngx.log(ngx.WARN, ...)
- end
-
- warn(ngx.http_time(5678))
- ';
---- config
- location /t {
- echo ok;
- }
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[error]
---- grep_error_log eval: qr/warn\(\): .*?(?=, context)/
---- grep_error_log_out
-warn(): Thu, 01 Jan 1970 01:34:38 GMT
-
-
-
-=== TEST 13: cosocket with resolver
---- timeout: 10
---- http_config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- init_worker_by_lua '
- -- global
- logs = ""
- done = false
- local function say(...)
- logs = logs .. table.concat({...}) .. "\\n"
- end
-
- local function handler()
- local sock = ngx.socket.tcp()
- local port = 80
- local ok, err = sock:connect("agentzh.org", port)
- if not ok then
- say("failed to connect: ", err)
- done = true
- return
- end
-
- say("connected: ", ok)
-
- local req = "GET / HTTP/1.0\\r\\nHost: agentzh.org\\r\\nConnection: close\\r\\n\\r\\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- say("failed to send request: ", err)
- done = true
- return
- end
-
- say("request sent: ", bytes)
-
- local line, err = sock:receive()
- if line then
- say("first line received: ", line)
-
- else
- say("failed to receive the first line: ", err)
- end
-
- line, err = sock:receive()
- if line then
- say("second line received: ", line)
-
- else
- say("failed to receive the second line: ", err)
- end
-
- done = true
- end
-
- local ok, err = ngx.timer.at(0, handler)
- if not ok then
- say("failed to create timer: ", err)
- else
- say("timer created")
- end
- ';
-
---- config
- location = /t {
- content_by_lua '
- local i = 0
- while not done and i < 3000 do
- ngx.sleep(0.001)
- i = i + 1
- end
- ngx.print(logs)
- ';
- }
---- request
-GET /t
---- response_body_like
-connected: 1
-request sent: 56
-first line received: HTTP\/1\.1 200 OK
-second line received: (?:Date|Server): .*?
---- no_error_log
-[error]
---- timeout: 10
---- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 14: connection refused (tcp) - log_errors on by default
---- http_config
- init_worker_by_lua '
- logs = ""
- done = false
- local function say(...)
- logs = logs .. table.concat{...} .. "\\n"
- end
-
- local function handler()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", 16787)
- if not ok then
- say("failed to connect: ", err)
- else
- say("connect: ", ok, " ", err)
- end
- done = true
- end
-
- local ok, err = ngx.timer.at(0, handler)
- if not ok then
- say("failed to create timer: ", err)
- else
- say("timer created")
- end
- ';
-
---- config
- location = /t {
- content_by_lua '
- local i = 0
- while not done and i < 1000 do
- ngx.sleep(0.001)
- i = i + 1
- end
- ngx.print(logs)
- ';
- }
-
---- request
- GET /t
---- response_body
-timer created
-failed to connect: connection refused
---- error_log eval
-qr/connect\(\) failed \(\d+: Connection refused\), context: ngx\.timer$/
-
-
-
-=== TEST 15: connection refused (tcp) - log_errors explicitly on
---- http_config
- lua_socket_log_errors on;
- init_worker_by_lua '
- logs = ""
- done = false
- local function say(...)
- logs = logs .. table.concat{...} .. "\\n"
- end
-
- local function handler()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", 16787)
- if not ok then
- say("failed to connect: ", err)
- else
- say("connect: ", ok, " ", err)
- end
- done = true
- end
-
- local ok, err = ngx.timer.at(0, handler)
- if not ok then
- say("failed to create timer: ", err)
- else
- say("timer created")
- end
- ';
-
---- config
- location = /t {
- content_by_lua '
- local i = 0
- while not done and i < 1000 do
- ngx.sleep(0.001)
- i = i + 1
- end
- ngx.print(logs)
- ';
- }
-
---- request
- GET /t
---- response_body
-timer created
-failed to connect: connection refused
---- error_log eval
-qr/connect\(\) failed \(\d+: Connection refused\)/
-
-
-
-=== TEST 16: connection refused (tcp) - log_errors explicitly off
---- http_config
- lua_socket_log_errors off;
- init_worker_by_lua '
- logs = ""
- done = false
- local function say(...)
- logs = logs .. table.concat{...} .. "\\n"
- end
-
- local function handler()
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", 16787)
- if not ok then
- say("failed to connect: ", err)
- else
- say("connect: ", ok, " ", err)
- end
- done = true
- end
-
- local ok, err = ngx.timer.at(0, handler)
- if not ok then
- say("failed to create timer: ", err)
- else
- say("timer created")
- end
- ';
-
---- config
- location = /t {
- content_by_lua '
- local i = 0
- while not done and i < 1000 do
- ngx.sleep(0.001)
- i = i + 1
- end
- ngx.print(logs)
- ';
- }
-
---- request
- GET /t
---- response_body
-timer created
-failed to connect: connection refused
---- no_error_log eval
-[
-'qr/connect\(\) failed \(\d+: Connection refused\)/',
-'[error]',
-]
-
-
-
-=== TEST 17: init_by_lua + proxy_temp_path which has side effects in cf->cycle->paths
---- http_config eval
-qq{
- proxy_temp_path $::ServerRoot/proxy_temp;
- init_worker_by_lua '
- local a = 2 + 3
- ';
-}
---- config
- location /t {
- echo ok;
- }
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 18: syslog error log
---- http_config
- #error_log syslog:server=127.0.0.1:12345 error;
- init_worker_by_lua '
- done = false
- os.execute("sleep 0.1")
- ngx.log(ngx.ERR, "Bad bad bad")
- done = true
- ';
---- config
- location /t {
- content_by_lua '
- while not done do
- ngx.sleep(0.001)
- end
- ngx.say("ok")
- ';
- }
---- log_level: error
---- error_log_file: syslog:server=127.0.0.1:$TEST_NGINX_RAND_PORT_1
---- udp_listen: $TEST_NGINX_RAND_PORT_1
---- udp_query eval: qr/Bad bad bad/
---- udp_reply: hello
---- wait: 0.1
---- request
- GET /t
---- response_body
-ok
---- error_log
-Bad bad bad
---- skip_nginx: 4: < 1.7.1
-
-
-
-=== TEST 19: fake module calls ngx_http_conf_get_module_srv_conf in its merge_srv_conf callback (GitHub issue #554)
-This also affects merge_loc_conf
---- http_config
- init_worker_by_lua return;
---- config
- location = /t {
- return 200 ok;
- }
---- request
-GET /t
---- response_body chomp
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 20: destroy Lua VM in cache processes (without privileged agent or shdict)
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
-
- proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
-
- #lua_shared_dict dummy 500k;
-
- init_by_lua_block {
- require "resty.core.regex"
- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
- assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
- }
-
---- config
- location = /t {
- return 200;
- }
---- request
- GET /t
---- grep_error_log eval: qr/lua close the global Lua VM \S+ in the cache helper process \d+|lua close the global Lua VM \S+$/
---- grep_error_log_out eval
-qr/\A(?:lua close the global Lua VM ([0-9A-F]+) in the cache helper process \d+
-lua close the global Lua VM \1
-lua close the global Lua VM \1 in the cache helper process \d+
-lua close the global Lua VM \1
-|lua close the global Lua VM ([0-9A-F]+) in the cache helper process \d+
-lua close the global Lua VM \2 in the cache helper process \d+
-lua close the global Lua VM \2
-lua close the global Lua VM \2
-|lua close the global Lua VM ([0-9A-F]+)
-lua close the global Lua VM \3 in the cache helper process \d+
-lua close the global Lua VM \3
-lua close the global Lua VM \3 in the cache helper process \d+
-|lua close the global Lua VM ([0-9A-F]+)
-lua close the global Lua VM \4 in the cache helper process \d+
-lua close the global Lua VM \4 in the cache helper process \d+
-lua close the global Lua VM \4
-)(?:lua close the global Lua VM [0-9A-F]+
-)*\z/
---- no_error_log
-[error]
-start privileged agent process
-
-
-
-=== TEST 21: destroy Lua VM in cache processes (without privileged agent but with shdict)
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
-
- proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
-
- lua_shared_dict dummy 500k;
-
- init_by_lua_block {
- require "resty.core.regex"
- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
- assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
- }
-
---- config
- location = /t {
- return 200;
- }
---- request
- GET /t
---- grep_error_log eval: qr/lua close the global Lua VM \S+ in the cache helper process \d+|lua close the global Lua VM \S+$/
---- grep_error_log_out eval
-qr/\A(?:lua close the global Lua VM ([0-9A-F]+) in the cache helper process \d+
-lua close the global Lua VM \1
-lua close the global Lua VM \1 in the cache helper process \d+
-lua close the global Lua VM \1
-|lua close the global Lua VM ([0-9A-F]+) in the cache helper process \d+
-lua close the global Lua VM \2 in the cache helper process \d+
-lua close the global Lua VM \2
-lua close the global Lua VM \2
-|lua close the global Lua VM ([0-9A-F]+)
-lua close the global Lua VM \3 in the cache helper process \d+
-lua close the global Lua VM \3
-lua close the global Lua VM \3 in the cache helper process \d+
-)(?:lua close the global Lua VM [0-9A-F]+
-|lua close the global Lua VM ([0-9A-F]+)
-lua close the global Lua VM \4 in the cache helper process \d+
-lua close the global Lua VM \4 in the cache helper process \d+
-lua close the global Lua VM \4
-lua close the global Lua VM \4
-)*\z/
---- no_error_log
-[error]
-start privileged agent process
-
-
-
-=== TEST 22: destroy Lua VM in cache processes (with privileged agent)
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
-
- #lua_shared_dict dogs 1m;
-
- proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
-
- init_by_lua_block {
- assert(require "ngx.process".enable_privileged_agent())
- require "resty.core.regex"
- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
- assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
- }
-
---- config
- location = /t {
- return 200;
- }
---- request
- GET /t
---- grep_error_log eval: qr/lua close the global Lua VM \S+ in the cache helper process \d+|lua close the global Lua VM \S+$/
---- grep_error_log_out eval
-qr/\A(?:lua close the global Lua VM ([0-9A-F]+) in the cache helper process \d+
-lua close the global Lua VM \1
-lua close the global Lua VM \1 in the cache helper process \d+
-lua close the global Lua VM \1
-|lua close the global Lua VM ([0-9A-F]+) in the cache helper process \d+
-lua close the global Lua VM \2 in the cache helper process \d+
-lua close the global Lua VM \2
-lua close the global Lua VM \2
-|lua close the global Lua VM ([0-9A-F]+)
-lua close the global Lua VM \3 in the cache helper process \d+
-lua close the global Lua VM \3
-lua close the global Lua VM \3 in the cache helper process \d+
-|lua close the global Lua VM ([0-9A-F]+)
-lua close the global Lua VM \4 in the cache helper process \d+
-lua close the global Lua VM \4 in the cache helper process \d+
-lua close the global Lua VM \4
-)(?:lua close the global Lua VM [0-9A-F]+
-)*\z/
---- error_log eval
-qr/start privileged agent process \d+/
---- no_error_log
-[error]
-
-
-
-=== TEST 23: destroy Lua VM in cache processes (with init worker and privileged agent)
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
-
- #lua_shared_dict dogs 1m;
-
- proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
-
- init_by_lua_block {
- assert(require "ngx.process".enable_privileged_agent())
- require "resty.core.regex"
- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
- assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
- }
-
- init_worker_by_lua_block {
- ngx.log(ngx.WARN, "hello from init worker by lua")
- }
-
---- config
- location = /t {
- return 200;
- }
---- request
- GET /t
---- grep_error_log eval: qr/hello from init worker by lua/
---- grep_error_log_out
-hello from init worker by lua
-hello from init worker by lua
-
---- error_log eval
-[
-qr/start privileged agent process \d+$/,
-qr/lua close the global Lua VM ([0-9A-F]+) in the cache helper process \d+$/,
-qr/lua close the global Lua VM ([0-9A-F]+)$/,
-]
---- no_error_log
-[error]
-
-
-
-=== TEST 24: destroy Lua VM in cache processes (with init worker but without privileged agent)
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
-
- #lua_shared_dict dogs 1m;
-
- proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
-
- init_by_lua_block {
- require "resty.core.regex"
- assert(ngx.re.match("hello, world", [[hello, \w+]], "joi"))
- assert(ngx.re.match("hi, world", [[hi, \w+]], "ji"))
- }
-
- init_worker_by_lua_block {
- ngx.log(ngx.WARN, "hello from init worker by lua")
- }
-
---- config
- location = /t {
- return 200;
- }
---- request
- GET /t
-
---- grep_error_log eval: qr/hello from init worker by lua/
---- grep_error_log_out
-hello from init worker by lua
-
---- error_log eval
-[
-qr/lua close the global Lua VM ([0-9A-F]+) in the cache helper process \d+$/,
-qr/lua close the global Lua VM ([0-9A-F]+)$/,
-]
---- no_error_log
-[error]
-start privileged agent process
-
-
-
-=== TEST 25: syntax error in init_worker_by_lua_block
---- http_config
- init_worker_by_lua_block {
- ngx.log(ngx.debug, "pass")
- error("failed to init"
- ngx.log(ngx.debug, "unreachable")
- }
---- config
- location /t {
- content_by_lua_block {
- ngx.say("hello world")
- }
- }
---- request
- GET /t
---- response_body
-hello world
---- error_log
-init_worker_by_lua error: init_worker_by_lua(nginx.conf:25):4: ')' expected (to close '(' at line 3) near 'ngx'
---- no_error_log
-no_such_error_log
-
-
-
-=== TEST 26: syntax error in init_worker_by_lua_file
---- http_config
- init_worker_by_lua_file html/init.lua;
---- config
- location /t {
- content_by_lua_block {
- ngx.say("hello world")
- }
- }
---- user_files
->>> init.lua
- ngx.log(ngx.debug, "pass")
- error("failed to init"
- ngx.log(ngx.debug, "unreachable")
-
---- request
- GET /t
---- response_body
-hello world
---- error_log eval
-qr|init_worker_by_lua_file error: .*?t/servroot\w*/html/init.lua:3: '\)' expected \(to close '\(' at line 2\) near 'ngx'|
---- no_error_log
-no_such_error_log
diff --git a/src/deps/src/lua-nginx-module/t/125-configure-args.t b/src/deps/src/lua-nginx-module/t/125-configure-args.t
deleted file mode 100644
index 4160d4e3a..000000000
--- a/src/deps/src/lua-nginx-module/t/125-configure-args.t
+++ /dev/null
@@ -1,31 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: nginx configure
---- config
- location /configure_args {
- content_by_lua '
- ngx.say(ngx.config.nginx_configure())
- ';
- }
---- request
-GET /configure_args
---- response_body_like chop
-^\s*\-\-[^-]+
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/126-shdict-frag.t b/src/deps/src/lua-nginx-module/t/126-shdict-frag.t
deleted file mode 100644
index 33646d17c..000000000
--- a/src/deps/src/lua-nginx-module/t/126-shdict-frag.t
+++ /dev/null
@@ -1,1266 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-#repeat_each(2);
-
-plan tests => repeat_each() * 39;
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: merge 2 single-page free blocks (forcibly evicted, merge forward)
---- http_config
- lua_shared_dict dogs 20k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local function check_key(key)
- local res, err = dogs:get(key)
- if res then
- ngx.say("found ", key, ": ", #res)
- else
- if not err then
- ngx.say(key, " not found")
- else
- ngx.say("failed to fetch key: ", err)
- end
- end
- end
-
- local function set_key(key, value)
- local ok, err, force = dogs:set(key, value)
- if ok then
- ngx.print("successfully set ", key)
- if force then
- ngx.say(" with force.")
- else
- ngx.say(".")
- end
- else
- ngx.say("failed to set ", key, ": ", err)
- end
- end
-
- for i = 1, 2 do
- set_key("foo", string.rep("a", 4000))
- set_key("bar", string.rep("b", 4001))
- set_key("baz", string.rep("c", 8102))
-
- check_key("foo")
- check_key("bar")
- check_key("baz")
- end
-
- collectgarbage()
- ';
- }
---- request
-GET /test
---- stap
-global first_time = 1
-global active = 1
-
-F(ngx_http_lua_shdict_init_zone) {
- active = 0
-}
-
-F(ngx_http_lua_shdict_init_zone).return {
- active = 1
-}
-
-F(ngx_slab_alloc_pages) {
- if (first_time) {
- printf("total pages: %d\n", $pool->pages->slab)
- first_time = 0
- }
- if (active) {
- printf("alloc pages: %d", $pages)
- //print_ubacktrace()
- } else {
- printf("init zone alloc pages: %d", $pages)
- }
-}
-
-F(ngx_slab_alloc_pages).return {
- if ($return) {
- printf(" ok\n")
-
- } else {
- printf(" NOT OK\n")
- }
-}
-
-F(ngx_slab_free_pages) {
- printf("free pages: %d\n", $pages)
-}
-
---- stap_out
-total pages: 4
-init zone alloc pages: 1 ok
-init zone alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 ok
-alloc pages: 1 NOT OK
-free pages: 2
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 ok
-
---- response_body
-successfully set foo.
-successfully set bar.
-successfully set baz with force.
-foo not found
-bar not found
-found baz: 8102
-successfully set foo with force.
-successfully set bar.
-successfully set baz with force.
-foo not found
-bar not found
-found baz: 8102
-
---- no_error_log
-[error]
-
-
-
-=== TEST 2: merge 2 single-page free slabs (forcibly evicted, merge backward)
---- http_config
- lua_shared_dict dogs 20k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local function check_key(key)
- local res, err = dogs:get(key)
- if res then
- ngx.say("found ", key, ": ", #res)
- else
- if not err then
- ngx.say(key, " not found")
- else
- ngx.say("failed to fetch key: ", err)
- end
- end
- end
-
- local function set_key(key, value)
- local ok, err, force = dogs:set(key, value)
- if ok then
- ngx.print("successfully set ", key)
- if force then
- ngx.say(" with force.")
- else
- ngx.say(".")
- end
- else
- ngx.say("failed to set ", key, ": ", err)
- end
- end
-
- for i = 1, 2 do
- set_key("foo", string.rep("a", 4000))
- set_key("bar", string.rep("b", 4001))
- check_key("foo")
- set_key("baz", string.rep("c", 8102))
-
- check_key("foo")
- check_key("bar")
- check_key("baz")
- end
-
- collectgarbage()
- ';
- }
---- request
-GET /test
---- stap
-global first_time = 1
-global active = 1
-
-F(ngx_http_lua_shdict_init_zone) {
- active = 0
-}
-
-F(ngx_http_lua_shdict_init_zone).return {
- active = 1
-}
-
-F(ngx_slab_alloc_pages) {
- if (first_time) {
- printf("total pages: %d\n", $pool->pages->slab)
- first_time = 0
- }
- if (active) {
- printf("alloc pages: %d", $pages)
- //print_ubacktrace()
- } else {
- printf("init zone alloc pages: %d", $pages)
- }
-}
-
-F(ngx_slab_alloc_pages).return {
- if ($return) {
- printf(" ok\n")
-
- } else {
- printf(" NOT OK\n")
- }
-}
-
-F(ngx_slab_free_pages) {
- printf("free pages: %d\n", $pages)
-}
-
---- stap_out
-total pages: 4
-init zone alloc pages: 1 ok
-init zone alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 ok
-alloc pages: 1 NOT OK
-free pages: 2
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 ok
-
---- response_body
-successfully set foo.
-successfully set bar.
-found foo: 4000
-successfully set baz with force.
-foo not found
-bar not found
-found baz: 8102
-successfully set foo with force.
-successfully set bar.
-found foo: 4000
-successfully set baz with force.
-foo not found
-bar not found
-found baz: 8102
-
---- no_error_log
-[error]
-
-
-
-=== TEST 3: merge 3 single-page free slabs (actively deleted, merge backward AND forward)
---- http_config
- lua_shared_dict dogs 25k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local function check_key(key)
- local res, err = dogs:get(key)
- if res then
- ngx.say("found ", key, ": ", #res)
- else
- if not err then
- ngx.say(key, " not found")
- else
- ngx.say("failed to fetch key: ", err)
- end
- end
- end
-
- local function set_key(key, value)
- local ok, err, force = dogs:set(key, value)
- if ok then
- ngx.print("successfully set ", key)
- if force then
- ngx.say(" with force.")
- else
- ngx.say(".")
- end
- else
- ngx.say("failed to set ", key, ": ", err)
- end
- end
-
- local function safe_set_key(key, value)
- local ok, err = dogs:safe_set(key, value)
- if ok then
- ngx.say("successfully safe set ", key)
- else
- ngx.say("failed to safe set ", key, ": ", err)
- end
- end
-
- for i = 1, 2 do
- set_key("foo", string.rep("a", 4000))
- set_key("bar", string.rep("b", 4001))
- set_key("baz", string.rep("c", 4002))
-
- check_key("foo")
- check_key("bar")
- check_key("baz")
-
- dogs:delete("foo")
- safe_set_key("blah", string.rep("a", 8100))
- dogs:delete("baz")
- safe_set_key("blah", string.rep("a", 8100))
- dogs:delete("bar")
- safe_set_key("blah", string.rep("a", 12010))
- end
-
- collectgarbage()
- ';
- }
---- request
-GET /test
---- stap
-global first_time = 1
-global active = 1
-
-F(ngx_http_lua_shdict_init_zone) {
- active = 0
-}
-
-F(ngx_http_lua_shdict_init_zone).return {
- active = 1
-}
-
-F(ngx_slab_alloc_pages) {
- if (first_time) {
- printf("total pages: %d\n", $pool->pages->slab)
- first_time = 0
- }
- if (active) {
- printf("alloc pages: %d", $pages)
- //print_ubacktrace()
- } else {
- printf("init zone alloc pages: %d", $pages)
- }
-}
-
-F(ngx_slab_alloc_pages).return {
- if ($return) {
- printf(" ok\n")
-
- } else {
- printf(" NOT OK\n")
- }
-}
-
-F(ngx_slab_free_pages) {
- printf("free pages: %d\n", $pages)
-}
-
---- stap_out
-total pages: 5
-init zone alloc pages: 1 ok
-init zone alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 3 ok
-alloc pages: 1 NOT OK
-free pages: 3
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 3 ok
-
---- response_body
-successfully set foo.
-successfully set bar.
-successfully set baz.
-found foo: 4000
-found bar: 4001
-found baz: 4002
-failed to safe set blah: no memory
-failed to safe set blah: no memory
-successfully safe set blah
-successfully set foo with force.
-successfully set bar.
-successfully set baz.
-found foo: 4000
-found bar: 4001
-found baz: 4002
-failed to safe set blah: no memory
-failed to safe set blah: no memory
-successfully safe set blah
-
---- no_error_log
-[error]
-
-
-
-=== TEST 4: merge one single-page block backward, but no more
---- http_config
- lua_shared_dict dogs 25k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local function check_key(key)
- local res, err = dogs:get(key)
- if res then
- ngx.say("found ", key, ": ", #res)
- else
- if not err then
- ngx.say(key, " not found")
- else
- ngx.say("failed to fetch key: ", err)
- end
- end
- end
-
- local function set_key(key, value)
- local ok, err, force = dogs:set(key, value)
- if ok then
- ngx.print("successfully set ", key)
- if force then
- ngx.say(" with force.")
- else
- ngx.say(".")
- end
- else
- ngx.say("failed to set ", key, ": ", err)
- end
- end
-
- local function safe_set_key(key, value)
- local ok, err = dogs:safe_set(key, value)
- if ok then
- ngx.say("successfully safe set ", key)
- else
- ngx.say("failed to safe set ", key, ": ", err)
- end
- end
-
- for i = 1, 1 do
- set_key("foo", string.rep("a", 4000))
- set_key("bar", string.rep("b", 4001))
- set_key("baz", string.rep("c", 4002))
-
- check_key("foo")
- check_key("bar")
- check_key("baz")
-
- dogs:delete("bar")
- safe_set_key("blah", string.rep("a", 8100))
- dogs:delete("baz")
- safe_set_key("blah", string.rep("a", 8100))
- check_key("foo")
- dogs:delete("foo")
- check_key("blah")
- end
-
- collectgarbage()
- ';
- }
---- request
-GET /test
---- stap
-global first_time = 1
-global active = 1
-
-F(ngx_http_lua_shdict_init_zone) {
- active = 0
-}
-
-F(ngx_http_lua_shdict_init_zone).return {
- active = 1
-}
-
-F(ngx_slab_alloc_pages) {
- if (first_time) {
- printf("total pages: %d\n", $pool->pages->slab)
- first_time = 0
- }
- if (active) {
- printf("alloc pages: %d", $pages)
- //print_ubacktrace()
- } else {
- printf("init zone alloc pages: %d", $pages)
- }
-}
-
-F(ngx_slab_alloc_pages).return {
- if ($return) {
- printf(" ok\n")
-
- } else {
- printf(" NOT OK\n")
- }
-}
-
-F(ngx_slab_free_pages) {
- printf("free pages: %d\n", $pages)
-}
-
---- stap_out
-total pages: 5
-init zone alloc pages: 1 ok
-init zone alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 ok
-free pages: 1
-
---- response_body
-successfully set foo.
-successfully set bar.
-successfully set baz.
-found foo: 4000
-found bar: 4001
-found baz: 4002
-failed to safe set blah: no memory
-successfully safe set blah
-found foo: 4000
-found blah: 8100
-
---- no_error_log
-[error]
-
-
-
-=== TEST 5: merge one single-page block forward, but no more
---- http_config
- lua_shared_dict dogs 25k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local function check_key(key)
- local res, err = dogs:get(key)
- if res then
- ngx.say("found ", key, ": ", #res)
- else
- if not err then
- ngx.say(key, " not found")
- else
- ngx.say("failed to fetch key: ", err)
- end
- end
- end
-
- local function set_key(key, value)
- local ok, err, force = dogs:set(key, value)
- if ok then
- ngx.print("successfully set ", key)
- if force then
- ngx.say(" with force.")
- else
- ngx.say(".")
- end
- else
- ngx.say("failed to set ", key, ": ", err)
- end
- end
-
- local function safe_set_key(key, value)
- local ok, err = dogs:safe_set(key, value)
- if ok then
- ngx.say("successfully safe set ", key)
- else
- ngx.say("failed to safe set ", key, ": ", err)
- end
- end
-
- for i = 1, 1 do
- set_key("foo", string.rep("a", 4000))
- set_key("bar", string.rep("b", 4001))
- set_key("baz", string.rep("c", 4002))
-
- check_key("foo")
- check_key("bar")
- check_key("baz")
-
- dogs:delete("bar")
- safe_set_key("blah", string.rep("a", 8100))
- dogs:delete("foo")
- safe_set_key("blah", string.rep("a", 8100))
- check_key("baz")
- dogs:delete("baz")
- check_key("blah")
- end
-
- collectgarbage()
- ';
- }
---- request
-GET /test
---- stap
-global first_time = 1
-global active = 1
-
-F(ngx_http_lua_shdict_init_zone) {
- active = 0
-}
-
-F(ngx_http_lua_shdict_init_zone).return {
- active = 1
-}
-
-F(ngx_slab_alloc_pages) {
- if (first_time) {
- printf("total pages: %d\n", $pool->pages->slab)
- first_time = 0
- }
- if (active) {
- printf("alloc pages: %d", $pages)
- //print_ubacktrace()
- } else {
- printf("init zone alloc pages: %d", $pages)
- }
-}
-
-F(ngx_slab_alloc_pages).return {
- if ($return) {
- printf(" ok\n")
-
- } else {
- printf(" NOT OK\n")
- }
-}
-
-F(ngx_slab_free_pages) {
- printf("free pages: %d\n", $pages)
-}
-
---- stap_out
-total pages: 5
-init zone alloc pages: 1 ok
-init zone alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 ok
-free pages: 1
-
---- response_body
-successfully set foo.
-successfully set bar.
-successfully set baz.
-found foo: 4000
-found bar: 4001
-found baz: 4002
-failed to safe set blah: no memory
-successfully safe set blah
-found baz: 4002
-found blah: 8100
-
---- no_error_log
-[error]
-
-
-
-=== TEST 6: merge 2 multi-page blocks (forcibly evicted, merge backward)
---- http_config
- lua_shared_dict dogs 30k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local function check_key(key)
- local res, err = dogs:get(key)
- if res then
- ngx.say("found ", key, ": ", #res)
- else
- if not err then
- ngx.say(key, " not found")
- else
- ngx.say("failed to fetch key: ", err)
- end
- end
- end
-
- local function set_key(key, value)
- local ok, err, force = dogs:set(key, value)
- if ok then
- ngx.print("successfully set ", key)
- if force then
- ngx.say(" with force.")
- else
- ngx.say(".")
- end
- else
- ngx.say("failed to set ", key, ": ", err)
- end
- end
-
- local function safe_set_key(key, value)
- local ok, err = dogs:safe_set(key, value)
- if ok then
- ngx.say("successfully safe set ", key)
- else
- ngx.say("failed to safe set ", key, ": ", err)
- end
- end
-
- for i = 1, 1 do
- set_key("foo", string.rep("a", 8100))
- set_key("bar", string.rep("b", 8101))
- check_key("foo")
- safe_set_key("baz", string.rep("c", 16300))
- dogs:delete("foo")
- check_key("bar")
- dogs:delete("bar")
- safe_set_key("baz", string.rep("c", 16300))
-
- check_key("foo")
- check_key("bar")
- check_key("baz")
- end
-
- collectgarbage()
- ';
- }
---- request
-GET /test
---- stap
-global first_time = 1
-global active = 1
-
-F(ngx_http_lua_shdict_init_zone) {
- active = 0
-}
-
-F(ngx_http_lua_shdict_init_zone).return {
- active = 1
-}
-
-F(ngx_slab_alloc_pages) {
- if (first_time) {
- printf("total pages: %d\n", $pool->pages->slab)
- first_time = 0
- }
- if (active) {
- printf("alloc pages: %d", $pages)
- //print_ubacktrace()
- } else {
- printf("init zone alloc pages: %d", $pages)
- }
-}
-
-F(ngx_slab_alloc_pages).return {
- if ($return) {
- printf(" ok\n")
-
- } else {
- printf(" NOT OK\n")
- }
-}
-
-F(ngx_slab_free_pages) {
- printf("free pages: %d\n", $pages)
-}
-
---- stap_out
-total pages: 6
-init zone alloc pages: 1 ok
-init zone alloc pages: 1 ok
-alloc pages: 2 ok
-alloc pages: 2 ok
-alloc pages: 4 NOT OK
-free pages: 2
-free pages: 2
-alloc pages: 4 ok
-
---- response_body
-successfully set foo.
-successfully set bar.
-found foo: 8100
-failed to safe set baz: no memory
-found bar: 8101
-successfully safe set baz
-foo not found
-bar not found
-found baz: 16300
-
---- no_error_log
-[error]
-
-
-
-=== TEST 7: merge big slabs (less than max slab size) backward
---- http_config
- lua_shared_dict dogs 20k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local function check_key(key)
- local res, err = dogs:get(key)
- if res then
- ngx.say("found ", key, ": ", #res)
- else
- if not err then
- ngx.say(key, " not found")
- else
- ngx.say("failed to fetch key: ", err)
- end
- end
- end
-
- local function set_key(key, value)
- local ok, err, force = dogs:set(key, value)
- if ok then
- ngx.print("successfully set ", key)
- if force then
- ngx.say(" with force.")
- else
- ngx.say(".")
- end
- else
- ngx.say("failed to set ", key, ": ", err)
- end
- end
-
- local function safe_set_key(key, value)
- local ok, err = dogs:safe_set(key, value)
- if ok then
- ngx.say("successfully safe set ", key)
- else
- ngx.say("failed to safe set ", key, ": ", err)
- end
- end
-
- for i = 1, 1 do
- for j = 1, 50 do
- dogs:set("foo" .. j, string.rep("a", 5))
- end
- set_key("bar", string.rep("a", 4000))
-
- for j = 1, 50 do
- dogs:delete("foo" .. j)
- end
-
- safe_set_key("baz", string.rep("b", 8100))
- check_key("bar")
-
- ngx.say("delete bar")
- dogs:delete("bar")
-
- safe_set_key("baz", string.rep("b", 8100))
- end
-
- collectgarbage()
- ';
- }
---- request
-GET /test
---- stap
-global first_time = 1
-global active = 1
-
-F(ngx_http_lua_shdict_init_zone) {
- active = 0
-}
-
-F(ngx_http_lua_shdict_init_zone).return {
- active = 1
-}
-
-F(ngx_slab_alloc_pages) {
- if (first_time) {
- //printf("slab max size: %d\n", @var("ngx_slab_max_size"))
- printf("total pages: %d\n", $pool->pages->slab)
- first_time = 0
- }
- if (active) {
- printf("alloc pages: %d", $pages)
- //print_ubacktrace()
- } else {
- printf("init zone alloc pages: %d", $pages)
- }
-}
-
-F(ngx_slab_alloc_pages).return {
- if ($return) {
- printf(" ok\n")
-
- } else {
- printf(" NOT OK\n")
- }
-}
-
-F(ngx_slab_free_pages) {
- printf("free pages: %d\n", $pages)
-}
-
---- stap_out
-total pages: 4
-init zone alloc pages: 1 ok
-init zone alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-free pages: 1
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 ok
-
---- response_body
-successfully set bar.
-failed to safe set baz: no memory
-found bar: 4000
-delete bar
-successfully safe set baz
-
---- no_error_log
-[error]
-
-
-
-=== TEST 8: cannot merge in-used big slabs page (backward)
---- http_config
- lua_shared_dict dogs 20k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local function check_key(key)
- local res, err = dogs:get(key)
- if res then
- ngx.say("found ", key, ": ", #res)
- else
- if not err then
- ngx.say(key, " not found")
- else
- ngx.say("failed to fetch key: ", err)
- end
- end
- end
-
- local function set_key(key, value)
- local ok, err, force = dogs:set(key, value)
- if ok then
- ngx.print("successfully set ", key)
- if force then
- ngx.say(" with force.")
- else
- ngx.say(".")
- end
- else
- ngx.say("failed to set ", key, ": ", err)
- end
- end
-
- local function safe_set_key(key, value)
- local ok, err = dogs:safe_set(key, value)
- if ok then
- ngx.say("successfully safe set ", key)
- else
- ngx.say("failed to safe set ", key, ": ", err)
- end
- end
-
- for i = 1, 1 do
- for j = 1, 63 do
- dogs:set("foo" .. j, string.rep("a", 5))
- end
- set_key("bar", string.rep("a", 4000))
-
- --[[
- for j = 1, 50 do
- dogs:delete("foo" .. j)
- end
- ]]
-
- safe_set_key("baz", string.rep("b", 8100))
- check_key("bar")
-
- ngx.say("delete bar")
- dogs:delete("bar")
-
- safe_set_key("baz", string.rep("b", 8100))
- end
-
- collectgarbage()
- ';
- }
---- request
-GET /test
---- stap
-global first_time = 1
-global active = 1
-
-F(ngx_http_lua_shdict_init_zone) {
- active = 0
-}
-
-F(ngx_http_lua_shdict_init_zone).return {
- active = 1
-}
-
-F(ngx_slab_alloc_pages) {
- if (first_time) {
- //printf("slab max size: %d\n", @var("ngx_slab_max_size"))
- printf("total pages: %d\n", $pool->pages->slab)
- first_time = 0
- }
- if (active) {
- printf("alloc pages: %d", $pages)
- //print_ubacktrace()
- } else {
- printf("init zone alloc pages: %d", $pages)
- }
-}
-
-F(ngx_slab_alloc_pages).return {
- if ($return) {
- printf(" ok\n")
-
- } else {
- printf(" NOT OK\n")
- }
-}
-
-F(ngx_slab_free_pages) {
- printf("free pages: %d\n", $pages)
-}
-
---- stap_out
-total pages: 4
-init zone alloc pages: 1 ok
-init zone alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 NOT OK
-
---- response_body
-successfully set bar.
-failed to safe set baz: no memory
-found bar: 4000
-delete bar
-failed to safe set baz: no memory
-
---- no_error_log
-[error]
-
-
-
-=== TEST 9: cannot merge in-used big slabs page (forward)
---- http_config
- lua_shared_dict dogs 20k;
---- config
- location = /test {
- content_by_lua '
- local dogs = ngx.shared.dogs
-
- local function check_key(key)
- local res, err = dogs:get(key)
- if res then
- ngx.say("found ", key, ": ", #res)
- else
- if not err then
- ngx.say(key, " not found")
- else
- ngx.say("failed to fetch key: ", err)
- end
- end
- end
-
- local function set_key(key, value)
- local ok, err, force = dogs:set(key, value)
- if ok then
- ngx.print("successfully set ", key)
- if force then
- ngx.say(" with force.")
- else
- ngx.say(".")
- end
- else
- ngx.say("failed to set ", key, ": ", err)
- end
- end
-
- local function safe_set_key(key, value)
- local ok, err = dogs:safe_set(key, value)
- if ok then
- ngx.say("successfully safe set ", key)
- else
- ngx.say("failed to safe set ", key, ": ", err)
- end
- end
-
- for i = 1, 1 do
- set_key("bar", string.rep("a", 4000))
- for j = 1, 50 do
- dogs:set("foo" .. j, string.rep("a", 5))
- end
-
- --[[
- for j = 1, 50 do
- dogs:delete("foo" .. j)
- end
- ]]
-
- safe_set_key("baz", string.rep("b", 8100))
- check_key("bar")
-
- ngx.say("delete bar")
- dogs:delete("bar")
-
- safe_set_key("baz", string.rep("b", 8100))
- end
-
- collectgarbage()
- ';
- }
---- request
-GET /test
---- stap
-global first_time = 1
-global active = 1
-
-F(ngx_http_lua_shdict_init_zone) {
- active = 0
-}
-
-F(ngx_http_lua_shdict_init_zone).return {
- active = 1
-}
-
-F(ngx_slab_alloc_pages) {
- if (first_time) {
- //printf("slab max size: %d\n", @var("ngx_slab_max_size"))
- printf("total pages: %d\n", $pool->pages->slab)
- first_time = 0
- }
- if (active) {
- printf("alloc pages: %d", $pages)
- //print_ubacktrace()
- } else {
- printf("init zone alloc pages: %d", $pages)
- }
-}
-
-F(ngx_slab_alloc_pages).return {
- if ($return) {
- printf(" ok\n")
-
- } else {
- printf(" NOT OK\n")
- }
-}
-
-F(ngx_slab_free_pages) {
- printf("free pages: %d\n", $pages)
-}
-
---- stap_out
-total pages: 4
-init zone alloc pages: 1 ok
-init zone alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 1 ok
-alloc pages: 2 NOT OK
-free pages: 1
-alloc pages: 2 NOT OK
-
---- response_body
-successfully set bar.
-failed to safe set baz: no memory
-found bar: 4000
-delete bar
-failed to safe set baz: no memory
-
---- no_error_log
-[error]
-
-
-
-=== TEST 10: fuzz testing
---- http_config
- lua_shared_dict dogs 200k;
---- config
- location = /t {
- content_by_lua '
- local rand = math.random
- local dogs = ngx.shared.dogs
- local maxsz = 9000
- local maxkeyidx = 30
- local rep = string.rep
-
- math.randomseed(ngx.time())
- for i = 1, 30000 do
- local key = "mylittlekey" .. rand(maxkeyidx)
- local ok, err = dogs:get(key)
- if not ok or rand() > 0.6 then
- local sz = rand(maxsz)
- local val = rep("a", sz)
- local ok, err, forcible = dogs:set(key, val)
- if err then
- ngx.log(ngx.ERR, "failed to set key: ", err)
- -- return
- end
- if forcible then
- -- error("forcible")
- end
- end
- end
- ngx.say("ok")
- collectgarbage()
- ';
- }
---- request
-GET /t
---- response_body
-ok
-
---- no_error_log
-[error]
---- timeout: 60
diff --git a/src/deps/src/lua-nginx-module/t/127-uthread-kill.t b/src/deps/src/lua-nginx-module/t/127-uthread-kill.t
deleted file mode 100644
index 11caee582..000000000
--- a/src/deps/src/lua-nginx-module/t/127-uthread-kill.t
+++ /dev/null
@@ -1,507 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = $t::StapThread::GCScript;
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 5 + 1);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
-
-#no_shuffle();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: kill pending sleep
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello from f()")
- ngx.sleep(1)
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.say("failed to kill thread: ", err)
- return
- end
-
- ngx.say("killed")
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.say("failed to kill thread: ", err)
- return
- end
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-hello from f()
-thread created: running
-killed
-failed to kill thread: already waited or killed
-
---- no_error_log
-[error]
---- error_log
-lua clean up the timer for pending ngx.sleep
-
-
-
-=== TEST 2: already waited
---- config
- location /lua {
- content_by_lua '
- local function f()
- ngx.say("hello from f()")
- ngx.sleep(0.001)
- return 32
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.say("failed to kill thread: ", res)
- return
- end
-
- ngx.say("waited: ", res)
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.say("failed to kill thread: ", err)
- return
- end
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-terminate 2: ok
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-hello from f()
-thread created: running
-waited: 32
-failed to kill thread: already waited or killed
-
---- no_error_log
-[error]
-lua clean up the timer for pending ngx.sleep
-
-
-
-=== TEST 3: kill pending resolver
---- config
- resolver 127.0.0.2:12345;
- resolver_timeout 5ms;
- location /lua {
- content_by_lua '
- local function f()
- local sock = ngx.socket.tcp()
- sock:connect("some.127.0.0.2", 12345)
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.say("failed to kill thread: ", err)
- return
- end
-
- ngx.say("killed")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-thread created: running
-killed
-
---- no_error_log
-[error]
---- error_log
-lua tcp socket abort resolver
-
-
-
-=== TEST 4: kill pending connect
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /lua {
- content_by_lua '
- local ready = false
- local function f()
- local sock = ngx.socket.tcp()
- sock:connect("agentzh.org", 80)
- sock:close()
- ready = true
- sock:settimeout(10000)
- sock:connect("127.0.0.2", 12345)
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- while not ready do
- ngx.sleep(0.001)
- end
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.say("failed to kill thread: ", err)
- return
- end
-
- ngx.say("killed")
- ';
- }
---- request
-GET /lua
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-create 2 in 1
-spawn user thread 2 in 1
-delete thread 2
-terminate 1: ok
-delete thread 1
-
---- response_body
-thread created: running
-killed
-
---- no_error_log
-[error]
-lua tcp socket abort resolver
---- grep_error_log: lua finalize socket
---- grep_error_log_out
-lua finalize socket
-lua finalize socket
-
---- error_log
-
-
-
-=== TEST 5: cannot kill a pending subrequest
---- config
- location = /sub {
- echo_sleep 0.3;
- echo ok;
- }
-
- location = /t {
- content_by_lua '
- local function f()
- ngx.location.capture("/sub")
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.say("failed to kill thread: ", err)
- return
- end
-
- ngx.say("killed")
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- response_body
-thread created: running
-failed to kill thread: pending subrequests
-
---- no_error_log
-[error]
-[alert]
-lua tcp socket abort resolver
---- error_log
-
-
-
-=== TEST 6: cannot kill a pending subrequest not in the thread being killed
---- config
- location = /sub {
- echo_sleep 0.3;
- echo ok;
- }
-
- location = /t {
- content_by_lua '
- local function f()
- ngx.location.capture("/sub")
- end
-
- local function g()
- ngx.sleep(0.3)
- end
-
- local tf, err = ngx.thread.spawn(f)
- if not tf then
- ngx.say("failed to spawn thread 1: ", err)
- return
- end
-
- ngx.say("thread f created: ", coroutine.status(tf))
-
- local tg, err = ngx.thread.spawn(g)
- if not tg then
- ngx.say("failed to spawn thread g: ", err)
- return
- end
-
- ngx.say("thread g created: ", coroutine.status(tg))
-
- collectgarbage()
-
- local ok, err = ngx.thread.kill(tf)
- if not ok then
- ngx.say("failed to kill thread f: ", err)
- else
- ngx.say("killed f")
- end
-
- local ok, err = ngx.thread.kill(tg)
- if not ok then
- ngx.say("failed to kill thread g: ", err)
- else
- ngx.say("killed g")
- end
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- response_body
-thread f created: running
-thread g created: running
-failed to kill thread f: pending subrequests
-killed g
-
---- no_error_log
-[error]
-[alert]
-lua tcp socket abort resolver
---- error_log
-
-
-
-=== TEST 7: kill a thread that has done a subrequest but no pending ones
---- config
- location = /sub {
- echo ok;
- }
-
- location = /t {
- content_by_lua '
- local ready = false
- local function f()
- ngx.location.capture("/sub")
- ready = true
- ngx.sleep(0.5)
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- while not ready do
- ngx.sleep(0.001)
- end
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.say("failed to kill thread: ", err)
- return
- end
-
- ngx.say("killed")
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- response_body
-thread created: running
-killed
-
---- no_error_log
-[error]
-[alert]
-lua tcp socket abort resolver
---- error_log
-
-
-
-=== TEST 8: kill a thread already terminated
---- config
- location = /t {
- content_by_lua '
- local function f()
- return
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
-
- collectgarbage()
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.say("failed to kill thread: ", err)
- return
- end
-
- ngx.say("killed")
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- response_body
-thread created: zombie
-failed to kill thread: already terminated
-
---- no_error_log
-[error]
-[alert]
-lua tcp socket abort resolver
---- error_log
-
-
-
-=== TEST 9: kill self
---- config
- location = /t {
- content_by_lua '
- local ok, err = ngx.thread.kill(coroutine.running())
- if not ok then
- ngx.say("failed to kill main thread: ", err)
- else
- ngx.say("killed main thread.")
- end
-
- local function f()
- local ok, err = ngx.thread.kill(coroutine.running())
- if not ok then
- ngx.say("failed to kill user thread: ", err)
- else
- ngx.say("user thread thread.")
- end
-
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.say("failed to spawn thread: ", err)
- return
- end
-
- ngx.say("thread created: ", coroutine.status(t))
- ';
- }
---- request
-GET /t
---- stap2 eval: $::StapScript
---- response_body
-failed to kill main thread: not user thread
-failed to kill user thread: killer not parent
-thread created: zombie
-
---- no_error_log
-[error]
-[alert]
-lua tcp socket abort resolver
---- error_log
diff --git a/src/deps/src/lua-nginx-module/t/128-duplex-tcp-socket.t b/src/deps/src/lua-nginx-module/t/128-duplex-tcp-socket.t
deleted file mode 100644
index 511cc20bf..000000000
--- a/src/deps/src/lua-nginx-module/t/128-duplex-tcp-socket.t
+++ /dev/null
@@ -1,631 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 2);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-run_tests();
-
-__DATA__
-
-=== TEST 1: pipelined memcached requests (sent one byte at a time)
---- config
- server_tokens off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\nget foo\\r\\nget bar\\r\\n"
- -- req = "OK"
- local send_idx = 1
-
- local function writer()
- local sub = string.sub
- while send_idx <= #req do
- local bytes, err = sock:send(sub(req, send_idx, send_idx))
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- -- if send_idx % 2 == 0 then
- ngx.sleep(0.001)
- -- end
- send_idx = send_idx + 1
- end
- -- ngx.say("request sent.")
- end
-
- local ok, err = ngx.thread.spawn(writer)
- if not ok then
- ngx.say("failed to spawn writer thread: ", err)
- return
- end
-
- for i = 1, 3 do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:setkeepalive()
- ngx.say("setkeepalive: ", ok, " ", err)
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-received: OK
-received: END
-received: END
-setkeepalive: 1 nil
-
---- no_error_log
-[error]
-
-
-
-=== TEST 2: read timeout errors won't affect writing
---- config
- server_tokens off;
- lua_socket_log_errors off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\n"
- -- req = "OK"
- local send_idx = 1
-
- sock:settimeout(1)
-
- local function writer()
- local sub = string.sub
- while send_idx <= #req do
- local bytes, err = sock:send(sub(req, send_idx, send_idx))
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.sleep(0.001)
- send_idx = send_idx + 1
- end
- -- ngx.say("request sent.")
- end
-
- local ok, err = ngx.thread.spawn(writer)
- if not ok then
- ngx.say("failed to spawn writer thread: ", err)
- return
- end
-
- local data = ""
- local ntm = 0
- local done = false
- for i = 1, 300 do
- local line, err, part = sock:receive()
- if not line then
- if part then
- data = data .. part
- end
- if err ~= "timeout" then
- ngx.say("failed to receive: ", err)
- return
- end
-
- ntm = ntm + 1
-
- else
- data = data .. line
- ngx.say("received: ", data)
- done = true
- break
- end
- end
-
- if not done then
- ngx.say("partial read: ", data)
- end
-
- ngx.say("read timed out: ", ntm)
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
---- request
-GET /t
---- response_body_like chop
-^connected: 1
-(?:received: OK|failed to send request: timeout
-partial read: )
-read timed out: [1-9]\d*
-close: 1 nil$
-
---- no_error_log
-[error]
-
-
-
-=== TEST 3: writes are rejected while reads are not
---- config
- server_tokens off;
- lua_socket_log_errors off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_RAND_PORT_1;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\n"
- -- req = "OK"
- local send_idx = 1
-
- local function writer()
- local sub = string.sub
- while send_idx <= #req do
- local bytes, err = sock:send(sub(req, send_idx, send_idx))
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- ngx.sleep(0.001)
- send_idx = send_idx + 1
- end
- -- ngx.say("request sent.")
- end
-
- local ok, err = ngx.thread.spawn(writer)
- if not ok then
- ngx.say("failed to spawn writer thread: ", err)
- return
- end
-
- local data = ""
- local ntm = 0
- local done = false
- for i = 1, 3 do
- local res, err, part = sock:receive(1)
- if not res then
- ngx.say("failed to receive: ", err)
- return
- else
- data = data .. res
- end
- ngx.sleep(0.001)
- end
-
- ngx.say("received: ", data)
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
---- request
-GET /t
---- response_body_like chop
-^connected: 1
-received: OK!
-close: (?:nil socket busy writing|1 nil
-failed to send request: closed)$
-
---- tcp_listen: $TEST_NGINX_RAND_PORT_1
---- tcp_shutdown: 0
---- tcp_reply: OK!
---- tcp_no_close: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 4: reads are rejected while writes are not
---- config
- server_tokens off;
- lua_socket_log_errors off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_RAND_PORT_1;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "flush_all\\r\\n"
- -- req = "OK"
- local send_idx = 1
-
- local function writer()
- local sub = string.sub
- while send_idx <= #req do
- local bytes, err = sock:send(sub(req, send_idx, send_idx))
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
- -- ngx.say("sent: ", bytes)
- ngx.sleep(0.001)
- send_idx = send_idx + 1
- end
- ngx.say("request sent.")
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end
-
- local ok, err = ngx.thread.spawn(writer)
- if not ok then
- ngx.say("failed to spawn writer thread: ", err)
- return
- end
-
- local data = ""
- local ntm = 0
- local aborted = false
- for i = 1, 3 do
- if not aborted then
- local res, err, part = sock:receive(1)
- if not res then
- ngx.say("failed to receive: ", err)
- aborted = true
- else
- data = data .. res
- end
- end
-
- ngx.sleep(0.001)
- end
-
- if not aborted then
- ngx.say("received: ", data)
- end
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to receive: closed
-request sent.
-close: 1 nil
-
---- stap2
-F(ngx_http_lua_socket_tcp_finalize_write_part) {
- print_ubacktrace()
-}
---- stap_out2
---- tcp_listen: $TEST_NGINX_RAND_PORT_1
---- tcp_shutdown: 1
---- tcp_query eval: "flush_all\r\n"
---- tcp_query_len: 11
---- no_error_log
-[error]
---- wait: 0.05
-
-
-
-=== TEST 5: concurrent socket operations while connecting
---- config
- server_tokens off;
- lua_socket_log_errors off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
-
- local function f()
- ngx.sleep(0.001)
- local res, err = sock:receive(1)
- ngx.say("receive: ", res, " ", err)
-
- local bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
-
- local ok, err = sock:getreusedtimes()
- ngx.say("getreusedtimes: ", ok, " ", err)
-
- local ok, err = sock:setkeepalive()
- ngx.say("setkeepalive: ", ok, " ", err)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- ngx.say("connect: ", ok, " ", err)
- end
-
- local ok, err = ngx.thread.spawn(f)
- if not ok then
- ngx.say("failed to spawn writer thread: ", err)
- return
- end
-
- sock:settimeout(300)
- local ok, err = sock:connect("127.0.0.2", 12345)
- ngx.say("connect: ", ok, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
---- request
-GET /t
---- response_body
-receive: nil socket busy connecting
-send: nil socket busy connecting
-close: nil socket busy connecting
-getreusedtimes: 0 nil
-setkeepalive: nil socket busy connecting
-connect: nil socket busy connecting
-connect: nil timeout
-close: nil closed
-
---- no_error_log
-[error]
-
-
-
-=== TEST 6: concurrent operations while resolving
---- config
- server_tokens off;
- lua_socket_log_errors off;
- resolver 127.0.0.2:12345;
- resolver_timeout 300ms;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
-
- local function f()
- ngx.sleep(0.001)
- local res, err = sock:receive(1)
- ngx.say("receive: ", res, " ", err)
-
- local bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
-
- local ok, err = sock:getreusedtimes()
- ngx.say("getreusedtimes: ", ok, " ", err)
-
- local ok, err = sock:setkeepalive()
- ngx.say("setkeepalive: ", ok, " ", err)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- ngx.say("connect: ", ok, " ", err)
- end
-
- local ok, err = ngx.thread.spawn(f)
- if not ok then
- ngx.say("failed to spawn writer thread: ", err)
- return
- end
-
- sock:settimeout(300)
- local ok, err = sock:connect("some2.agentzh.org", 80)
- ngx.say("connect: ", ok, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
---- request
-GET /t
---- response_body
-receive: nil closed
-send: nil closed
-close: nil closed
-getreusedtimes: nil closed
-setkeepalive: nil closed
-connect: nil socket busy connecting
-connect: nil some2.agentzh.org could not be resolved (110: Operation timed out)
-close: nil closed
-
---- no_error_log
-[error]
-
-
-
-=== TEST 7: concurrent operations while reading (receive)
---- config
- server_tokens off;
- lua_socket_log_errors off;
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- local ready = false
-
- local function f()
- while not ready do
- ngx.sleep(0.001)
- end
-
- local res, err = sock:receive(1)
- ngx.say("receive: ", res, " ", err)
-
- local bytes, err = sock:send("flush_all")
- ngx.say("send: ", bytes, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
-
- local ok, err = sock:getreusedtimes()
- ngx.say("getreusedtimes: ", ok, " ", err)
-
- local ok, err = sock:setkeepalive()
- ngx.say("setkeepalive: ", ok, " ", err)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- ngx.say("connect: ", ok, " ", err)
- end
-
- local ok, err = ngx.thread.spawn(f)
- if not ok then
- ngx.say("failed to spawn writer thread: ", err)
- return
- end
-
- sock:settimeout(300)
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- ngx.say("connect: ", ok, " ", err)
-
- ready = true
-
- local res, err = sock:receive(1)
- ngx.say("receive: ", res, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
---- request
-GET /t
---- response_body
-connect: 1 nil
-receive: nil socket busy reading
-send: 9 nil
-close: nil socket busy reading
-getreusedtimes: 0 nil
-setkeepalive: nil socket busy reading
-connect: nil socket busy reading
-receive: nil timeout
-close: 1 nil
-
---- no_error_log
-[error]
-
-
-
-=== TEST 8: concurrent operations while reading (receiveuntil)
---- config
- server_tokens off;
- lua_socket_log_errors off;
- location /t {
- content_by_lua '
- local ready = false
- local sock = ngx.socket.tcp()
-
- local function f()
- while not ready do
- ngx.sleep(0.001)
- end
-
- local res, err = sock:receive(1)
- ngx.say("receive: ", res, " ", err)
-
- local bytes, err = sock:send("flush_all")
- ngx.say("send: ", bytes, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
-
- local ok, err = sock:getreusedtimes()
- ngx.say("getreusedtimes: ", ok, " ", err)
-
- local ok, err = sock:setkeepalive()
- ngx.say("setkeepalive: ", ok, " ", err)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- ngx.say("connect: ", ok, " ", err)
- end
-
- local ok, err = ngx.thread.spawn(f)
- if not ok then
- ngx.say("failed to spawn writer thread: ", err)
- return
- end
-
- sock:settimeout(300)
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- ngx.say("connect: ", ok, " ", err)
-
- ready = true
-
- local it, err = sock:receiveuntil("\\r\\n")
- if not it then
- ngx.say("receiveuntil() failed: ", err)
- return
- end
-
- local res, err = it()
- ngx.say("receiveuntil() iterator: ", res, " ", err)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- ';
- }
-
---- request
-GET /t
---- response_body
-connect: 1 nil
-receive: nil socket busy reading
-send: 9 nil
-close: nil socket busy reading
-getreusedtimes: 0 nil
-setkeepalive: nil socket busy reading
-connect: nil socket busy reading
-receiveuntil() iterator: nil timeout
-close: 1 nil
-
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/129-ssl-socket.t b/src/deps/src/lua-nginx-module/t/129-ssl-socket.t
deleted file mode 100644
index ca8d5a49e..000000000
--- a/src/deps/src/lua-nginx-module/t/129-ssl-socket.t
+++ /dev/null
@@ -1,2946 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-BEGIN {
- if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- # FIXME: we still need to enable this test file for HTTP3.
- $SkipReason = "the test cases are very unstable, skip for now.";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-use Cwd qw(abs_path realpath);
-use File::Basename;
-
-repeat_each(2);
-
-sub resolve($$);
-
-plan tests => repeat_each() * (blocks() * 7 - 4);
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_SERVER_SSL_PORT} ||= 12345;
-$ENV{TEST_NGINX_CERT_DIR} ||= dirname(realpath(abs_path(__FILE__)));
-$ENV{TEST_NGINX_OPENRESTY_ORG_IP} ||= resolve("openresty.org", $ENV{TEST_NGINX_RESOLVER});
-
-my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
-my $openssl_version = eval { `$NginxBinary -V 2>&1` };
-if ($openssl_version =~ m/BoringSSL/) {
- $ENV{TEST_NGINX_USE_BORINGSSL} = 1;
-}
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-
-sub read_file {
- my $infile = shift;
- open my $in, $infile
- or die "cannot open $infile for reading: $!";
- my $cert = do { local $/; <$in> };
- close $in;
- $cert;
-}
-
-sub resolve ($$) {
- my ($domain, $resolver) = @_;
- my $ips = qx/dig \@$resolver +short $domain/;
-
- my $exit_code = $? >> 8;
- if (!$ips || $exit_code != 0) {
- die "failed to resolve '$domain' using '$resolver' as resolver";
- }
-
- my ($ip) = split /\n/, $ips;
- return $ip;
-}
-
-our $DSTRootCertificate = read_file("t/cert/dst-ca.crt");
-our $EquifaxRootCertificate = read_file("t/cert/equifax.crt");
-our $TestCertificate = read_file("t/cert/test.crt");
-our $TestCertificateKey = read_file("t/cert/test.key");
-our $TestCRL = read_file("t/cert/test.crl");
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: www.google.com
-access the public network is unstable, need a bigger timeout value.
---- quic_max_idle_timeout: 3
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- -- avoid flushing bing in "check leak" testing mode:
- local counter = package.loaded.counter
- if not counter then
- counter = 1
- elseif counter >= 2 then
- return ngx.exit(503)
- else
- counter = counter + 1
- end
- package.loaded.counter = counter
-
- do
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
- local ok, err = sock:connect("www.google.com", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake()
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET / HTTP/1.1\\r\\nHost: www.google.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body_like chop
-\Aconnected: 1
-ssl handshake: cdata
-sent http request: 59 bytes.
-received: HTTP/1.1 (?:200 OK|302 Found)
-close: 1 nil
-\z
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- no_error_log
-lua ssl server name:
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 2: no SNI, no verify
---- http_config
- server {
- listen $TEST_NGINX_SERVER_SSL_PORT ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- location / {
- content_by_lua_block {
- ngx.exit(201)
- }
- }
- }
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_SSL_PORT)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake()
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 53 bytes.
-received: HTTP/1.1 201 Created
-close: 1 nil
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- no_error_log
-lua ssl server name:
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 3: SNI, no verify
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\r\nHost: openresty.org\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 58 bytes.
-received: HTTP/1.1 302 Moved Temporarily
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- error_log
-lua ssl server name: "openresty.org"
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 4: ssl session reuse
-access the public network is unstable, need a bigger timeout value.
---- quic_max_idle_timeout: 3
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_protocols TLSv1.2;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(7000)
-
- do
-
- local session
- for i = 1, 2 do
- local ok, err = sock:connect("agentzh.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- session, err = sock:sslhandshake(session, "agentzh.org")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\\r\\nHost: agentzh.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end
-
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 200 OK
-close: 1 nil
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 200 OK
-close: 1 nil
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl set session: \1
-lua ssl save session: \1
-lua ssl free session: \1
-lua ssl free session: \1
-$/
-
---- error_log
-SSL reused session
-lua ssl free session
-
---- log_level: debug
---- no_error_log
-[error]
-[alert]
---- timeout: 10
-
-
-
-=== TEST 5: certificate does not match host name (verify)
-The certificate of "openresty.org" does not contain the name "blah.openresty.org".
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_ssl_verify_depth 5;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "blah.openresty.org", true)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- else
- ngx.say("ssl handshake: ", type(session))
- end
-
- local req = "GET / HTTP/1.1\\r\\nHost: openresty.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- user_files eval
-">>> trusted.crt
-$::DSTRootCertificate"
-
---- request
-GET /t
---- response_body_like chomp
-\Aconnected: 1
-failed to do SSL handshake: (?:handshake failed|certificate host mismatch)
-failed to send http request: closed
-\z
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log
-lua ssl server name: "blah.openresty.org"
---- no_error_log
-SSL reused session
-[alert]
---- timeout: 5
-
-
-
-=== TEST 6: certificate does not match host name (verify, no log socket errors)
-The certificate for "openresty.org" does not contain the name "blah.openresty.org".
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_socket_log_errors off;
- lua_ssl_verify_depth 2;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "blah.openresty.org", true)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- else
- ngx.say("ssl handshake: ", type(session))
- end
-
- local req = "GET / HTTP/1.1\\r\\nHost: blah.openresty.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- user_files eval
-">>> trusted.crt
-$::DSTRootCertificate"
-
---- request
-GET /t
---- response_body_like chomp
-\Aconnected: 1
-failed to do SSL handshake: (?:handshake failed|certificate host mismatch)
-failed to send http request: closed
-\z
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log
-lua ssl server name: "blah.openresty.org"
---- no_error_log
-lua ssl certificate does not match host
-SSL reused session
-[alert]
---- timeout: 5
-
-
-
-=== TEST 7: certificate does not match host name (no verify)
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(4000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org", false)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET /en/linux-packages.html HTTP/1.1\\r\\nHost: openresty.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 80 bytes.
-received: HTTP/1.1 404 Not Found
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
-
---- error_log
-lua ssl server name: "openresty.org"
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 8: openresty.org: passing SSL verify
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_ssl_verify_depth 2;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(4000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org", true)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\\r\\nHost: openresty.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- user_files eval
-">>> trusted.crt
-$::DSTRootCertificate"
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 58 bytes.
-received: HTTP/1.1 302 Moved Temporarily
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]++/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
-
---- error_log
-lua ssl server name: "openresty.org"
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 9: ssl verify depth not enough (with automatic error logging)
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_ssl_verify_depth 0;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org", true)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- else
- ngx.say("ssl handshake: ", type(session))
- end
-
- local req = "GET / HTTP/1.1\\r\\nHost: openresty.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- user_files eval
-">>> trusted.crt
-$::DSTRootCertificate"
-
---- request
-GET /t
---- response_body eval
-qr{connected: 1
-failed to do SSL handshake: (22: certificate chain too long|20: unable to get local issuer certificate|21: unable to verify the first certificate)
-failed to send http request: closed
-}
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log eval
-['lua ssl server name: "openresty.org"',
-qr/lua ssl certificate verify error: \((22: certificate chain too long|20: unable to get local issuer certificate|21: unable to verify the first certificate)\)/]
---- no_error_log
-SSL reused session
-[alert]
---- timeout: 5
-
-
-
-=== TEST 10: ssl verify depth not enough (without automatic error logging)
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_ssl_verify_depth 0;
- lua_socket_log_errors off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org", true)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- else
- ngx.say("ssl handshake: ", type(session))
- end
-
- local req = "GET / HTTP/1.1\\r\\nHost: openresty.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- user_files eval
-">>> trusted.crt
-$::DSTRootCertificate"
-
---- request
-GET /t
---- response_body eval
-qr/connected: 1
-failed to do SSL handshake: (22: certificate chain too long|20: unable to get local issuer certificate|21: unable to verify the first certificate)
-failed to send http request: closed
-/
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log
-lua ssl server name: "openresty.org"
---- no_error_log
-lua ssl certificate verify error
-SSL reused session
-[alert]
---- timeout: 7
-
-
-
-=== TEST 11: openresty.org: SSL verify enabled and no corresponding trusted certificates
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_ssl_verify_depth 2;
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(4000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org", true)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\r\nHost: openresty.org\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- }
- }
-
---- user_files eval
-">>> trusted.crt
-$::EquifaxRootCertificate"
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: 20: unable to get local issuer certificate
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log
-lua ssl server name: "openresty.org"
-lua ssl certificate verify error: (20: unable to get local issuer certificate)
---- no_error_log
-SSL reused session
-[alert]
---- timeout: 5
-
-
-
-=== TEST 12: openresty.org: passing SSL verify with multiple certificates
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_ssl_verify_depth 2;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(4000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org", true)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\\r\\nHost: openresty.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- user_files eval
-">>> trusted.crt
-$::EquifaxRootCertificate
-$::DSTRootCertificate"
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 58 bytes.
-received: HTTP/1.1 302 Moved Temporarily
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
-
---- error_log
-lua ssl server name: "openresty.org"
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 13: default cipher
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\\r\\nHost: openresty.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 58 bytes.
-received: HTTP/1.1 302 Moved Temporarily
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- error_log eval
-[
-'lua ssl server name: "openresty.org"',
-qr/SSL: TLSv1\.2, cipher: "(?:ECDHE-RSA-AES(?:256|128)-GCM-SHA(?:384|256)|ECDHE-(?:RSA|ECDSA)-CHACHA20-POLY1305) TLSv1\.2/,
-]
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 14: explicit cipher configuration
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_protocols TLSv1;
-
- location / {
- content_by_lua_block {
- ngx.exit(200)
- }
- }
- }
---- config
- server_tokens off;
- lua_ssl_ciphers ECDHE-RSA-AES256-SHA;
-
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "test.com")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\\r\\nHost: test.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 53 bytes.
-received: HTTP/1.1 200 OK
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- error_log eval
-['lua ssl server name: "test.com"',
-qr/SSL: TLSv\d(?:\.\d)?, cipher: "ECDHE-RSA-AES256-SHA (SSLv3|TLSv1)/]
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 10
-
-
-
-=== TEST 15: explicit ssl protocol configuration
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_protocols TLSv1;
-
- location / {
- content_by_lua_block {
- ngx.exit(200)
- }
- }
- }
---- config
- server_tokens off;
- lua_ssl_protocols TLSv1;
-
- location /t {
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "test.com")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\\r\\nHost: test.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 53 bytes.
-received: HTTP/1.1 200 OK
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- error_log eval
-['lua ssl server name: "test.com"',
-qr/SSL: TLSv1, cipher: "ECDHE-RSA-AES256-SHA (SSLv3|TLSv1)/]
---- no_error_log
-SSL reused session
-[error]
-[alert]
-
-
-
-=== TEST 16: unsupported ssl protocol
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_protocols SSLv2;
- lua_socket_log_errors off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- else
- ngx.say("ssl handshake: ", type(session))
- end
-
- local req = "GET / HTTP/1.1\\r\\nHost: openresty.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-failed to send http request: closed
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log eval
-[
-qr/\[(crit|error)\] .*?SSL_do_handshake\(\) failed .*?(unsupported protocol|no protocols available)/,
-'lua ssl server name: "openresty.org"',
-]
---- no_error_log
-SSL reused session
-[alert]
-[emerg]
---- timeout: 5
-
-
-
-=== TEST 17: openresty.org: passing SSL verify: keepalive (reuse the ssl session)
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_ssl_verify_depth 2;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
- set $openresty_org_ip $TEST_NGINX_OPENRESTY_ORG_IP;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
-
- local session
- for i = 1, 3 do
- -- Use the same IP to ensure that the connection can be reused
- local ok, err = sock:connect(ngx.var.openresty_org_ip, 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- session, err = sock:sslhandshake(session, "openresty.org", true)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local ok, err = sock:setkeepalive()
- ngx.say("set keepalive: ", ok, " ", err)
- end -- do
-
- end
- collectgarbage()
- ';
- }
-
---- user_files eval
-">>> trusted.crt
-$::DSTRootCertificate"
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-set keepalive: 1 nil
-connected: 1
-ssl handshake: cdata
-set keepalive: 1 nil
-connected: 1
-ssl handshake: cdata
-set keepalive: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: \1
-$/
-
---- error_log
-lua tcp socket get keepalive peer: using connection
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 18: openresty.org: passing SSL verify: keepalive (no reusing the ssl session)
-The session returned by SSL_get1_session maybe different.
-After function tls_process_new_session_ticket, the session saved in SSL->session
-will be replace by a new one.
-
-ngx_ssl_session_t *
-ngx_ssl_get_session(ngx_connection_t *c)
-{
-#ifdef TLS1_3_VERSION
- if (c->ssl->session) {
- SSL_SESSION_up_ref(c->ssl->session);
- return c->ssl->session;
- }
-#endif
-
- return SSL_get1_session(c->ssl->connection);
-}
-
-SSL_SESSION *SSL_get1_session(SSL *ssl)
-/* variant of SSL_get_session: caller really gets something */
-{
- SSL_SESSION *sess;
- /*
- * Need to lock this all up rather than just use CRYPTO_add so that
- * somebody doesn't free ssl->session between when we check it's non-null
- * and when we up the reference count.
- */
- CRYPTO_THREAD_read_lock(ssl->lock);
- sess = ssl->session;
- if (sess)
- SSL_SESSION_up_ref(sess);
- CRYPTO_THREAD_unlock(ssl->lock);
- return sess;
-}
-
-#0 tls_process_new_session_ticket (s=0x7e6ea0, pkt=0x7fffffffc820) at ssl/statem/statem_clnt.c:2650
-#1 0x00007ffff7af50fd in read_state_machine (s=0x7e6ea0) at ssl/statem/statem.c:636
-#2 state_machine (s=0x7e6ea0, server=0) at ssl/statem/statem.c:434
-#3 0x00007ffff7aca6b3 in ssl3_read_bytes (s=, type=23, recvd_type=0x0, buf=0x7fffffffc9d7 "\027\320\355t", len=1,
- peek=0, readbytes=0x7fffffffc978) at ssl/record/rec_layer_s3.c:1677
-#4 0x00007ffff7ad2250 in ssl3_read_internal (readbytes=0x7fffffffc978, peek=0, len=1, buf=0x7fffffffc9d7, s=0x7e6ea0)
- at ssl/s3_lib.c:4477
-#5 ssl3_read (s=0x7e6ea0, buf=0x7fffffffc9d7, len=1, readbytes=0x7fffffffc978) at ssl/s3_lib.c:4500
-#6 0x00007ffff7ade695 in SSL_read (s=, buf=buf@entry=0x7fffffffc9d7, num=num@entry=1) at ssl/ssl_lib.c:1799
-#7 0x000000000045a965 in ngx_ssl_recv (c=0x72c3b0, buf=0x7fffffffc9d7 "\027\320\355t", size=1)
- at src/event/ngx_event_openssl.c:2337
-#8 0x0000000000533b17 in ngx_http_lua_socket_keepalive_close_handler (ev=0x7e2f20)
- at /var/code/openresty/lua-nginx-module/src/ngx_http_lua_socket_tcp.c:5753
-#9 0x000000000052cf40 in ngx_http_lua_socket_tcp_setkeepalive (L=0x74edd0)
- at /var/code/openresty/lua-nginx-module/src/ngx_http_lua_socket_tcp.c:5602
-#10 0x00007ffff7f0fabe in lj_BC_FUNCC ()
- from /tmp/undodb.72729.1722915526.2470007.80d50d088e818fd4/debuggee-1-zwqz8svp/symbol-files/opt/luajit-sysm/lib/libluajit-5.1.so.2
-#11 0x000000000051f2b2 in ngx_http_lua_run_thread (L=L@entry=0x767670, r=r@entry=0x7edf80, ctx=ctx@entry=0x750e40, nrets=0)
- at /var/code/openresty/lua-nginx-module/src/ngx_http_lua_util.c:1194
-#12 0x0000000000524347 in ngx_http_lua_content_by_chunk (L=0x767670, r=0x7edf80)
- at /var/code/openresty/lua-nginx-module/src/ngx_http_lua_contentby.c:124
-#13 0x000000000047c663 in ngx_http_core_content_phase (r=0x7edf80, ph=0x7b4470) at src/http/ngx_http_core_module.c:1271
-#14 0x000000000047b80d in ngx_http_core_run_phases (r=0x7edf80) at src/http/ngx_http_core_module.c:885
-#15 ngx_http_handler (r=r@entry=0x7edf80) at src/http/ngx_http_core_module.c:868
-#16 0x00000000004854ad in ngx_http_process_request (r=r@entry=0x7edf80) at src/http/ngx_http_request.c:2140
-#17 0x00000000004868e8 in ngx_http_process_request_headers (rev=rev@entry=0x7e2f80) at src/http/ngx_http_request.c:1529
-#18 0x0000000000486468 in ngx_http_process_request_line (rev=0x7e2f80) at src/http/ngx_http_request.c:1196
-#19 0x000000000044b338 in ngx_event_process_posted (cycle=cycle@entry=0x721690, posted=0x62f250 )
- at src/event/ngx_event_posted.c:35
-#20 0x000000000044a522 in ngx_process_events_and_timers (cycle=cycle@entry=0x721690) at src/event/ngx_event.c:273
-#21 0x0000000000453819 in ngx_single_process_cycle (cycle=cycle@entry=0x721690) at src/os/unix/ngx_process_cycle.c:323
-#22 0x0000000000429dee in main (argc=argc@entry=5, argv=argv@entry=0x7fffffffd1a8) at src/core/nginx.c:384
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_ssl_verify_depth 2;
- location /t {
- #set $port 5000;
- set $openresty_org_ip $TEST_NGINX_OPENRESTY_ORG_IP;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
-
- for i = 1, 3 do
- -- Use the same IP to ensure that the connection can be reused
- local ok, err = sock:connect(ngx.var.openresty_org_ip, 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "openresty.org", true)
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local ok, err = sock:setkeepalive()
- ngx.say("set keepalive: ", ok, " ", err)
- end -- do
-
- end
- collectgarbage()
- ';
- }
-
---- user_files eval
-">>> trusted.crt
-$::DSTRootCertificate"
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-set keepalive: 1 nil
-connected: 1
-ssl handshake: cdata
-set keepalive: 1 nil
-connected: 1
-ssl handshake: cdata
-set keepalive: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl save session: ([0-9A-F]+)
-lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
-
---- error_log
-lua tcp socket get keepalive peer: using connection
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 19: downstream cosockets do not support ssl handshake
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/trusted.crt;
- lua_ssl_verify_depth 2;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.req.socket()
- local sess, err = sock:sslhandshake()
- if not sess then
- ngx.say("failed to do ssl handshake: ", err)
- else
- ngx.say("ssl handshake: ", type(sess))
- end
- ';
- }
-
---- user_files eval
-">>> trusted.crt
-$::DSTRootCertificate"
-
---- request
-POST /t
-hello world
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log
-attempt to call method 'sslhandshake' (a nil value)
---- no_error_log
-[alert]
---- timeout: 3
---- skip_eval: 5:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 20: unix domain ssl cosocket (no verify)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua 'ngx.status = 201 ngx.say("foo") ngx.exit(201)';
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- do
- local sock = ngx.socket.tcp()
- sock:settimeout(3000)
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake()
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: test.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- no_error_log
-lua ssl server name:
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 21: unix domain ssl cosocket (verify)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua 'ngx.status = 201 ngx.say("foo") ngx.exit(201)';
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/test.crt;
-
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- do
- local sock = ngx.socket.tcp()
- sock:settimeout(3000)
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: test.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- error_log
-lua ssl server name: "test.com"
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 22: unix domain ssl cosocket (no ssl on server)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- server_name test.com;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua 'ngx.status = 201 ngx.say("foo") ngx.exit(201)';
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake()
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: test.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- user_files eval
-">>> test.crt
-$::TestCertificate"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log eval
-qr/SSL_do_handshake\(\) failed .*?(unknown protocol|wrong version number)/
---- no_error_log
-lua ssl server name:
-SSL reused session
-[alert]
---- timeout: 3
-
-
-
-=== TEST 23: lua_ssl_crl
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua 'ngx.status = 201 ngx.say("foo") ngx.exit(201)';
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_crl ../html/test.crl;
- lua_ssl_trusted_certificate ../html/test.crt;
- lua_socket_log_errors off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(3000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- else
- ngx.say("ssl handshake: ", type(sess))
- end
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: test.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body eval
-# Since nginx version 1.19.1, invalidity date is considered a non-critical CRL
-# entry extension, in other words, revoke still works even if CRL has expired.
-$Test::Nginx::Util::NginxVersion >= 1.019001 ?
-
-"connected: 1
-failed to do SSL handshake: 23: certificate revoked
-failed to send http request: closed\n" :
-
-"connected: 1
-failed to do SSL handshake: 12: CRL has expired
-failed to send http request: closed\n";
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate
->>> test.crl
-$::TestCRL"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log
-lua ssl server name: "test.com"
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 24: multiple handshake calls
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- for i = 1, 2 do
- local session, err = sock:sslhandshake(nil, "openresty.org")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
- end
-
- local req = "GET / HTTP/1.1\\r\\nHost: openresty.org\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-ssl handshake: cdata
-sent http request: 58 bytes.
-received: HTTP/1.1 302 Moved Temporarily
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- error_log
-lua ssl server name: "openresty.org"
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 25: handshake timed out
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:settimeout(1); -- should timeout immediately
- local session, err = sock:sslhandshake(nil, "openresty.org")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: timeout
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 26: unix domain ssl cosocket (no gen session)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua 'ngx.status = 201 ngx.say("foo") ngx.exit(201)';
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- do
- local sock = ngx.socket.tcp()
- sock:settimeout(3000)
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", sess)
-
- sock:close()
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: true
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- no_error_log
-lua ssl server name:
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 27: unix domain ssl cosocket (gen session, true)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua 'ngx.status = 201 ngx.say("foo") ngx.exit(201)';
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- do
- local sock = ngx.socket.tcp()
- sock:settimeout(3000)
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- sock:close()
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- no_error_log
-lua ssl server name:
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 28: unix domain ssl cosocket (keepalive)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua 'ngx.status = 201 ngx.say("foo") ngx.exit(201)';
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- local sock = ngx.socket.tcp()
- sock:settimeout(3000)
- for i = 1, 2 do
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", sess)
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set keepalive: ", err)
- return
- end
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: true
-connected: 1
-ssl handshake: true
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- no_error_log
-lua ssl server name:
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 29: unix domain ssl cosocket (verify cert but no host name check, passed)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua 'ngx.status = 201 ngx.say("foo") ngx.exit(201)';
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate ../html/test.crt;
-
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- do
- local sock = ngx.socket.tcp()
- sock:settimeout(3000)
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, nil, true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: test.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- error_log
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 30: unix domain ssl cosocket (verify cert but no host name check, NOT passed)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua 'ngx.status = 201 ngx.say("foo") ngx.exit(201)';
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- #lua_ssl_trusted_certificate ../html/test.crt;
-
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua '
- do
- local sock = ngx.socket.tcp()
- sock:settimeout(3000)
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, nil, true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\\r\\nHost: test.com\\r\\nConnection: close\\r\\n\\r\\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- ';
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: 18: self signed certificate
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
-
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log
-lua ssl certificate verify error: (18: self signed certificate)
---- no_error_log
-SSL reused session
-[alert]
---- timeout: 5
-
-
-
-=== TEST 31: handshake, too few arguments
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(7000)
-
- local ok, err = sock:connect("openresty.org", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock.sslhandshake()
- }
- }
-
---- request
-GET /t
---- ignore_response
---- error_log eval
-qr/\[error\] .* ngx.socket sslhandshake: expecting 1 ~ 5 arguments \(including the object\), but seen 0/
---- no_error_log
-[alert]
---- timeout: 10
---- curl_error eval
-qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
-
-
-
-=== TEST 32: default cipher -TLSv1.3
---- skip_openssl: 8: < 1.1.1
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_protocols TLSv1.3;
-
- location / {
- content_by_lua_block {
- ngx.exit(200)
- }
- }
- }
---- config
- server_tokens off;
- lua_ssl_protocols TLSv1.3;
-
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "test.com")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 53 bytes.
-received: HTTP/1.1 200 OK
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- error_log eval
-['lua ssl server name: "test.com"',
-qr/SSL: TLSv1.3, cipher: "TLS_AES_256_GCM_SHA384 TLSv1.3/]
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 10
-
-
-
-=== TEST 33: explicit cipher configuration - TLSv1.3
---- skip_openssl: 8: < 1.1.1
---- skip_nginx: 8: < 1.19.4
---- skip_eval: 8:$ENV{TEST_NGINX_USE_BORINGSSL}
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_protocols TLSv1.3;
-
- location / {
- content_by_lua_block {
- ngx.exit(200)
- }
- }
- }
---- config
- server_tokens off;
- lua_ssl_protocols TLSv1.3;
- lua_ssl_conf_command Ciphersuites TLS_AES_128_GCM_SHA256;
-
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "test.com")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 53 bytes.
-received: HTTP/1.1 200 OK
-close: 1 nil
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- error_log eval
-['lua ssl server name: "test.com"',
-qr/SSL: TLSv1.3, cipher: "TLS_AES_128_GCM_SHA256 TLSv1.3/]
---- no_error_log
-SSL reused session
-[error]
-[alert]
---- timeout: 10
-
-
-
-=== TEST 34: explicit cipher configuration not in the default list - TLSv1.3
---- skip_openssl: 8: < 1.1.1
---- skip_nginx: 8: < 1.19.4
---- skip_eval: 8:$ENV{TEST_NGINX_USE_BORINGSSL}
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_protocols TLSv1.3;
-
- location / {
- content_by_lua_block {
- ngx.exit(200)
- }
- }
- }
---- config
- server_tokens off;
- lua_ssl_protocols TLSv1.3;
- lua_ssl_conf_command Ciphersuites TLS_AES_128_CCM_SHA256;
-
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- do
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local session, err = sock:sslhandshake(nil, "test.com")
- if not session then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(session))
-
- local req = "GET / HTTP/1.1\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- log_level: debug
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out
---- error_log eval
-[
-qr/\[info\] .*?SSL_do_handshake\(\) failed .*?no shared cipher/,
-'lua ssl server name: "test.com"',
-]
---- no_error_log
-SSL reused session
-[alert]
-[emerg]
---- timeout: 10
diff --git a/src/deps/src/lua-nginx-module/t/130-internal-api.t b/src/deps/src/lua-nginx-module/t/130-internal-api.t
deleted file mode 100644
index 2158e878b..000000000
--- a/src/deps/src/lua-nginx-module/t/130-internal-api.t
+++ /dev/null
@@ -1,40 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * blocks() * 3;
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: req
---- config
- location = /t {
- content_by_lua '
- local ffi = require "ffi"
- local function tonum(ud)
- return tonumber(ffi.cast("uintptr_t", ud))
- end
- ngx.say(string.format("content req=%#x", tonum(exdata())))
- ';
- }
---- request
-GET /t
-
---- response_body_like chop
-^content req=0x[a-f0-9]{4,}
-$
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/131-duplex-req-socket.t b/src/deps/src/lua-nginx-module/t/131-duplex-req-socket.t
deleted file mode 100644
index f88649b8d..000000000
--- a/src/deps/src/lua-nginx-module/t/131-duplex-req-socket.t
+++ /dev/null
@@ -1,147 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if (!defined $ENV{LD_PRELOAD}) {
- $ENV{LD_PRELOAD} = '';
- }
-
- if ($ENV{LD_PRELOAD} !~ /\bmockeagain\.so\b/) {
- $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}";
- }
-
- if ($ENV{MOCKEAGAIN} eq 'r') {
- $ENV{MOCKEAGAIN} = 'rw';
-
- } else {
- $ENV{MOCKEAGAIN} = 'w';
- }
-
- $ENV{TEST_NGINX_EVENT_TYPE} = 'poll';
- $ENV{MOCKEAGAIN_WRITE_TIMEOUT_PATTERN} = 'slow';
-
- if ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "http3 does not support ngx.req.socket()";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: raw downstream cosocket used in two different threads. See issue #481
---- config
- lua_socket_read_timeout 1ms;
- lua_socket_send_timeout 1s;
- lua_socket_log_errors off;
-
- location /t {
- content_by_lua '
- local function reader(req_socket)
- -- First we receive in a blocking fashion so that ctx->downstream_co_ctx will be changed
- local data, err, partial = req_socket:receive(1)
- if err ~= "timeout" then
- ngx.log(ngx.ERR, "Did not get timeout in the receiving thread!")
- return
- end
-
- -- Now, sleep so that coctx->data is changed to sleep handler
- ngx.sleep(1)
- end
-
- local function writer(req_socket)
- -- send in a slow manner with a low timeout, so that the timeout handler will be
- local bytes, err = req_socket:send("slow!!!")
- if err ~= "timeout" then
- return error("Did not get timeout in the sending thread!")
- end
- end
-
- local req_socket, err = ngx.req.socket(true)
- if req_socket == nil then
- ngx.status = 500
- return error("Unable to get request socket:" .. (err or "nil"))
- end
-
- local writer_thread = ngx.thread.spawn(writer, req_socket)
- local reader_thread = ngx.thread.spawn(reader, req_socket)
-
- ngx.thread.wait(writer_thread)
- ngx.thread.wait(reader_thread)
- print("The two threads finished")
-';
- }
---- request
-POST /t
---- more_headers
-Content-Length: 1
---- no_error_log
-[error]
---- error_log: The two threads finished
---- wait: 0.1
---- ignore_response
---- timeout: 10
-
-
-
-=== TEST 2: normal downstream cosocket used in two different threads. See issue #481
---- config
- lua_socket_read_timeout 1ms;
- lua_socket_send_timeout 1s;
- lua_socket_log_errors off;
- send_timeout 1s;
-
- location /t {
- content_by_lua '
- local function reader(req_socket)
- -- First we receive in a blocking fashion so that ctx->downstream_co_ctx will be changed
- local data, err, partial = req_socket:receive(1)
- if err ~= "timeout" then
- ngx.log(ngx.ERR, "Did not get timeout in the receiving thread!")
- return
- end
-
- -- Now, sleep so that coctx->data is changed to sleep handler
- ngx.sleep(1)
- end
-
- local function writer(req_socket)
- -- send in a slow manner with a low timeout, so that the timeout handler will be
- ngx.sleep(0.3)
- ngx.say("slow!!!")
- ngx.flush(true)
- end
-
- local req_socket, err = ngx.req.socket()
- if req_socket == nil then
- ngx.status = 500
- return error("Unable to get request socket:" .. (err or "nil"))
- end
-
- local writer_thread = ngx.thread.spawn(writer, req_socket)
- local reader_thread = ngx.thread.spawn(reader, req_socket)
-
- ngx.thread.wait(writer_thread)
- ngx.thread.wait(reader_thread)
- print("The two threads finished")
-';
- }
---- request
-POST /t
---- more_headers
-Content-Length: 1
---- no_error_log
-[error]
---- error_log: The two threads finished
---- wait: 0.1
---- ignore_response
---- timeout: 10
diff --git a/src/deps/src/lua-nginx-module/t/132-lua-blocks.t b/src/deps/src/lua-nginx-module/t/132-lua-blocks.t
deleted file mode 100644
index 35638a848..000000000
--- a/src/deps/src/lua-nginx-module/t/132-lua-blocks.t
+++ /dev/null
@@ -1,644 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3 + 3);
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: content_by_lua_block (simplest)
---- config
- location = /t {
- content_by_lua_block {
- ngx.say("hello, world")
- }
- }
---- request
-GET /t
---- response_body
-hello, world
---- no_error_log
-[error]
-
-
-
-=== TEST 2: content_by_lua_block (nested curly braces)
---- config
- location = /t {
- content_by_lua_block {
- local a = {
- dogs = {32, 78, 96},
- cat = "kitty",
- }
- ngx.say("a.dogs[1] = ", a.dogs[1])
- ngx.say("a.dogs[2] = ", a.dogs[2])
- ngx.say("a.dogs[3] = ", a.dogs[3])
- ngx.say("a.cat = ", a.cat)
- }
- }
---- request
-GET /t
---- response_body
-a.dogs[1] = 32
-a.dogs[2] = 78
-a.dogs[3] = 96
-a.cat = kitty
-
---- no_error_log
-[error]
-
-
-
-=== TEST 3: content_by_lua_block (curly braces in strings)
---- config
- location = /t {
- content_by_lua_block {
- ngx.say("}1, 2)")
- ngx.say('{1, 2)')
- }
- }
---- request
-GET /t
---- response_body
-}1, 2)
-{1, 2)
-
---- no_error_log
-[error]
-
-
-
-=== TEST 4: content_by_lua_block (curly braces in strings, with escaped terminators)
---- config
- location = /t {
- content_by_lua_block {
- ngx.say("\"}1, 2)")
- ngx.say('\'{1, 2)')
- }
- }
---- request
-GET /t
---- response_body
-"}1, 2)
-'{1, 2)
-
---- no_error_log
-[error]
-
-
-
-=== TEST 5: content_by_lua_block (curly braces in long brackets)
---- config
- location = /t {
- content_by_lua_block {
- --[[
- {{{
-
- }
- ]]
- --[==[
- }}}
-
- {
- ]==]
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 6: content_by_lua_block ("nested" long brackets)
---- config
- location = /t {
- content_by_lua_block {
- --[[
- ]=]
- ' "
- }
- ]]
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 7: content_by_lua_block (curly braces in line comments)
---- config
- location = /t {
- content_by_lua_block {
- --}} {}
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- no_error_log
-[error]
-
-
-
-=== TEST 8: content_by_lua_block (cosockets)
---- no_http2
---- config
- server_tokens off;
- location = /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect('127.0.0.1', tonumber(ngx.var.server_port))
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say('connected: ', ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
- -- req = "OK"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent: ", bytes)
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
-
- location /foo {
- content_by_lua_block { ngx.say("foo") }
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 57
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-failed to receive a line: closed []
-close: 1 nil
---- no_error_log
-[error]
-
-
-
-=== TEST 9: all in one
---- http_config
- init_by_lua_block {
- glob = "init by lua }here{"
- }
-
- init_worker_by_lua_block {
- glob = glob .. ", init worker }here{"
- }
---- config
- location = /t {
- set $a '';
- rewrite_by_lua_block {
- local s = ngx.var.a
- s = s .. "}rewrite{\n"
- ngx.var.a = s
- }
- access_by_lua_block {
- local s = ngx.var.a
- s = s .. '}access{\n'
- ngx.var.a = s
- }
- content_by_lua_block {
- local s = ngx.var.a
- s = s .. [[}content{]]
- ngx.say(s)
- ngx.say("glob: ", glob)
- }
- log_by_lua_block {
- print("log by lua running \"}{!\"")
- }
- header_filter_by_lua_block {
- ngx.header["Foo"] = "\"Hello, world\""
- ngx.header["Content-Length"] = nil
- }
- body_filter_by_lua_block {
- local data, eof = ngx.arg[1], ngx.arg[2]
- print("eof = ", eof)
- if eof then
- if not data then
- data = ""
- end
- data = data .. "}body filter{\n"
- print("data: ", data)
- ngx.arg[1] = data
- end
- }
- }
---- request
-GET /t
---- response_body
-}rewrite{
-}access{
-}content{
-glob: init by lua }here{, init worker }here{
-}body filter{
-
---- response_headers
-Foo: "Hello, world"
---- error_log
-log by lua running "}{!"
---- no_error_log
-[error]
-
-
-
-=== TEST 10: missing ]] (string)
---- config
- location = /t {
- content_by_lua_block {
- ngx.say([[hello, world")
- }
- }
---- request
-GET /t
---- response_body
-hello, world
---- no_error_log
-[error]
---- must_die
---- error_log eval
-qr/\[emerg\] .*? Lua code block missing the closing long bracket "]]", the inlined Lua code may be too long in .*?\bnginx\.conf:\d+/
-
-
-
-=== TEST 11: missing ]==] (string)
---- config
- location = /t {
- content_by_lua_block {
- ngx.say([==[hello, world")
- }
- }
---- request
-GET /t
---- response_body
-hello, world
---- no_error_log
-[error]
---- must_die
---- error_log eval
-qr/\[emerg\] .*? Lua code block missing the closing long bracket "]==]", the inlined Lua code may be too long in .*?\bnginx.conf:\d+/
-
-
-
-=== TEST 12: missing ]] (comment)
---- config
- location = /t {
- content_by_lua_block {
- ngx.say(--[[hello, world")
- }
- }
---- request
-GET /t
---- response_body
-hello, world
---- no_error_log
-[error]
---- must_die
---- error_log eval
-qr/\[emerg\] .*? Lua code block missing the closing long bracket "]]", the inlined Lua code may be too long in .*?\bnginx\.conf:\d+/
-
-
-
-=== TEST 13: missing ]=] (comment)
---- config
- location = /t {
- content_by_lua_block {
- ngx.say(--[=[hello, world")
- }
- }
---- request
-GET /t
---- response_body
-hello, world
---- no_error_log
-[error]
---- must_die
---- error_log eval
-qr/\[emerg\] .*? Lua code block missing the closing long bracket "]=]", the inlined Lua code may be too long in .*?\bnginx\.conf:\d+/
-
-
-
-=== TEST 14: missing }
-FIXME: we need better diagnostics by actually loading the inlined Lua code while parsing
-the *_by_lua_block directive.
-
---- config
- location = /t {
- content_by_lua_block {
- ngx.say("hello")
---- request
-GET /t
---- response_body
-hello, world
---- no_error_log
-[error]
---- error_log
-"events" directive is not allowed here
---- must_die
-
-
-
-=== TEST 15: content_by_lua_block (compact)
---- config
- location = /t {
- content_by_lua_block {ngx.say("hello, world", {"!"})}
- }
---- request
-GET /t
---- response_body
-hello, world!
---- no_error_log
-[error]
-
-
-
-=== TEST 16: content_by_lua_block unexpected closing long brackets must FAIL
---- config
- location = /t {
- content_by_lua_block {
- ]=]
- }
- }
---- request
-GET /t
---- error_code: 500
---- error_log eval
-qr{\[error\] .*? unexpected symbol near ']'}
-
-
-
-=== TEST 17: content_by_lua_block unexpected closing long brackets ignored (GitHub #748)
---- config
- location = /t {
- content_by_lua_block {
- local t1, t2 = {"hello world"}, {1}
- ngx.say(t1[t2[1]])
- }
- }
---- request
-GET /t
---- response_body
-hello world
---- no_error_log
-[error]
-
-
-
-=== TEST 18: simple set_by_lua_block (integer)
---- config
- location /lua {
- set_by_lua_block $res { return 1+1 }
- echo $res;
- }
---- request
-GET /lua
---- response_body
-2
---- no_error_log
-[error]
-
-
-
-=== TEST 19: ambiguous line comments inside a long bracket string (GitHub #596)
---- config
- location = /t {
- content_by_lua_block {
- ngx.say([[ok--]])
- ngx.say([==[ok--]==])
- ngx.say([==[ok-- ]==])
- --[[ --]] ngx.say("done")
- }
- }
---- request
-GET /t
---- response_body
-ok--
-ok--
-ok--
-done
---- no_error_log
-[error]
-
-
-
-=== TEST 20: double quotes in long brackets
---- config
- location = /t {
- rewrite_by_lua_block { print([[Hey, it is "!]]) } content_by_lua_block { ngx.say([["]]) }
- }
---- request
-GET /t
---- response_body
-"
---- error_log
-Hey, it is "!
---- no_error_log
-[error]
-
-
-
-=== TEST 21: single quotes in long brackets
---- config
- location = /t {
- rewrite_by_lua_block { print([[Hey, it is '!]]) } content_by_lua_block { ngx.say([[']]) }
- }
---- request
-GET /t
---- response_body
-'
---- error_log
-Hey, it is '!
---- no_error_log
-[error]
-
-
-
-=== TEST 22: lexer no match due to incomplete data chunks in a fixed size buffer
---- config
- location /test1 {
- content_by_lua_block {
- ngx.say("1: this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error")
- }
- }
- location /test2 {
- content_by_lua_block {
- ngx.say("2: this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error")
- }
- }
-
- location /test3 {
- content_by_lua_block {
- ngx.say("3: this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error",
- "this is just some random filler to cause an error")
- }
- }
---- request
-GET /test3
---- response_body eval
-"3: " . ("this is just some random filler to cause an error" x 20) . "\n"
---- no_error_log
-[error]
-
-
-
-=== TEST 23: lexer should not stop lexing in the middle of a value
---- config
- location /t {
- content_by_lua_block {
- ngx.say("} }")
- ngx.say("} }")
- }
- }
---- request
-GET /t
---- response_body_like: }
---- no_error_log
-[error]
-
-
-
-=== TEST 24: too long bracket
---- config
- location = /t {
- content_by_lua_block {
- local foo = [[
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- ]]
- ngx.say(foo)
- }
- }
---- request
-GET /t
---- response_body
-hello, world
---- no_error_log
-[error]
---- must_die
---- error_log eval
-qr/\[emerg\] .*? Lua code block missing the closing long bracket "]]", the inlined Lua code may be too long in .*?\bnginx\.conf:\d+/
diff --git a/src/deps/src/lua-nginx-module/t/133-worker-count.t b/src/deps/src/lua-nginx-module/t/133-worker-count.t
deleted file mode 100644
index 3e03ecc84..000000000
--- a/src/deps/src/lua-nginx-module/t/133-worker-count.t
+++ /dev/null
@@ -1,72 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: content_by_lua
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("workers: ", ngx.worker.count())
- }
- }
---- request
-GET /lua
---- response_body
-workers: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 2: init_by_lua
---- http_config
- init_by_lua_block {
- package.loaded.count = ngx.worker.count()
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("workers: ", package.loaded.count)
- }
- }
---- request
-GET /lua
---- response_body
-workers: 1
---- no_error_log
-[error]
-
-
-
-=== TEST 3: init_worker_by_lua
---- http_config
- init_worker_by_lua_block {
- init_worker_count = ngx.worker.count()
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("workers: ", init_worker_count)
- }
- }
---- request
-GET /lua
---- response_body
-workers: 1
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/134-worker-count-5.t b/src/deps/src/lua-nginx-module/t/134-worker-count-5.t
deleted file mode 100644
index ec6d0e7e3..000000000
--- a/src/deps/src/lua-nginx-module/t/134-worker-count-5.t
+++ /dev/null
@@ -1,78 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-master_on();
-workers(5);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("worker count: ", ngx.worker.count())
- }
- }
---- request
-GET /lua
---- response_body
-worker count: 5
---- no_error_log
-[error]
-
-
-
-=== TEST 2: init_by_lua
---- http_config
- init_by_lua_block {
- package.loaded.count = ngx.worker.count()
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("workers: ", package.loaded.count)
- }
- }
---- request
-GET /lua
---- response_body
-workers: 5
---- no_error_log
-[error]
-
-
-
-=== TEST 3: init_by_lua + module (github #681)
---- http_config
- lua_package_path "$TEST_NGINX_SERVER_ROOT/html/?.lua;;";
-
- init_by_lua_block {
- local blah = require "file"
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("ok")
- }
- }
---- user_files
->>> file.lua
-local timer_interval = 1
-local time_factor = timer_interval / (ngx.worker.count() * 60)
---- request
-GET /lua
---- response_body
-ok
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/135-worker-id.t b/src/deps/src/lua-nginx-module/t/135-worker-id.t
deleted file mode 100644
index 8241157cb..000000000
--- a/src/deps/src/lua-nginx-module/t/135-worker-id.t
+++ /dev/null
@@ -1,33 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-master_on();
-workers(2);
-#log_level('warn');
-
-#repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("worker id: ", ngx.worker.id())
- }
- }
---- request
-GET /lua
---- response_body_like chop
-^worker id: [0-1]$
---- no_error_log
-[error]
---- skip_nginx: 3: <=1.9.0
diff --git a/src/deps/src/lua-nginx-module/t/136-timer-counts.t b/src/deps/src/lua-nginx-module/t/136-timer-counts.t
deleted file mode 100644
index 8f5329b97..000000000
--- a/src/deps/src/lua-nginx-module/t/136-timer-counts.t
+++ /dev/null
@@ -1,111 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(1);
-
-plan tests => blocks() * (repeat_each() * 3);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: running count with no running timers
---- config
- location /timers {
- content_by_lua_block { ngx.say(ngx.timer.running_count()) }
- }
---- request
-GET /timers
---- response_body
-0
---- no_error_log
-[error]
-
-
-
-=== TEST 2: running count with no pending timers
---- config
- location /timers {
- content_by_lua_block { ngx.say(ngx.timer.pending_count()) }
- }
---- request
-GET /timers
---- response_body
-0
---- no_error_log
-[error]
-
-
-
-=== TEST 3: pending count with one pending timer
---- config
- location /timers {
- content_by_lua_block {
- ngx.timer.at(3, function() end)
- ngx.say(ngx.timer.pending_count())
- }
- }
---- request
-GET /timers
---- response_body
-1
---- no_error_log
-[error]
-
-
-
-=== TEST 4: pending count with 3 pending timers
---- config
- location /timers {
- content_by_lua_block {
- ngx.timer.at(4, function() end)
- ngx.timer.at(2, function() end)
- ngx.timer.at(1, function() end)
- ngx.say(ngx.timer.pending_count())
- }
- }
---- request
-GET /timers
---- response_body
-3
---- no_error_log
-[error]
-
-
-
-=== TEST 5: one running timer
---- config
- location /timers {
- content_by_lua_block {
- ngx.timer.at(0.1, function() ngx.sleep(0.3) end)
- ngx.sleep(0.2)
- ngx.say(ngx.timer.running_count())
- }
- }
---- request
-GET /timers
---- response_body
-1
---- no_error_log
-[error]
-
-
-
-=== TEST 6: 3 running timers
---- config
- location /timers {
- content_by_lua_block {
- ngx.timer.at(0.1, function() ngx.sleep(0.3) end)
- ngx.timer.at(0.11, function() ngx.sleep(0.3) end)
- ngx.timer.at(0.09, function() ngx.sleep(0.3) end)
- ngx.sleep(0.2)
- ngx.say(ngx.timer.running_count())
- }
- }
---- request
-GET /timers
---- response_body
-3
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/137-req-misc.t b/src/deps/src/lua-nginx-module/t/137-req-misc.t
deleted file mode 100644
index d56f80e6f..000000000
--- a/src/deps/src/lua-nginx-module/t/137-req-misc.t
+++ /dev/null
@@ -1,61 +0,0 @@
-use Test::Nginx::Socket::Lua;
-
-#master_on();
-#workers(1);
-#worker_connections(1014);
-#log_level('warn');
-#master_process_enabled(1);
-
-repeat_each(2);
-
-plan tests => repeat_each() * blocks() * 2;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#no_diff();
-no_long_string();
-#no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: not internal request
---- config
- location /test {
- rewrite ^/test$ /lua last;
- }
- location /lua {
- content_by_lua '
- if ngx.req.is_internal() then
- ngx.say("internal")
- else
- ngx.say("not internal")
- end
- ';
- }
---- request
-GET /lua
---- response_body
-not internal
-
-
-
-=== TEST 2: internal request
---- config
- location /test {
- rewrite ^/test$ /lua last;
- }
- location /lua {
- content_by_lua '
- if ngx.req.is_internal() then
- ngx.say("internal")
- else
- ngx.say("not internal")
- end
- ';
- }
---- request
-GET /test
---- response_body
-internal
diff --git a/src/deps/src/lua-nginx-module/t/138-balancer-upstream-bind.t b/src/deps/src/lua-nginx-module/t/138-balancer-upstream-bind.t
deleted file mode 100644
index 442f37c8f..000000000
--- a/src/deps/src/lua-nginx-module/t/138-balancer-upstream-bind.t
+++ /dev/null
@@ -1,142 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: bind to empty
---- no_http2
---- http_config
- lua_package_path "$TEST_NGINX_SERVER_ROOT/html/?.lua;;";
-
- upstream backend {
- server 127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
---- config
- set $proxy_local_addr "";
- proxy_bind $proxy_local_addr;
-
- location = /t {
- proxy_pass http://backend/back;
- }
-
- location = /back {
- echo ok;
- }
-
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[cirt]
-
-
-
-=== TEST 2: bind to 127.0.0.1
---- no_http2
---- http_config
- lua_package_path "$TEST_NGINX_SERVER_ROOT/html/?.lua;;";
-
- upstream backend {
- server 127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
---- config
- set $proxy_local_addr "";
- proxy_bind $proxy_local_addr;
-
- location = /t {
- access_by_lua_block {
- ngx.var.proxy_local_addr="127.0.0.1"
- }
- proxy_pass http://backend/back;
- }
-
- location = /back {
- echo ok;
- }
-
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[cirt]
-
-
-
-=== TEST 3: bind to 127.0.0.10
---- no_http2
---- http_config
- lua_package_path "$TEST_NGINX_SERVER_ROOT/html/?.lua;;";
-
- upstream backend {
- server 127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
---- config
- set $proxy_local_addr "";
- proxy_bind $proxy_local_addr;
-
- location = /t {
- access_by_lua_block {
- ngx.var.proxy_local_addr="127.0.0.10"
- }
- proxy_pass http://backend/back;
- }
-
- location = /back {
- echo ok;
- }
-
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[cirt]
-
-
-
-=== TEST 4: bind to not exist addr 100.100.100.100
---- no_http2
---- http_config
- lua_package_path "$TEST_NGINX_SERVER_ROOT/html/?.lua;;";
-
- upstream backend {
- server 127.0.0.1:$TEST_NGINX_SERVER_PORT;
- }
---- config
- set $proxy_local_addr "";
- proxy_bind $proxy_local_addr;
-
- location = /t {
- access_by_lua_block {
- ngx.var.proxy_local_addr="100.100.100.100"
- }
- proxy_pass http://backend/back;
- }
-
- location = /back {
- echo ok;
- }
-
---- request
- GET /t
---- response_body_like chomp
-500 Internal Server Error
---- error_code: 500
---- error_log
-bind(100.100.100.100) failed (99: Cannot assign requested address)
diff --git a/src/deps/src/lua-nginx-module/t/138-balancer.t b/src/deps/src/lua-nginx-module/t/138-balancer.t
deleted file mode 100644
index 41be75fcd..000000000
--- a/src/deps/src/lua-nginx-module/t/138-balancer.t
+++ /dev/null
@@ -1,680 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-#connect 0.0.0.1 on newer kernel won't return EINVAL
-#so add an route with cmd: sudo ip route add prohibit 0.0.0.1/32
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 7);
-
-#no_diff();
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple logging
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- print("hello from balancer by lua!")
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-[
-'[lua] balancer_by_lua(nginx.conf:27):2: hello from balancer by lua! while connecting to upstream,',
-qr{\[crit\] .*? connect\(\) to 0\.0\.0\.1:80 failed .*?, upstream: "http://0\.0\.0\.1:80/t"},
-]
---- no_error_log
-[warn]
-
-
-
-=== TEST 2: exit 403
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- print("hello from balancer by lua!")
- ngx.exit(403)
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- response_body_like: 403 Forbidden
---- error_code: 403
---- error_log
-[lua] balancer_by_lua(nginx.conf:27):2: hello from balancer by lua! while connecting to upstream,
---- no_error_log eval
-[
-'[warn]',
-qr{\[crit\] .*? connect\(\) to 0\.0\.0\.1:80 failed .*?, upstream: "http://0\.0\.0\.1:80/t"},
-]
-
-
-
-=== TEST 3: exit OK
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- print("hello from balancer by lua!")
- ngx.exit(ngx.OK)
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-[
-'[lua] balancer_by_lua(nginx.conf:27):2: hello from balancer by lua! while connecting to upstream,',
-qr{\[crit\] .*? connect\(\) to 0\.0\.0\.1:80 failed .*?, upstream: "http://0\.0\.0\.1:80/t"},
-]
---- no_error_log
-[warn]
-
-
-
-=== TEST 4: ngx.var works
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- print("1: variable foo = ", ngx.var.foo)
- ngx.var.foo = tonumber(ngx.var.foo) + 1
- print("2: variable foo = ", ngx.var.foo)
- }
- }
---- config
- location = /t {
- set $foo 32;
- proxy_pass http://backend;
- }
---- request
- GET /t
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-[
-"1: variable foo = 32",
-"2: variable foo = 33",
-qr/\[crit\] .* connect\(\) .*? failed/,
-]
---- no_error_log
-[warn]
-
-
-
-=== TEST 5: ngx.req.get_headers works
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- print("header foo: ", ngx.req.get_headers()["foo"])
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- more_headers
-Foo: bar
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-[
-"header foo: bar",
-qr/\[crit\] .* connect\(\) .*? failed/,
-]
---- no_error_log
-[warn]
-
-
-
-=== TEST 6: ngx.req.get_uri_args() works
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- print("arg foo: ", (ngx.req.get_uri_args())["foo"])
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t?baz=blah&foo=bar
---- more_headers
-Foo: bar
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-["arg foo: bar",
-qr/\[crit\] .* connect\(\) .*? failed/,
-]
---- no_error_log
-[warn]
-
-
-
-=== TEST 7: ngx.req.get_method() works
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- print("method: ", ngx.req.get_method())
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- more_headers
-Foo: bar
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-[
-"method: GET",
-qr/\[crit\] .* connect\(\) .*? failed/,
-]
---- no_error_log
-[warn]
-
-
-
-=== TEST 8: simple logging (by_lua_file)
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_file html/a.lua;
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- user_files
->>> a.lua
-print("hello from balancer by lua!")
---- request
- GET /t
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-[
-'[lua] a.lua:1: hello from balancer by lua! while connecting to upstream,',
-qr{\[crit\] .*? connect\(\) to 0\.0\.0\.1:80 failed .*?, upstream: "http://0\.0\.0\.1:80/t"},
-]
---- no_error_log
-[warn]
-
-
-
-=== TEST 9: cosockets are disabled
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- local sock, err = ngx.socket.tcp()
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/\[error\] .*? failed to run balancer_by_lua\*: balancer_by_lua\(nginx\.conf:27\):2: API disabled in the context of balancer_by_lua\*/
-
-
-
-=== TEST 10: ngx.sleep is disabled
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- ngx.sleep(0.1)
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
-qr/\[error\] .*? failed to run balancer_by_lua\*: balancer_by_lua\(nginx\.conf:27\):2: API disabled in the context of balancer_by_lua\*/
-
-
-
-=== TEST 11: get_phase
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- print("I am in phase ", ngx.get_phase())
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- grep_error_log eval: qr/I am in phase \w+/
---- grep_error_log_out
-I am in phase balancer
---- error_log eval
-qr{\[crit\] .*? connect\(\) to 0\.0\.0\.1:80 failed .*?, upstream: "http://0\.0\.0\.1:80/t"}
---- no_error_log
-[error]
-
-
-
-=== TEST 12: code cache off
---- no_http2
---- http_config
- lua_package_path "$TEST_NGINX_SERVER_ROOT/html/?.lua;;";
-
- lua_code_cache off;
-
- upstream backend {
- server 127.0.0.1:$TEST_NGINX_SERVER_PORT;
- balancer_by_lua_block {
- require("test")
- }
- }
---- config
- location = /t {
- echo_location /main;
- echo_location /update;
- echo_location /main;
- }
-
- location = /update {
- content_by_lua_block {
- -- os.execute("(echo HERE; pwd) > /dev/stderr")
- local f = assert(io.open("$TEST_NGINX_SERVER_ROOT/html/test.lua", "w"))
- f:write("print('me: ', 101)")
- f:close()
- ngx.say("updated")
- }
- }
-
- location = /main {
- proxy_pass http://backend/back;
- }
-
- location = /back {
- echo ok;
- }
---- request
- GET /t
---- user_files
->>> test.lua
-print("me: ", 32)
-return {}
---- response_body
-ok
-updated
-ok
---- grep_error_log eval: qr/\bme: \w+/
---- grep_error_log_out
-me: 32
-me: 101
---- no_error_log
-[error]
-
-
-
-=== TEST 13: lua subrequests
---- http_config
- lua_code_cache off;
-
- upstream backend {
- server 127.0.0.1:$TEST_NGINX_SERVER_PORT;
- balancer_by_lua_block {
- print("ctx counter: ", ngx.ctx.count)
- if not ngx.ctx.count then
- ngx.ctx.count = 1
- else
- ngx.ctx.count = ngx.ctx.count + 1
- end
- }
- }
---- config
- location = /t {
- content_by_lua_block {
- local res = ngx.location.capture("/main")
- ngx.print(res.body)
- res = ngx.location.capture("/main")
- ngx.print(res.body)
- }
- }
-
- location = /main {
- proxy_pass http://backend/back;
- }
-
- location = /back {
- echo ok;
- }
---- request
- GET /t
---- response_body
-ok
-ok
---- grep_error_log eval: qr/\bctx counter: \w+/
---- grep_error_log_out
-ctx counter: nil
-ctx counter: nil
---- no_error_log
-[error]
-
-
-
-=== TEST 14: ngx.log(ngx.ERR, ...) github #816
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- ngx.log(ngx.ERR, "hello from balancer by lua!")
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-[
-'[lua] balancer_by_lua(nginx.conf:27):2: hello from balancer by lua! while connecting to upstream,',
-qr{\[crit\] .*? connect\(\) to 0\.0\.0\.1:80 failed .*?, upstream: "http://0\.0\.0\.1:80/t"},
-]
---- no_error_log
-[warn]
-
-
-
-=== TEST 15: test if exceed proxy_next_upstream_limit
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;;";
-
- proxy_next_upstream_tries 5;
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- local b = require "ngx.balancer"
-
- if not ngx.ctx.tries then
- ngx.ctx.tries = 0
- end
-
- if ngx.ctx.tries >= 6 then
- ngx.log(ngx.ERR, "retry count exceed limit")
- ngx.exit(500)
- end
-
- ngx.ctx.tries = ngx.ctx.tries + 1
- print("retry counter: ", ngx.ctx.tries)
-
- local ok, err = b.set_more_tries(2)
- if not ok then
- return error("failed to set more tries: ", err)
- elseif err then
- ngx.log(ngx.WARN, "set more tries: ", err)
- end
-
- assert(b.set_current_peer("127.0.0.1", 81))
- }
- }
---- config
- location = /t {
- proxy_pass http://backend/back;
- }
-
- location = /back {
- return 404;
- }
---- request
- GET /t
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- grep_error_log eval: qr/\bretry counter: \w+/
---- grep_error_log_out
-retry counter: 1
-retry counter: 2
-retry counter: 3
-retry counter: 4
-retry counter: 5
-
---- error_log
-set more tries: reduced tries due to limit
-
-
-
-=== TEST 16: set_more_tries bugfix
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;;";
- proxy_next_upstream_tries 0;
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- local balancer = require "ngx.balancer"
- local ctx = ngx.ctx
- if not ctx.has_run then
- ctx.has_run = true
- local _, err = balancer.set_more_tries(3)
- if err then
- ngx.log(ngx.ERR, "failed to set more tries: ", err)
- end
- end
- balancer.set_current_peer("127.0.0.1", 81)
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- error_code: 502
---- grep_error_log eval: qr/http next upstream, \d+/
---- grep_error_log_out
-http next upstream, 2
-http next upstream, 2
-http next upstream, 2
-http next upstream, 2
---- no_error_log
-failed to set more tries: reduced tries due to limit
-[alert]
-
-
-
-=== TEST 17: recreate_request buffer bugfix
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;;";
-
- server {
- listen 127.0.0.1:$TEST_NGINX_RAND_PORT_1;
-
- location / {
- return 200 "it works";
- }
- }
-
- upstream foo {
- server 127.0.0.1:$TEST_NGINX_RAND_PORT_1 max_fails=0;
- server 127.0.0.1:$TEST_NGINX_RAND_PORT_2 max_fails=0 weight=9999;
-
- balancer_by_lua_block {
- local bal = require "ngx.balancer"
-
- assert(bal.recreate_request())
- }
- }
-
---- config
- location = /t {
- proxy_http_version 1.1;
- proxy_set_header Connection "";
- proxy_pass http://foo;
- }
---- request
-GET /t
---- error_code: 200
---- error_log
-connect() failed (111: Connection refused) while connecting to upstream
---- no_error_log
-upstream sent more data than specified in "Content-Length" header while reading upstream
-[alert]
-
-
-
-=== TEST 18: error in balancer_by_lua_block
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- ngx.say("hello"
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- request
- GET /t
---- response_body_like: 500 Internal Server Error
---- error_code: 500
---- error_log eval
- "failed to load inlined Lua code: balancer_by_lua(nginx.conf:27):3: ')' expected (to close '(' at line 2) near ''",
---- no_error_log
-[warn]
-
-
-
-=== TEST 19: disable ssl
---- http_config
- lua_package_path "$TEST_NGINX_SERVER_ROOT/html/?.lua;;";
-
- upstream backend {
- server 127.0.0.1:$TEST_NGINX_SERVER_PORT;
- balancer_by_lua_block {
- local ffi = require "ffi"
- local C = ffi.C
-ffi.cdef[[
-int
-ngx_http_lua_ffi_balancer_set_upstream_tls(ngx_http_request_t *r, int on, char **err);
-]]
- local errmsg = ffi.new("char *[1]")
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- local rc = C.ngx_http_lua_ffi_balancer_set_upstream_tls(r, 0, errmsg)
- if rc < 0 then
- ngx.log(ngx.ERR, "failed to disable ssl: ", ffi.string(errmsg[0]))
- return
- end
- }
- }
---- config
- location = /t {
- proxy_pass https://backend/back;
- }
-
- location = /back {
- echo ok;
- }
-
---- request
- GET /t
---- response_body
-ok
---- no_error_log
-[error]
-[cirt]
-
-
-
-=== TEST 20: recreate_request refresh body buffer when ngx.req.set_body_data is used in balancer phase
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;;";
-
- server {
- listen 127.0.0.1:$TEST_NGINX_RAND_PORT_1;
-
- location / {
- content_by_lua_block {
- ngx.req.read_body()
- local body = ngx.req.get_body_data()
- ngx.log(ngx.ERR, "body: ", body)
- ngx.say(body)
- }
- }
- }
-
- upstream foo {
- server 127.0.0.1:$TEST_NGINX_RAND_PORT_1 max_fails=0;
-
- balancer_by_lua_block {
- local bal = require "ngx.balancer"
- ngx.req.set_body_data("hello world")
- assert(bal.recreate_request())
- }
- }
-
---- config
- location = /t {
- proxy_http_version 1.1;
- proxy_set_header Connection "";
- proxy_pass http://foo;
- }
---- request
-GET /t
---- error_code: 200
---- response_body
-hello world
diff --git a/src/deps/src/lua-nginx-module/t/139-ssl-cert-by.t b/src/deps/src/lua-nginx-module/t/139-ssl-cert-by.t
deleted file mode 100644
index abf447856..000000000
--- a/src/deps/src/lua-nginx-module/t/139-ssl-cert-by.t
+++ /dev/null
@@ -1,2323 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(3);
-
-# All these tests need to have new openssl
-my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
-my $openssl_version = eval { `$NginxBinary -V 2>&1` };
-
-if ($openssl_version =~ m/built with OpenSSL (0|1\.0\.(?:0|1[^\d]|2[a-d]).*)/) {
- plan(skip_all => "too old OpenSSL, need 1.0.2e, was $1");
-} else {
- plan tests => repeat_each() * (blocks() * 6 + 4);
-}
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple logging
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block { print("ssl cert by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
---- grep_error_log eval: qr/ssl_certificate_by_lua\(nginx.conf:\d+\):.*?,|\bssl cert: connection reusable: \d+|\breusable connection: \d+/
---- grep_error_log_out eval
-# Since nginx version 1.17.9, nginx call ngx_reusable_connection(c, 0)
-# before call ssl callback function
-$Test::Nginx::Util::NginxVersion >= 1.017009 ?
-qr/reusable connection: 0
-ssl cert: connection reusable: 0
-ssl_certificate_by_lua\(nginx.conf:28\):1: ssl cert by lua is running!,/
-: qr /reusable connection: 1
-ssl cert: connection reusable: 1
-reusable connection: 0
-ssl_certificate_by_lua\(nginx.conf:28\):1: ssl cert by lua is running!,/
-
-
-
-=== TEST 2: sleep
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- local begin = ngx.now()
- ngx.sleep(0.1)
- print("elapsed in ssl cert by lua: ", ngx.now() - begin)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log eval
-[
-'lua ssl server name: "test.com"',
-qr/elapsed in ssl cert by lua: 0.(?:09|1\d)\d+,/,
-]
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 3: timer
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- local function f()
- print("my timer run!")
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to create timer: ", err)
- return
- end
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-my timer run!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 4: cosocket
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to memc: ", err)
- return
- end
-
- local bytes, err = sock:send("flush_all\r\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send flush_all command: ", err)
- return
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive memc reply: ", err)
- return
- end
-
- print("received memc reply: ", res)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-received memc reply: OK
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 5: ngx.exit(0) - no yield
---- http_config
- server {
- listen 127.0.0.2:$TEST_NGINX_RAND_PORT_1 ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- ngx.exit(0)
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.2", $TEST_NGINX_RAND_PORT_1)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: boolean
-
---- error_log
-lua exit with code 0
-
---- no_error_log
-should never reached here
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 6: ngx.exit(ngx.ERROR) - no yield
---- http_config
- server {
- listen 127.0.0.2:$TEST_NGINX_RAND_PORT_1 ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- ngx.exit(ngx.ERROR)
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.2", $TEST_NGINX_RAND_PORT_1)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'lua_certificate_by_lua: handler return value: -1, cert cb exit code: 0',
-qr/(\[info\] .*? SSL_do_handshake\(\) failed .*?cert cb error|routines:OPENSSL_internal:CERT_CB_ERROR)/,
-'lua exit with code -1',
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 7: ngx.exit(0) - yield
---- http_config
- server {
- listen 127.0.0.2:$TEST_NGINX_RAND_PORT_1 ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- ngx.sleep(0.001)
- ngx.exit(0)
-
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.2", $TEST_NGINX_RAND_PORT_1)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: boolean
-
---- error_log
-lua exit with code 0
-
---- no_error_log
-should never reached here
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 8: ngx.exit(ngx.ERROR) - yield
---- http_config
- server {
- listen 127.0.0.2:$TEST_NGINX_RAND_PORT_1 ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- ngx.sleep(0.001)
- ngx.exit(ngx.ERROR)
-
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.2", $TEST_NGINX_RAND_PORT_1)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'lua_certificate_by_lua: cert cb exit code: 0',
-qr/(\[info\] .*? SSL_do_handshake\(\) failed .*?cert cb error|routines:OPENSSL_internal:CERT_CB_ERROR)/,
-'lua exit with code -1',
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 9: lua exception - no yield
---- http_config
- server {
- listen 127.0.0.2:$TEST_NGINX_RAND_PORT_1 ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- error("bad bad bad")
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.2", $TEST_NGINX_RAND_PORT_1)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'runtime error: ssl_certificate_by_lua(nginx.conf:28):2: bad bad bad',
-'lua_certificate_by_lua: handler return value: 500, cert cb exit code: 0',
-qr/(\[info\] .*? SSL_do_handshake\(\) failed .*?cert cb error|routines:OPENSSL_internal:CERT_CB_ERROR)/,
-qr/context: ssl_certificate_by_lua\*, client: \d+\.\d+\.\d+\.\d+, server: \d+\.\d+\.\d+\.\d+:\d+/,
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 10: lua exception - yield
---- http_config
- server {
- listen 127.0.0.2:$TEST_NGINX_RAND_PORT_1 ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- ngx.sleep(0.001)
- error("bad bad bad")
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.2", $TEST_NGINX_RAND_PORT_1)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'runtime error: ssl_certificate_by_lua(nginx.conf:28):3: bad bad bad',
-'lua_certificate_by_lua: cert cb exit code: 0',
-qr/(\[info\] .*? SSL_do_handshake\(\) failed .*?cert cb error|routines:OPENSSL_internal:CERT_CB_ERROR)/,
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 11: get phase
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {print("get_phase: ", ngx.get_phase())}
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end
- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-
---- error_log
-lua ssl server name: "test.com"
-get_phase: ssl_cert
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 12: connection aborted prematurely
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- ngx.sleep(0.3)
- -- local ssl = require "ngx.ssl"
- -- ssl.clear_certs()
- print("ssl-cert-by-lua: after sleeping")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(150)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
-
---- response_body
-connected: 1
-failed to do SSL handshake: timeout
-
---- error_log
-lua ssl server name: "test.com"
-ssl-cert-by-lua: after sleeping
-
---- no_error_log
-[error]
-[alert]
---- wait: 0.6
-
-
-
-=== TEST 13: subrequests disabled
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {ngx.location.capture("/foo")}
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'lua ssl server name: "test.com"',
-'ssl_certificate_by_lua(nginx.conf:28):1: API disabled in the context of ssl_certificate_by_lua*',
-qr/(\[info\] .*? SSL_do_handshake\(\) failed .*?cert cb error|routines:OPENSSL_internal:CERT_CB_ERROR)/,
-]
-
---- no_error_log
-[alert]
-
-
-
-=== TEST 14: simple logging (by_lua_file)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_file html/a.lua;
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
-
---- user_files
->>> a.lua
-print("ssl cert by lua is running!")
-
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-a.lua:1: ssl cert by lua is running!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 15: coroutine API
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
-
- local function f()
- local cnt = 0
- for i = 1, 20 do
- print("co yield: ", cnt)
- cy()
- cnt = cnt + 1
- end
- end
-
- local c = cc(f)
- for i = 1, 3 do
- print("co resume, status: ", coroutine.status(c))
- cr(c)
- end
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- grep_error_log eval: qr/co (?:yield: \d+|resume, status: \w+)/
---- grep_error_log_out
-co resume, status: suspended
-co yield: 0
-co resume, status: suspended
-co yield: 1
-co resume, status: suspended
-co yield: 2
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 16: simple user thread wait with yielding
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- local function f()
- ngx.sleep(0.01)
- print("uthread: hello in thread")
- return "done"
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.log(ngx.ERR, "uthread: failed to spawn thread: ", err)
- return ngx.exit(ngx.ERROR)
- end
-
- print("uthread: thread created: ", coroutine.status(t))
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- print("uthread: failed to wait thread: ", res)
- return
- end
-
- print("uthread: ", res)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- no_error_log
-[error]
-[alert]
---- grep_error_log eval: qr/uthread: [^.,]+/
---- grep_error_log_out
-uthread: thread created: running
-uthread: hello in thread
-uthread: done
-
-
-
-=== TEST 17: simple logging - use ssl_certificate_by_lua* on the http {} level
-GitHub openresty/lua-resty-core#42
---- http_config
- ssl_certificate_by_lua_block { print("ssl cert by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-ssl_certificate_by_lua(nginx.conf:25):1: ssl cert by lua is running!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 18: simple logging (syslog)
-github issue #723
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- error_log syslog:server=127.0.0.1:12345 debug;
-
- ssl_certificate_by_lua_block { print("ssl cert by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log eval
-[
-qr/\[error\] .*? send\(\) failed/,
-'lua ssl server name: "test.com"',
-]
---- no_error_log
-[alert]
-ssl_certificate_by_lua:1: ssl cert by lua is running!
-
-
-
-=== TEST 19: check the count of running timers
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block { print("ssl cert by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /timers {
- default_type 'text/plain';
- content_by_lua_block {
- ngx.timer.at(0.1, function() ngx.sleep(0.3) end)
- ngx.timer.at(0.11, function() ngx.sleep(0.3) end)
- ngx.timer.at(0.09, function() ngx.sleep(0.3) end)
- ngx.sleep(0.2)
- ngx.say(ngx.timer.running_count())
- }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /timers HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 59 bytes.
-received: HTTP/1.1 200 OK
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 2
-received: Connection: close
-received:
-received: 3
-close: 1 nil
-
---- error_log eval
-[
-'ssl_certificate_by_lua(nginx.conf:29):1: ssl cert by lua is running!',
-'lua ssl server name: "test.com"',
-]
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 20: some server {} block missing ssl_certificate_by_lua* handlers (literal server name)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block { print("ssl cert by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /timers {
- default_type 'text/plain';
- content_by_lua_block {
- ngx.timer.at(0.1, function() ngx.sleep(0.3) end)
- ngx.timer.at(0.11, function() ngx.sleep(0.3) end)
- ngx.timer.at(0.09, function() ngx.sleep(0.3) end)
- ngx.sleep(0.2)
- ngx.say(ngx.timer.running_count())
- }
- more_clear_headers Date;
- }
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test2.com;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test2.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /timers HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-qr/\[alert\] .*? no ssl_certificate_by_lua\* defined in server test2\.com\b/,
-qr/\[info\] .*? SSL_do_handshake\(\) failed\b/,
-]
-
-
-
-=== TEST 21: some server {} block missing ssl_certificate_by_lua* handlers (regex server name)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block { print("ssl cert by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /timers {
- default_type 'text/plain';
- content_by_lua_block {
- ngx.timer.at(0.1, function() ngx.sleep(0.3) end)
- ngx.timer.at(0.11, function() ngx.sleep(0.3) end)
- ngx.timer.at(0.09, function() ngx.sleep(0.3) end)
- ngx.sleep(0.2)
- ngx.say(ngx.timer.running_count())
- }
- more_clear_headers Date;
- }
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name ~test2\.com;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test2.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /timers HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-qr/\[alert\] .*? no ssl_certificate_by_lua\* defined in server ~test2\\\.com\b/,
-qr/\[info\] .*? SSL_do_handshake\(\) failed\b/,
-]
-
-
-
-=== TEST 22: get raw_client_addr - IPv4
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;;";
-
- server {
- listen 127.0.0.1:$TEST_NGINX_RAND_PORT_1 ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- local ssl = require "ngx.ssl"
- local byte = string.byte
- local addr, addrtype, err = ssl.raw_client_addr()
- local ip = string.format("%d.%d.%d.%d", byte(addr, 1), byte(addr, 2),
- byte(addr, 3), byte(addr, 4))
- print("client ip: ", ip)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_RAND_PORT_1)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-client ip: 127.0.0.1
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 23: get raw_client_addr - unix domain socket
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;;";
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- local ssl = require "ngx.ssl"
- local addr, addrtyp, err = ssl.raw_client_addr()
- print("client socket file: ", addr)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-client socket file:
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 24: ssl_certificate_by_lua* can yield when reading early data
---- skip_openssl: 6: < 1.1.1
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- ssl_early_data on;
- server_tokens off;
-
- ssl_certificate_by_lua_block {
- local begin = ngx.now()
- ngx.sleep(0.1)
- print("elapsed in ssl_certificate_by_lua*: ", ngx.now() - begin)
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: boolean
---- grep_error_log eval
-qr/elapsed in ssl_certificate_by_lua\*: 0\.(?:09|1\d)\d+,/,
---- grep_error_log_out eval
-[
-qr/elapsed in ssl_certificate_by_lua\*: 0\.(?:09|1\d)\d+,/,
-qr/elapsed in ssl_certificate_by_lua\*: 0\.(?:09|1\d)\d+,/,
-qr/elapsed in ssl_certificate_by_lua\*: 0\.(?:09|1\d)\d+,/,
-]
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 25: cosocket (UDP)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- server_tokens off;
-
- ssl_certificate_by_lua_block {
- local sock = ngx.socket.udp()
-
- sock:settimeout(1000)
-
- local ok, err = sock:setpeername("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to memc: ", err)
- return
- end
-
- local req = "\0\1\0\0\0\1\0\0flush_all\r\n"
- local ok, err = sock:send(req)
- if not ok then
- ngx.log(ngx.ERR, "failed to send flush_all to memc: ", err)
- return
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive memc reply: ", err)
- return
- end
-
- ngx.log(ngx.INFO, "received memc reply of ", #res, " bytes")
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
---- no_error_log
-[error]
-[alert]
-[emerg]
---- grep_error_log eval: qr/received memc reply of \d+ bytes/
---- grep_error_log_out eval
-[
-'received memc reply of 12 bytes
-',
-'received memc reply of 12 bytes
-',
-'received memc reply of 12 bytes
-',
-'received memc reply of 12 bytes
-',
-]
-
-
-
-=== TEST 26: uthread (kill)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- server_tokens off;
-
- ssl_certificate_by_lua_block {
- local function f()
- ngx.log(ngx.INFO, "uthread: hello from f()")
- ngx.sleep(1)
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.log(ngx.ERR, "failed to spawn thread: ", err)
- return ngx.exit(ngx.ERROR)
- end
-
- local ok, res = ngx.thread.kill(t)
- if not ok then
- ngx.log(ngx.ERR, "failed to kill thread: ", res)
- return
- end
-
- ngx.log(ngx.INFO, "uthread: killed")
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.log(ngx.INFO, "uthread: failed to kill: ", err)
- end
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
---- no_error_log
-[error]
-[alert]
-[emerg]
---- grep_error_log eval: qr/uthread: [^.,]+/
---- grep_error_log_out
-uthread: hello from f()
-uthread: killed
-uthread: failed to kill: already waited or killed
diff --git a/src/deps/src/lua-nginx-module/t/140-ssl-c-api.t b/src/deps/src/lua-nginx-module/t/140-ssl-c-api.t
deleted file mode 100644
index 4c81b4f05..000000000
--- a/src/deps/src/lua-nginx-module/t/140-ssl-c-api.t
+++ /dev/null
@@ -1,1779 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(3);
-
-# All these tests need to have new openssl
-my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
-my $openssl_version = eval { `$NginxBinary -V 2>&1` };
-
-if ($openssl_version =~ m/built with OpenSSL (0|1\.0\.(?:0|1[^\d]|2[a-d]).*)/) {
- plan(skip_all => "too old OpenSSL, need 1.0.2e, was $1");
-
-} else {
- plan tests => repeat_each() * (blocks() * 5 - 1);
-}
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-
-add_block_preprocessor(sub {
- my $block = shift;
-
- if (!defined $block->user_files) {
- $block->set_value("user_files", <<'_EOC_');
->>> defines.lua
-local ffi = require "ffi"
-
-ffi.cdef[[
- int ngx_http_lua_ffi_cert_pem_to_der(const unsigned char *pem,
- size_t pem_len, unsigned char *der, char **err);
-
- int ngx_http_lua_ffi_priv_key_pem_to_der(const unsigned char *pem,
- size_t pem_len, const unsigned char *passphrase,
- unsigned char *der, char **err);
-
- int ngx_http_lua_ffi_ssl_set_der_certificate(void *r,
- const char *data, size_t len, char **err);
-
- int ngx_http_lua_ffi_ssl_set_der_private_key(void *r,
- const char *data, size_t len, char **err);
-
- int ngx_http_lua_ffi_ssl_clear_certs(void *r, char **err);
-
- void *ngx_http_lua_ffi_parse_pem_cert(const unsigned char *pem,
- size_t pem_len, char **err);
-
- void *ngx_http_lua_ffi_parse_pem_priv_key(const unsigned char *pem,
- size_t pem_len, char **err);
-
- void *ngx_http_lua_ffi_parse_der_cert(const char *data, size_t len,
- char **err);
-
- void *ngx_http_lua_ffi_parse_der_priv_key(const char *data, size_t len,
- char **err);
-
- int ngx_http_lua_ffi_set_cert(void *r,
- void *cdata, char **err);
-
- int ngx_http_lua_ffi_set_priv_key(void *r,
- void *cdata, char **err);
-
- void *ngx_http_lua_ffi_get_req_ssl_pointer(void *r);
-
- void ngx_http_lua_ffi_free_cert(void *cdata);
-
- void ngx_http_lua_ffi_free_priv_key(void *cdata);
-
- int ngx_http_lua_ffi_ssl_verify_client(void *r, void *cdata,
- void *cdata, int depth, char **err);
-
- int ngx_http_lua_ffi_ssl_client_random(ngx_http_request_t *r,
- unsigned char *out, size_t *outlen, char **err);
-
-]]
-_EOC_
- }
-
- my $http_config = $block->http_config || '';
- $http_config .= <<'_EOC_';
-lua_package_path "$prefix/html/?.lua;../lua-resty-core/lib/?.lua;;";
-_EOC_
- $block->set_value("http_config", $http_config);
-});
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple cert + private key
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- require "defines"
- local ffi = require "ffi"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- ffi.C.ngx_http_lua_ffi_ssl_clear_certs(r, errmsg)
-
- local f = assert(io.open("t/cert/test.crt", "rb"))
- local cert = f:read("*all")
- f:close()
-
- local out = ffi.new("char [?]", #cert)
-
- local rc = ffi.C.ngx_http_lua_ffi_cert_pem_to_der(cert, #cert, out, errmsg)
- if rc < 1 then
- ngx.log(ngx.ERR, "failed to parse PEM cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local cert_der = ffi.string(out, rc)
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_set_der_certificate(r, cert_der, #cert_der, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set DER cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- f = assert(io.open("t/cert/test.key", "rb"))
- local pkey = f:read("*all")
- f:close()
-
- out = ffi.new("char [?]", #pkey)
-
- local rc = ffi.C.ngx_http_lua_ffi_priv_key_pem_to_der(pkey, #pkey, nil, out, errmsg)
- if rc < 1 then
- ngx.log(ngx.ERR, "failed to parse PEM priv key: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local pkey_der = ffi.string(out, rc)
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_set_der_private_key(r, pkey_der, #pkey_der, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set DER priv key: ",
- ffi.string(errmsg[0]))
- return
- end
- }
-
- ssl_certificate ../../cert/test2.crt;
- ssl_certificate_key ../../cert/test2.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 2: ECDSA cert + private key
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- local ffi = require "ffi"
- require "defines"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- ffi.C.ngx_http_lua_ffi_ssl_clear_certs(r, errmsg)
-
- local f = assert(io.open("t/cert/test_ecdsa.crt", "rb"))
- local cert = f:read("*all")
- f:close()
-
- local out = ffi.new("char [?]", #cert)
-
- local rc = ffi.C.ngx_http_lua_ffi_cert_pem_to_der(cert, #cert, out, errmsg)
- if rc < 1 then
- ngx.log(ngx.ERR, "failed to parse PEM cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local cert_der = ffi.string(out, rc)
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_set_der_certificate(r, cert_der, #cert_der, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set DER cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- f = assert(io.open("t/cert/test_ecdsa.key", "rb"))
- local pkey = f:read("*all")
- f:close()
-
- out = ffi.new("char [?]", #pkey)
-
- local rc = ffi.C.ngx_http_lua_ffi_priv_key_pem_to_der(pkey, #pkey, nil, out, errmsg)
- if rc < 1 then
- ngx.log(ngx.ERR, "failed to parse PEM priv key: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local pkey_der = ffi.string(out, rc)
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_set_der_private_key(r, pkey_der, #pkey_der, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set DER priv key: ",
- ffi.string(errmsg[0]))
- return
- end
- }
-
- ssl_certificate ../../cert/test2.crt;
- ssl_certificate_key ../../cert/test2.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test_ecdsa.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 3: Handshake continue when cert_pem_to_der errors
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- local ffi = require "ffi"
- require "defines"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- local cert = "garbage data"
-
- local out = ffi.new("char [?]", #cert)
-
- local rc = ffi.C.ngx_http_lua_ffi_cert_pem_to_der(cert, #cert, out, errmsg)
- if rc < 1 then
- ngx.log(ngx.ERR, "failed to parse PEM cert: ",
- ffi.string(errmsg[0]))
- end
-
- local pkey = "garbage key data"
-
- out = ffi.new("char [?]", #pkey)
-
- local rc = ffi.C.ngx_http_lua_ffi_priv_key_pem_to_der(pkey, #pkey, nil, out, errmsg)
- if rc < 1 then
- ngx.log(ngx.ERR, "failed to parse PEM priv key: ",
- ffi.string(errmsg[0]))
- end
- }
-
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-failed to parse PEM cert: PEM_read_bio_X509_AUX()
-failed to parse PEM priv key: PEM_read_bio_PrivateKey() failed
-
---- no_error_log
-[alert]
-
-
-
-=== TEST 4: simple cert + private key cdata
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- local ffi = require "ffi"
- require "defines"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- ffi.C.ngx_http_lua_ffi_ssl_clear_certs(r, errmsg)
-
- local f = assert(io.open("t/cert/test.crt", "rb"))
- local cert_data = f:read("*all")
- f:close()
-
- local cert = ffi.C.ngx_http_lua_ffi_parse_pem_cert(cert_data, #cert_data, errmsg)
- if not cert then
- ngx.log(ngx.ERR, "failed to parse PEM cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_set_cert(r, cert, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set cdata cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_cert(cert)
-
- f = assert(io.open("t/cert/test.key", "rb"))
- local pkey_data = f:read("*all")
- f:close()
-
- local pkey = ffi.C.ngx_http_lua_ffi_parse_pem_priv_key(pkey_data, #pkey_data, errmsg)
- if pkey == nil then
- ngx.log(ngx.ERR, "failed to parse PEM priv key: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_set_priv_key(r, pkey, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set cdata priv key: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_priv_key(pkey)
- }
-
- ssl_certificate ../../cert/test2.crt;
- ssl_certificate_key ../../cert/test2.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 5: ECDSA cert + private key cdata
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- local ffi = require "ffi"
- require "defines"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- ffi.C.ngx_http_lua_ffi_ssl_clear_certs(r, errmsg)
-
- local f = assert(io.open("t/cert/test_ecdsa.crt", "rb"))
- local cert_data = f:read("*all")
- f:close()
-
- local cert = ffi.C.ngx_http_lua_ffi_parse_pem_cert(cert_data, #cert_data, errmsg)
- if not cert then
- ngx.log(ngx.ERR, "failed to parse PEM cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_set_cert(r, cert, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set cdata cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_cert(cert)
-
- f = assert(io.open("t/cert/test_ecdsa.key", "rb"))
- local pkey_data = f:read("*all")
- f:close()
-
- local pkey = ffi.C.ngx_http_lua_ffi_parse_pem_priv_key(pkey_data, #pkey_data, errmsg)
- if pkey == nil then
- ngx.log(ngx.ERR, "failed to parse PEM priv key: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_set_priv_key(r, pkey, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set cdata priv key: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_priv_key(pkey)
- }
-
- ssl_certificate ../../cert/test2.crt;
- ssl_certificate_key ../../cert/test2.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test_ecdsa.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 6: verify client with CA certificates
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- require "defines"
- local ffi = require "ffi"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- local f = assert(io.open("t/cert/test.crt", "rb"))
- local cert_data = f:read("*all")
- f:close()
-
- local client_cert = ffi.C.ngx_http_lua_ffi_parse_pem_cert(cert_data, #cert_data, errmsg)
- if not client_cert then
- ngx.log(ngx.ERR, "failed to parse PEM client cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_verify_client(r, client_cert, nil, 1, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to verify client: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_cert(client_cert)
- }
-
- ssl_certificate ../../cert/test2.crt;
- ssl_certificate_key ../../cert/test2.key;
-
- location / {
- default_type 'text/plain';
- content_by_lua_block {
- print('client certificate subject: ', ngx.var.ssl_client_s_dn)
- ngx.say(ngx.var.ssl_client_verify)
- }
- more_clear_headers Date;
- }
- }
---- config
- location /t {
- proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- proxy_ssl_certificate ../../cert/test.crt;
- proxy_ssl_certificate_key ../../cert/test.key;
- proxy_ssl_session_reuse off;
- }
-
---- request
-GET /t
---- response_body
-SUCCESS
-
---- error_log
-client certificate subject: emailAddress=agentzh@gmail.com,CN=test.com
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 7: verify client without CA certificates
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- require "defines"
- local ffi = require "ffi"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_verify_client(r, nil, nil, -1, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to verify client: ",
- ffi.string(errmsg[0]))
- return
- end
- }
-
- ssl_certificate ../../cert/test2.crt;
- ssl_certificate_key ../../cert/test2.key;
-
- location / {
- default_type 'text/plain';
- content_by_lua_block {
- print('client certificate subject: ', ngx.var.ssl_client_s_dn)
- ngx.say(ngx.var.ssl_client_verify)
- }
- more_clear_headers Date;
- }
- }
---- config
- location /t {
- proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- proxy_ssl_certificate ../../cert/test.crt;
- proxy_ssl_certificate_key ../../cert/test.key;
- proxy_ssl_session_reuse off;
- }
-
---- request
-GET /t
---- response_body
-FAILED:self signed certificate
-
---- error_log
-client certificate subject: emailAddress=agentzh@gmail.com,CN=test.com
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 8: verify client but client provides no certificate
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- require "defines"
- local ffi = require "ffi"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- local f = assert(io.open("t/cert/test.crt", "rb"))
- local cert_data = f:read("*all")
- f:close()
-
- local client_cert = ffi.C.ngx_http_lua_ffi_parse_pem_cert(cert_data, #cert_data, errmsg)
- if not client_cert then
- ngx.log(ngx.ERR, "failed to parse PEM client cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_verify_client(r, client_cert, nil, 1, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to verify client: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_cert(client_cert)
- }
-
- ssl_certificate ../../cert/test2.crt;
- ssl_certificate_key ../../cert/test2.key;
-
- location / {
- default_type 'text/plain';
- content_by_lua_block {
- print('client certificate subject: ', ngx.var.ssl_client_s_dn)
- ngx.say(ngx.var.ssl_client_verify)
- }
- more_clear_headers Date;
- }
- }
---- config
- location /t {
- proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- proxy_ssl_session_reuse off;
- }
-
---- request
-GET /t
---- response_body
-NONE
-
---- error_log
-client certificate subject: nil
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 9: simple cert + private key with passphrase
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- local ffi = require "ffi"
-
- ffi.cdef[[
- int ngx_http_lua_ffi_cert_pem_to_der(const unsigned char *pem,
- size_t pem_len, unsigned char *der, char **err);
-
- int ngx_http_lua_ffi_priv_key_pem_to_der(const unsigned char *pem,
- size_t pem_len, const unsigned char *passphrase,
- unsigned char *der, char **err);
-
- int ngx_http_lua_ffi_ssl_set_der_certificate(void *r,
- const char *data, size_t len, char **err);
-
- int ngx_http_lua_ffi_ssl_set_der_private_key(void *r,
- const char *data, size_t len, char **err);
-
- int ngx_http_lua_ffi_ssl_clear_certs(void *r, char **err);
- ]]
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if not r then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- ffi.C.ngx_http_lua_ffi_ssl_clear_certs(r, errmsg)
-
- local f = assert(io.open("t/cert/test_passphrase.crt", "rb"))
- local cert = f:read("*all")
- f:close()
-
- local out = ffi.new("char [?]", #cert)
-
- local rc = ffi.C.ngx_http_lua_ffi_cert_pem_to_der(cert, #cert, out, errmsg)
- if rc < 1 then
- ngx.log(ngx.ERR, "failed to parse PEM cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local cert_der = ffi.string(out, rc)
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_set_der_certificate(r, cert_der, #cert_der, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set DER cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- f = assert(io.open("t/cert/test_passphrase.key", "rb"))
- local pkey = f:read("*all")
- f:close()
-
- local passphrase = "123456"
-
- out = ffi.new("char [?]", #pkey)
-
- local rc = ffi.C.ngx_http_lua_ffi_priv_key_pem_to_der(pkey, #pkey, passphrase, out, errmsg)
- if rc < 1 then
- ngx.log(ngx.ERR, "failed to parse PEM priv key: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local pkey_der = ffi.string(out, rc)
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_set_der_private_key(r, pkey_der, #pkey_der, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set DER priv key: ",
- ffi.string(errmsg[0]))
- return
- end
- }
-
- ssl_certificate ../../cert/test2.crt;
- ssl_certificate_key ../../cert/test2.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test_passphrase.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to recieve response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 10: Raw SSL pointer
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- local ffi = require "ffi"
- require "defines"
-
- local r = require "resty.core.base" .get_request()
- if not r then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- local ssl = ffi.C.ngx_http_lua_ffi_get_req_ssl_pointer(r);
- if ssl == nil then
- ngx.log(ngx.ERR, "failed to retrieve SSL*")
- return
- end
-
- ffi.cdef[[
- const char *SSL_get_servername(const void *, const int);
- ]]
- local TLSEXT_NAMETYPE_host_name = 0
- local sni = ffi.C.SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name)
- if sni == nil then
- ngx.log(ngx.ERR, "failed to get sni")
- return
- end
-
- ngx.log(ngx.INFO, "SNI is ", ffi.string(sni))
- }
-
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-SNI is test.com
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 11: DER cert + private key cdata
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- local ffi = require "ffi"
- require "defines"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- ffi.C.ngx_http_lua_ffi_ssl_clear_certs(r, errmsg)
-
- local f = assert(io.open("t/cert/test_der.crt", "rb"))
- local cert_data = f:read("*all")
- f:close()
-
- local cert = ffi.C.ngx_http_lua_ffi_parse_der_cert(cert_data, #cert_data, errmsg)
- if not cert then
- ngx.log(ngx.ERR, "failed to parse DER cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_set_cert(r, cert, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set cdata cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_cert(cert)
-
- f = assert(io.open("t/cert/test_der.key", "rb"))
- local pkey_data = f:read("*all")
- f:close()
-
- local pkey = ffi.C.ngx_http_lua_ffi_parse_der_priv_key(pkey_data, #pkey_data, errmsg)
- if pkey == nil then
- ngx.log(ngx.ERR, "failed to parse DER priv key: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_set_priv_key(r, pkey, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to set cdata priv key: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_priv_key(pkey)
- }
-
- ssl_certificate ../../cert/test2.crt;
- ssl_certificate_key ../../cert/test2.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 12: client random
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- local ffi = require "ffi"
- require "defines"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- -- test client random length
- local out = ffi.new("unsigned char[?]", 0)
- local sizep = ffi.new("size_t[1]", 0)
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_client_random(r, out, sizep, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to get client random length: ",
- ffi.string(errmsg[0]))
- return
- end
-
- if tonumber(sizep[0]) ~= 32 then
- ngx.log(ngx.ERR, "client random length does not equal 32")
- return
- end
-
- -- test client random value
- out = ffi.new("unsigned char[?]", 50)
- sizep = ffi.new("size_t[1]", 50)
-
- rc = ffi.C.ngx_http_lua_ffi_ssl_client_random(r, out, sizep, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to get client random: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local init_v = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- if ffi.string(out, sizep[0]) == init_v then
- ngx.log(ngx.ERR, "maybe the client random value is incorrect")
- return
- end
- }
-
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 13: verify client, but server don't trust root ca
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name example.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- require "defines"
- local ffi = require "ffi"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- local f = assert(io.open("t/cert/mtls_server.crt", "rb"))
- local cert_data = f:read("*all")
- f:close()
-
- local client_cert = ffi.C.ngx_http_lua_ffi_parse_pem_cert(cert_data, #cert_data, errmsg)
- if not client_cert then
- ngx.log(ngx.ERR, "failed to parse PEM client cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_verify_client(r, client_cert, nil, 2, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to verify client: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_cert(client_cert)
- }
-
- ssl_certificate ../../cert/mtls_server.crt;
- ssl_certificate_key ../../cert/mtls_server.key;
-
- location / {
- default_type 'text/plain';
- content_by_lua_block {
- ngx.say(ngx.var.ssl_client_verify)
- }
- more_clear_headers Date;
- }
- }
---- config
- location /t {
- proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- proxy_ssl_certificate ../../cert/mtls_client.crt;
- proxy_ssl_certificate_key ../../cert/mtls_client.key;
- proxy_ssl_session_reuse off;
- }
-
---- request
-GET /t
---- response_body
-FAILED:unable to verify the first certificate
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 14: verify client and server trust root ca
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name example.com;
-
- ssl_certificate_by_lua_block {
- collectgarbage()
-
- require "defines"
- local ffi = require "ffi"
-
- local errmsg = ffi.new("char *[1]")
-
- local r = require "resty.core.base" .get_request()
- if r == nil then
- ngx.log(ngx.ERR, "no request found")
- return
- end
-
- local f = assert(io.open("t/cert/mtls_server.crt", "rb"))
- local cert_data = f:read("*all")
- f:close()
-
- local client_cert = ffi.C.ngx_http_lua_ffi_parse_pem_cert(cert_data, #cert_data, errmsg)
- if not client_cert then
- ngx.log(ngx.ERR, "failed to parse PEM client cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local f = assert(io.open("t/cert/mtls_ca.crt", "rb"))
- local cert_data = f:read("*all")
- f:close()
-
- local trusted_cert = ffi.C.ngx_http_lua_ffi_parse_pem_cert(cert_data, #cert_data, errmsg)
- if not trusted_cert then
- ngx.log(ngx.ERR, "failed to parse PEM trusted cert: ",
- ffi.string(errmsg[0]))
- return
- end
-
- local rc = ffi.C.ngx_http_lua_ffi_ssl_verify_client(r, cert, trusted_cert, 2, errmsg)
- if rc ~= 0 then
- ngx.log(ngx.ERR, "failed to verify client: ",
- ffi.string(errmsg[0]))
- return
- end
-
- ffi.C.ngx_http_lua_ffi_free_cert(client_cert)
- ffi.C.ngx_http_lua_ffi_free_cert(trusted_cert)
- }
-
- ssl_certificate ../../cert/mtls_server.crt;
- ssl_certificate_key ../../cert/mtls_server.key;
-
- location / {
- default_type 'text/plain';
- content_by_lua_block {
- ngx.say(ngx.var.ssl_client_verify)
- }
- more_clear_headers Date;
- }
- }
---- config
- location /t {
- proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- proxy_ssl_certificate ../../cert/mtls_client.crt;
- proxy_ssl_certificate_key ../../cert/mtls_client.key;
- proxy_ssl_session_reuse off;
- }
-
---- request
-GET /t
---- response_body
-SUCCESS
-
---- no_error_log
-[error]
-[alert]
diff --git a/src/deps/src/lua-nginx-module/t/141-luajit.t b/src/deps/src/lua-nginx-module/t/141-luajit.t
deleted file mode 100644
index 36418d102..000000000
--- a/src/deps/src/lua-nginx-module/t/141-luajit.t
+++ /dev/null
@@ -1,48 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua
- skip_all => 'no mmap(sbrk(0)) trick since glibc leaks memory in this case';
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: avoid the data segment from growing on Linux
-This is to maximize the address space that can be used by LuaJIT.
---- config
- location = /t {
- content_by_lua_block {
- local ffi = require "ffi"
- ffi.cdef[[
- void *malloc(size_t size);
- void free(void *p);
- ]]
- local p = ffi.C.malloc(1);
- local num = tonumber(ffi.cast("uintptr_t", p))
- ffi.C.free(p)
- if ffi.abi("64bit") then
- if num < 2^31 then
- ngx.say("fail: ", string.format("p = %#x", num))
- return
- end
- end
- ngx.say("pass")
- }
- }
---- request
-GET /t
---- response_body
-pass
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/142-ssl-session-store.t b/src/deps/src/lua-nginx-module/t/142-ssl-session-store.t
deleted file mode 100644
index 11deb8320..000000000
--- a/src/deps/src/lua-nginx-module/t/142-ssl-session-store.t
+++ /dev/null
@@ -1,978 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use Cwd qw(abs_path realpath);
-use File::Basename;
-
-repeat_each(3);
-
-plan tests => repeat_each() * (blocks() * 6 - 1);
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_CERT_DIR} ||= dirname(realpath(abs_path(__FILE__)));
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple logging
---- http_config
- ssl_session_store_by_lua_block { print("ssl session store by lua is running!") }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
---- grep_error_log eval: qr/ssl_session_store_by_lua\(nginx.conf:\d+\):.*?,|\bssl session store: connection reusable: \d+|\breusable connection: \d+/
---- grep_error_log_out eval
-qr/^reusable connection: 0
-ssl session store: connection reusable: 0
-ssl_session_store_by_lua\(nginx\.conf:25\):1: ssl session store by lua is running!,
-/m,
-
-
-
-=== TEST 2: sleep is not allowed
---- http_config
- ssl_session_store_by_lua_block {
- local begin = ngx.now()
- ngx.sleep(0.1)
- print("elapsed in ssl store session by lua: ", ngx.now() - begin)
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-API disabled in the context of ssl_session_store_by_lua*
-
---- no_error_log
-[alert]
-[emerg]
-
-
-
-=== TEST 3: timer
---- http_config
- ssl_session_store_by_lua_block {
- local function f()
- print("my timer run!")
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to create timer: ", err)
- return
- end
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-my timer run!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 4: cosocket is not allowed
---- http_config
- ssl_session_store_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to memc: ", err)
- return
- end
-
- local bytes, err = sock:send("flush_all\\r\\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send flush_all command: ", err)
- return
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive memc reply: ", err)
- return
- end
-
- print("received memc reply: ", res)
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-API disabled in the context of ssl_session_store_by_lua*
-
---- no_error_log
-[alert]
-[emerg]
-
-
-
-=== TEST 5: ngx.exit(0) - no yield
---- http_config
- ssl_session_store_by_lua_block {
- ngx.exit(0)
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_verify_depth 3;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-lua exit with code 0
-
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 6: ngx.exit(ngx.ERROR) - no yield
-ngx.exit does not yield and the error code is eaten.
---- http_config
- ssl_session_store_by_lua_block {
- ngx.exit(ngx.ERROR)
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_verify_depth 3;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-lua exit with code -1
-ssl_session_store_by_lua*: handler return value: 0, sess new cb exit code: 0
-
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 7: lua exception - no yield
---- http_config
- ssl_session_store_by_lua_block {
- error("bad bad bad")
- ngx.log(ngx.ERR, "should never reached here...")
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_verify_depth 3;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-failed to run session_store_by_lua*: ssl_session_store_by_lua(nginx.conf:25):2: bad bad bad
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 8: get phase
---- http_config
- ssl_session_store_by_lua_block {
- print("get_phase: ", ngx.get_phase())
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_verify_depth 3;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-get_phase: ssl_session_store
-
---- no_error_log
-[alert]
-[emerg]
-[error]
-
-
-
-=== TEST 9: inter-operation with ssl_certificate_by_lua
---- http_config
- ssl_session_store_by_lua_block { print("ssl store session by lua is running!") }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- local begin = ngx.now()
- ngx.sleep(0.1)
- print("elapsed in ssl cert by lua: ", ngx.now() - begin)
- }
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log eval
-[
-'lua ssl server name: "test.com"',
-qr/elapsed in ssl cert by lua: 0.(?:09|1[01])\d+,/,
-'ssl_session_store_by_lua(nginx.conf:25):1: ssl store session by lua is running!',
-]
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 10: simple logging (by file)
---- http_config
- ssl_session_store_by_lua_file html/a.lua;
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- user_files
->>> a.lua
-print("ssl store session by lua is running!")
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-a.lua:1: ssl store session by lua is running!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 11: will crash when ssl_session_store_by_lua* is allowed in server context
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name foo.com;
- ssl_session_store_by_lua_block {
- print("handler in test.com")
- }
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
-
- server_tokens off;
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_verify_depth 3;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- no_error_log
-[error]
---- must_die
---- error_log eval
-qr/\[emerg\] .*? "ssl_session_store_by_lua_block" directive is not allowed here .*?\bnginx\.conf:28/
-
-
-
-=== TEST 12: mixing ssl virtual servers with non-ssl virtual servers
---- http_config
- ssl_session_store_by_lua_block { print("ssl session store by lua is running!") }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/https.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/http.sock;
- server_name foo.com;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/https.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-ssl_session_store_by_lua(nginx.conf:25):1: ssl session store by lua is running!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 13: ssl_session_store_by_lua* is skipped when using TLSv1.3
---- skip_openssl: 6: < 1.1.1
---- http_config
- ssl_session_store_by_lua_block { ngx.log(ngx.ERR, "ssl_session_store_by_lua* is running!") }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
- ssl_protocols TLSv1.3;
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1.3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
---- error_log eval
-qr/ssl_session_store_by_lua\*: skipped since TLS version >= 1\.3 \(\d+\)/
---- no_error_log
-[error]
-[alert]
-[emerg]
---- skip_eval: 6:$ENV{TEST_NGINX_USE_HTTP3}
diff --git a/src/deps/src/lua-nginx-module/t/143-ssl-session-fetch.t b/src/deps/src/lua-nginx-module/t/143-ssl-session-fetch.t
deleted file mode 100644
index 2f988ded9..000000000
--- a/src/deps/src/lua-nginx-module/t/143-ssl-session-fetch.t
+++ /dev/null
@@ -1,1789 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use lib 'lib';
-use Test::Nginx::Socket::Lua;
-use Cwd qw(abs_path realpath);
-use File::Basename;
-
-repeat_each(3);
-
-plan tests => repeat_each() * (blocks() * 6);
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-$ENV{TEST_NGINX_CERT_DIR} ||= dirname(realpath(abs_path(__FILE__)));
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple logging
---- http_config
- ssl_session_fetch_by_lua_block { print("ssl fetch sess by lua is running!") }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval: qr/ssl_session_fetch_by_lua\(nginx\.conf:\d+\):.*?,|\bssl session fetch: connection reusable: \d+|\breusable connection: \d+/
-
---- grep_error_log_out eval
-# Since nginx version 1.17.9, nginx call ngx_reusable_connection(c, 0)
-# before call ssl callback function
-$Test::Nginx::Util::NginxVersion >= 1.017009 ?
-[
-qr/\A(?:reusable connection: [01]\n)+\z/s,
-qr/^reusable connection: 0
-ssl session fetch: connection reusable: 0
-ssl_session_fetch_by_lua\(nginx\.conf:25\):1: ssl fetch sess by lua is running!,
-/m,
-qr/^reusable connection: 0
-ssl session fetch: connection reusable: 0
-ssl_session_fetch_by_lua\(nginx\.conf:25\):1: ssl fetch sess by lua is running!,
-/m,
-]
-:
-[
-qr/\A(?:reusable connection: [01]\n)+\z/s,
-qr/^reusable connection: 1
-ssl session fetch: connection reusable: 1
-reusable connection: 0
-ssl_session_fetch_by_lua\(nginx\.conf:25\):1: ssl fetch sess by lua is running!,
-/m,
-qr/^reusable connection: 1
-ssl session fetch: connection reusable: 1
-reusable connection: 0
-ssl_session_fetch_by_lua\(nginx\.conf:25\):1: ssl fetch sess by lua is running!,
-/m,
-]
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 2: sleep
---- http_config
- ssl_session_fetch_by_lua_block {
- local begin = ngx.now()
- ngx.sleep(0.1)
- print("elapsed in ssl fetch session by lua: ", ngx.now() - begin)
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/elapsed in ssl fetch session by lua: 0.(?:09|1[01])\d+,/,
-
---- grep_error_log_out eval
-[
-'',
-qr/elapsed in ssl fetch session by lua: 0.(?:09|1[01])\d+,/,
-qr/elapsed in ssl fetch session by lua: 0.(?:09|1[01])\d+,/,
-]
-
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 3: timer
---- http_config
- ssl_session_fetch_by_lua_block {
- local function f()
- print("my timer run!")
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to create timer: ", err)
- return
- end
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/my timer run!/s
-
---- grep_error_log_out eval
-[
-'',
-'my timer run!
-',
-'my timer run!
-',
-]
-
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 4: cosocket
---- http_config
- ssl_session_fetch_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to memc: ", err)
- return
- end
-
- local bytes, err = sock:send("flush_all\r\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send flush_all command: ", err)
- return
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive memc reply: ", err)
- return
- end
-
- print("received memc reply: ", res)
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/received memc reply: OK/s
-
---- grep_error_log_out eval
-[
-'',
-'received memc reply: OK
-',
-'received memc reply: OK
-',
-]
-
---- no_error_log
-[alert]
-[error]
-[emerg]
-
-
-
-=== TEST 5: ngx.exit(0) - yield
---- http_config
- ssl_session_fetch_by_lua_block {
- ngx.exit(0)
- ngx.log(ngx.ERR, "should never reached here...")
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_verify_depth 3;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/lua exit with code 0/s
-
---- grep_error_log_out eval
-[
-'',
-'lua exit with code 0
-',
-'lua exit with code 0
-',
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 6: ngx.exit(ngx.ERROR) - yield
---- http_config
- ssl_session_fetch_by_lua_block {
- ngx.exit(ngx.ERROR)
- ngx.log(ngx.ERR, "should never reached here...")
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_verify_depth 3;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/ssl_session_fetch_by_lua\*: handler return value: -1, sess get cb exit code: 0/s
-
---- grep_error_log_out eval
-[
-'',
-'ssl_session_fetch_by_lua*: handler return value: -1, sess get cb exit code: 0
-',
-'ssl_session_fetch_by_lua*: handler return value: -1, sess get cb exit code: 0
-',
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 7: ngx.exit(ngx.ERROR) - yield
---- http_config
- ssl_session_fetch_by_lua_block {
- ngx.sleep(0.001)
- ngx.exit(ngx.ERROR)
- ngx.log(ngx.ERR, "should never reached here...")
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_verify_depth 3;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/ssl_session_fetch_by_lua\*: sess get cb exit code: 0/s
-
---- grep_error_log_out eval
-[
-'',
-'ssl_session_fetch_by_lua*: sess get cb exit code: 0
-',
-'ssl_session_fetch_by_lua*: sess get cb exit code: 0
-',
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 8: lua exception - no yield
---- http_config
- ssl_session_fetch_by_lua_block {
- error("bad bad bad")
- ngx.log(ngx.ERR, "should never reached here...")
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
- lua_ssl_verify_depth 3;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/ssl_session_fetch_by_lua\(nginx.conf:\d+\):2: bad bad bad/s
-
---- grep_error_log_out eval
-[
-'',
-'ssl_session_fetch_by_lua(nginx.conf:25):2: bad bad bad
-',
-'ssl_session_fetch_by_lua(nginx.conf:25):2: bad bad bad
-',
-
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 9: lua exception - yield
---- http_config
- ssl_session_fetch_by_lua_block {
- ngx.sleep(0.001)
- error("bad bad bad")
- ngx.log(ngx.ERR, "should never reached here...")
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
- lua_ssl_verify_depth 3;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/ssl_session_fetch_by_lua\(nginx.conf:\d+\):3: bad bad bad|ssl_session_fetch_by_lua\*: sess get cb exit code: 0/s
-
---- grep_error_log_out eval
-[
-'',
-'ssl_session_fetch_by_lua(nginx.conf:25):3: bad bad bad
-ssl_session_fetch_by_lua*: sess get cb exit code: 0
-',
-'ssl_session_fetch_by_lua(nginx.conf:25):3: bad bad bad
-ssl_session_fetch_by_lua*: sess get cb exit code: 0
-',
-
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 10: get phase
---- http_config
- ssl_session_fetch_by_lua_block { print("get_phase: ", ngx.get_phase()) }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/get_phase: ssl_session_fetch/s
-
---- grep_error_log_out eval
-[
-'',
-'get_phase: ssl_session_fetch
-',
-'get_phase: ssl_session_fetch
-',
-]
-
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 11: inter-operation with ssl_certificate_by_lua
---- http_config
- ssl_session_store_by_lua_block { print("ssl store session by lua is running!") }
- ssl_session_fetch_by_lua_block {
- ngx.sleep(0.1)
- print("ssl fetch session by lua is running!")
- }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- ngx.sleep(0.1)
- print("ssl cert by lua is running!")
- }
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
-
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/ssl ((fetch|store) session|cert) by lua is running!/s
-
---- grep_error_log_out eval
-if ($ENV{TEST_NGINX_USE_HTTP3}) {
-[
-'ssl cert by lua is running!
-ssl store session by lua is running!
-',
-'ssl cert by lua is running!
-ssl fetch session by lua is running!
-ssl store session by lua is running!
-',
-'ssl cert by lua is running!
-ssl fetch session by lua is running!
-ssl store session by lua is running!
-',
-]
-} else {
-[
-'ssl cert by lua is running!
-ssl store session by lua is running!
-',
-'ssl fetch session by lua is running!
-ssl cert by lua is running!
-ssl store session by lua is running!
-',
-'ssl fetch session by lua is running!
-ssl cert by lua is running!
-ssl store session by lua is running!
-',
-]
-}
-
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 12: simple logging (by file)
---- http_config
- ssl_session_fetch_by_lua_file html/a.lua;
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- user_files
->>> a.lua
-print("ssl fetch sess by lua is running!")
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/\S+:\d+: ssl fetch sess by lua is running!/s
-
---- grep_error_log_out eval
-[
-'',
-'a.lua:1: ssl fetch sess by lua is running!
-',
-'a.lua:1: ssl fetch sess by lua is running!
-',
-]
-
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 13: mixing ssl virtual servers with non-ssl virtual servers
---- http_config
- ssl_session_fetch_by_lua_block { print("ssl fetch sess by lua is running!") }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/http.sock;
- server_name foo.com;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
-
---- grep_error_log eval
-qr/ssl_session_fetch_by_lua\(nginx.conf:\d+\):1: ssl fetch sess by lua is running!/s
-
---- grep_error_log_out eval
-[
-'',
-'ssl_session_fetch_by_lua(nginx.conf:25):1: ssl fetch sess by lua is running!
-',
-'ssl_session_fetch_by_lua(nginx.conf:25):1: ssl fetch sess by lua is running!
-',
-]
-
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 14: keep global variable in ssl_session_(store|fetch)_by_lua when OpenResty LuaJIT is used
---- http_config
- ssl_session_store_by_lua_block {
- ngx.log(ngx.WARN, "new foo: ", foo)
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- }
- ssl_session_fetch_by_lua_block {
- ngx.log(ngx.WARN, "new bar: ", foo)
- if not bar then
- bar = 1
- else
- ngx.log(ngx.WARN, "old bar: ", bar)
- bar = bar + 1
- end
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- ssl_session_tickets off;
-
- server_tokens off;
- location /foo {
- content_by_lua_block {
- ngx.say("foo: ", foo)
- ngx.say("bar: ", bar)
- }
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- package.loaded.session = sess
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- local m, err = ngx.re.match(line, "^foo: (.*)$", "jo")
- if err then
- ngx.say("failed to match line: ", err)
- end
-
- if m and m[1] then
- ngx.print(m[1])
- end
- end
-
- local ok, err = sock:close()
- ngx.say("done")
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body_like chomp
-\A[123]done\n\z
---- grep_error_log eval: qr/old (foo|bar): \d+/
---- grep_error_log_out eval
-["", "old foo: 1\n", "old bar: 1\nold foo: 2\n"]
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 15: ssl_session_fetch_by_lua* is skipped when session ticket is provided
---- http_config
- ssl_session_fetch_by_lua_block { ngx.log(ngx.ERR, "ssl_session_fetch_by_lua* is running!") }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
---- no_error_log
-[warn]
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 16: ssl_session_fetch_by_lua* always runs when using SSLv3 (SSLv3 does not support session tickets)
---- http_config
- ssl_session_fetch_by_lua_block { print("ssl_session_fetch_by_lua* is running!") }
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_protocols SSLv3;
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols SSLv3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
---- grep_error_log eval: qr/ssl_session_fetch_by_lua\(nginx\.conf:\d+\):.*?,|\bssl session fetch: connection reusable: \d+|\breusable connection: \d+/
---- grep_error_log_out eval
-# Since nginx version 1.17.9, nginx call ngx_reusable_connection(c, 0)
-# before call ssl callback function
-$Test::Nginx::Util::NginxVersion >= 1.017009 ?
-[
-qr/\A(?:reusable connection: [01]\n)+\z/s,
-qr/^reusable connection: 0
-ssl session fetch: connection reusable: 0
-ssl_session_fetch_by_lua\(nginx\.conf:\d+\):1: ssl_session_fetch_by_lua\* is running!,
-/m,
-qr/^reusable connection: 0
-ssl session fetch: connection reusable: 0
-ssl_session_fetch_by_lua\(nginx\.conf:\d+\):1: ssl_session_fetch_by_lua\* is running!,
-/m,
-]
-:
-[
-qr/\A(?:reusable connection: [01]\n)+\z/s,
-qr/^reusable connection: 1
-ssl session fetch: connection reusable: 1
-reusable connection: 0
-ssl_session_fetch_by_lua\(nginx\.conf:\d+\):1: ssl_session_fetch_by_lua\* is running!,
-/m,
-qr/^reusable connection: 1
-ssl session fetch: connection reusable: 1
-reusable connection: 0
-ssl_session_fetch_by_lua\(nginx\.conf:\d+\):1: ssl_session_fetch_by_lua\* is running!,
-/m,
-]
---- no_error_log
-[error]
-[alert]
-[emerg]
---- skip_eval: 6:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 17: ssl_session_fetch_by_lua* can yield when reading early data
---- skip_openssl: 6: < 1.1.1
---- http_config
- ssl_session_fetch_by_lua_block {
- local begin = ngx.now()
- ngx.sleep(0.1)
- print("elapsed in ssl_session_fetch_by_lua*: ", ngx.now() - begin)
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
- ssl_early_data on;
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
---- grep_error_log eval
-qr/elapsed in ssl_session_fetch_by_lua\*: 0\.(?:09|1[01])\d+,/,
---- grep_error_log_out eval
-[
-'',
-qr/elapsed in ssl_session_fetch_by_lua\*: 0\.(?:09|1[01])\d+,/,
-qr/elapsed in ssl_session_fetch_by_lua\*: 0\.(?:09|1[01])\d+,/,
-]
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 18: cosocket (UDP)
---- http_config
- ssl_session_fetch_by_lua_block {
- local sock = ngx.socket.udp()
-
- sock:settimeout(1000)
-
- local ok, err = sock:setpeername("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to memc: ", err)
- return
- end
-
- local req = "\0\1\0\0\0\1\0\0flush_all\r\n"
- local ok, err = sock:send(req)
- if not ok then
- ngx.log(ngx.ERR, "failed to send flush_all to memc: ", err)
- return
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive memc reply: ", err)
- return
- end
-
- ngx.log(ngx.INFO, "received memc reply of ", #res, " bytes")
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
---- grep_error_log eval: qr/received memc reply of \d+ bytes/
---- grep_error_log_out eval
-[
-'',
-'received memc reply of 12 bytes
-',
-'received memc reply of 12 bytes
-',
-]
---- no_error_log
-[alert]
-[error]
-[emerg]
-
-
-
-=== TEST 19: uthread (kill)
---- http_config
- ssl_session_fetch_by_lua_block {
- local function f()
- ngx.log(ngx.INFO, "uthread: hello from f()")
- ngx.sleep(1)
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.log(ngx.ERR, "failed to spawn thread: ", err)
- return
- end
-
- collectgarbage()
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.log(ngx.ERR, "failed to kill thread: ", err)
- return
- end
-
- ngx.log(ngx.INFO, "uthread: killed")
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.log(ngx.INFO, "uthread: failed to kill: ", err)
- end
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
---- grep_error_log eval: qr/uthread: [^.,]+/
---- grep_error_log_out eval
-[
-'',
-'uthread: hello from f()
-uthread: killed
-uthread: failed to kill: already waited or killed
-',
-'uthread: hello from f()
-uthread: killed
-uthread: failed to kill: already waited or killed
-'
-]
---- no_error_log
-[alert]
-[error]
-[emerg]
-
-
-
-=== TEST 20: uthread (wait)
---- http_config
- ssl_session_fetch_by_lua_block {
- local function f()
- ngx.log(ngx.INFO, "uthread: hello from f()")
- ngx.sleep(0.001)
- return 32
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.log(ngx.ERR, "failed to spawn thread: ", err)
- return
- end
-
- collectgarbage()
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- ngx.log(ngx.ERR, "failed to wait on thread: ", res)
- return
- end
-
- ngx.log(ngx.INFO, "uthread: ", res)
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.log(ngx.INFO, "uthread: failed to kill: ", err)
- end
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
- ssl_session_tickets off;
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
- lua_ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(5000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- package.loaded.session = sess
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-close: 1 nil
---- grep_error_log eval: qr/uthread: [^.,]+/
---- grep_error_log_out eval
-[
-'',
-'uthread: hello from f()
-uthread: 32
-uthread: failed to kill: already waited or killed
-',
-'uthread: hello from f()
-uthread: 32
-uthread: failed to kill: already waited or killed
-'
-]
---- no_error_log
-[alert]
-[error]
-[emerg]
diff --git a/src/deps/src/lua-nginx-module/t/144-shdict-incr-init.t b/src/deps/src/lua-nginx-module/t/144-shdict-incr-init.t
deleted file mode 100644
index 71bb56603..000000000
--- a/src/deps/src/lua-nginx-module/t/144-shdict-incr-init.t
+++ /dev/null
@@ -1,226 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use lib 'lib';
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 0);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: incr key with init (key exists)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("foo", 32)
- local res, err = dogs:incr("foo", 10502, 1)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- }
- }
---- request
-GET /test
---- response_body
-incr: 10534 nil
-foo = 10534
---- no_error_log
-[error]
-
-
-
-=== TEST 2: incr key with init (key not exists)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:flush_all()
- dogs:set("bah", 32)
- local res, err = dogs:incr("foo", 10502, 1)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- }
- }
---- request
-GET /test
---- response_body
-incr: 10503 nil
-foo = 10503
---- no_error_log
-[error]
-
-
-
-=== TEST 3: incr key with init (key expired and size not matched)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- for i = 1, 20 do
- dogs:set("bar" .. i, i, 0.001)
- end
- dogs:set("foo", "32", 0.001)
- ngx.location.capture("/sleep/0.002")
- local res, err = dogs:incr("foo", 10502, 0)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- }
- }
- location ~ ^/sleep/(.+) {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-incr: 10502 nil
-foo = 10502
---- no_error_log
-[error]
-
-
-
-=== TEST 4: incr key with init (key expired and size matched)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- for i = 1, 20 do
- dogs:set("bar" .. i, i, 0.001)
- end
- dogs:set("foo", 32, 0.001)
- ngx.location.capture("/sleep/0.002")
- local res, err = dogs:incr("foo", 10502, 0)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- }
- }
- location ~ ^/sleep/(.+) {
- echo_sleep $1;
- }
---- request
-GET /test
---- response_body
-incr: 10502 nil
-foo = 10502
---- no_error_log
-[error]
-
-
-
-=== TEST 5: incr key with init (forcibly override other valid entries)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:flush_all()
- local long_prefix = string.rep("1234567890", 100)
- for i = 1, 1000 do
- local success, err, forcible = dogs:set(long_prefix .. i, i)
- if forcible then
- dogs:delete(long_prefix .. i)
- break
- end
- end
- local res, err, forcible = dogs:incr(long_prefix .. "bar", 10502, 0)
- ngx.say("incr: ", res, " ", err, " ", forcible)
- local res, err, forcible = dogs:incr(long_prefix .. "foo", 10502, 0)
- ngx.say("incr: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get(long_prefix .. "foo"))
- }
- }
---- request
-GET /test
---- response_body
-incr: 10502 nil false
-incr: 10502 nil true
-foo = 10502
---- no_error_log
-[error]
-
-
-
-=== TEST 6: incr key without init (no forcible returned)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("foo", 1)
- local res, err, forcible = dogs:incr("foo", 1)
- ngx.say("incr: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- }
- }
---- request
-GET /test
---- response_body
-incr: 2 nil nil
-foo = 2
---- no_error_log
-[error]
-
-
-
-=== TEST 7: incr key (original value is not number)
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("foo", true)
- local res, err = dogs:incr("foo", 1, 0)
- ngx.say("incr: ", res, " ", err)
- ngx.say("foo = ", dogs:get("foo"))
- }
- }
---- request
-GET /test
---- response_body
-incr: nil not a number
-foo = true
---- no_error_log
-[error]
-
-
-
-=== TEST 8: init is not number
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- local res, err, forcible = dogs:incr("foo", 1, "bar")
- ngx.say("incr: ", res, " ", err, " ", forcible)
- ngx.say("foo = ", dogs:get("foo"))
- }
- }
---- request
-GET /test
---- error_code: 500
---- response_body_like: 500 Internal Server Error
---- error_log
-number expected, got string
diff --git a/src/deps/src/lua-nginx-module/t/145-shdict-list.t b/src/deps/src/lua-nginx-module/t/145-shdict-list.t
deleted file mode 100644
index 5672adbc5..000000000
--- a/src/deps/src/lua-nginx-module/t/145-shdict-list.t
+++ /dev/null
@@ -1,853 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-#repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 0);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: lpush & lpop
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local len, err = dogs:lpush("foo", "bar")
- if len then
- ngx.say("push success")
- else
- ngx.say("push err: ", err)
- end
-
- local val, err = dogs:llen("foo")
- ngx.say(val, " ", err)
-
- local val, err = dogs:lpop("foo")
- ngx.say(val, " ", err)
-
- local val, err = dogs:llen("foo")
- ngx.say(val, " ", err)
-
- local val, err = dogs:lpop("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-push success
-1 nil
-bar nil
-0 nil
-nil nil
---- no_error_log
-[error]
-
-
-
-=== TEST 2: get operation on list type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local len, err = dogs:lpush("foo", "bar")
- if len then
- ngx.say("push success")
- else
- ngx.say("push err: ", err)
- end
-
- local val, err = dogs:get("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-push success
-nil value is a list
---- no_error_log
-[error]
-
-
-
-=== TEST 3: set operation on list type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local len, err = dogs:lpush("foo", "bar")
- if len then
- ngx.say("push success")
- else
- ngx.say("push err: ", err)
- end
-
- local ok, err = dogs:set("foo", "bar")
- ngx.say(ok, " ", err)
-
- local val, err = dogs:get("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-push success
-true nil
-bar nil
---- no_error_log
-[error]
-
-
-
-=== TEST 4: replace operation on list type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local len, err = dogs:lpush("foo", "bar")
- if len then
- ngx.say("push success")
- else
- ngx.say("push err: ", err)
- end
-
- local ok, err = dogs:replace("foo", "bar")
- ngx.say(ok, " ", err)
-
- local val, err = dogs:get("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-push success
-true nil
-bar nil
---- no_error_log
-[error]
-
-
-
-=== TEST 5: add operation on list type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local len, err = dogs:lpush("foo", "bar")
- if len then
- ngx.say("push success")
- else
- ngx.say("push err: ", err)
- end
-
- local ok, err = dogs:add("foo", "bar")
- ngx.say(ok, " ", err)
-
- local val, err = dogs:get("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-push success
-false exists
-nil value is a list
---- no_error_log
-[error]
-
-
-
-=== TEST 6: delete operation on list type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local len, err = dogs:lpush("foo", "bar")
- if len then
- ngx.say("push success")
- else
- ngx.say("push err: ", err)
- end
-
- local ok, err = dogs:delete("foo")
- ngx.say(ok, " ", err)
-
- local val, err = dogs:get("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-push success
-true nil
-nil nil
---- no_error_log
-[error]
-
-
-
-=== TEST 7: incr operation on list type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local len, err = dogs:lpush("foo", "bar")
- if len then
- ngx.say("push success")
- else
- ngx.say("push err: ", err)
- end
-
- local ok, err = dogs:incr("foo", 1)
- ngx.say(ok, " ", err)
-
- local val, err = dogs:get("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-push success
-nil not a number
-nil value is a list
---- no_error_log
-[error]
-
-
-
-=== TEST 8: get_keys operation on list type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local len, err = dogs:lpush("foo", "bar")
- if len then
- ngx.say("push success")
- else
- ngx.say("push err: ", err)
- end
-
- local keys, err = dogs:get_keys()
- ngx.say("key: ", keys[1])
- }
- }
---- request
-GET /test
---- response_body
-push success
-key: foo
---- no_error_log
-[error]
-
-
-
-=== TEST 9: push operation on key-value type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local ok, err = dogs:set("foo", "bar")
- if ok then
- ngx.say("set success")
- else
- ngx.say("set err: ", err)
- end
-
- local len, err = dogs:lpush("foo", "bar")
- ngx.say(len, " ", err)
-
- local val, err = dogs:get("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-set success
-nil value not a list
-bar nil
---- no_error_log
-[error]
-
-
-
-=== TEST 10: pop operation on key-value type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local ok, err = dogs:set("foo", "bar")
- if ok then
- ngx.say("set success")
- else
- ngx.say("set err: ", err)
- end
-
- local val, err = dogs:lpop("foo")
- ngx.say(val, " ", err)
-
- local val, err = dogs:get("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-set success
-nil value not a list
-bar nil
---- no_error_log
-[error]
-
-
-
-=== TEST 11: llen operation on key-value type
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local ok, err = dogs:set("foo", "bar")
- if ok then
- ngx.say("set success")
- else
- ngx.say("set err: ", err)
- end
-
- local val, err = dogs:llen("foo")
- ngx.say(val, " ", err)
-
- local val, err = dogs:get("foo")
- ngx.say(val, " ", err)
- }
- }
---- request
-GET /test
---- response_body
-set success
-nil value not a list
-bar nil
---- no_error_log
-[error]
-
-
-
-=== TEST 12: lpush and lpop
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- for i = 1, 3 do
- local len, err = dogs:lpush("foo", i)
- if len ~= i then
- ngx.say("push err: ", err)
- break
- end
- end
-
- for i = 1, 3 do
- local val, err = dogs:lpop("foo")
- if not val then
- ngx.say("pop err: ", err)
- break
- else
- ngx.say(val)
- end
- end
- }
- }
---- request
-GET /test
---- response_body
-3
-2
-1
---- no_error_log
-[error]
-
-
-
-=== TEST 13: lpush and rpop
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- for i = 1, 3 do
- local len, err = dogs:lpush("foo", i)
- if len ~= i then
- ngx.say("push err: ", err)
- break
- end
- end
-
- for i = 1, 3 do
- local val, err = dogs:rpop("foo")
- if not val then
- ngx.say("pop err: ", err)
- break
- else
- ngx.say(val)
- end
- end
- }
- }
---- request
-GET /test
---- response_body
-1
-2
-3
---- no_error_log
-[error]
-
-
-
-=== TEST 14: rpush and lpop
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- for i = 1, 3 do
- local len, err = dogs:rpush("foo", i)
- if len ~= i then
- ngx.say("push err: ", err)
- break
- end
- end
-
- for i = 1, 3 do
- local val, err = dogs:lpop("foo")
- if not val then
- ngx.say("pop err: ", err)
- break
- else
- ngx.say(val)
- end
- end
- }
- }
---- request
-GET /test
---- response_body
-1
-2
-3
---- no_error_log
-[error]
-
-
-
-=== TEST 15: list removed: expired
---- http_config
- lua_shared_dict dogs 900k;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local N = 100000
- local max = 0
-
- for i = 1, N do
- local key = string.format("%05d", i)
-
- local len , err = dogs:lpush(key, i)
- if not len then
- max = i
- break
- end
- end
-
- local keys = dogs:get_keys(0)
-
- ngx.say("max - 1 matched keys length: ", max - 1 == #keys)
-
- dogs:flush_all()
-
- local keys = dogs:get_keys(0)
-
- ngx.say("keys all expired, left number: ", #keys)
-
- for i = 100000, 1, -1 do
- local key = string.format("%05d", i)
-
- local len, err = dogs:lpush(key, i)
- if not len then
- ngx.say("loop again, max matched: ", N + 1 - i == max)
- break
- end
- end
-
- dogs:flush_all()
-
- dogs:flush_expired()
-
- for i = 1, N do
- local key = string.format("%05d", i)
-
- local len, err = dogs:lpush(key, i)
- if not len then
- ngx.say("loop again, max matched: ", i == max)
- break
- end
- end
- }
- }
---- request
-GET /test
---- response_body
-max - 1 matched keys length: true
-keys all expired, left number: 0
-loop again, max matched: true
-loop again, max matched: true
---- no_error_log
-[error]
---- timeout: 9
-
-
-
-=== TEST 16: list removed: forcibly
---- http_config
- lua_shared_dict dogs 900k;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local N = 200000
- local max = 0
- for i = 1, N do
- local ok, err, forcible = dogs:set(i, i)
- if not ok or forcible then
- max = i
- break
- end
- end
-
- local two = dogs:get(2)
-
- ngx.say("two == number 2: ", two == 2)
-
- dogs:flush_all()
- dogs:flush_expired()
-
- local keys = dogs:get_keys(0)
-
- ngx.say("no one left: ", #keys)
-
- for i = 1, N do
- local key = string.format("%05d", i)
-
- local len, err = dogs:lpush(key, i)
- if not len then
- break
- end
- end
-
- for i = 1, max do
- local ok, err = dogs:set(i, i)
- if not ok then
- ngx.say("set err: ", err)
- break
- end
- end
-
- local two = dogs:get(2)
-
- ngx.say("two == number 2: ", two == 2)
- }
- }
---- request
-GET /test
---- response_body
-two == number 2: true
-no one left: 0
-two == number 2: true
---- no_error_log
-[error]
---- timeout: 9
-
-
-
-=== TEST 17: expire on all types
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local len, err = dogs:lpush("list", "foo")
- if not len then
- ngx.say("push err: ", err)
- end
-
- local ok, err = dogs:set("key", "bar")
- if not ok then
- ngx.say("set err: ", err)
- end
-
- local keys = dogs:get_keys(0)
-
- ngx.say("keys number: ", #keys)
-
- dogs:flush_all()
-
- local keys = dogs:get_keys(0)
-
- ngx.say("keys number: ", #keys)
- }
- }
---- request
-GET /test
---- response_body
-keys number: 2
-keys number: 0
---- no_error_log
-[error]
-
-
-
-=== TEST 18: long list node
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local long_str = string.rep("foo", 10)
-
- for i = 1, 3 do
- local len, err = dogs:lpush("list", long_str)
- if not len then
- ngx.say("push err: ", err)
- end
- end
-
- for i = 1, 3 do
- local val, err = dogs:lpop("list")
- if val then
- ngx.say(val)
- end
- end
- }
- }
---- request
-GET /test
---- response_body
-foofoofoofoofoofoofoofoofoofoo
-foofoofoofoofoofoofoofoofoofoo
-foofoofoofoofoofoofoofoofoofoo
---- no_error_log
-[error]
-
-
-
-=== TEST 19: incr on expired list
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
-
- local long_str = string.rep("foo", 10 * 1024) -- 30k
-
- for i = 1, 100 do
- for j = 1, 10 do
- local key = "list" .. j
- local len, err = dogs:lpush(key, long_str)
- if not len then
- ngx.say("push err: ", err)
- end
- end
-
- dogs:flush_all()
-
- for j = 10, 1, -1 do
- local key = "list" .. j
- local newval, err = dogs:incr(key, 1, 0)
- if not newval then
- ngx.say("incr err: ", err)
- end
- end
-
- dogs:flush_all()
- end
-
- ngx.say("done")
- }
- }
---- request
-GET /test
---- response_body
-done
---- no_error_log
-[error]
-
-
-
-=== TEST 20: push to an expired list
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- local len, err = dogs:lpush("cc", "1") --add another list to avoid key"aa" be cleaned (run ‘ngx_http_lua_shdict_expire(ctx, 1)’ may clean key ,ensure key'aa' not clean ,just expired))
- if not len then
- ngx.say("push cc err: ", err)
- end
- local len, err = dogs:lpush("aa", "1")
- if not len then
- ngx.say("push1 err: ", err)
- end
- local succ, err = dogs:expire("aa", 0.2)
- if not succ then
- ngx.say("expire err: ",err)
- end
- ngx.sleep(0.3) -- list aa expired
- local len, err = dogs:lpush("aa", "2") --push to an expired list may set as a new list
- if not len then
- ngx.say("push2 err: ", err)
- end
- local len, err = dogs:llen("aa") -- new list len is 1
- if not len then
- ngx.say("llen err: ", err)
- else
- ngx.say("aa:len :", dogs:llen("aa"))
- end
- }
- }
-
---- request
-GET /test
---- response_body
-aa:len :1
---- no_error_log
-[error]
-
-
-
-=== TEST 21: push to an expired list then pop many time (more then list len )
---- http_config
- lua_shared_dict dogs 1m;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- local len, err = dogs:lpush("cc", "1") --add another list to avoid key"aa" be cleaned (run ‘ngx_http_lua_shdict_expire(ctx, 1)’ may clean key ,ensure key'aa' not clean ,just expired))
- if not len then
- ngx.say("push cc err: ", err)
- end
- local len, err = dogs:lpush("aa", "1")
- if not len then
- ngx.say("push1 err: ", err)
- end
- local succ, err = dogs:expire("aa", 0.2)
- if not succ then
- ngx.say("expire err: ",err)
- end
- ngx.sleep(0.3) -- list aa expired
- local len, err = dogs:lpush("aa", "2") --push to an expired list may set as a new list
- if not len then
- ngx.say("push2 err: ", err)
- end
- local val, err = dogs:lpop("aa")
- if not val then
- ngx.say("llen err: ", err)
- end
- local val, err = dogs:lpop("aa") -- val == nil
- ngx.say("aa list value: ", val)
- }
- }
-
---- request
-GET /test
---- response_body
-aa list value: nil
---- no_error_log
-[error]
-
-
-
-=== TEST 22: lpush return nil
---- http_config
- lua_shared_dict dogs 100k;
---- config
- location = /test {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- for i = 1, 2920
- do
- local len, err = dogs:lpush("foo", "bar")
- end
- local len, err = dogs:lpush("foo", "bar")
- ngx.say(len)
- }
- }
---- request
-GET /test
---- response_body
-nil
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/146-malloc-trim.t b/src/deps/src/lua-nginx-module/t/146-malloc-trim.t
deleted file mode 100644
index fc425ce72..000000000
--- a/src/deps/src/lua-nginx-module/t/146-malloc-trim.t
+++ /dev/null
@@ -1,342 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-#repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4 + 3);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: malloc_trim() every 1 req, in subreq
---- http_config
- lua_malloc_trim 1;
---- config
- location = /t {
- return 200 "ok\n";
- }
-
- location = /main {
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- }
---- request
-GET /main
---- response_body
-ok
-ok
-ok
-ok
-ok
---- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
---- grep_error_log_out eval
-qr/\Amalloc_trim\(1\) returned [01]
-\z/
---- wait: 0.2
---- no_error_log
-[error]
-
-
-
-=== TEST 2: malloc_trim() every 1 req, in subreq
---- http_config
- lua_malloc_trim 1;
---- config
- location = /t {
- log_subrequest on;
- return 200 "ok\n";
- }
-
- location = /main {
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- }
---- request
-GET /main
---- response_body
-ok
-ok
-ok
-ok
-ok
---- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
---- grep_error_log_out eval
-qr/\Amalloc_trim\(1\) returned [01]
-malloc_trim\(1\) returned [01]
-malloc_trim\(1\) returned [01]
-malloc_trim\(1\) returned [01]
-malloc_trim\(1\) returned [01]
-malloc_trim\(1\) returned [01]
-\z/
---- wait: 0.2
---- no_error_log
-[error]
-
-
-
-=== TEST 3: malloc_trim() every 2 req, in subreq
---- http_config
- lua_malloc_trim 2;
---- config
- location = /t {
- log_subrequest on;
- return 200 "ok\n";
- }
-
- location = /main {
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- }
---- request
-GET /main
---- response_body
-ok
-ok
-ok
-ok
-ok
---- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
---- grep_error_log_out eval
-qr/\Amalloc_trim\(1\) returned [01]
-malloc_trim\(1\) returned [01]
-malloc_trim\(1\) returned [01]
-\z/
---- wait: 0.2
---- no_error_log
-[error]
-
-
-
-=== TEST 4: malloc_trim() every 3 req, in subreq
---- http_config
- lua_malloc_trim 3;
---- config
- location = /t {
- log_subrequest on;
- return 200 "ok\n";
- }
-
- location = /main {
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- }
---- request
-GET /main
---- response_body
-ok
-ok
-ok
-ok
-ok
---- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
---- grep_error_log_out eval
-qr/\Amalloc_trim\(1\) returned [01]
-malloc_trim\(1\) returned [01]
-\z/
---- wait: 0.2
---- no_error_log
-[error]
-
-
-
-=== TEST 5: malloc_trim() every 2 req, in subreq, big memory usage
---- http_config
- lua_malloc_trim 2;
- lua_package_path "$prefix/html/?.lua;;";
---- config
- location = /t {
- log_subrequest on;
- content_by_lua_block {
- require("foo")()
- }
- }
-
- location = /main {
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- }
---- user_files
->>> foo.lua
-local ffi = require "ffi"
-
-ffi.cdef[[
- void *malloc(size_t sz);
- void free(void *p);
-]]
-
-return function ()
- local t = {}
- for i = 1, 10 do
- t[i] = ffi.C.malloc(1024 * 128)
- end
- for i = 1, 10 do
- ffi.C.free(t[i])
- end
- ngx.say("ok")
-end
---- request
-GET /main
---- response_body
-ok
-ok
-ok
-ok
-ok
---- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
---- grep_error_log_out
-malloc_trim(1) returned 1
-malloc_trim(1) returned 1
-malloc_trim(1) returned 1
---- wait: 0.2
---- no_error_log
-[error]
-
-
-
-=== TEST 6: zero count means off
---- http_config
- lua_malloc_trim 0;
- lua_package_path "$prefix/html/?.lua;;";
---- config
- location = /t {
- content_by_lua_block {
- require("foo")()
- }
- }
---- user_files
->>> foo.lua
-local ffi = require "ffi"
-
-ffi.cdef[[
- void *malloc(size_t sz);
- void free(void *p);
-]]
-
-return function ()
- local t = {}
- for i = 1, 10 do
- t[i] = ffi.C.malloc(1024 * 128)
- end
- for i = 1, 10 do
- ffi.C.free(t[i])
- end
- ngx.say("ok")
-end
-
---- request
-GET /t
---- response_body
-ok
---- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
---- grep_error_log_out
---- wait: 0.2
---- no_error_log
-malloc_trim() disabled
-[error]
-
-
-
-=== TEST 7: zero count means off, log_by_lua
---- http_config
- lua_malloc_trim 0;
- lua_package_path "$prefix/html/?.lua;;";
---- config
- location = /t {
- content_by_lua_block {
- require("foo")()
- }
- log_by_lua_block {
- print("Hello from log")
- }
- }
---- user_files
->>> foo.lua
-local ffi = require "ffi"
-
-ffi.cdef[[
- void *malloc(size_t sz);
- void free(void *p);
-]]
-
-return function ()
- local t = {}
- for i = 1, 10 do
- t[i] = ffi.C.malloc(1024 * 128)
- end
- for i = 1, 10 do
- ffi.C.free(t[i])
- end
- ngx.say("ok")
-end
-
---- request
-GET /t
---- response_body
-ok
---- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
---- grep_error_log_out
---- wait: 0.2
---- error_log
-Hello from log
-malloc_trim() disabled
---- no_error_log
-[error]
-
-
-
-=== TEST 8: malloc_trim() every 1 req
---- http_config
- lua_malloc_trim 1;
---- config
- location = /t {
- return 200 "ok\n";
- }
-
- location = /main {
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- echo_location /t;
- }
---- request
-GET /main
---- response_body
-ok
-ok
-ok
-ok
-ok
---- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
---- grep_error_log_out eval
-qr/\Amalloc_trim\(1\) returned [01]
-\z/
---- wait: 0.2
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/147-tcp-socket-timeouts.t b/src/deps/src/lua-nginx-module/t/147-tcp-socket-timeouts.t
deleted file mode 100644
index ceddb61dc..000000000
--- a/src/deps/src/lua-nginx-module/t/147-tcp-socket-timeouts.t
+++ /dev/null
@@ -1,628 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-BEGIN {
- if (!defined $ENV{LD_PRELOAD}) {
- $ENV{LD_PRELOAD} = '';
- }
-
- if ($ENV{LD_PRELOAD} !~ /\bmockeagain\.so\b/) {
- $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}";
- }
-
- if ($ENV{MOCKEAGAIN} eq 'r') {
- $ENV{MOCKEAGAIN} = 'rw';
-
- } else {
- $ENV{MOCKEAGAIN} = 'w';
- }
-
- $ENV{TEST_NGINX_EVENT_TYPE} = 'poll';
- delete($ENV{TEST_NGINX_USE_HTTP2});
- $ENV{MOCKEAGAIN_WRITE_TIMEOUT_PATTERN} = 'slowdata';
-}
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 1);
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- config
- server_tokens off;
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeouts(150, 150, 150) -- 150ms read timeout
-
- local port = ngx.var.server_port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- sock:close()
- }
- }
-
- location /foo {
- content_by_lua_block {
- ngx.sleep(0.01) -- 10 ms
- ngx.say("foo")
- }
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body_like
-received: foo
---- no_error_log
-[error]
-
-
-
-=== TEST 2: read timeout
---- config
- server_tokens off;
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeouts(150, 150, 2) -- 2ms read timeout
-
- local port = ngx.var.server_port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET /foo HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- sock:close()
- }
- }
-
- location /foo {
- content_by_lua_block {
- ngx.sleep(0.01) -- 10 ms
- ngx.say("foo")
- }
- more_clear_headers Date;
- }
-
---- request
-GET /t
---- response_body_like
-failed to receive a line: timeout \[\]
---- error_log
-lua tcp socket read timed out
-
-
-
-=== TEST 3: send ok
---- config
- server_tokens off;
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeouts(500, 500, 500) -- 500ms timeout
-
- local port = ngx.var.server_port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local data = string.rep("a", 8) -- 8 bytes
- local num = 10 -- total: 80 bytes
-
- local req = "POST /foo HTTP/1.0\r\nHost: localhost\r\nContent-Length: "
- .. #data * num .. "\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- for i = 1, num do
- local bytes, err = sock:send(data)
- if not bytes then
- ngx.say("failed to send body: ", err)
- return
- end
- end
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- sock:close()
- }
- }
-
- location /foo {
- content_by_lua_block {
- local content_length = ngx.req.get_headers()["Content-Length"]
-
- local sock = ngx.req.socket()
-
- sock:settimeouts(500, 500, 500)
-
- local chunk = 8
-
- for i = 1, content_length, chunk do
- local data, err = sock:receive(chunk)
- if not data then
- ngx.say("failed to receive chunk: ", err)
- return
- end
- end
-
- ngx.say("got len: ", content_length)
- }
- }
-
---- request
-GET /t
---- response_body_like
-received: got len: 80
---- no_error_log
-[error]
-
-
-
-=== TEST 4: send timeout
---- config
- server_tokens off;
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeouts(500, 500, 500) -- 500ms timeout
-
- local port = ngx.var.server_port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local data = "slowdata" -- slow data
- local num = 10
-
- local req = "POST /foo HTTP/1.0\r\nHost: localhost\r\nContent-Length: "
- .. #data * num .. "\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- for i = 1, num do
- local bytes, err = sock:send(data)
- if not bytes then
- ngx.say("failed to send body: ", err)
- return
- end
- end
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- sock:close()
- }
- }
-
- location /foo {
- content_by_lua_block {
- local content_length = ngx.req.get_headers()["Content-Length"]
-
- local sock = ngx.req.socket()
-
- sock:settimeouts(500, 500, 500)
-
- local chunk = 8
-
- for i = 1, content_length, chunk do
- local data, err = sock:receive(chunk)
- if not data then
- ngx.say("failed to receive chunk: ", err)
- return
- end
- end
-
- ngx.say("got len: ", content_length)
- }
- }
-
---- request
-GET /t
---- response_body
-failed to send body: timeout
---- error_log
-lua tcp socket write timed out
-
-
-
-=== TEST 5: connection timeout (tcp)
---- config
- resolver $TEST_NGINX_RESOLVER ipv6=off;
- resolver_timeout 3s;
- location /test {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeouts(100, 100, 100)
-
- local ok, err = sock:connect("127.0.0.2", 12345)
- ngx.say("connect: ", ok, " ", err)
-
- local bytes
- bytes, err = sock:send("hello")
- ngx.say("send: ", bytes, " ", err)
-
- local line
- line, err = sock:receive()
- ngx.say("receive: ", line, " ", err)
-
- ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- }
- }
---- request
- GET /test
---- response_body
-connect: nil timeout
-send: nil closed
-receive: nil closed
-close: nil closed
---- error_log
-lua tcp socket connect timed out, when connecting to 127.0.0.2:12345
---- timeout: 10
-
-
-
-=== TEST 6: different timeout with duplex socket (settimeout)
---- config
- server_tokens off;
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeouts(200, 200, 200) -- 200ms timeout
-
- local port = ngx.var.server_port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local data = string.rep("a", 4) -- 4 bytes
- local num = 3
-
- local req = "POST /foo HTTP/1.0\r\nHost: localhost\r\nContent-Length: "
- .. #data * num .. "\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- for i = 1, num do
- local bytes, err = sock:send(data)
- if not bytes then
- ngx.log(ngx.ERR, "failed to send body: ", err)
- return
- end
- ngx.sleep(0.12) -- 120ms
- end
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- sock:close()
- }
- }
-
- location /foo {
- content_by_lua_block {
- local content_length = ngx.req.get_headers()["Content-Length"]
-
- local sock = ngx.req.socket(true)
-
- local chunk = 4
-
- local function read()
- sock:settimeout(200) -- read: 200 ms
-
- local data, err = sock:receive(content_length)
- if not data then
- ngx.log(ngx.ERR, "failed to receive data: ", err)
- return
- end
- end
-
- local co = ngx.thread.spawn(read)
-
- sock:settimeout(100) -- send: 100ms
- sock:send("ok\n")
-
- local ok, err = ngx.thread.wait(co)
- if not ok then
- ngx.log(ngx.ERR, "failed to wait co: ", err)
- end
- }
- }
-
---- request
-GET /t
---- response_body
-received: ok
-failed to receive a line: closed []
---- error_log
-lua tcp socket read timed out
-failed to receive data: timeout
-
-
-
-=== TEST 7: different timeout with duplex socket (settimeouts)
---- config
- server_tokens off;
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeouts(200, 200, 200) -- 200ms timeout
-
- local port = ngx.var.server_port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local data = string.rep("a", 4) -- 4 bytes
- local num = 3
-
- local req = "POST /foo HTTP/1.0\r\nHost: localhost\r\nContent-Length: "
- .. #data * num .. "\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- for i = 1, num do
- local bytes, err = sock:send(data)
- if not bytes then
- ngx.log(ngx.ERR, "failed to send body: ", err)
- return
- end
- ngx.sleep(0.12) -- 120ms
- end
-
- while true do
- local line, err, part = sock:receive()
- if line then
- ngx.say("received: ", line)
-
- else
- ngx.say("failed to receive a line: ", err, " [", part, "]")
- break
- end
- end
-
- sock:close()
- }
- }
-
- location /foo {
- content_by_lua_block {
- local content_length = ngx.req.get_headers()["Content-Length"]
-
- local sock = ngx.req.socket(true)
-
- sock:settimeouts(0, 100, 200) -- send: 100ms, read: 200ms
-
- local chunk = 4
-
- local function read()
- local data, err = sock:receive(content_length)
- if not data then
- ngx.log(ngx.ERR, "failed to receive data: ", err)
- return
- end
- end
-
- local co = ngx.thread.spawn(read)
-
- sock:send("ok\n")
-
- local ok, err = ngx.thread.wait(co)
- if not ok then
- ngx.log(ngx.ERR, "failed to wait co: ", err)
- end
- }
- }
-
---- request
-GET /t
---- response_body
-received: ok
-failed to receive a line: closed []
---- no_error_log
-[error]
-
-
-
-=== TEST 8: connection timeout overflow detection
---- config
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local ok, err = pcall(sock.settimeouts, sock,
- (2 ^ 31) - 1, 500, 500)
- if not ok then
- ngx.say("failed to set timeouts: ", err)
- else
- ngx.say("settimeouts: ok")
- end
-
- ok, err = pcall(sock.settimeouts, sock, 2 ^ 31, 500, 500)
- if not ok then
- ngx.say("failed to set timeouts: ", err)
- else
- ngx.say("settimeouts: ok")
- end
- }
- }
---- request
-GET /t
---- response_body_like
-settimeouts: ok
-failed to set timeouts: bad timeout value
---- no_error_log
-[error]
-
-
-
-=== TEST 9: send timeout overflow detection
---- config
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local ok, err = pcall(sock.settimeouts, sock,
- 500, (2 ^ 31) - 1, 500)
- if not ok then
- ngx.say("failed to set timeouts: ", err)
- else
- ngx.say("settimeouts: ok")
- end
-
- ok, err = pcall(sock.settimeouts, sock, 500, 2 ^ 31, 500)
- if not ok then
- ngx.say("failed to set timeouts: ", err)
- else
- ngx.say("settimeouts: ok")
- end
- }
- }
---- request
-GET /t
---- response_body_like
-settimeouts: ok
-failed to set timeouts: bad timeout value
---- no_error_log
-[error]
-
-
-
-=== TEST 10: read timeout overflow detection
---- config
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local ok, err = pcall(sock.settimeouts, sock,
- 500, 500, (2 ^ 31) - 1)
- if not ok then
- ngx.say("failed to set timeouts: ", err)
- else
- ngx.say("settimeouts: ok")
- end
-
- ok, err = pcall(sock.settimeouts, sock, 500, 500, 2 ^ 31)
- if not ok then
- ngx.say("failed to set timeouts: ", err)
- else
- ngx.say("settimeouts: ok")
- end
- }
- }
---- request
-GET /t
---- response_body_like
-settimeouts: ok
-failed to set timeouts: bad timeout value
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/148-fake-shm-zone.t b/src/deps/src/lua-nginx-module/t/148-fake-shm-zone.t
deleted file mode 100644
index b8a92270a..000000000
--- a/src/deps/src/lua-nginx-module/t/148-fake-shm-zone.t
+++ /dev/null
@@ -1,170 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use lib 'lib';
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-#repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 - 1);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: require test
---- http_config
- lua_fake_shm x1 1m;
- lua_fake_shm x2 1m;
---- config
- location = /test {
- content_by_lua_block {
- local shm_zones = require("fake_shm_zones")
- ngx.say(type(shm_zones))
- local x1 = shm_zones.x1
- ngx.say(type(x1))
- local x2 = shm_zones.x2
- ngx.say(type(x1))
- }
- }
---- request
-GET /test
---- response_body
-table
-table
-table
---- no_error_log
-[error]
-
-
-
-=== TEST 2: index shm_zone
---- http_config
- lua_fake_shm x1 1m;
---- config
- location = /test {
- content_by_lua_block {
- local shm_zones = require("fake_shm_zones")
- local x1 = shm_zones.x1
- ngx.say(type(x1))
- }
- }
---- request
-GET /test
---- response_body
-table
---- no_error_log
-[error]
-
-
-
-=== TEST 3: get_info
---- http_config
- lua_fake_shm x1 1m;
---- config
- location = /test {
- content_by_lua_block {
- local shm_zones = require("fake_shm_zones")
- local name, size, isinit, isold
- local x1 = shm_zones.x1
-
- name, size, isinit, isold = x1:get_info()
- ngx.say("name=", name)
- ngx.say("size=", size)
- ngx.say("isinit=", isinit)
- ngx.say("isold=", isold)
- }
- }
---- request
-GET /test
---- response_body
-name=x1
-size=1048576
-isinit=true
-isold=false
---- no_error_log
-[error]
-
-
-
-=== TEST 4: multiply zones
---- http_config
- lua_fake_shm x1 1m;
- lua_fake_shm x2 2m;
- lua_fake_shm x3 3m;
---- config
- location = /test {
- content_by_lua_block {
- local shm_zones = require("fake_shm_zones")
- local name, size, isinit, isold
- local x1 = shm_zones.x1
- local x2 = shm_zones.x2
- local x3 = shm_zones.x3
-
- name, size, isinit, isold = x1:get_info()
- ngx.say("name=", name)
- ngx.say("size=", size)
- ngx.say("isinit=", isinit)
- ngx.say("isold=", isold)
-
- name, size, isinit, isold = x2:get_info()
- ngx.say("name=", name)
- ngx.say("size=", size)
- ngx.say("isinit=", isinit)
- ngx.say("isold=", isold)
-
- name, size, isinit, isold = x3:get_info()
- ngx.say("name=", name)
- ngx.say("size=", size)
- ngx.say("isinit=", isinit)
- ngx.say("isold=", isold)
- }
- }
---- request
-GET /test
---- response_body
-name=x1
-size=1048576
-isinit=true
-isold=false
-name=x2
-size=2097152
-isinit=true
-isold=false
-name=x3
-size=3145728
-isinit=true
-isold=false
---- no_error_log
-[error]
-
-
-
-=== TEST 5: duplicate zones
---- http_config
- lua_fake_shm x1 1m;
- lua_fake_shm x1 1m;
---- config
- location = /test {
- content_by_lua_block {
- local shm_zones = require("fake_shm_zones")
- local x1 = shm_zones.x1
- ngx.say("error")
- }
- }
---- request
-GET /test
---- request_body_unlike
-error
---- must_die
---- error_log
-lua_fake_shm "x1" is already defined as "x1"
---- error_log
-[emerg]
diff --git a/src/deps/src/lua-nginx-module/t/149-hup-fake-shm-zone.t b/src/deps/src/lua-nginx-module/t/149-hup-fake-shm-zone.t
deleted file mode 100644
index 1b7b4b5f7..000000000
--- a/src/deps/src/lua-nginx-module/t/149-hup-fake-shm-zone.t
+++ /dev/null
@@ -1,91 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_CHECK_LEAK}) {
- $SkipReason = "unavailable for the hup tests";
-
- } else {
- $ENV{TEST_NGINX_USE_HUP} = 1;
- undef $ENV{TEST_NGINX_USE_STAP};
- }
-}
-
-use lib 'lib';
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: get_info, before HUP reload
---- http_config
- lua_fake_shm x1 1m;
---- config
- location = /test {
- content_by_lua_block {
- local shm_zones = require("fake_shm_zones")
- local name, size, isinit, isold
- local x1 = shm_zones.x1
-
- name, size, isinit, isold = x1:get_info()
- ngx.say("name=", name)
- ngx.say("size=", size)
- ngx.say("isinit=", isinit)
- ngx.say("isold=", isold)
- }
- }
---- request
-GET /test
---- response_body
-name=x1
-size=1048576
-isinit=true
-isold=false
---- no_error_log
-[error]
-
-
-
-=== TEST 2: get_info, after HUP reload
---- http_config
- lua_fake_shm x1 1m;
---- config
- location = /test {
- content_by_lua_block {
- local shm_zones = require("fake_shm_zones")
- local name, size, isinit, isold
- local x1 = shm_zones.x1
-
- name, size, isinit, isold = x1:get_info()
- ngx.say("name=", name)
- ngx.say("size=", size)
- ngx.say("isinit=", isinit)
- ngx.say("isold=", isold)
- }
- }
---- request
-GET /test
---- response_body
-name=x1
-size=1048576
-isinit=true
-isold=true
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/150-fake-delayed-load.t b/src/deps/src/lua-nginx-module/t/150-fake-delayed-load.t
deleted file mode 100644
index 232bbf3a8..000000000
--- a/src/deps/src/lua-nginx-module/t/150-fake-delayed-load.t
+++ /dev/null
@@ -1,56 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use lib 'lib';
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_process_enabled(1);
-#log_level('warn');
-
-#repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-no_long_string();
-#master_on();
-#workers(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: lua code cache on
---- http_config
- lua_code_cache on;
---- config
- location = /cache_on {
- content_by_lua_block {
- local delayed_load = require("ngx.delayed_load")
- ngx.say(type(delayed_load.get_function))
- }
- }
---- request
-GET /cache_on
---- response_body
-function
---- no_error_log
-[error]
-
-
-
-=== TEST 2: lua code cache off
---- http_config
- lua_code_cache off;
---- config
- location = /cache_off {
- content_by_lua_block {
- local delayed_load = require("ngx.delayed_load")
- ngx.say(type(delayed_load.get_function))
- }
- }
---- request
-GET /cache_off
---- response_body
-function
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/151-initby-hup.t b/src/deps/src/lua-nginx-module/t/151-initby-hup.t
deleted file mode 100644
index a37db9fe4..000000000
--- a/src/deps/src/lua-nginx-module/t/151-initby-hup.t
+++ /dev/null
@@ -1,168 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_CHECK_LEAK}) {
- $SkipReason = "unavailable for the hup tests";
-
- } else {
- $ENV{TEST_NGINX_USE_HUP} = 1;
- undef $ENV{TEST_NGINX_USE_STAP};
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-#no_diff();
-#no_long_string();
-no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: no error in init before HUP
---- http_config
- init_by_lua_block {
- foo = "hello, FOO"
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(foo)
- }
- }
---- request
-GET /lua
---- response_body
-hello, FOO
---- no_error_log
-[error]
-
-
-
-=== TEST 2: error in init after HUP (master still alive, worker process still the same as before)
---- http_config
- init_by_lua_block {
- error("failed to init")
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(foo)
- }
- }
---- request
-GET /lua
---- response_body
-hello, FOO
---- error_log
-failed to init
---- reload_fails
-
-
-
-=== TEST 3: no error in init again
---- http_config
- init_by_lua_block {
- foo = "hello, foo"
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(foo)
- }
- }
---- request
-GET /lua
---- response_body
-hello, foo
---- no_error_log
-[error]
-
-
-
-=== TEST 4: no error in init before HUP, used ngx.shared.DICT
---- http_config
- lua_shared_dict dogs 1m;
-
- init_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("foo", "hello, FOO")
- }
---- config
- location /lua {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- local foo = dogs:get("foo")
- ngx.say(foo)
- }
- }
---- request
-GET /lua
---- response_body
-hello, FOO
---- no_error_log
-[error]
-
-
-
-=== TEST 5: error in init after HUP, not reloaded but foo have changed.
---- http_config
- lua_shared_dict dogs 1m;
-
- init_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("foo", "foo have changed")
-
- error("failed to init")
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("HUP reload failed")
- }
- }
---- request
-GET /lua
---- response_body
-foo have changed
---- error_log
-failed to init
---- reload_fails
-
-
-
-=== TEST 6: no error in init again, reload success and foo still have changed.
---- http_config
- lua_shared_dict dogs 1m;
-
- init_by_lua_block {
- -- do nothing
- }
---- config
- location /lua {
- content_by_lua_block {
- local dogs = ngx.shared.dogs
- local foo = dogs:get("foo")
- ngx.say(foo)
- ngx.say("reload success")
- }
- }
---- request
-GET /lua
---- response_body
-foo have changed
-reload success
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/152-timer-every.t b/src/deps/src/lua-nginx-module/t/152-timer-every.t
deleted file mode 100644
index 374e80e04..000000000
--- a/src/deps/src/lua-nginx-module/t/152-timer-every.t
+++ /dev/null
@@ -1,386 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 7 + 2);
-
-#no_diff();
-no_long_string();
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-$ENV{TEST_NGINX_HTML_DIR} = $HtmlDir;
-
-worker_connections(1024);
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple very
---- config
- location /t {
- content_by_lua_block {
- local begin = ngx.now()
- local function f(premature)
- print("elapsed: ", ngx.now() - begin)
- print("timer prematurely expired: ", premature)
- end
-
- local ok, err = ngx.timer.every(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
-
- ngx.say("registered timer")
- }
- }
---- request
-GET /t
---- response_body
-registered timer
---- wait: 0.11
---- no_error_log
-[error]
-[alert]
-[crit]
-timer prematurely expired: true
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.0(?:4[4-9]|5[0-6])\d*, context: ngx\.timer, client: \d+\.\d+\.\d+\.\d+, server: 0\.0\.0\.0:\d+/,
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: 0\.(?:09|10)\d*, context: ngx\.timer, client: \d+\.\d+\.\d+\.\d+, server: 0\.0\.0\.0:\d+/,
-"lua ngx.timer expired",
-"http lua close fake http connection",
-"timer prematurely expired: false",
-]
-
-
-
-=== TEST 2: shared global env
---- config
- location /t {
- content_by_lua_block {
- local begin = ngx.now()
- local function f()
- foo = 3
- print("foo in timer: ", foo)
- end
- local ok, err = ngx.timer.every(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.sleep(0.11)
- ngx.say("foo = ", foo)
- }
- }
---- request
-GET /t
---- response_body
-foo = 3
---- wait: 0.12
---- no_error_log
-[error]
-[alert]
-[crit]
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: foo in timer: 3/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 3: lua variable sharing via upvalue
---- config
- location /t {
- content_by_lua_block {
- local begin = ngx.now()
- local foo = 0
- local function f()
- foo = foo + 3
- print("foo in timer: ", foo)
- end
- local ok, err = ngx.timer.every(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.11)
- ngx.say("foo = ", foo)
- }
- }
---- request
-GET /t
---- response_body
-registered timer
-foo = 6
---- wait: 0.12
---- no_error_log
-[error]
-[alert]
-[crit]
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: foo in timer: 3/,
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: foo in timer: 6/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 4: create the next timer immediately when timer start running
---- config
- location /t {
- content_by_lua_block {
- local begin = ngx.now()
- local foo = 0
- local function f()
- foo = foo + 3
- print("foo in timer: ", foo)
-
- ngx.sleep(0.1)
- end
- local ok, err = ngx.timer.every(0.05, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- ngx.sleep(0.11)
- ngx.say("foo = ", foo)
- }
- }
---- request
-GET /t
---- response_body
-registered timer
-foo = 6
---- wait: 0.12
---- no_error_log
-[error]
-[alert]
-[crit]
---- error_log eval
-[
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: foo in timer: 3/,
-qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: foo in timer: 6/,
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 5: callback args
---- config
- location /t {
- content_by_lua_block {
- local n = 0
-
- local function f(premature, a, b, c)
- n = n + 1
- print("the ", n, " time, args: ", a, ", ", b, ", ", c)
-
- a, b, c = 0, 0, 0
- end
-
- local ok, err = ngx.timer.every(0.05, f, 1, 2)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
-
- ngx.say("registered timer")
- ngx.sleep(0.11)
- }
- }
---- request
-GET /t
---- response_body
-registered timer
---- wait: 0.12
---- no_error_log
-[error]
-[alert]
-[crit]
---- error_log eval
-[
-"the 1 time, args: 1, 2, nil",
-"the 2 time, args: 1, 2, nil",
-"lua ngx.timer expired",
-"http lua close fake http connection"
-]
-
-
-
-=== TEST 6: memory leak check
---- quic_max_idle_timeout: 8
---- config
- location /t {
- content_by_lua_block {
- local function f()
- local a = 1
- -- do nothing
- end
-
- for i = 1, 100 do
- local ok, err = ngx.timer.every(0.1, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- end
-
- ngx.say("registered timer")
-
- collectgarbage("collect")
- local start = collectgarbage("count")
-
- ngx.sleep(0.21)
-
- collectgarbage("collect")
- local growth1 = collectgarbage("count") - start
-
- ngx.sleep(0.51)
-
- collectgarbage("collect")
- local growth2 = collectgarbage("count") - start
-
- ngx.say("growth1 == growth2: ", growth1 == growth2)
- }
- }
---- request
-GET /t
---- response_body
-registered timer
-growth1 == growth2: true
---- no_error_log
-[error]
-[alert]
-[crit]
---- timeout: 8
-
-
-
-=== TEST 7: respect lua_max_pending_timers
---- http_config
- lua_max_pending_timers 10;
---- config
- location /t {
- content_by_lua_block {
- local function f()
- local a = 1
- -- do nothing
- end
-
- for i = 1, 11 do
- local ok, err = ngx.timer.every(0.1, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- end
-
- ngx.say("registered 10 timers")
- }
- }
---- request
-GET /t
---- response_body
-failed to set timer: too many pending timers
---- no_error_log
-[error]
-[alert]
-[crit]
-
-
-
-=== TEST 8: respect lua_max_running_timers
---- http_config
- lua_max_pending_timers 100;
- lua_max_running_timers 9;
---- config
- location /t {
- content_by_lua_block {
- local function f()
- local a = 1
- ngx.sleep(0.02)
- -- do nothing
- end
-
- for i = 1, 10 do
- local ok, err = ngx.timer.every(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- end
-
- ngx.say("registered 10 timers")
-
- ngx.sleep(0.03)
- }
- }
---- request
-GET /t
---- response_body
-registered 10 timers
---- no_error_log
-[error]
-[crit]
---- error_log
-lua_max_running_timers are not enough
-
-
-
-=== TEST 9: lua_code_cache off
-FIXME: it is know that this test case leaks memory.
-so we skip it in the "check leak" testing mode.
---- http_config
- lua_code_cache off;
---- config
- location /t {
- content_by_lua_block {
- local function f()
- local a = 1
- -- do nothing
- end
-
- local ok, err = ngx.timer.every(0.01, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
-
- collectgarbage("collect")
- ngx.say("registered timer")
-
- ngx.sleep(0.03)
-
- collectgarbage("collect")
-
- ngx.sleep(0.03)
-
- collectgarbage("collect")
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-registered timer
-ok
---- no_error_log
-[error]
-[crit]
---- no_check_leak
diff --git a/src/deps/src/lua-nginx-module/t/153-semaphore-hup.t b/src/deps/src/lua-nginx-module/t/153-semaphore-hup.t
deleted file mode 100644
index 496db6862..000000000
--- a/src/deps/src/lua-nginx-module/t/153-semaphore-hup.t
+++ /dev/null
@@ -1,156 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use lib 'lib';
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(10140);
-#workers(1);
-log_level('warn');
-master_process_enabled(1);
-repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-no_long_string();
-#no_diff();
-
-add_block_preprocessor(sub {
- my $block = shift;
-
- my $http_config = $block->http_config || '';
- $http_config .= <<'_EOC_';
- lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
- lua_shared_dict shdict 4m;
-
- init_by_lua_block {
- require "resty.core"
- local process = require "ngx.process"
- local ok, err = process.enable_privileged_agent()
- if not ok then
- ngx.log(ngx.ERR, "failed to enable_privileged_agent: ", err)
- end
- }
-
- init_worker_by_lua_block {
- local function test(pre)
- if pre then
- return
- end
-
- local semaphore = require "ngx.semaphore"
- local sem = semaphore.new()
-
- ngx.log(ngx.ERR, "created semaphore object")
-
- local function sem_wait()
-
- local ok, err = sem:wait(100)
- if not ok then
- ngx.log(ngx.ERR, "err: ", err)
- else
- ngx.log(ngx.ERR, "wait success")
- end
- end
-
- while not ngx.worker.exiting() do
- local co = ngx.thread.spawn(sem_wait)
- ngx.thread.wait(co)
- end
- end
-
- local ok, err = ngx.timer.at(0, test)
- if not ok then
- ngx.log(ngx.ERR, "failed to create semaphore timer err: ", err)
- end
-
- local function reload(pre)
- if pre then
- return
- end
-
- local shdict = ngx.shared.shdict
- local success = shdict:add("reloaded", 1)
- if not success then
- return
- end
-
- ngx.log(ngx.ERR, "try to reload nginx")
-
- local f, err = io.open(ngx.config.prefix() .. "/logs/nginx.pid", "r")
- if not f then
- ngx.say("failed to open nginx.pid: ", err)
- return
- end
-
- local pid = f:read()
-
- f:close()
- os.execute("kill -HUP " .. pid)
- end
-
- local typ = require "ngx.process".type
- if typ() == "privileged agent" then
- local ok, err = ngx.timer.at(0.1, reload)
- if not ok then
- ngx.log(ngx.ERR, "failed to create semaphore timer err: ", err)
- end
- end
- }
-_EOC_
- $block->set_value("http_config", $http_config);
-});
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: timer + reload
---- quic_max_idle_timeout: 1.1
---- config
- location /test {
- content_by_lua_block {
- ngx.sleep(1)
- ngx.say("hello")
- }
- }
---- request
-GET /test
---- response_body
-hello
---- grep_error_log eval: qr/created semaphore object|try to reload nginx|semaphore gc wait queue is not empty/
---- grep_error_log_out
-created semaphore object
-created semaphore object
-try to reload nginx
-created semaphore object
-created semaphore object
---- skip_nginx: 3: < 1.11.2
---- no_check_leak
---- wait: 0.2
-
-
-
-=== TEST 2: timer + reload (lua code cache off)
---- quic_max_idle_timeout: 1.1
---- http_config
- lua_code_cache off;
---- config
- location /test {
- content_by_lua_block {
- ngx.sleep(1)
- ngx.say("hello")
- }
- }
---- request
-GET /test
---- response_body
-hello
---- grep_error_log eval: qr/created semaphore object|try to reload nginx|semaphore gc wait queue is not empty/
---- grep_error_log_out
-created semaphore object
-created semaphore object
-try to reload nginx
-created semaphore object
-created semaphore object
---- skip_nginx: 3: < 1.11.2
---- no_check_leak
---- wait: 0.2
diff --git a/src/deps/src/lua-nginx-module/t/154-semaphore.t b/src/deps/src/lua-nginx-module/t/154-semaphore.t
deleted file mode 100644
index 5bb2b937a..000000000
--- a/src/deps/src/lua-nginx-module/t/154-semaphore.t
+++ /dev/null
@@ -1,170 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-use lib 'lib';
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(10140);
-#workers(1);
-#log_level('warn');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3) + 1;
-
-no_long_string();
-#no_diff();
-
-add_block_preprocessor(sub {
- my $block = shift;
-
- my $http_config = $block->http_config || '';
- $http_config .= <<'_EOC_';
- lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
-
- init_by_lua_block {
- require "resty.core"
- }
-_EOC_
- $block->set_value("http_config", $http_config);
-});
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: timer + shutdown error log
---- config
- location /test {
- content_by_lua_block {
- local function test(pre)
-
- local semaphore = require "ngx.semaphore"
- local sem = semaphore.new()
-
- local function sem_wait()
-
- local ok, err = sem:wait(10)
- if not ok then
- ngx.log(ngx.ERR, "err: ", err)
- else
- ngx.log(ngx.ERR, "wait success")
- end
- end
-
- while not ngx.worker.exiting() do
- local co = ngx.thread.spawn(sem_wait)
- ngx.thread.wait(co)
- end
- end
-
- local ok, err = ngx.timer.at(0, test)
- ngx.log(ngx.ERR, "hello, world")
- ngx.say("time: ", ok)
- }
- }
---- request
-GET /test
---- response_body
-time: 1
---- grep_error_log eval: qr/hello, world|semaphore gc wait queue is not empty/
---- grep_error_log_out
-hello, world
---- shutdown_error_log
---- no_shutdown_error_log
-semaphore gc wait queue is not empty
-
-
-
-=== TEST 2: timer + shutdown error log (lua code cache off)
-FIXME: this test case leaks memory.
---- http_config
- lua_code_cache off;
---- config
- location /test {
- content_by_lua_block {
- local function test(pre)
-
- local semaphore = require "ngx.semaphore"
- local sem = semaphore.new()
-
- local function sem_wait()
-
- local ok, err = sem:wait(10)
- if not ok then
- ngx.log(ngx.ERR, "err: ", err)
- else
- ngx.log(ngx.ERR, "wait success")
- end
- end
-
- while not ngx.worker.exiting() do
- local co = ngx.thread.spawn(sem_wait)
- ngx.thread.wait(co)
- end
- end
-
- local ok, err = ngx.timer.at(0, test)
- ngx.log(ngx.ERR, "hello, world")
- ngx.say("time: ", ok)
- }
- }
---- request
-GET /test
---- response_body
-time: 1
---- grep_error_log eval: qr/hello, world|semaphore gc wait queue is not empty/
---- grep_error_log_out
-hello, world
---- shutdown_error_log
---- no_shutdown_error_log
-semaphore gc wait queue is not empty
---- SKIP
-
-
-
-=== TEST 3: exit before post_handler was called
-If gc is called before the ngx_http_lua_sema_handler and free the sema memory
-ngx_http_lua_sema_handler would use the freed memory.
---- config
- location /up {
- content_by_lua_block {
- local semaphore = require "ngx.semaphore"
- local sem = semaphore.new()
-
- local function sem_wait()
- ngx.log(ngx.ERR, "ngx.sem wait start")
- local ok, err = sem:wait(10)
- if not ok then
- ngx.log(ngx.ERR, "ngx.sem wait err: ", err)
- else
- ngx.log(ngx.ERR, "ngx.sem wait success")
- end
- end
- local co = ngx.thread.spawn(sem_wait)
- ngx.log(ngx.ERR, "ngx.sem post start")
- sem:post()
- ngx.log(ngx.ERR, "ngx.sem post end")
- ngx.say("hello")
- ngx.exit(200)
- ngx.say("not reach here")
- }
- }
-
- location /t {
- content_by_lua_block {
- local res = ngx.location.capture("/up")
- collectgarbage()
- ngx.print(res.body)
- }
- }
-
---- request
-GET /t
---- response_body
-hello
---- grep_error_log eval: qr/(ngx.sem .*?,|http close request|semaphore handler: wait queue: empty, resource count: 1|in lua gc, semaphore)/
---- grep_error_log_out
-ngx.sem wait start,
-ngx.sem post start,
-ngx.sem post end,
-in lua gc, semaphore
-http close request
diff --git a/src/deps/src/lua-nginx-module/t/155-tls13.t b/src/deps/src/lua-nginx-module/t/155-tls13.t
deleted file mode 100644
index 4e684cd33..000000000
--- a/src/deps/src/lua-nginx-module/t/155-tls13.t
+++ /dev/null
@@ -1,106 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(3);
-
-# All these tests need to have new openssl
-my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
-my $openssl_version = eval { `$NginxBinary -V 2>&1` };
-
-if ($openssl_version =~ m/built with OpenSSL (0\S*|1\.0\S*|1\.1\.0\S*)/) {
- plan(skip_all => "too old OpenSSL, need 1.1.1, was $1");
-} else {
- plan tests => repeat_each() * (blocks() * 5);
-}
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-sub read_file {
- my $infile = shift;
- open my $in, $infile
- or die "cannot open $infile for reading: $!";
- my $cert = do { local $/; <$in> };
- close $in;
- $cert;
-}
-
-our $TestCertificate = read_file("t/cert/test.crt");
-our $TestCertificateKey = read_file("t/cert/test.key");
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: handshake, TLSv1.3
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../html/test.crt;
- ssl_certificate_key ../html/test.key;
- ssl_protocols TLSv1.2 TLSv1.3;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../html/test.crt;
- lua_ssl_protocols TLSv1.2 TLSv1.3;
- location /t {
- #set $port 5000;
- set $port $TEST_NGINX_MEMCACHED_PORT;
-
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(3000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- else
- ngx.say("ssl handshake: ", type(sess))
- end
- end -- do
- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-
---- user_files eval
-">>> test.key
-$::TestCertificateKey
->>> test.crt
-$::TestCertificate"
---- error_log
-SSL: TLSv1.3,
---- no_error_log
-[error]
-[alert]
---- timeout: 5
diff --git a/src/deps/src/lua-nginx-module/t/156-slow-network.t b/src/deps/src/lua-nginx-module/t/156-slow-network.t
deleted file mode 100644
index d5897fb33..000000000
--- a/src/deps/src/lua-nginx-module/t/156-slow-network.t
+++ /dev/null
@@ -1,139 +0,0 @@
-BEGIN {
- if (!defined $ENV{LD_PRELOAD}) {
- $ENV{LD_PRELOAD} = '';
- }
-
- if ($ENV{LD_PRELOAD} !~ /\bmockeagain\.so\b/) {
- $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}";
- }
-
- if ($ENV{MOCKEAGAIN} eq 'r') {
- $ENV{MOCKEAGAIN} = 'rw';
-
- } else {
- $ENV{MOCKEAGAIN} = 'w';
- }
-
- $ENV{TEST_NGINX_EVENT_TYPE} = 'poll';
- delete($ENV{TEST_NGINX_USE_HTTP2});
-}
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-add_block_preprocessor(sub {
- my $block = shift;
-
- if (!defined $block->error_log) {
- $block->set_value("no_error_log", "[error]");
- }
-
- if (!defined $block->request) {
- $block->set_value("request", "GET /t");
- }
-
-});
-
-
-log_level("debug");
-no_long_string();
-#no_diff();
-run_tests();
-
-__DATA__
-
-=== TEST 1: receiveany returns anything once socket receives
---- config
- server_tokens off;
- location = /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- sock:settimeout(500)
- assert(sock:connect("127.0.0.1", ngx.var.port))
- local req = {
- 'GET /foo HTTP/1.0\r\n',
- 'Host: localhost\r\n',
- 'Connection: close\r\n\r\n',
- }
- local ok, err = sock:send(req)
- if not ok then
- ngx.say("send request failed: ", err)
- return
- end
-
-
- -- skip http header
- while true do
- local data, err, _ = sock:receive('*l')
- if err then
- ngx.say('unexpected error occurs when receiving http head: ' .. err)
- return
- end
- if #data == 0 then -- read last line of head
- break
- end
- end
-
- -- receive http body
- while true do
- local data, err = sock:receiveany(1024)
- if err then
- if err ~= 'closed' then
- ngx.say('unexpected err: ', err)
- end
- break
- end
- ngx.say(data)
- end
-
- sock:close()
- }
- }
-
- location = /foo {
- content_by_lua_block {
- local resp = {
- '1',
- 'hello',
- }
-
- local length = 0
- for _, v in ipairs(resp) do
- length = length + #v
- end
-
- -- flush http header
- ngx.header['Content-Length'] = length
- ngx.flush(true)
- ngx.sleep(0.01)
-
- -- send http body bytes by bytes
- for _, v in ipairs(resp) do
- ngx.print(v)
- ngx.flush(true)
- ngx.sleep(0.01)
- end
- }
- }
-
---- response_body
-1
-h
-e
-l
-l
-o
---- grep_error_log eval
-qr/lua tcp socket read any/
---- grep_error_log_out
-lua tcp socket read any
-lua tcp socket read any
-lua tcp socket read any
-lua tcp socket read any
-lua tcp socket read any
-lua tcp socket read any
-lua tcp socket read any
diff --git a/src/deps/src/lua-nginx-module/t/157-socket-keepalive-hup.t b/src/deps/src/lua-nginx-module/t/157-socket-keepalive-hup.t
deleted file mode 100644
index 4ebf637a3..000000000
--- a/src/deps/src/lua-nginx-module/t/157-socket-keepalive-hup.t
+++ /dev/null
@@ -1,96 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_CHECK_LEAK}) {
- $SkipReason = "unavailable for the hup tests";
-
- } elsif (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- #os.execute("kill -HUP " .. pid)
- $SkipReason = "send HUP relaod signal by self make two workers with same id";
-
- } else {
- $ENV{TEST_NGINX_USE_HUP} = 1;
- undef $ENV{TEST_NGINX_USE_STAP};
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 8);
-
-#no_diff();
-no_long_string();
-
-worker_connections(1024);
-run_tests();
-
-__DATA__
-
-=== TEST 1: exiting
---- config
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local pidfile = ngx.config.prefix() .. "/logs/nginx.pid"
- local f, err = io.open(pidfile, "r")
- if not f then
- ngx.say("failed to open nginx.pid: ", err)
- return
- end
-
- local pid = f:read()
- -- ngx.say("master pid: [", pid, "]")
-
- f:close()
-
- local i = 0
- local port = ngx.var.port
-
- local function f(premature)
- print("timer prematurely expired: ", premature)
-
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- print("failed to connect: ", err)
- return
- end
-
- local ok, err = sock:setkeepalive()
- if not ok then
- print("failed to setkeepalive: ", err)
- return
- end
-
- print("setkeepalive successfully")
- end
- local ok, err = ngx.timer.at(3, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.say("registered timer")
- os.execute("kill -HUP " .. pid)
- }
- }
---- request
-GET /t
-
---- response_body
-registered timer
-
---- wait: 0.3
---- no_error_log
-[error]
-[alert]
-[crit]
---- error_log
-timer prematurely expired: true
-setkeepalive successfully
-lua tcp socket set keepalive while process exiting, closing connection
diff --git a/src/deps/src/lua-nginx-module/t/158-global-var.t b/src/deps/src/lua-nginx-module/t/158-global-var.t
deleted file mode 100644
index 3f5db60fa..000000000
--- a/src/deps/src/lua-nginx-module/t/158-global-var.t
+++ /dev/null
@@ -1,508 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-log_level('debug');
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 14);
-
-our $HtmlDir = html_dir;
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-
-no_long_string();
-
-sub read_file {
- my $infile = shift;
- open my $in, $infile
- or die "cannot open $infile for reading: $!";
- my $cert = do { local $/; <$in> };
- close $in;
- $cert;
-}
-
-our $TestCertificate = read_file("t/cert/test.crt");
-our $TestCertificateKey = read_file("t/cert/test.key");
-
-add_block_preprocessor(sub {
- my $block = shift;
-
- if (!defined $block->error_log) {
- $block->set_value("no_error_log", "[error]");
- }
-
- if (!defined $block->request) {
- $block->set_value("request", "GET /t");
- }
-
-});
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: set_by_lua
---- config
- location /t {
- set_by_lua_block $res {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- return foo
- }
- echo $res;
- }
---- response_body_like chomp
-\A[12]\n\z
---- grep_error_log eval
-qr/(old foo: \d+|\[\w+\].*?writing a global Lua variable \('[^'\s]+'\)|set_by_lua\(nginx.conf:\d+\):\d+: in main chunk, )/
---- grep_error_log_out eval
-[qr/\A\[warn\] .*?writing a global Lua variable \('foo'\)
-set_by_lua\(nginx.conf:40\):3: in main chunk, \n\z/, "old foo: 1\n"]
-
-
-
-=== TEST 2: rewrite_by_lua
---- config
- location /t {
- rewrite_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- ngx.say(foo)
- }
- }
---- response_body_like chomp
-\A[12]\n\z
---- grep_error_log eval
-qr/(old foo: \d+|\[\w+\].*?writing a global Lua variable \('[^'\s]+'\)|\w+_by_lua\(.*?\):\d+: in main chunk, )/
---- grep_error_log_out eval
-[qr/\A\[warn\] .*?writing a global Lua variable \('foo'\)
-rewrite_by_lua\(nginx\.conf:\d+\):\d+: in main chunk, \n\z/, "old foo: 1\n"]
-
-
-
-=== TEST 3: access_by_lua
---- config
- location /t {
- access_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- ngx.say(foo)
- }
- }
---- response_body_like chomp
-\A[12]\n\z
---- grep_error_log eval
-qr/(old foo: \d+|\[\w+\].*?writing a global Lua variable \('[^'\s]+'\)|\w+_by_lua\(.*?\):\d+: in main chunk, )/
---- grep_error_log_out eval
-[qr/\A\[warn\] .*?writing a global Lua variable \('foo'\)
-access_by_lua\(nginx\.conf:\d+\):\d+: in main chunk, \n\z/, "old foo: 1\n"]
-
-
-
-=== TEST 4: content_by_lua
---- config
- location /t {
- content_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- ngx.say(foo)
- }
- }
---- response_body_like chomp
-\A[12]\n\z
---- grep_error_log eval
-qr/(old foo: \d+|\[\w+\].*?writing a global Lua variable \('[^'\s]+'\)|\w+_by_lua\(.*?\):\d+: in main chunk, )/
---- grep_error_log_out eval
-[qr/\A\[warn\] .*?writing a global Lua variable \('foo'\)
-content_by_lua\(nginx\.conf:\d+\):\d+: in main chunk, \n\z/, "old foo: 1\n"]
-
-
-
-=== TEST 5: header_filter_by_lua
---- config
- location /t {
- content_by_lua_block {
- ngx.say(foo)
- }
- header_filter_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- }
- }
---- response_body_like chomp
-\A(?:nil|1)\n\z
---- grep_error_log eval
-qr/(old foo: \d+|\[\w+\].*?writing a global Lua variable \('[^'\s]+'\)|\w+_by_lua\(nginx\.conf:\d+\):\d+: in main chunk, )/
---- grep_error_log_out eval
-[qr/\A\[warn\] .*?writing a global Lua variable \('foo'\)
-header_filter_by_lua\(nginx.conf:43\):3: in main chunk, \n\z/, "old foo: 1\n"]
-
-
-
-=== TEST 6: body_filter_by_lua
---- config
- location /t {
- content_by_lua_block {
- ngx.say(foo)
- }
- body_filter_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- }
- }
---- response_body_like chomp
-\A(?:nil|2)\n\z
---- grep_error_log eval
-qr/(old foo: \d+|\[\w+\].*?writing a global Lua variable \('[^'\s]+'\)|\w+_by_lua\(nginx\.conf:\d+\):\d+: in main chunk,)/
---- grep_error_log_out eval
-[qr/\[warn\] .*?writing a global Lua variable \('foo'\)
-body_filter_by_lua\(nginx.conf:43\):3: in main chunk,
-old foo: 1\n\z/, "old foo: 2\nold foo: 3\n"]
-
-
-
-=== TEST 7: log_by_lua
---- config
- location /t {
- content_by_lua_block {
- ngx.say(foo)
- }
- log_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- }
- }
---- response_body_like chomp
-\A(?:nil|1)\n\z
---- grep_error_log eval
-qr/(old foo: \d+|\[\w+\].*?writing a global Lua variable \('[^'\s]+'\)|\w+_by_lua\(.*?\):\d+: in main chunk)/
---- grep_error_log_out eval
-[qr/\A\[warn\] .*?writing a global Lua variable \('foo'\)
-log_by_lua\(nginx\.conf:\d+\):\d+: in main chunk\n\z/, "old foo: 1\n"]
-
-
-
-=== TEST 8: ssl_certificate_by_lua
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- content_by_lua_block {
- ngx.say("foo: ", foo)
- }
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- -- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- -- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- -- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- local m, err = ngx.re.match(line, "^foo: (.*)$", "jo")
- if err then
- ngx.say("failed to match line: ", err)
- end
-
- if m and m[1] then
- ngx.print(m[1])
- end
- end
-
- local ok, err = sock:close()
- ngx.say("done")
- end -- do
- }
- }
-
---- response_body_like chomp
-\A[12]done\n\z
---- grep_error_log eval
-qr/(old foo: \d+|\[\w+\].*?writing a global Lua variable \('[^'\s]+'\)|\w+_by_lua\(nginx.conf:\d+\):\d+: in main chunk)/
---- grep_error_log_out eval
-[qr/\A\[warn\] .*?writing a global Lua variable \('foo'\)
-ssl_certificate_by_lua\(nginx.conf:28\):3: in main chunk\n\z/, "old foo: 1\n"]
-
-
-
-=== TEST 9: timer
---- config
- location /t {
- content_by_lua_block {
- local function f()
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.sleep(0.01)
- ngx.say(foo)
- }
- }
---- response_body_like chomp
-\A[12]\n\z
---- grep_error_log eval
-qr/(old foo: \d+|\[\w+\].*?writing a global Lua variable \('[^'\s]+'\)|\w+_by_lua\(.*?\):\d+: in\b)/
---- grep_error_log_out eval
-[qr/\A\[warn\] .*?writing a global Lua variable \('foo'\)
-content_by_lua\(nginx\.conf:\d+\):\d+: in\n\z/, "old foo: 1\n"]
-
-
-
-=== TEST 10: init_by_lua
---- http_config
- init_by_lua_block {
- foo = 1
- }
---- config
- location /t {
- content_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- ngx.say(foo)
- }
- }
---- response_body_like chomp
-\A[23]\n\z
---- grep_error_log eval: qr/old foo: \d+/
---- grep_error_log_out eval
-["old foo: 1\n", "old foo: 2\n"]
-
-
-
-=== TEST 11: init_worker_by_lua
---- http_config
- init_worker_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- }
---- config
- location /t {
- content_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- ngx.say(foo)
- }
- }
---- response_body_like chomp
-\A[23]\n\z
---- grep_error_log eval: qr/old foo: \d+/
---- grep_error_log_out eval
-["old foo: 1\n", "old foo: 2\n"]
-
-
-
-=== TEST 12: init_by_lua + init_worker_by_lua
---- http_config
- init_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- }
- init_worker_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- }
---- config
- location /t {
- content_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- ngx.say(foo)
- }
- }
---- response_body_like chomp
-\A[34]\n\z
---- grep_error_log eval: qr/old foo: \d+/
---- grep_error_log_out eval
-["old foo: 1\nold foo: 2\n", "old foo: 3\n"]
-
-
-
-=== TEST 13: don't show warn messages in init/init_worker
---- http_config
- init_by_lua_block {
- foo = 1
- }
-
- init_worker_by_lua_block {
- bar = 2
- }
---- config
- location /t {
- content_by_lua_block {
- ngx.say(foo)
- ngx.say(bar)
- }
- }
---- response_body
-1
-2
---- no_error_log
-setting global variable
-
-
-
-=== TEST 14: uthread
---- config
- location /t {
- content_by_lua_block {
- local function f()
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- end
- local ok, err = ngx.thread.spawn(f)
- if not ok then
- ngx.say("failed to set timer: ", err)
- return
- end
- ngx.sleep(0.01)
- ngx.say(foo)
- }
- }
---- response_body_like chomp
-\A[12]\n\z
---- grep_error_log eval
-qr/(old foo: \d+|writing a global Lua variable \('\w+'\))/
---- grep_error_log_out eval
-["writing a global Lua variable \('foo'\)\n", "old foo: 1\n"]
-
-
-
-=== TEST 15: balancer_by_lua
---- http_config
- upstream backend {
- server 0.0.0.1;
- balancer_by_lua_block {
- if not foo then
- foo = 1
- else
- ngx.log(ngx.WARN, "old foo: ", foo)
- foo = foo + 1
- end
- }
- }
---- config
- location = /t {
- proxy_pass http://backend;
- }
---- response_body_like: 502 Bad Gateway
---- error_code: 502
---- error_log eval
-qr/\[crit\].*?\Qconnect() to 0.0.0.1:80 failed\E/
---- grep_error_log eval: qr/(old foo: \d+|writing a global Lua variable \('\w+'\))/
---- grep_error_log_out eval
-["writing a global Lua variable \('foo'\)\n", "old foo: 1\n"]
diff --git a/src/deps/src/lua-nginx-module/t/159-sa-restart.t b/src/deps/src/lua-nginx-module/t/159-sa-restart.t
deleted file mode 100644
index a0f0c0eeb..000000000
--- a/src/deps/src/lua-nginx-module/t/159-sa-restart.t
+++ /dev/null
@@ -1,180 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-add_block_preprocessor(sub {
- my $block = shift;
-
- my $http_config = $block->http_config || '';
-
- $http_config .= <<_EOC_;
- init_by_lua_block {
- function test_sa_restart()
- local signals = {
- --"HUP",
- --"INFO",
- --"XCPU",
- --"USR1",
- --"USR2",
- "ALRM",
- --"INT",
- "IO",
- "CHLD",
- --"WINCH",
- }
-
- for _, signame in ipairs(signals) do
- local cmd = string.format("kill -s %s %d && sleep 0.01",
- signame, ngx.worker.pid())
- local err = select(2, io.popen(cmd):read("*a"))
- if err then
- error("SIG" .. signame .. " caused: " .. err)
- end
- end
- end
- }
-_EOC_
-
- $block->set_value("http_config", $http_config);
-
- if (!defined $block->config) {
- my $config = <<_EOC_;
- location /t {
- echo ok;
- }
-_EOC_
-
- $block->set_value("config", $config);
- }
-
- if (!defined $block->request) {
- $block->set_value("request", "GET /t");
- }
-
- if (!defined $block->response_body) {
- $block->set_value("ignore_response_body");
- }
-
- if (!defined $block->no_error_log) {
- $block->set_value("no_error_log", "[error]");
- }
-});
-
-plan tests => repeat_each() * (blocks() * 2 + 1);
-
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: lua_sa_restart default - sets SA_RESTART in init_worker_by_lua*
---- http_config
- init_worker_by_lua_block {
- test_sa_restart()
- }
-
-
-
-=== TEST 2: lua_sa_restart off - does not set SA_RESTART
---- http_config
- lua_sa_restart off;
-
- init_worker_by_lua_block {
- test_sa_restart()
- }
---- no_error_log
-[crit]
---- error_log
-Interrupted system call
-
-
-
-=== TEST 3: lua_sa_restart on (default) - sets SA_RESTART if no init_worker_by_lua* phase is defined
---- config
- location /t {
- content_by_lua_block {
- test_sa_restart()
- }
- }
-
-
-
-=== TEST 4: lua_sa_restart on (default) - SA_RESTART is effective in rewrite_by_lua*
---- config
- location /t {
- rewrite_by_lua_block {
- test_sa_restart()
- }
-
- echo ok;
- }
-
-
-
-=== TEST 5: lua_sa_restart on (default) - SA_RESTART is effective in access_by_lua*
---- config
- location /t {
- access_by_lua_block {
- test_sa_restart()
- }
-
- echo ok;
- }
-
-
-
-=== TEST 6: lua_sa_restart on (default) - SA_RESTART is effective in content_by_lua*
---- config
- location /t {
- content_by_lua_block {
- test_sa_restart()
- }
- }
-
-
-
-=== TEST 7: lua_sa_restart on (default) - SA_RESTART is effective in header_filter_by_lua*
---- config
- location /t {
- echo ok;
-
- header_filter_by_lua_block {
- test_sa_restart()
- }
- }
-
-
-
-=== TEST 8: lua_sa_restart on (default) - SA_RESTART is effective in body_filter_by_lua*
---- config
- location /t {
- echo ok;
-
- body_filter_by_lua_block {
- test_sa_restart()
- }
- }
-
-
-
-=== TEST 9: lua_sa_restart on (default) - SA_RESTART is effective in log_by_lua*
---- config
- location /t {
- echo ok;
-
- log_by_lua_block {
- test_sa_restart()
- }
- }
-
-
-
-=== TEST 10: lua_sa_restart on (default) - SA_RESTART is effective in timer phase
---- config
- location /t {
- echo ok;
-
- log_by_lua_block {
- ngx.timer.at(0, test_sa_restart)
- }
- }
diff --git a/src/deps/src/lua-nginx-module/t/160-disable-init-by-lua.t b/src/deps/src/lua-nginx-module/t/160-disable-init-by-lua.t
deleted file mode 100644
index e98c136dc..000000000
--- a/src/deps/src/lua-nginx-module/t/160-disable-init-by-lua.t
+++ /dev/null
@@ -1,207 +0,0 @@
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-
-my $html_dir = $ENV{TEST_NGINX_HTML_DIR};
-my $http_config = <<_EOC_;
- init_by_lua_block {
- function set_up_ngx_tmp_conf(conf)
- if conf == nil then
- conf = [[
- # to prevent the test process from overwriting the
- # original pid file
- pid logs/test_nginx.pid;
- events {
- worker_connections 64;
- }
- http {
- init_by_lua_block {
- ngx.log(ngx.ERR, "run init_by_lua")
- }
- }
- ]]
- end
-
- assert(os.execute("mkdir -p $html_dir/logs"))
-
- local conf_file = "$html_dir/nginx.conf"
- local f, err = io.open(conf_file, "w")
- if not f then
- ngx.log(ngx.ERR, err)
- return
- end
-
- assert(f:write(conf))
- f:close()
-
- return conf_file
- end
-
- function get_ngx_bin_path()
- local ffi = require "ffi"
- ffi.cdef[[char **ngx_argv;]]
- return ffi.string(ffi.C.ngx_argv[0])
- end
- }
-_EOC_
-
-add_block_preprocessor(sub {
- my $block = shift;
-
- if (!defined $block->http_config) {
- $block->set_value("http_config", $http_config);
- }
-
- if (!defined $block->request) {
- $block->set_value("request", "GET /t");
- }
-});
-
-env_to_nginx("PATH");
-log_level("warn");
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: ensure init_by_lua* is not run in signaller process
---- config
- location = /t {
- content_by_lua_block {
- local conf_file = set_up_ngx_tmp_conf()
- local nginx = get_ngx_bin_path()
-
- local cmd = nginx .. " -p $TEST_NGINX_HTML_DIR -c " .. conf_file .. " -s reopen"
- local p, err = io.popen(cmd)
- if not p then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local out, err = p:read("*a")
- if not out then
- ngx.log(ngx.ERR, err)
-
- else
- ngx.log(ngx.WARN, out)
- end
- p:close()
- collectgarbage("collect")
- }
- }
---- error_log
-failed (2: No such file or directory)
---- no_error_log eval
-qr/\[error\] .*? init_by_lua:\d+: run init_by_lua/
-
-
-
-=== TEST 2: init_by_lua* does not run when testing Nginx configuration
---- config
- location = /t {
- content_by_lua_block {
- local conf_file = set_up_ngx_tmp_conf()
- local nginx = get_ngx_bin_path()
-
- local cmd = nginx .. " -p $TEST_NGINX_HTML_DIR -c " .. conf_file .. " -t"
- local p, err = io.popen(cmd)
- if not p then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local out, err = p:read("*a")
- if not out then
- ngx.log(ngx.ERR, err)
-
- else
- ngx.log(ngx.WARN, out)
- end
- p:close()
-
- local cmd = nginx .. " -p $TEST_NGINX_HTML_DIR -c " .. conf_file .. " -T"
- local p, err = io.popen(cmd)
- if not p then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local out, err = p:read("*a")
- if not out then
- ngx.log(ngx.ERR, err)
-
- else
- ngx.log(ngx.WARN, out)
- end
- p:close()
- collectgarbage("collect")
- }
- }
---- error_log
-test is successful
---- no_error_log eval
-qr/\[error\] .*? init_by_lua:\d+: run init_by_lua/
-
-
-
-=== TEST 3: init_by_lua* does not run when testing Nginx configuration which contains 'lua_shared_dict' (GitHub #1462)
---- config
- location = /t {
- content_by_lua_block {
- local conf = [[
- pid logs/test_nginx.pid;
- events {
- worker_connections 64;
- }
- http {
- lua_shared_dict test 64k;
- init_by_lua_block {
- ngx.log(ngx.ERR, "run init_by_lua with lua_shared_dict")
- }
- }
- ]]
- local conf_file = set_up_ngx_tmp_conf(conf)
- local nginx = get_ngx_bin_path()
-
- local cmd = nginx .. " -p $TEST_NGINX_HTML_DIR -c " .. conf_file .. " -t"
- local p, err = io.popen(cmd)
- if not p then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local out, err = p:read("*a")
- if not out then
- ngx.log(ngx.ERR, err)
-
- else
- ngx.log(ngx.WARN, out)
- end
- p:close()
-
- local cmd = nginx .. " -p $TEST_NGINX_HTML_DIR -c " .. conf_file .. " -T"
- local p, err = io.popen(cmd)
- if not p then
- ngx.log(ngx.ERR, err)
- return
- end
-
- local out, err = p:read("*a")
- if not out then
- ngx.log(ngx.ERR, err)
-
- else
- ngx.log(ngx.WARN, out)
- end
- p:close()
- collectgarbage("collect")
- }
- }
---- error_log
-test is successful
---- no_error_log eval
-qr/\[error\] .*? init_by_lua:\d+: run init_by_lua with lua_shared_dict/
diff --git a/src/deps/src/lua-nginx-module/t/161-load-resty-core.t b/src/deps/src/lua-nginx-module/t/161-load-resty-core.t
deleted file mode 100644
index 2c2643068..000000000
--- a/src/deps/src/lua-nginx-module/t/161-load-resty-core.t
+++ /dev/null
@@ -1,166 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-
-add_block_preprocessor(sub {
- my $block = shift;
-
- if (!defined $block->request) {
- $block->set_value("request", "GET /t");
- }
-
- if (!defined $block->no_error_log) {
- $block->set_value("no_error_log", "[error]");
- }
-});
-
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: resty.core is automatically loaded in the Lua VM
---- config
- location = /t {
- content_by_lua_block {
- local loaded_resty_core = package.loaded["resty.core"]
- local resty_core = require "resty.core"
-
- ngx.say("resty.core loaded: ", loaded_resty_core == resty_core)
- }
- }
---- response_body
-resty.core loaded: true
-
-
-
-=== TEST 2: resty.core is automatically loaded in the Lua VM when 'lua_shared_dict' is used
---- http_config
- lua_shared_dict dogs 128k;
---- config
- location = /t {
- content_by_lua_block {
- local loaded_resty_core = package.loaded["resty.core"]
- local resty_core = require "resty.core"
-
- ngx.say("resty.core loaded: ", loaded_resty_core == resty_core)
- }
- }
---- response_body
-resty.core loaded: true
-
-
-
-=== TEST 3: resty.core is automatically loaded in the Lua VM with 'lua_code_cache off'
---- http_config
- lua_code_cache off;
---- config
- location = /t {
- content_by_lua_block {
- local loaded_resty_core = package.loaded["resty.core"]
- local resty_core = require "resty.core"
-
- ngx.say("resty.core loaded: ", loaded_resty_core == resty_core)
- }
- }
---- response_body
-resty.core loaded: true
-
-
-
-=== TEST 4: resty.core loading honors the lua_package_path directive
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;;';"
---- config
- location = /t {
- content_by_lua_block {
- local loaded_resty_core = package.loaded["resty.core"]
- local resty_core = require "resty.core"
-
- ngx.say("resty.core loaded: ", loaded_resty_core == resty_core)
-
- resty_core.go()
- }
- }
---- response_body
-resty.core loaded: true
-loaded from html dir
---- user_files
->>> resty/core.lua
-return {
- go = function ()
- ngx.say("loaded from html dir")
- end
-}
-
-
-
-=== TEST 5: resty.core not loading aborts the initialization
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;';"
---- config
- location = /t {
- return 200;
- }
---- must_die
---- error_log eval
-qr/\[alert\] .*? failed to load the 'resty\.core' module .*? \(reason: module 'resty\.core' not found:/
-
-
-
-=== TEST 6: resty.core not loading produces an error with 'lua_code_cache off'
---- http_config
- lua_code_cache off;
-
- init_by_lua_block {
- package.path = ""
- }
---- config
- location = /t {
- content_by_lua_block {
- ngx.say("ok")
- }
- }
---- error_code: 500
---- error_log eval
-qr/\[error\] .*? failed to load the 'resty\.core' module .*? \(reason: module 'resty\.core' not found:/
---- no_error_log eval
-qr/\[alert\] .*? failed to load the 'resty\.core' module/
-
-
-
-=== TEST 7: lua_load_resty_core logs a deprecation warning when specified (on)
---- http_config
- lua_load_resty_core on;
---- config
- location = /t {
- return 200;
- }
---- grep_error_log eval: qr/\[warn\] .*? lua_load_resty_core is deprecated.*/
---- grep_error_log_out eval
-[
-qr/\[warn\] .*? lua_load_resty_core is deprecated \(the lua-resty-core library is required since ngx_lua v0\.10\.16\) in .*?nginx\.conf:\d+/,
-""
-]
-
-
-
-=== TEST 8: lua_load_resty_core logs a deprecation warning when specified (off)
---- http_config
- lua_load_resty_core off;
---- config
- location = /t {
- return 200;
- }
---- grep_error_log eval: qr/\[warn\] .*? lua_load_resty_core is deprecated.*/
---- grep_error_log_out eval
-[
-qr/\[warn\] .*? lua_load_resty_core is deprecated \(the lua-resty-core library is required since ngx_lua v0\.10\.16\) in .*?nginx\.conf:\d+/,
-""
-]
diff --git a/src/deps/src/lua-nginx-module/t/162-exit-worker.t b/src/deps/src/lua-nginx-module/t/162-exit-worker.t
deleted file mode 100644
index 7aff2a619..000000000
--- a/src/deps/src/lua-nginx-module/t/162-exit-worker.t
+++ /dev/null
@@ -1,242 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-master_on();
-repeat_each(2);
-
-# NB: the shutdown_error_log block is independent from repeat times
-plan tests => repeat_each() * (blocks() * 2 + 1) + 15;
-
-#log_level("warn");
-no_long_string();
-our $HtmlDir = html_dir;
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple exit_worker_by_lua_block
---- http_config
- exit_worker_by_lua_block {
- ngx.log(ngx.NOTICE, "log from exit_worker_by_lua_block")
- }
---- config
- location /t {
- echo "ok";
- }
---- request
-GET /t
---- response_body
-ok
---- shutdown_error_log
-log from exit_worker_by_lua_block
-
-
-
-=== TEST 2: simple exit_worker_by_lua_file
---- http_config
- exit_worker_by_lua_file html/exit_worker.lua;
---- config
- location /t {
- echo "ok";
- }
---- user_files
->>> exit_worker.lua
-ngx.log(ngx.NOTICE, "log from exit_worker_by_lua_file")
---- request
-GET /t
---- response_body
-ok
---- shutdown_error_log
-log from exit_worker_by_lua_file
-
-
-
-=== TEST 3: exit_worker_by_lua (require a global table)
---- http_config eval
- qq{lua_package_path '$::HtmlDir/?.lua;;';
- exit_worker_by_lua_block {
- foo = require("foo")
- ngx.log(ngx.NOTICE, foo.bar)
- }}
---- config
- location /t {
- content_by_lua_block {
- foo = require("foo")
- foo.bar = "hello, world"
- ngx.say("ok")
- }
- }
---- user_files
->>> foo.lua
-return {}
---- request
-GET /t
---- response_body
-ok
---- shutdown_error_log
-hello, world
-
-
-
-=== TEST 4: ngx.timer is not allow
---- http_config
- exit_worker_by_lua_block {
- local function bar()
- ngx.log(ngx.ERR, "run the timer!")
- end
-
- local ok, err = ngx.timer.at(0, bar)
- if not ok then
- ngx.log(ngx.ERR, "failed to create timer: ", err)
- else
- ngx.log(ngx.NOTICE, "success")
- end
- }
---- config
- location /t {
- echo "ok";
- }
---- request
-GET /t
---- response_body
-ok
---- shutdown_error_log
-API disabled in the context of exit_worker_by_lua*
-
-
-
-=== TEST 5: exit_worker_by_lua use shdict
---- http_config
- lua_shared_dict dog 1m;
- exit_worker_by_lua_block {
- local dog = ngx.shared.dog
- local val, err = dog:get("foo")
- if not val then
- ngx.log(ngx.ERR, "failed get shdict: ", err)
- else
- ngx.log(ngx.NOTICE, "get val: ", val)
- end
- }
---- config
- location /t {
- content_by_lua_block {
- local dog = ngx.shared.dog
- dog:set("foo", 100)
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- shutdown_error_log
-get val: 100
-
-
-
-=== TEST 6: skip in cache processes (with exit worker and privileged agent)
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
-
- proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
-
- init_by_lua_block {
- assert(require "ngx.process".enable_privileged_agent())
- }
-
- exit_worker_by_lua_block {
- local process = require "ngx.process"
- ngx.log(ngx.INFO, "hello from exit worker by lua, process type: ", process.type())
- }
---- config
- location = /t {
- return 200;
- }
---- request
- GET /t
---- no_error_log
-[error]
---- shutdown_error_log eval
-[
-qr/cache loader process \d+ exited/,
-qr/cache manager process \d+ exited/,
-qr/hello from exit worker by lua, process type: worker/,
-qr/hello from exit worker by lua, process type: privileged agent/,
-qr/privileged agent process \d+ exited/,
-]
-
-
-
-=== TEST 7: skipin cache processes (with init worker but without privileged agent)
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
-
- proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
-
- exit_worker_by_lua_block {
- local process = require "ngx.process"
- ngx.log(ngx.INFO, "hello from exit worker by lua, process type: ", process.type())
- }
---- config
- location = /t {
- return 200;
- }
---- request
- GET /t
---- no_error_log
-[error]
-start privileged agent process
---- shutdown_error_log eval
-[
-qr/cache loader process \d+ exited/,
-qr/cache manager process \d+ exited/,
-qr/hello from exit worker by lua, process type: worker/,
-]
-
-
-
-=== TEST 8: syntax error in exit_worker_by_lua_block
---- http_config
- exit_worker_by_lua_block {
- ngx.log(ngx.debug, "pass")
- error("failed to init"
- ngx.log(ngx.debug, "unreachable")
- }
---- config
- location /t {
- content_by_lua_block {
- ngx.say("hello world")
- }
- }
---- request
- GET /t
---- response_body
-hello world
---- shutdown_error_log
-exit_worker_by_lua error: exit_worker_by_lua(nginx.conf:25):4: ')' expected (to close '(' at line 3) near 'ngx'
-
-
-
-=== TEST 9: syntax error in exit_worker_by_lua_file
---- http_config
- exit_worker_by_lua_file html/exit.lua;
---- config
- location /t {
- content_by_lua_block {
- ngx.say("hello world")
- }
- }
---- user_files
->>> exit.lua
- ngx.log(ngx.debug, "pass")
- error("failed to init"
- ngx.log(ngx.debug, "unreachable")
-
---- request
- GET /t
---- response_body
-hello world
---- shutdown_error_log eval
-qr|exit_worker_by_lua_file error: .*?t/servroot\w*/html/exit.lua:3: '\)' expected \(to close '\(' at line 2\) near 'ngx'|
diff --git a/src/deps/src/lua-nginx-module/t/162-socket-tls-handshake.t b/src/deps/src/lua-nginx-module/t/162-socket-tls-handshake.t
deleted file mode 100644
index 19ad67a74..000000000
--- a/src/deps/src/lua-nginx-module/t/162-socket-tls-handshake.t
+++ /dev/null
@@ -1,373 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * 43;
-
-$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
-
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-
-sub read_file {
- my $infile = shift;
- open my $in, $infile
- or die "cannot open $infile for reading: $!";
- my $cert = do { local $/; <$in> };
- close $in;
- $cert;
-}
-
-our $MTLSCA = read_file("t/cert/mtls_ca.crt");
-our $MTLSClient = read_file("t/cert/mtls_client.crt");
-our $MTLSClientKey = read_file("t/cert/mtls_client.key");
-our $MTLSServer = read_file("t/cert/mtls_server.crt");
-our $MTLSServerKey = read_file("t/cert/mtls_server.key");
-
-our $HtmlDir = html_dir;
-
-our $mtls_http_config = <<"_EOC_";
-server {
- listen unix:$::HtmlDir/mtls.sock ssl;
-
- ssl_certificate $::HtmlDir/mtls_server.crt;
- ssl_certificate_key $::HtmlDir/mtls_server.key;
- ssl_client_certificate $::HtmlDir/mtls_ca.crt;
- ssl_verify_client on;
- server_tokens off;
-
- location / {
- return 200 "hello, \$ssl_client_s_dn";
- }
-}
-_EOC_
-
-our $mtls_user_files = <<"_EOC_";
->>> mtls_server.key
-$::MTLSServerKey
->>> mtls_server.crt
-$::MTLSServer
->>> mtls_ca.crt
-$::MTLSCA
->>> mtls_client.key
-$::MTLSClientKey
->>> mtls_client.crt
-$::MTLSClient
-_EOC_
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity: www.google.com
---- config
- server_tokens off;
- resolver $TEST_NGINX_RESOLVER ipv6=off;
-
- location /t {
- content_by_lua_block {
- -- avoid flushing bing in "check leak" testing mode:
- local counter = package.loaded.counter
- if not counter then
- counter = 1
- elseif counter >= 2 then
- return ngx.exit(503)
- else
- counter = counter + 1
- end
-
- package.loaded.counter = counter
-
- do
- local sock = ngx.socket.tcp()
- sock:settimeout(2000)
-
- local ok, err = sock:connect("www.google.com", 443)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake()
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- local line, err = sock:receive()
- if not line then
- ngx.say("failed to receive response status line: ", err)
- return
- end
-
- ngx.say("received: ", line)
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
-
- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body_like chop
-\Aconnected: 1
-ssl handshake: cdata
-sent http request: 59 bytes.
-received: HTTP/1.1 (?:200 OK|302 Found)
-close: 1 nil
-\z
---- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
---- grep_error_log_out eval
-qr/^lua ssl save session: ([0-9A-F]+)
-lua ssl free session: ([0-9A-F]+)
-$/
---- no_error_log
-lua ssl server name:
-SSL reused session
-[error]
-[alert]
---- timeout: 5
-
-
-
-=== TEST 2: mutual TLS handshake, upstream is not accessible without client certs
---- http_config eval: $::mtls_http_config
---- config eval
-"
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect('unix:$::HtmlDir/mtls.sock')
- if not ok then
- ngx.say('failed to connect: ', err)
- end
-
- assert(sock:sslhandshake())
-
- ngx.say('connected: ', ok)
-
- local req = 'GET /\\r\\n'
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say('failed to send request: ', err)
- return
- end
-
- ngx.say('request sent: ', bytes)
-
- ngx.say(sock:receive('*a'))
-
- assert(sock:close())
- }
- }
-"
---- user_files eval: $::mtls_user_files
---- request
-GET /t
---- response_body_like: 400 No required SSL certificate was sent
---- no_error_log
-[alert]
-[error]
-[crit]
-[emerg]
-
-
-
-=== TEST 3: mutual TLS handshake, upstream is accessible with client certs
---- http_config eval: $::mtls_http_config
---- config eval
-"
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect('unix:$::HtmlDir/mtls.sock')
- if not ok then
- ngx.say('failed to connect: ', err)
- end
-
- local f = assert(io.open('$::HtmlDir/mtls_client.crt'))
- local cert_data = f:read('*a')
- f:close()
-
- f = assert(io.open('$::HtmlDir/mtls_client.key'))
- local key_data = f:read('*a')
- f:close()
-
- local ssl = require('ngx.ssl')
-
- local chain = assert(ssl.parse_pem_cert(cert_data))
- local priv = assert(ssl.parse_pem_priv_key(key_data))
-
- sock:setclientcert(chain, priv)
-
- assert(sock:sslhandshake())
-
- ngx.say('connected: ', ok)
-
- local req = 'GET /\\r\\n'
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say('failed to send request: ', err)
- return
- end
-
- ngx.say('request sent: ', bytes)
-
- ngx.say(sock:receive('*a'))
-
- assert(sock:close())
- }
- }
-"
---- user_files eval: $::mtls_user_files
---- request
-GET /t
---- response_body
-connected: 1
-request sent: 7
-hello, CN=foo@example.com,O=OpenResty,ST=California,C=US
---- no_error_log
-[alert]
-[error]
-[crit]
-[emerg]
-
-
-
-=== TEST 4: incorrect type of client cert
---- config
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:setclientcert("doesnt", "work")
- if not ok then
- ngx.say('failed to setclientcert: ', err)
- return
- end
-
- assert(sock:close())
- }
- }
---- request
-GET /t
---- response_body
-failed to setclientcert: bad cert arg: cdata expected, got string
---- no_error_log
-[alert]
-[error]
-[crit]
-[emerg]
-
-
-
-=== TEST 5: incorrect type of client key
---- config eval
-"
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- local f = assert(io.open('$::HtmlDir/mtls_client.crt'))
- local cert_data = f:read('*a')
- f:close()
-
- local ssl = require('ngx.ssl')
-
- local chain = assert(ssl.parse_pem_cert(cert_data))
-
- local ok, err = sock:setclientcert(chain, 'work')
- if not ok then
- ngx.say('failed to setclientcert: ', err)
- return
- end
-
- assert(sock:close())
- }
- }
-"
---- user_files eval: $::mtls_user_files
---- request
-GET /t
---- response_body
-failed to setclientcert: bad pkey arg: cdata expected, got string
---- no_error_log
-[alert]
-[error]
-[crit]
-[emerg]
-
-
-
-=== TEST 6: missing client cert
---- config
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:setclientcert(nil, "work")
- if not ok then
- ngx.say('failed to setclientcert: ', err)
- return
- end
-
- assert(sock:close())
- }
- }
---- request
-GET /t
---- response_body
-failed to setclientcert: client certificate must be supplied with corresponding private key
---- no_error_log
-[alert]
-[error]
-[crit]
-[emerg]
-
-
-
-=== TEST 7: missing private key
---- config
- location /t {
- content_by_lua_block {
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:setclientcert('doesnt', nil)
- if not ok then
- ngx.say('failed to setclientcert: ', err)
- return
- end
-
- assert(sock:close())
- }
- }
---- request
-GET /t
---- response_body
-failed to setclientcert: client certificate must be supplied with corresponding private key
---- no_error_log
-[alert]
-[error]
-[crit]
-[emerg]
diff --git a/src/deps/src/lua-nginx-module/t/162-static-module-location.t b/src/deps/src/lua-nginx-module/t/162-static-module-location.t
deleted file mode 100644
index 9f09dbe63..000000000
--- a/src/deps/src/lua-nginx-module/t/162-static-module-location.t
+++ /dev/null
@@ -1,103 +0,0 @@
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3);
-
-our $HtmlDir = html_dir;
-
-no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: decoded url contains '\0' and '\r\n'
---- config
- server_tokens off;
- location = /t {
- rewrite_by_lua_block {
- ngx.req.read_body();
- local args, _ = ngx.req.get_post_args();
- ngx.req.set_uri(args["url"], true, true);
- }
- }
---- request
-POST /t
-url=%00%0a%0dset-cookie:1234567
---- error_code: 301
---- response_headers
-Location: %00%0A%0Dset-cookie:1234567/
---- response_body_like
-.*301 Moved Permanently.*
-
-
-
-=== TEST 2: uri contain chinese characters
---- config
- server_tokens off;
---- user_files
->>> t/䏿–‡/foo.txt
-Hello, world
---- request
-GET /t/䏿–‡
---- more_headers
-host: localhost
---- error_code: 301
---- response_headers_like
-Location: https?:\/\/localhost:\d+\/t\/%E4%B8%AD%E6%96%87\/
---- response_body_like
-.*301 Moved Permanently.*
-
-
-
-=== TEST 3: uri contain chinese characters with args
---- config
- server_tokens off;
---- user_files
->>> t/䏿–‡/foo.txt
-Hello, world
---- request
-GET /t/䏿–‡?q=name
---- more_headers
-host: localhost
---- error_code: 301
---- response_headers_like
-Location: https?:\/\/localhost:\d+\/t\/%E4%B8%AD%E6%96%87\/\?q=name
---- response_body_like
-.*301 Moved Permanently.*
-
-
-
-=== TEST 4: uri already encoded
---- config
- server_tokens off;
---- user_files
->>> t/䏿–‡/foo.txt
-Hello, world
---- request
-GET /t/%E4%B8%AD%E6%96%87
---- more_headers
-host: localhost
---- error_code: 301
---- response_headers_like
-Location: https?:\/\/localhost:\d+\/t\/%E4%B8%AD%E6%96%87\/
---- response_body_like
-.*301 Moved Permanently.*
-
-
-
-=== TEST 5: uri already encoded with args
---- config
- server_tokens off;
---- user_files
->>> t/䏿–‡/foo.txt
-Hello, world
---- request
-GET /t/%E4%B8%AD%E6%96%87?q=name
---- more_headers
-host: localhost
---- error_code: 301
---- response_headers_like
-Location: https?://localhost:\d+\/t\/%E4%B8%AD%E6%96%87\/\?q=name
---- response_body_like
-.*301 Moved Permanently.*
diff --git a/src/deps/src/lua-nginx-module/t/163-exit-worker-hup.t b/src/deps/src/lua-nginx-module/t/163-exit-worker-hup.t
deleted file mode 100644
index 136efdc7f..000000000
--- a/src/deps/src/lua-nginx-module/t/163-exit-worker-hup.t
+++ /dev/null
@@ -1,89 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_CHECK_LEAK}) {
- $SkipReason = "unavailable for the hup tests";
-
- } elsif ($ENV{TEST_NGINX_USE_HTTP3}) {
- $SkipReason = "http3 does not support hub reload";
-
- } else {
- $ENV{TEST_NGINX_USE_HUP} = 1;
- undef $ENV{TEST_NGINX_USE_STAP};
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 2 + 1) + 2;
-
-no_long_string();
-
-worker_connections(1024);
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple exit_worker_by_lua_block with hup
---- http_config
- exit_worker_by_lua_block {
- ngx.log(ngx.NOTICE, "log from exit_worker_by_lua_block")
- }
---- config
- location /t {
- content_by_lua_block {
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- shutdown_error_log
-log from exit_worker_by_lua_block
-
-
-
-=== TEST 2: exit after worker_shutdown_timeout
---- main_config
- worker_shutdown_timeout 1;
---- http_config
- exit_worker_by_lua_block {
- ngx.log(ngx.NOTICE, "log from exit_worker_by_lua_block")
- }
-
- server {
- listen $TEST_NGINX_RAND_PORT_1;
-
- location = /t {
- echo 'hello world';
- }
- }
---- config
- location /t {
- content_by_lua_block {
- ngx.timer.at(0, function ()
- local sock = ngx.socket.tcp()
- sock:connect("127.0.0.1", $TEST_NGINX_RAND_PORT_1)
- local reader = sock:receiveuntil("unknow")
- ngx.log(ngx.NOTICE, "reading to block the exiting")
- reader()
- end)
-
- ngx.sleep(0)
-
- ngx.say("ok")
- }
- }
---- request
-GET /t
---- response_body
-ok
---- error_log
-reading to block the exiting
---- shutdown_error_log
-log from exit_worker_by_lua_block
diff --git a/src/deps/src/lua-nginx-module/t/163-signal.t b/src/deps/src/lua-nginx-module/t/163-signal.t
deleted file mode 100644
index 0ce8fa261..000000000
--- a/src/deps/src/lua-nginx-module/t/163-signal.t
+++ /dev/null
@@ -1,64 +0,0 @@
-# vi:ft=
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_USE_HUP}) {
- $SkipReason = "unavailable under hup test mode";
-
- } elsif ($ENV{TEST_NGINX_CHECK_LEAK}) {
- $SkipReason = "unavailable under check leak test mode";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-plan tests => 2 * blocks();
-
-no_long_string();
-
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: SIGHUP followed by SIGQUIT
---- config
- location = /t {
- content_by_lua_block {
- local pid = ngx.worker.pid()
- os.execute("kill -HUP " .. pid)
- ngx.sleep(0.01)
-
- os.execute("kill -QUIT " .. pid)
- }
- }
---- request
-GET /t
---- ignore_response
---- wait: 0.1
---- error_log eval
-qr/\[notice\] \d+#\d+: exit$/
---- no_error_log eval
-qr/\[notice\] \d+#\d+: reconfiguring/
---- curl_error eval
-qr/curl: \(28\) Operation timed out after \d+ milliseconds with 0 bytes received|curl: \(56\) Recv failure: Connection reset by peer|curl: \(55\) sendmsg\(\) returned -1 \(errno 111\)/
-
-
-
-=== TEST 2: exit after receiving SIGHUP in single process mode
---- config
- location = /t {
- content_by_lua_block {
- local pid = ngx.worker.pid()
- os.execute("kill -HUP " .. pid)
- }
- }
---- request
-GET /t
---- ignore_response
---- wait: 0.1
---- error_log eval
-qr/\[notice\] \d+#\d+: exit$/
---- no_error_log eval
-qr/\[notice\] \d+#\d+: reconfiguring/
diff --git a/src/deps/src/lua-nginx-module/t/164-say.t b/src/deps/src/lua-nginx-module/t/164-say.t
deleted file mode 100644
index 40ec1ff1b..000000000
--- a/src/deps/src/lua-nginx-module/t/164-say.t
+++ /dev/null
@@ -1,111 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(2);
-
-plan tests => blocks() * repeat_each() * 2;
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: ngx.say (integer)
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(2)
- }
- }
---- request
-GET /lua
---- response_body
-2
-
-
-
-=== TEST 2: ngx.say (floating point number)
-the maximum number of significant digits is 14 in lua
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(3.1415926)
- ngx.say(3.14159265357939723846)
- }
- }
---- request
-GET /lua
---- response_body
-3.1415926
-3.1415926535794
-
-
-
-=== TEST 3: ngx.say (table with number)
---- config
- location /lua {
- content_by_lua_block {
- local data = {123," ", 3.1415926}
- ngx.say(data)
- }
- }
---- request
-GET /lua
---- response_body
-123 3.1415926
-
-
-
-=== TEST 4: ngx.say min int32 -2147483648
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(-2147483648)
- }
- }
---- request
-GET /lua
---- response_body
--2147483648
-
-
-
-=== TEST 5: ngx.say big integer 2147483647
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(2147483647)
- }
- }
---- request
-GET /lua
---- response_body
-2147483647
-
-
-
-=== TEST 6: ngx.say big integer -9223372036854775808
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(-9223372036854775808)
- }
- }
---- request
-GET /lua
---- response_body
--9.2233720368548e+18
-
-
-
-=== TEST 7: ngx.say big integer 18446744073709551615
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(18446744073709551615)
- }
- }
---- request
-GET /lua
---- response_body
-1.844674407371e+19
diff --git a/src/deps/src/lua-nginx-module/t/165-thread-cache.t b/src/deps/src/lua-nginx-module/t/165-thread-cache.t
deleted file mode 100644
index 0adc6c625..000000000
--- a/src/deps/src/lua-nginx-module/t/165-thread-cache.t
+++ /dev/null
@@ -1,79 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(2);
-#repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 4);
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: thread cache size == 1
---- http_config
- lua_thread_cache_max_entries 1;
-
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- content_by_lua '
- local ok, err = ngx.print("Hello, Lua!\\n")
- if not ok then
- ngx.log(ngx.ERR, "print failed: ", err)
- end
- ';
- }
---- request
-GET /lua
---- response_body
-Hello, Lua!
---- no_error_log
-[error]
---- grep_error_log eval: qr/lua caching unused lua thread|lua reusing cached lua thread/
---- grep_error_log_out eval
-[
- "lua caching unused lua thread\n",
- "lua reusing cached lua thread
-lua caching unused lua thread
-",
-]
-
-
-
-=== TEST 2: thread cache size == 0
---- http_config
- lua_thread_cache_max_entries 0;
-
---- config
- location /lua {
- # NOTE: the newline escape sequence must be double-escaped, as nginx config
- # parser will unescape first!
- content_by_lua '
- local ok, err = ngx.print("Hello, Lua!\\n")
- if not ok then
- ngx.log(ngx.ERR, "print failed: ", err)
- end
- ';
- }
---- request
-GET /lua
---- response_body
-Hello, Lua!
---- no_error_log
-[error]
---- grep_error_log eval: qr/lua caching unused lua thread|lua reusing cached lua thread/
---- grep_error_log_out eval
-[
- "",
- "",
-]
diff --git a/src/deps/src/lua-nginx-module/t/166-ssl-client-hello.t b/src/deps/src/lua-nginx-module/t/166-ssl-client-hello.t
deleted file mode 100644
index a356b6eea..000000000
--- a/src/deps/src/lua-nginx-module/t/166-ssl-client-hello.t
+++ /dev/null
@@ -1,2639 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(3);
-
-# All these tests need to have new openssl
-my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
-my $openssl_version = eval { `$NginxBinary -V 2>&1` };
-
-if ($openssl_version =~ m/built with OpenSSL (0\S*|1\.0\S*|1\.1\.0\S*)/) {
- plan(skip_all => "too old OpenSSL, need 1.1.1, was $1");
-} elsif ($openssl_version =~ m/running with BoringSSL/) {
- plan(skip_all => "does not support BoringSSL");
-} else {
- plan tests => repeat_each() * (blocks() * 6 + 8);
-}
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple logging
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block { print("ssl client hello by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
---- grep_error_log eval: qr/ssl_client_hello_by_lua\(.*?,|\bssl client hello: connection reusable: \d+|\breusable connection: \d+/
---- grep_error_log_out eval
-# Since nginx version 1.17.9, nginx call ngx_reusable_connection(c, 0)
-# before call ssl callback function
-$Test::Nginx::Util::NginxVersion >= 1.017009 ?
-qr/reusable connection: 0
-ssl client hello: connection reusable: 0
-ssl_client_hello_by_lua\(nginx.conf:\d+\):1: ssl client hello by lua is running!,/
-: qr /reusable connection: 1
-ssl client hello: connection reusable: 1
-reusable connection: 0
-ssl_client_hello_by_lua\(nginx.conf:\d+\):1: ssl client hello by lua is running!,/
-
-
-
-=== TEST 2: sleep
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- local begin = ngx.now()
- ngx.sleep(0.1)
- print("elapsed in ssl client hello by lua: ", ngx.now() - begin)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log eval
-[
-'lua ssl server name: "test.com"',
-qr/elapsed in ssl client hello by lua: 0.(?:09|1\d)\d+,/,
-]
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 3: timer
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- local function f()
- print("my timer run!")
- end
- local ok, err = ngx.timer.at(0, f)
- if not ok then
- ngx.log(ngx.ERR, "failed to create timer: ", err)
- return
- end
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-my timer run!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 4: cosocket
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to memc: ", err)
- return
- end
-
- local bytes, err = sock:send("flush_all\r\n")
- if not bytes then
- ngx.log(ngx.ERR, "failed to send flush_all command: ", err)
- return
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive memc reply: ", err)
- return
- end
-
- print("received memc reply: ", res)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-received memc reply: OK
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 5: ngx.exit(0) - no yield
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- ngx.exit(0)
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: boolean
-
---- error_log
-lua exit with code 0
-
---- no_error_log
-should never reached here
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 6: ngx.exit(ngx.ERROR) - no yield
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- ngx.exit(ngx.ERROR)
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'lua_client_hello_by_lua: handler return value: -1, client hello cb exit code: 0',
-qr/\[info\] .*? SSL_do_handshake\(\) failed .*?callback failed/,
-'lua exit with code -1',
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 7: ngx.exit(0) - yield
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- ngx.sleep(0.001)
- ngx.exit(0)
-
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: boolean
-
---- error_log
-lua exit with code 0
-
---- no_error_log
-should never reached here
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 8: ngx.exit(ngx.ERROR) - yield
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- ngx.sleep(0.001)
- ngx.exit(ngx.ERROR)
-
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'lua_client_hello_by_lua: client hello cb exit code: 0',
-qr/\[info\] .*? SSL_do_handshake\(\) failed .*?callback failed/,
-'lua exit with code -1',
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 9: lua exception - no yield
---- http_config
- server {
- listen 127.0.0.2:$TEST_NGINX_RAND_PORT_2 ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- error("bad bad bad")
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.2", $TEST_NGINX_RAND_PORT_2)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'runtime error: ssl_client_hello_by_lua(nginx.conf:28):2: bad bad bad',
-'lua_client_hello_by_lua: handler return value: 500, client hello cb exit code: 0',
-qr/\[info\] .*? SSL_do_handshake\(\) failed .*?callback failed/,
-qr/context: ssl_client_hello_by_lua\*, client: \d+\.\d+\.\d+\.\d+, server: \d+\.\d+\.\d+\.\d+:\d+/,
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 10: lua exception - yield
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- ngx.sleep(0.001)
- error("bad bad bad")
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'runtime error: ssl_client_hello_by_lua(nginx.conf:28):3: bad bad bad',
-'lua_client_hello_by_lua: client hello cb exit code: 0',
-qr/\[info\] .*? SSL_do_handshake\(\) failed .*?callback failed/,
-]
-
---- no_error_log
-should never reached here
-[alert]
-[emerg]
-
-
-
-=== TEST 11: get phase
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {print("get_phase: ", ngx.get_phase())}
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end
- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-
---- error_log
-lua ssl server name: "test.com"
-get_phase: ssl_client_hello
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 12: connection aborted prematurely
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- ngx.sleep(0.3)
- print("ssl-client-hello-by-lua: after sleeping")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(150)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
-
---- response_body
-connected: 1
-failed to do SSL handshake: timeout
-
---- error_log
-lua ssl server name: "test.com"
-ssl-client-hello-by-lua: after sleeping
-
---- no_error_log
-[error]
-[alert]
---- wait: 0.6
-
-
-
-=== TEST 13: subrequests disabled
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {ngx.location.capture("/foo")}
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-failed to do SSL handshake: handshake failed
-
---- error_log eval
-[
-'lua ssl server name: "test.com"',
-'ssl_client_hello_by_lua(nginx.conf:28):1: API disabled in the context of ssl_client_hello_by_lua*',
-qr/\[info\] .*?callback failed/,
-]
-
---- no_error_log
-[alert]
-
-
-
-=== TEST 14: simple logging (by_lua_file)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_file html/a.lua;
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
-
---- user_files
->>> a.lua
-print("ssl client hello by lua is running!")
-
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-a.lua:1: ssl client hello by lua is running!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 15: coroutine API
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- local cc, cr, cy = coroutine.create, coroutine.resume, coroutine.yield
-
- local function f()
- local cnt = 0
- for i = 1, 20 do
- print("co yield: ", cnt)
- cy()
- cnt = cnt + 1
- end
- end
-
- local c = cc(f)
- for i = 1, 3 do
- print("co resume, status: ", coroutine.status(c))
- cr(c)
- end
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- grep_error_log eval: qr/co (?:yield: \d+|resume, status: \w+)/
---- grep_error_log_out
-co resume, status: suspended
-co yield: 0
-co resume, status: suspended
-co yield: 1
-co resume, status: suspended
-co yield: 2
-
---- error_log
-lua ssl server name: "test.com"
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 16: simple user thread wait with yielding
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- local function f()
- ngx.sleep(0.01)
- print("uthread: hello in thread")
- return "done"
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.log(ngx.ERR, "uthread: failed to spawn thread: ", err)
- return ngx.exit(ngx.ERROR)
- end
-
- print("uthread: thread created: ", coroutine.status(t))
-
- local ok, res = ngx.thread.wait(t)
- if not ok then
- print("uthread: failed to wait thread: ", res)
- return
- end
-
- print("uthread: ", res)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- no_error_log
-[error]
-[alert]
---- grep_error_log eval: qr/uthread: [^.,]+/
---- grep_error_log_out
-uthread: thread created: running
-uthread: hello in thread
-uthread: done
-
-
-
-=== TEST 17: simple logging - use ssl_client_hello_by_lua* on the http {} level
-GitHub openresty/lua-resty-core#42
---- http_config
- ssl_client_hello_by_lua_block { print("ssl client hello by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-ssl_client_hello_by_lua(nginx.conf:25):1: ssl client hello by lua is running!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 18: simple logging - use ssl_client_hello_by_lua* on the http {} level and server {} level
---- http_config
- ssl_client_hello_by_lua_block { print("ssl client hello by lua on the http level is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- ssl_client_hello_by_lua_block { print("ssl client hello by lua on the server level is running!") }
- server_name test.com;
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-ssl_client_hello_by_lua(nginx.conf:31):1: ssl client hello by lua on the server level is running!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 19: use ssl_client_hello_by_lua* on the server {} level with non-ssl server
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- ssl_client_hello_by_lua_block { print("ssl client hello by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- server_name test.com;
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- no_error_log
-ssl client hello by lua is running!
-[error]
-[alert]
-
-
-
-=== TEST 20: use ssl_client_hello_by_lua* on the http {} level with non-ssl server
---- http_config
- ssl_client_hello_by_lua_block { print("ssl client hello by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
- server_name test.com;
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- no_error_log
-ssl client hello by lua is running!
-[error]
-[alert]
---- skip_eval: 5:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 21: listen two ports (one for ssl and one for non-ssl) in one server - connect ssl port
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- listen unix:$TEST_NGINX_HTML_DIR/nginx2.sock;
- ssl_client_hello_by_lua_block { print("ssl client hello by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- server_name test.com;
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-ssl_client_hello_by_lua(nginx.conf:28):1: ssl client hello by lua is running!
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 22: listen two ports (one for ssl and one for non-ssl) in one server - connect non-ssl port
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- listen unix:$TEST_NGINX_HTML_DIR/nginx2.sock;
- ssl_client_hello_by_lua_block { print("ssl client hello by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- server_name test.com;
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx2.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
-
---- no_error_log
-ssl client hello by lua is running!
-[error]
-[alert]
-
-
-
-=== TEST 23: simple logging - use ssl_client_hello_by_lua* in multiple virtual servers
---- http_config
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- ssl_client_hello_by_lua_block { print("ssl client hello by lua in server1 is running!") }
- server_name test.com;
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- ssl_client_hello_by_lua_block { print("ssl client hello by lua in server2 is running!") }
- server_name test2.com;
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo2") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test2.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 57 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 5
-received: Connection: close
-received:
-received: foo2
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-ssl_client_hello_by_lua(nginx.conf:29):1: ssl client hello by lua in server1 is running!
-
---- no_error_log
-ssl client hello by lua in server2 is running!
-[error]
-[alert]
-
-
-
-=== TEST 24: simple logging (syslog)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- error_log syslog:server=127.0.0.1:12345 debug;
-
- ssl_client_hello_by_lua_block { print("ssl client hello by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log eval
-[
-qr/\[error\] .*? send\(\) failed/,
-'lua ssl server name: "test.com"',
-]
---- no_error_log
-[alert]
-ssl client hello by lua is running!
-
-
-
-=== TEST 25: get raw_client_addr - IPv4
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;;";
-
- server {
- listen 127.0.0.1:$TEST_NGINX_RAND_PORT_1 ssl;
- server_name test.com;
-
- ssl_client_hello_by_lua_block {
- local ssl = require "ngx.ssl"
- local byte = string.byte
- local addr, addrtype, err = ssl.raw_client_addr()
- local ip = string.format("%d.%d.%d.%d", byte(addr, 1), byte(addr, 2),
- byte(addr, 3), byte(addr, 4))
- print("client ip: ", ip)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_RAND_PORT_1)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-client ip: 127.0.0.1
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 26: get raw_client_addr - unix domain socket
---- http_config
- lua_package_path "../lua-resty-core/lib/?.lua;;";
-
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
-
- ssl_client_hello_by_lua_block {
- local ssl = require "ngx.ssl"
- local addr, addrtyp, err = ssl.raw_client_addr()
- print("client socket file: ", addr)
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-client socket file:
-
---- no_error_log
-[error]
-[alert]
-
-
-
-=== TEST 27: ssl_client_hello_by_lua* can yield when reading early data
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- ssl_early_data on;
- server_tokens off;
-
- ssl_client_hello_by_lua_block {
- local begin = ngx.now()
- ngx.sleep(0.1)
- print("elapsed in ssl_client_hello_by_lua*: ", ngx.now() - begin)
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: boolean
---- grep_error_log eval
-qr/elapsed in ssl_client_hello_by_lua\*: 0\.(?:09|1\d)\d+,/,
---- grep_error_log_out eval
-[
-qr/elapsed in ssl_client_hello_by_lua\*: 0\.(?:09|1\d)\d+,/,
-qr/elapsed in ssl_client_hello_by_lua\*: 0\.(?:09|1\d)\d+,/,
-qr/elapsed in ssl_client_hello_by_lua\*: 0\.(?:09|1\d)\d+,/,
-]
---- no_error_log
-[error]
-[alert]
-[emerg]
-
-
-
-=== TEST 28: cosocket (UDP)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- server_tokens off;
-
- ssl_client_hello_by_lua_block {
- local sock = ngx.socket.udp()
-
- sock:settimeout(1000)
-
- local ok, err = sock:setpeername("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT)
- if not ok then
- ngx.log(ngx.ERR, "failed to connect to memc: ", err)
- return
- end
-
- local req = "\0\1\0\0\0\1\0\0flush_all\r\n"
- local ok, err = sock:send(req)
- if not ok then
- ngx.log(ngx.ERR, "failed to send flush_all to memc: ", err)
- return
- end
-
- local res, err = sock:receive()
- if not res then
- ngx.log(ngx.ERR, "failed to receive memc reply: ", err)
- return
- end
-
- ngx.log(ngx.INFO, "received memc reply of ", #res, " bytes")
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
---- no_error_log
-[error]
-[alert]
-[emerg]
---- grep_error_log eval: qr/received memc reply of \d+ bytes/
---- grep_error_log_out eval
-[
-'received memc reply of 12 bytes
-',
-'received memc reply of 12 bytes
-',
-'received memc reply of 12 bytes
-',
-'received memc reply of 12 bytes
-',
-]
-
-
-
-=== TEST 29: uthread (kill)
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- server_tokens off;
-
- ssl_client_hello_by_lua_block {
- local function f()
- ngx.log(ngx.INFO, "uthread: hello from f()")
- ngx.sleep(1)
- end
-
- local t, err = ngx.thread.spawn(f)
- if not t then
- ngx.log(ngx.ERR, "failed to spawn thread: ", err)
- return ngx.exit(ngx.ERROR)
- end
-
- local ok, res = ngx.thread.kill(t)
- if not ok then
- ngx.log(ngx.ERR, "failed to kill thread: ", res)
- return
- end
-
- ngx.log(ngx.INFO, "uthread: killed")
-
- local ok, err = ngx.thread.kill(t)
- if not ok then
- ngx.log(ngx.INFO, "uthread: failed to kill: ", err)
- end
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- -- collectgarbage()
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
---- no_error_log
-[error]
-[alert]
-[emerg]
---- grep_error_log eval: qr/uthread: [^.,]+/
---- grep_error_log_out
-uthread: hello from f()
-uthread: killed
-uthread: failed to kill: already waited or killed
-
-
-
-=== TEST 30: ngx.exit(ngx.OK) - no yield
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block {
- ngx.exit(ngx.OK)
- ngx.log(ngx.ERR, "should never reached here...")
- }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block {ngx.status = 201 ngx.say("foo") ngx.exit(201)}
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_trusted_certificate ../../cert/test.crt;
- lua_ssl_verify_depth 3;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(false, nil, true, false)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
- end -- do
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: boolean
-
---- error_log eval
-[
-'lua_client_hello_by_lua: handler return value: 0, client hello cb exit code: 1',
-qr/\[debug\] .*? SSL_do_handshake: 1/,
-'lua exit with code 0',
-]
---- no_error_log
-should never reached here
-[alert]
-[emerg]
diff --git a/src/deps/src/lua-nginx-module/t/166-worker-thread.t b/src/deps/src/lua-nginx-module/t/166-worker-thread.t
deleted file mode 100644
index 1cbeec5eb..000000000
--- a/src/deps/src/lua-nginx-module/t/166-worker-thread.t
+++ /dev/null
@@ -1,1675 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-our $SkipReason;
-
-BEGIN {
- if ($ENV{TEST_NGINX_EVENT_TYPE}
- && $ENV{TEST_NGINX_EVENT_TYPE} !~ /^kqueue|epoll|eventport$/)
- {
- $SkipReason = "unavailable for the event type '$ENV{TEST_NGINX_EVENT_TYPE}'";
- }
-}
-
-use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
-
-#worker_connections(1014);
-#master_on();
-#workers(2);
-#log_level('warn');
-
-repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 2);
-
-our $HtmlDir = html_dir;
-
-our $HttpConfig = qq{
- lua_package_path "$::HtmlDir/?.lua;./?.lua;;";
- lua_worker_thread_vm_pool_size 1;
-};
-
-#no_diff();
-#no_long_string();
-run_tests();
-
-__DATA__
-
-=== TEST 1: hello from worker thread
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return "hello"
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : hello
-
-
-
-=== TEST 2: thread_pool not found
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return "hello"
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-false : thread pool testpool not found
-
-
-
-=== TEST 3: pass table
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, ok_or_err = ngx.run_worker_thread("testpool", "hello", "hello", {["hello"]="world", [1]={["embed"]=1}})
- ngx.say(ok, " , ", ok_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello(arg1)
- if arg1.hello == "world" and arg1[1].embed == 1 then
- return true
- end
- return false
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true , true
-
-
-
-=== TEST 4: expecting at least 3 arguments
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, err = ngx.run_worker_thread("testpool")
- ngx.say(ok, " : ", err)
- }
-}
---- request
-GET /hello
---- response_body
-false : expecting at least 3 arguments
-
-
-
-=== TEST 5: base64
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, base64 = ngx.run_worker_thread("testpool", "hello", "enc", "hello")
- ngx.say(ok, " , ", base64 == "aGVsbG8=")
- }
-}
---- user_files
->>> hello.lua
-local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-
-local function enc(data)
- return ((data:gsub('.', function(x)
- local r,b='',x:byte()
- for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
- return r;
- end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
- if (#x < 6) then return '' end
- local c=0
- for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
- return b:sub(c+1,c+1)
- end)..({ '', '==', '=' })[#data%3+1])
-end
-
-return {enc=enc}
---- request
-GET /hello
---- response_body
-true , true
-
-
-
-=== TEST 6: return table
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, ret = ngx.run_worker_thread("testpool", "hello", "hello")
- if ret.hello == "world" and ret[1].embed == 1 then
- ngx.say(ok, " , ", true)
- end
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return {["hello"]="world", [1]={["embed"]=1}}
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true , true
-
-
-
-=== TEST 7: unsupported argument type
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local function dummy() end
- local ok, err = ngx.run_worker_thread("testpool", "hello", "hello", dummy)
- ngx.say(ok, " : ", err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return "hello"
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-false : unsupported Lua type: LUA_TFUNCTION in the argument
-
-
-
-=== TEST 8: multiple return values
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, res1, res2 = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", res1, " , ", res2)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return "hello", 200
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : hello , 200
-
-
-
-=== TEST 9: module not found
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", err)
- }
-}
---- request
-GET /hello
---- response_body_like
-false : module 'hello' not found.*
-
-
-
-=== TEST 10: the number of Lua VM exceeds the pool size
---- no_http2
---- quic_max_idle_timeout: 5
---- main_config
- thread_pool testpool threads=100;
---- http_config eval: $::HttpConfig
---- config
-location /foo {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
-
-location /bar {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, foobar_or_err = ngx.run_worker_thread("testpool", "foobar", "foobar")
- ngx.say(ok, " : ", foobar_or_err)
- }
-}
-
-location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local function t(path)
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET " .. path .. " HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- local ret, err, part = sock:receive("*a")
- local _, idx = string.find(ret, "\r\n\r\n");
- idx = idx + 1
- ngx.print(string.sub(ret, idx))
- ok, err = sock:close()
- end
-
- local t1 = ngx.thread.spawn(t, "/foo")
- local t2 = ngx.thread.spawn(t, "/bar")
- ngx.thread.wait(t1)
- ngx.thread.wait(t2)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- os.execute("sleep 3")
- return "hello"
-end
-return {hello=hello}
->>> foobar.lua
-local function foobar()
- return "foobar"
-end
-return {foobar=foobar}
---- request
-GET /t
---- response_body eval
-"false : no available Lua vm\ntrue : hello\n"
---- timeout: 10
-
-
-
-=== TEST 11: kill uthread before worker thread callback
---- no_http2
---- quic_max_idle_timeout: 10
---- main_config
- thread_pool testpool threads=100;
---- http_config eval: $::HttpConfig
---- config
-location /foo {
- default_type 'text/plain';
-
- content_by_lua_block {
- local function t()
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- end
- local t1 = ngx.thread.spawn(t)
- if ngx.var.arg_kill == "kill" then
- ngx.thread.kill(t1)
- ngx.say("killed")
- end
- }
-}
-
-location /t {
- set $port $TEST_NGINX_SERVER_PORT;
-
- content_by_lua_block {
- local function t(path)
- local sock = ngx.socket.tcp()
- local port = ngx.var.port
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- local req = "GET " .. path .. " HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n"
-
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- local ret, err, part = sock:receive("*a")
- local _, idx = string.find(ret, "\r\n\r\n");
- idx = idx + 1
- ngx.print(string.sub(ret, idx))
- ok, err = sock:close()
- end
-
- local t1 = ngx.thread.spawn(t, "/foo?kill=kill")
- ngx.thread.wait(t1)
- ngx.sleep(4)
- local t2 = ngx.thread.spawn(t, "/foo")
- ngx.thread.wait(t2)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- os.execute("sleep 1")
- return "hello"
-end
-return {hello=hello}
->>> foobar.lua
-local function foobar()
- return "foobar"
-end
-return {foobar=foobar}
---- request
-GET /t
---- response_body eval
-"killed\ntrue : hello\n"
---- timeout: 10
-
-
-
-=== TEST 12: exit before worker thread callback
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local function t()
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- end
- ngx.thread.spawn(t)
- ngx.exit(200)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- os.execute("sleep 3")
- return "hello"
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
---- timeout: 10
-
-
-
-=== TEST 13: unsupported argument type in nested table
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local function dummy() end
- local ok, err = ngx.run_worker_thread("testpool", "hello", "hello",
- {["hello"]="world", [1]={["embed"]=1, ["dummy"]=dummy}})
- ngx.say(ok, " : ", err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return "hello"
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-false : unsupported Lua type: LUA_TFUNCTION in the argument
-
-
-
-=== TEST 14: return table with unsupported type
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, ret = ngx.run_worker_thread("testpool", "hello", "hello")
- if ok == false then
- ngx.say("false", " , ", ret)
- end
- if ret.hello == "world" and ret[1].embed == 1 then
- ngx.say(ok, " , ", true)
- end
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- local function dummy() end
- return {["hello"]="world", [1]={["embed"]=1, ["dummy"]=dummy}}
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-false , unsupported Lua type: LUA_TFUNCTION in the return value
-
-
-
-=== TEST 15: the type of module name is not string
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local function dummy() end
- local ok, err = ngx.run_worker_thread("testpool", dummy, "hello")
- ngx.say(ok, " : ", err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return "hello"
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-false : module name should be a string
-
-
-
-=== TEST 16: the type of function name is not string
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local function dummy() end
- local ok, err = ngx.run_worker_thread("testpool", "hello", dummy)
- ngx.say(ok, " : ", err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return "hello"
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-false : function name should be a string
-
-
-
-=== TEST 17: the type of thread pool name is not string
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local function dummy() end
- local ok, err = ngx.run_worker_thread(dummy, "hello", "hello")
- ngx.say(ok, " : ", err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return "hello"
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-false : threadpool should be a string
-
-
-
-=== TEST 18: ngx.encode_base64
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.encode_base64("hello")
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : aGVsbG8=
-
-
-
-=== TEST 19: ngx.config.subsystem
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.config.subsystem
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : http
-
-
-
-=== TEST 20: ngx.hmac_sha1
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- local key = "thisisverysecretstuff"
- local src = "some string we want to sign"
- local digest = ngx.hmac_sha1(key, src)
- return ngx.encode_base64(digest)
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : R/pvxzHC4NLtj7S+kXFg/NePTmk=
-
-
-
-=== TEST 21: ngx.encode_args
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.encode_args({foo = 3, ["b r"] = "hello world"})
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body eval
-qr/foo=3&b%20r=hello%20world|b%20r=hello%20world&foo=3/
-
-
-
-=== TEST 22: ngx.decode_args
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, ret = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", ret.a, " : ", ret.b)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- local args = "a=bar&b=foo"
- args = ngx.decode_args(args)
- return args
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : bar : foo
-
-
-
-=== TEST 23: ngx.quote_sql_str
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- location /hello {
- content_by_lua '
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello", "a\\026b\\026")
- ngx.say(ok, " : ", hello_or_err)
- ';
- }
---- user_files
->>> hello.lua
-local function hello(str)
- return ngx.quote_sql_str(str)
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : 'a\Zb\Z'
-
-
-
-=== TEST 24: ngx.decode_base64
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.decode_base64("aGVsbG8=")
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : hello
-
-
-
-=== TEST 25: ngx.crc32_short
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.crc32_short("hello, world")
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : 4289425978
-
-
-
-=== TEST 26: ngx.crc32_long
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.crc32_long("hello, world")
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : 4289425978
-
-
-
-=== TEST 27: ngx.md5_bin
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- local s = ngx.md5_bin(45)
- s = string.gsub(s, ".", function (c)
- return string.format("%02x", string.byte(c))
- end)
- return s
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : 6c8349cc7260ae62e3b1396831a8398f
-
-
-
-=== TEST 28: ngx.md5
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.md5("hello")
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : 5d41402abc4b2a76b9719d911017c592
-
-
-
-=== TEST 29: ngx.config.debug
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.config.debug
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body_like chop
-^true : (?:true|false)$
-
-
-
-=== TEST 30: ngx.config.prefix
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.config.prefix()
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body_like chop
-^true : \/\S+$
-
-
-
-=== TEST 31: ngx.config.nginx_version
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.config.nginx_version
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body_like chop
-^true : \d+$
-
-
-
-=== TEST 32: ngx.config.nginx_configure
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.config.nginx_configure()
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body_like chop
-^\s*\-\-[^-]+
-
-
-
-=== TEST 33: ngx.config.ngx_lua_version
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return ngx.config.ngx_lua_version
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body_like chop
-^true : \d+$
-
-
-
-=== TEST 34: write_log_file
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /write_log_file {
- default_type 'text/plain';
-
- access_by_lua_block {
- local ok, err = ngx.run_worker_thread("testpool", "write_log_file", "log", ngx.var.arg_str)
- if not ok then
- ngx.say(ok, " : ", err)
- return
- end
- ngx.say(ok)
- }
-}
---- user_files
->>> write_log_file.lua
-local function log(str)
- local file, err = io.open("/tmp/tmp.log", "w")
- if not file then
- return false, err
- end
- file:write(str)
- file:flush()
- file:close()
- return true
-end
-return {log=log}
---- request
-GET /write_log_file?str=hello
---- response_body
-true
-
-
-
-=== TEST 35: shdict get, int value
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 10m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictget {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 8)
- local ok, err = ngx.run_worker_thread("testpool", "test_shdict", "dictget")
- ngx.say(ok, ",", err)
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictget(str)
- local dogs = ngx.shared.dogs
- return dogs:get("Jim")
-end
-return {dictget=dictget}
---- request
-GET /dictget
---- response_body
-true,8
-
-
-
-=== TEST 36: shdict set nil in main thread
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 10m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictget {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 8)
- local ok, err = ngx.run_worker_thread("testpool", "test_shdict", "dictget")
- ngx.say(ok, ",", err)
- dogs:set("Jim", nil)
- local ok, err = ngx.run_worker_thread("testpool", "test_shdict", "dictget")
- ngx.say(ok, ",", err)
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictget(str)
- local dogs = ngx.shared.dogs
- return dogs:get("Jim")
-end
-return {dictget=dictget}
---- request
-GET /dictget
---- response_body
-true,8
-true,nil
-
-
-
-=== TEST 37: shdict set nil in worker thread
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 10m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictsetnil {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 8)
- local ok, err = ngx.run_worker_thread("testpool", "test_shdict", "dictsetnil")
- ngx.say(ok, ",", err)
- ngx.say(ok, ",", dogs:get("Jim"))
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictsetnil(str)
- local dogs = ngx.shared.dogs
- return dogs:set("Jim", nil)
-end
-return {dictsetnil=dictsetnil}
---- request
-GET /dictsetnil
---- response_body
-true,true
-true,nil
-
-
-
-=== TEST 38: shdict get_stale
-For http3: curl: (55) ngtcp2_conn_handle_expiry returned error: ERR_IDLE_CLOSE
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 10m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictget {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 8, 1)
- ngx.sleep(2)
- local ok, err = ngx.run_worker_thread("testpool", "test_shdict", "dictget")
- ngx.say(ok, ",", err)
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictget(str)
- local dogs = ngx.shared.dogs
- return dogs:get_stale("Jim")
-end
-return {dictget=dictget}
---- request
-GET /dictget
---- response_body
-true,8
-
-
-
-=== TEST 39: shdict add failed
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 10m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictadd {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 8)
- local ok, err, err2 = ngx.run_worker_thread("testpool", "test_shdict", "dictadd")
- ngx.say(ok, ",", err, ",", err2)
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictadd(str)
- local dogs = ngx.shared.dogs
- local success, err = dogs:add("Jim", "hello")
- return success, err
-end
-return {dictadd=dictadd}
---- request
-GET /dictadd
---- response_body
-true,false,exists
-
-
-
-=== TEST 40: shdict force add
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 6m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictadd {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- local bigstr = string.rep("A", 1024*1024*3)
- dogs:set("Jim", bigstr)
- local ok, ret, err, forcible = ngx.run_worker_thread("testpool", "test_shdict", "dictadd")
- ngx.say(ok, ",", ret, ",", forcible, ",", dogs:get("Jim"))
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictadd(str)
- local dogs = ngx.shared.dogs
- local bigstr = string.rep("A", 1024*1024*5)
- local success, err, forcible = dogs:add("King", bigstr)
- return success, err, forcible
-end
-return {dictadd=dictadd}
---- request
-GET /dictadd
---- response_body
-true,true,true,nil
-
-
-
-=== TEST 41: shdict replace
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 6m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictreplace {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- local bigstr = string.rep("A", 1024*1024*3)
- dogs:set("Jim", bigstr)
- local ok, ret, err = ngx.run_worker_thread("testpool", "test_shdict", "dictreplace")
- ngx.say(ok, ",", ret, ",", err, ",", dogs:get("Jim"))
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictreplace(str)
- local dogs = ngx.shared.dogs
- local success, err = dogs:replace("Jim", 8)
- return success, err
-end
-return {dictreplace=dictreplace}
---- request
-GET /dictreplace
---- response_body
-true,true,nil,8
-
-
-
-=== TEST 42: shdict replace not found
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 6m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictreplace {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- local ok, ret, err = ngx.run_worker_thread("testpool", "test_shdict", "dictreplace")
- ngx.say(ok, ",", ret, ",", err)
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictreplace(str)
- local dogs = ngx.shared.dogs
- local success, err = dogs:replace("Jim", 8)
- return success, err
-end
-return {dictreplace=dictreplace}
---- request
-GET /dictreplace
---- response_body
-true,false,not found
-
-
-
-=== TEST 43: shdict incr
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 6m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictincr {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- local success, err = dogs:set("Jim", 8)
- local ok, ret, err = ngx.run_worker_thread("testpool", "test_shdict", "dictincr")
- ngx.say(ok, ",", ret, ",", err, ",", dogs:get("Jim"))
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictincr(str)
- local dogs = ngx.shared.dogs
- local success, err = dogs:incr("Jim", 1)
- return success, err
-end
-return {dictincr=dictincr}
---- request
-GET /dictincr
---- response_body
-true,9,nil,9
-
-
-
-=== TEST 44: shdict lpush lpop
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 6m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictlpush {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:lpush("Jim", 8)
- dogs:lpush("Jim", 9)
- local ok, val, len, err = ngx.run_worker_thread("testpool", "test_shdict", "dictlpush")
- ngx.say(ok, ",", val, ",", len, ",", err, ",", dogs:lpop("Jim"))
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictlpush(str)
- local dogs = ngx.shared.dogs
- local val = dogs:lpop("Jim")
- local len, err = dogs:lpush("Jim", 7)
- return val, len, err
-end
-return {dictlpush=dictlpush}
---- request
-GET /dictlpush
---- response_body
-true,9,2,nil,7
-
-
-
-=== TEST 45: shdict expire ttl
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 6m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictexpire {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 8)
- local ok, success, err = ngx.run_worker_thread("testpool", "test_shdict", "dictexpire")
- ngx.say(ok, ",", success, ",", err, ",", dogs:ttl("Jim") <= 1)
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictexpire(str)
- local dogs = ngx.shared.dogs
- local success, err = dogs:expire("Jim", 1)
- return success, err
-end
-return {dictexpire=dictexpire}
---- request
-GET /dictexpire
---- response_body
-true,true,nil,true
-
-
-
-=== TEST 46: shdict flush_all
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 6m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictexpire {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 8)
- dogs:set("King", 9)
- local ok = ngx.run_worker_thread("testpool", "test_shdict", "dictexpire")
- ngx.say(ok, ",", dogs:get("Jim"), ",", dogs:get("King"))
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictexpire(str)
- local dogs = ngx.shared.dogs
- dogs:flush_all()
-end
-return {dictexpire=dictexpire}
---- request
-GET /dictexpire
---- response_body
-true,nil,nil
-
-
-
-=== TEST 47: shdict get_keys
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
-"
- lua_shared_dict dogs 6m;
- lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
-"
---- config
-location /dictgetkeys {
- default_type 'text/plain';
-
- access_by_lua_block {
- local dogs = ngx.shared.dogs
- dogs:set("Jim", 8)
- dogs:set("King", 9)
- local ok, keys = ngx.run_worker_thread("testpool", "test_shdict", "dictgetkeys")
- ngx.say(ok, ",", table.concat(keys, ":"))
- }
-}
---- user_files
->>> test_shdict.lua
-local function dictgetkeys(str)
- local dogs = ngx.shared.dogs
- return dogs:get_keys()
-end
-return {dictgetkeys=dictgetkeys}
---- request
-GET /dictgetkeys
---- response_body
-true,Jim:King
-
-
-
-=== TEST 48: unsupported argument type in self-reference table
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local t = {}
- t.a = t
- local ok, ok_or_err = ngx.run_worker_thread("testpool", "hello", "hello", t)
- ngx.say(ok, " , ", ok_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello(arg1)
- return true
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-false , suspicious circular references, table depth exceed max depth: 100 in the argument
-
-
-
-=== TEST 49: unsupported argument type in circular-reference table
---- main_config
- thread_pool testpool threads=100;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local t = {}
- local s = {}
- t.a = s
- s.b = t
-
- local ok, ok_or_err = ngx.run_worker_thread("testpool", "hello", "hello", t)
- ngx.say(ok, " , ", ok_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello(arg1)
- return true
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-false , suspicious circular references, table depth exceed max depth: 100 in the argument
-
-
-
-=== TEST 50: call run_worker_thread twice
---- main_config
- thread_pool testpool threads=1;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
-
- ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", hello_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return "hello"
-end
-return {hello=hello}
---- request
-GET /hello
---- response_body
-true : hello
-true : hello
-
-
-
-=== TEST 51: big object
---- main_config
- thread_pool testpool threads=1;
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
-location /hello {
- default_type 'text/plain';
-
- content_by_lua_block {
- local ok, hello_or_err = ngx.run_worker_thread("testpool", "hello", "hello")
- ngx.say(ok, " : ", #hello_or_err)
-
- local ok, gcsize_or_err = ngx.run_worker_thread("testpool", "hello", "gcsize")
- ngx.say(ok, " : ", gcsize_or_err)
- }
-}
---- user_files
->>> hello.lua
-local function hello()
- return string.rep("helloworld", 1000000)
-end
-
-local function gcsize()
- return collectgarbage("count")
-end
-
-return {
- hello = hello,
- gcsize = gcsize
-}
---- request
-GET /hello
---- response_body eval
-qr/\Atrue : 10000000
-true : \d{3,4}\.\d+
-\z/ms
diff --git a/src/deps/src/lua-nginx-module/t/167-server-rewrite.t b/src/deps/src/lua-nginx-module/t/167-server-rewrite.t
deleted file mode 100644
index 6aea288ef..000000000
--- a/src/deps/src/lua-nginx-module/t/167-server-rewrite.t
+++ /dev/null
@@ -1,490 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-use t::StapThread;
-
-our $GCScript = <<_EOC_;
-$t::StapThread::GCScript
-
-F(ngx_http_lua_check_broken_connection) {
- println("lua check broken conn")
-}
-
-F(ngx_http_lua_request_cleanup) {
- println("lua req cleanup")
-}
-_EOC_
-
-our $StapScript = $t::StapThread::StapScript;
-
-repeat_each(2);
-
-plan tests => repeat_each() * (blocks() * 3 + 10);
-
-#log_level("info");
-#no_long_string();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: server_rewrite_by_lua_block in http
---- http_config
- server_rewrite_by_lua_block {
- ngx.ctx.a = "server_rewrite_by_lua_block in http"
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say(ngx.ctx.a)
- ngx.log(ngx.INFO, ngx.ctx.a)
- }
- }
---- request
-GET /lua
---- response_body
-server_rewrite_by_lua_block in http
---- error_log
-server_rewrite_by_lua_block in http
---- no_error_log
-[error]
-
-
-
-=== TEST 2: server_rewrite_by_lua_block in server
---- config
- server_rewrite_by_lua_block {
- ngx.log(ngx.INFO, "server_rewrite_by_lua_block in server")
- }
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- response_body
-OK
---- error_log
-server_rewrite_by_lua_block in server
---- no_error_log
-[error]
-
-
-
-=== TEST 3: redirect
---- config
- server_rewrite_by_lua_block {
- ngx.redirect("/foo")
- }
---- request
-GET /lua
---- raw_response_headers_like eval
-qr{[Ll]ocation: /foo\r\n}
---- response_body_like: 302 Found
---- error_code: 302
---- no_error_log
-[error]
-
-
-
-=== TEST 4: flush
---- config
- server_rewrite_by_lua_block {
- ngx.say("foo")
- ngx.flush(true)
- }
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- response_body
-foo
---- no_error_log
-[error]
-
-
-
-=== TEST 5: eof
---- config
- server_rewrite_by_lua_block {
- ngx.say("foo")
- ngx.eof()
- }
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- response_body
-foo
---- no_error_log
-[error]
-
-
-
-=== TEST 6: send_headers
---- config
- server_rewrite_by_lua_block {
- ngx.header["Foox"] = {"conx1", "conx2" }
- ngx.header["Fooy"] = {"cony1", "cony2" }
- ngx.send_headers()
- }
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- response_body
---- response_headers
-Foox: conx1, conx2
-Fooy: cony1, cony2
---- no_error_log
-[error]
-
-
-
-=== TEST 7: read_body
---- config
- server_rewrite_by_lua_block {
- ngx.req.read_body()
- ngx.say(ngx.var.request_body)
- }
---- request
-POST /lua
-hello, world
---- response_body
-hello, world
---- no_error_log
-[error]
-
-
-
-=== TEST 8: req_sock
---- config
- server_rewrite_by_lua_block {
- local sock = ngx.req.socket()
- sock:receive(2)
- sock:receive(2)
- sock:receive(1)
- ngx.sleep(1)
- }
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-POST /lua
-hello
-
---- stap2 eval: $::StapScript
---- stap eval: $::GCScript
---- stap_out
-lua check broken conn
-lua check broken conn
-lua req cleanup
-delete thread 1
-
---- wait: 1
---- timeout: 0.2
---- abort
---- ignore_response
---- no_error_log
-[error]
---- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
-
-
-
-=== TEST 9: rewrite args (not break cycle by default)
---- config
- location /bar {
- echo "bar: $uri?$args";
- }
- server_rewrite_by_lua_block {
- if ngx.var.uri ~= "/bar" then
- ngx.req.set_uri_args("hello")
- ngx.req.set_uri("/bar", true)
- end
- }
- location /foo {
-
- echo "foo: $uri?$args";
- }
---- request
- GET /foo?world
---- response_body
-bar: /bar?hello
-
-
-
-=== TEST 10: server_rewrite_by_lua_block overwrite by server
---- http_config
- server_rewrite_by_lua_block {
- ngx.log(ngx.INFO, "server_rewrite_by_lua_block in http")
- }
---- config
- server_rewrite_by_lua_block {
- ngx.log(ngx.INFO, "server_rewrite_by_lua_block in server")
- }
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- response_body
-OK
---- error_log
-server_rewrite_by_lua_block in server
---- no_error_log
-[error]
-
-
-
-=== TEST 11: sleep
---- config
- server_rewrite_by_lua_block {
- ngx.sleep(0.001)
- ngx.log(ngx.INFO, "server_rewrite_by_lua_block in server")
- }
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- response_body
-OK
---- error_log
-server_rewrite_by_lua_block in server
---- no_error_log
-[error]
-
-
-
-=== TEST 12: ngx.exit(ngx.OK)
---- config
- server_rewrite_by_lua_block {
- ngx.log(ngx.INFO, "ngx.exit")
- ngx.exit(ngx.OK)
- }
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- response_body
-OK
---- error_log
-ngx.exit
---- no_error_log
-[error]
-
-
-
-=== TEST 13: ngx.exit(503)
---- config
- server_rewrite_by_lua_block {
- ngx.exit(503)
- }
- location /lua {
- content_by_lua_block {
- ngx.log(ngx.ERR, "content_by_lua")
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- error_code: 503
---- no_error_log
-[error]
-
-
-
-=== TEST 14: subrequests
---- config
- server_rewrite_by_lua_block {
- ngx.log(ngx.INFO, "is_subrequest:", ngx.is_subrequest)
- }
-
- location /lua {
- content_by_lua_block {
- local res = ngx.location.capture("/sub")
- ngx.print(res.body)
- }
- }
-
- location /sub {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
-
---- request
-GET /lua
---- response_body
-OK
---- error_log
-is_subrequest:false
-is_subrequest:true
---- no_error_log
-[error]
-
-
-
-=== TEST 15: rewrite by ngx_http_rewrite_module
---- config
- server_rewrite_by_lua_block {
- ngx.log(ngx.INFO, "uri is ", ngx.var.uri)
- }
-
- rewrite ^ /re;
-
- location /re {
- content_by_lua_block {
- ngx.say("RE")
- }
- }
-
- location /ok {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
-
---- request
-GET /lua
---- response_body
-RE
---- error_log
-uri is /lua
---- no_error_log
-[error]
-
-
-
-=== TEST 16: exec
---- config
- server_rewrite_by_lua_block {
- if ngx.var.uri ~= "/ok" then
- ngx.exec("/ok")
- end
- ngx.log(ngx.INFO, "uri is ", ngx.var.uri)
- }
-
- location /ok {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
-
---- request
-GET /lua
---- response_body
-OK
---- error_log
-uri is /ok
---- no_error_log
-[error]
-
-
-
-=== TEST 17: server_rewrite_by_lua and rewrite_by_lua
---- http_config
- server_rewrite_by_lua_block {
- ngx.log(ngx.INFO, "server_rewrite_by_lua_block in http")
- }
---- config
- location /lua {
- rewrite_by_lua_block {
- ngx.log(ngx.INFO, "rewrite_by_lua_block in location")
- }
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- response_body
-OK
---- error_log
-server_rewrite_by_lua_block in http
-rewrite_by_lua_block in location
---- no_error_log
-[error]
-
-
-
-=== TEST 18: server_rewrite_by_lua_file
---- http_config
- server_rewrite_by_lua_file 'html/foo.lua';
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- user_files
->>> foo.lua
-ngx.log(ngx.INFO, "rewrite_by_lua_file in server")
---- response_body
-OK
---- error_log
-rewrite_by_lua_file in server
---- no_error_log
-[error]
-
-
-
-=== TEST 19: syntax error server_rewrite_by_lua_block in http
---- http_config
- server_rewrite_by_lua_block {
- 'for end';
- }
---- config
- location /lua {
- content_by_lua_block {
- ngx.say("OK")
- }
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-failed to load inlined Lua code: server_rewrite_by_lua(nginx.conf:25):2: unexpected symbol near ''for end''
---- no_error_log
-no_such_error
-
-
-
-=== TEST 20: syntax error server_rewrite_by_lua_block in server
---- config
- server_rewrite_by_lua_block {
- 'for end';
- }
- location /lua {
- content_by_lua_block {
- ngx.say("Hello world")
- }
- }
---- request
-GET /lua
---- ignore_response
---- error_log
-failed to load inlined Lua code: server_rewrite_by_lua(nginx.conf:39):2: unexpected symbol near ''for end''
---- no_error_log
-no_such_error
diff --git a/src/deps/src/lua-nginx-module/t/168-tcp-socket-bind.t b/src/deps/src/lua-nginx-module/t/168-tcp-socket-bind.t
deleted file mode 100644
index a2aa50b4e..000000000
--- a/src/deps/src/lua-nginx-module/t/168-tcp-socket-bind.t
+++ /dev/null
@@ -1,367 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-# more times than usual(2) for test case 6
-repeat_each(4);
-
-plan tests => repeat_each() * (blocks() * 3 + 7);
-
-our $HtmlDir = html_dir;
-
-# get ip address in the dev which is default route outgoing dev
-my $dev = `ip route | awk '/default/ {printf "%s", \$5}'`;
-my $local_ip = `ip route | grep $dev | grep -o "src .*" | head -n 1 | awk '{print \$2}'`;
-chomp $local_ip;
-
-$ENV{TEST_NGINX_HTML_DIR} = $HtmlDir;
-$ENV{TEST_NGINX_NOT_EXIST_IP} ||= '8.8.8.8';
-$ENV{TEST_NGINX_INVALID_IP} ||= '127.0.0.1:8899';
-$ENV{TEST_NGINX_SERVER_IP} ||= $local_ip;
-
-no_long_string();
-#no_diff();
-
-#log_level 'warn';
-log_level 'debug';
-
-no_shuffle();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: upstream sockets bind 127.0.0.1
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local ip = "127.0.0.1"
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
- local ok, err = sock:bind(ip)
- if not ok then
- ngx.say("failed to bind", err)
- return
- end
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local bytes, err = sock:send("GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keepalive\r\n\r\n")
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent")
-
- local reader = sock:receiveuntil("\r\n0\r\n\r\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response")
- local remote_ip = string.match(data, "(bind: %d+%.%d+%.%d+%.%d+)")
- ngx.say(remote_ip)
-
- ngx.say("done")
- }
- }
-
- location /foo {
- echo bind: $remote_addr;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent
-received response
-bind: 127.0.0.1
-done
---- no_error_log
-["[error]",
-"bind(127.0.0.1) failed"]
---- error_log eval
-"lua tcp socket bind ip: 127.0.0.1"
-
-
-
-=== TEST 2: upstream sockets bind server ip, not 127.0.0.1
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local ip = "$TEST_NGINX_SERVER_IP"
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
- local ok, err = sock:bind(ip)
- if not ok then
- ngx.say("failed to bind", err)
- return
- end
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local bytes, err = sock:send("GET /foo HTTP/1.1\r\nHost: localhost\r\nConnection: keepalive\r\n\r\n")
- if not bytes then
- ngx.say("failed to send request: ", err)
- return
- end
-
- ngx.say("request sent")
-
- local reader = sock:receiveuntil("\r\n0\r\n\r\n")
- local data, err = reader()
-
- if not data then
- ngx.say("failed to receive response body: ", err)
- return
- end
-
- ngx.say("received response")
- local remote_ip = string.match(data, "(bind: %d+%.%d+%.%d+%.%d+)")
- if remote_ip == "bind: $TEST_NGINX_SERVER_IP" then
- ngx.say("ip matched")
- end
-
- ngx.say("done")
- }
- }
-
- location /foo {
- echo bind: $remote_addr;
- }
---- request
-GET /t
---- response_body
-connected: 1
-request sent
-received response
-ip matched
-done
---- no_error_log eval
-["[error]",
-"bind($ENV{TEST_NGINX_SERVER_IP}) failed"]
---- error_log eval
-"lua tcp socket bind ip: $ENV{TEST_NGINX_SERVER_IP}"
-
-
-
-=== TEST 3: add setkeepalive
---- http_config eval
- "lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local test = require "test"
- local t1 = test.go()
- local t2 = test.go()
- ngx.say("t2 - t1: ", t2 - t1)
- }
- }
---- user_files
->>> test.lua
-local _M = {}
-
-function _M.go()
- local ip = "127.0.0.1"
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
- local ok, err = sock:bind(ip)
- if not ok then
- ngx.say("failed to bind", err)
- return
- end
-
- ngx.say("bind: ", ip)
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local reused = sock:getreusedtimes()
-
- local ok, err = sock:setkeepalive()
- if not ok then
- ngx.say("failed to set reusable: ", err)
- end
-
- return reused
-end
-
-return _M
---- request
-GET /t
---- response_body
-bind: 127.0.0.1
-connected: 1
-bind: 127.0.0.1
-connected: 1
-t2 - t1: 1
---- no_error_log
-["[error]",
-"bind(127.0.0.1) failed"]
---- error_log eval
-"lua tcp socket bind ip: 127.0.0.1"
-
-
-
-=== TEST 4: upstream sockets bind not exist ip
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local ip = "$TEST_NGINX_NOT_EXIST_IP"
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
- local ok, err = sock:bind(ip)
- if not ok then
- ngx.say("failed to bind", err)
- return
- end
-
- ngx.say("bind: ", ip)
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- }
- }
---- request
-GET /t
---- response_body
-bind: 8.8.8.8
-failed to connect: cannot assign requested address
---- error_log eval
-["bind(8.8.8.8) failed",
-"lua tcp socket bind ip: 8.8.8.8"]
-
-
-
-=== TEST 5: upstream sockets bind invalid ip
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local ip = "$TEST_NGINX_INVALID_IP"
- local port = ngx.var.port
-
- local sock = ngx.socket.tcp()
- local ok, err = sock:bind(ip)
- if not ok then
- ngx.say("failed to bind: ", err)
- return
- end
-
- ngx.say("bind: ", ip)
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
- }
- }
---- request
-GET /t
---- response_body
-failed to bind: bad address
---- no_error_log
-[error]
-
-
-
-=== TEST 6: tcpsock across request after bind
---- http_config
- init_worker_by_lua_block {
- -- this is not the recommend way, just for test
- local function tcp()
- local sock = ngx.socket.tcp()
-
- local ok, err = sock:bind("127.0.0.1")
- if not ok then
- ngx.log(ngx.ERR, "failed to bind")
- end
-
- package.loaded.share_sock = sock
- end
-
- local ok, err = ngx.timer.at(0, tcp)
- if not ok then
- ngx.log(ngx.ERR, "failed to create timer")
- end
- }
---- config
- server_tokens off;
- location /t {
- set $port $TEST_NGINX_SERVER_PORT;
- content_by_lua_block {
- local port = ngx.var.port
-
- -- make sure share_sock is created
- ngx.sleep(0.002)
-
- local sock = package.loaded.share_sock
- if sock ~= nil then
- package.loaded.share_sock = nil
-
- local ok, err = sock:connect("127.0.0.1", port)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- sock:close()
- collectgarbage("collect")
- else
- -- the sock from package.loaded.share_sock is just
- -- for the first request after worker init
- -- add following code to keep the same result for other request
- ngx.say("connected: ", 1)
- end
- }
- }
---- request
-GET /t
---- response_body
-connected: 1
---- no_error_log
-[error]
diff --git a/src/deps/src/lua-nginx-module/t/185-ngx-buf-double-free.t b/src/deps/src/lua-nginx-module/t/185-ngx-buf-double-free.t
deleted file mode 100644
index 699083db2..000000000
--- a/src/deps/src/lua-nginx-module/t/185-ngx-buf-double-free.t
+++ /dev/null
@@ -1,25 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket 'no_plan';
-
-repeat_each(2);
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: one buf was linked to multiple ngx_chain_t nodes
---- config
- location /t {
- content_by_lua_block {
- local str = string.rep(".", 1300)
- ngx.print(str)
- ngx.flush()
- ngx.print("small chunk")
- ngx.flush()
- }
- body_filter_by_lua_block {local dummy=1}
- }
---- request
-GET /t
---- response_body_like: small chunk
diff --git a/src/deps/src/lua-nginx-module/t/186-cosocket-busy-bufs.t b/src/deps/src/lua-nginx-module/t/186-cosocket-busy-bufs.t
deleted file mode 100644
index 743944376..000000000
--- a/src/deps/src/lua-nginx-module/t/186-cosocket-busy-bufs.t
+++ /dev/null
@@ -1,91 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-
-use Test::Nginx::Socket;
-use Test::Nginx::Socket::Lua::Stream;
-
-log_level('warn');
-repeat_each(2);
-
-if (defined $ENV{TEST_NGINX_USE_HTTP3}) {
- plan(skip_all => "HTTP3 does not support client abort");
-} elsif (defined $ENV{TEST_NGINX_USE_HTTP2}) {
- plan(skip_all => "HTTP2 does not support client abort");
-} else {
- plan tests => repeat_each() * (blocks() * 2);
-}
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: ngx.say and cosocket
---- stream_server_config
- content_by_lua_block {
- local sock = assert(ngx.req.socket(true))
- sock:settimeout(1000)
- while true do
- local data = sock:receive(5)
- if not data then
- return
- end
- ngx.print(data)
- ngx.flush(true)
- end
- }
---- config
- location /test {
- content_by_lua_block {
- ngx.say("hello")
- --ngx.flush(true)
-
- local sock = ngx.socket.tcp()
- local ok, err = sock:connect("127.0.0.1", ngx.var.server_port + 1)
- assert(ok)
-
- local last_duration = 0
- local cnt = 0
- local t1, t2
- local err_cnt = 0
- local ERR_THRESHOLD_MS = 100
-
- for i = 1,100000 do
- if cnt == 0 then
- ngx.update_time()
- t1 = ngx.now()
- end
-
- cnt = cnt + 1
-
- local sent = sock:send("hello")
- local data = sock:receive(5)
- assert(data=="hello")
-
- if cnt == 1000 then
- cnt = 0
- ngx.update_time()
- t2 = ngx.now()
- local duration = (t2 - t1) * 1000
- if last_duration > 0 and (duration - last_duration) > ERR_THRESHOLD_MS then
- if err_cnt >= 3 then
- ngx.log(ngx.ERR,
- "more than ", err_cnt, " times, duration larger than ",
- ERR_THRESHOLD_MS, " ms, ",
- "last_duration: ", math.floor(duration), " ms")
- return ngx.exit(500)
- end
- err_cnt = err_cnt + 1
- end
- last_duration = duration
- end
- end
-
- sock:close()
- ngx.exit(200)
- }
- }
---- no_error_log
-[error]
---- timeout: 30
---- request
-GET /test
diff --git a/src/deps/src/lua-nginx-module/t/187-ssl-two-verification.t b/src/deps/src/lua-nginx-module/t/187-ssl-two-verification.t
deleted file mode 100644
index 312847252..000000000
--- a/src/deps/src/lua-nginx-module/t/187-ssl-two-verification.t
+++ /dev/null
@@ -1,145 +0,0 @@
-# vim:set ft= ts=4 sw=4 et fdm=marker:
-
-use Test::Nginx::Socket::Lua;
-
-repeat_each(3);
-
-# All these tests need to have new openssl
-my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
-my $openssl_version = eval { `$NginxBinary -V 2>&1` };
-
-if ($openssl_version =~ m/built with OpenSSL (0\S*|1\.0\S*|1\.1\.0\S*)/) {
- plan(skip_all => "too old OpenSSL, need 1.1.1, was $1");
-} elsif ($openssl_version =~ m/running with BoringSSL/) {
- plan(skip_all => "does not support BoringSSL");
-} else {
- plan tests => repeat_each() * (blocks() * 7);
-}
-
-$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
-$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
-
-#log_level 'warn';
-log_level 'debug';
-
-no_long_string();
-#no_diff();
-
-run_tests();
-
-__DATA__
-
-=== TEST 1: simple logging
---- http_config
- server {
- listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
- #listen 127.0.0.1:4433 ssl;
- server_name test.com;
- ssl_client_hello_by_lua_block { print("ssl client hello by lua is running!") }
- ssl_certificate ../../cert/test.crt;
- ssl_certificate_key ../../cert/test.key;
- #ssl_trusted_certificate ../../cert/test.crt;
- ssl_client_certificate ../../cert/test.crt;
- ssl_verify_client on;
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
-
- server_tokens off;
- location /foo {
- default_type 'text/plain';
- content_by_lua_block { ngx.status = 201 ngx.say("foo") ngx.exit(201) }
- log_by_lua_block {
- ngx.log(ngx.INFO, "ssl_client_s_dn: ", ngx.var.ssl_client_s_dn)
- }
- more_clear_headers Date;
- }
- }
---- config
- server_tokens off;
- lua_ssl_certificate ../../cert/test.crt;
- lua_ssl_certificate_key ../../cert/test.key;
- lua_ssl_trusted_certificate ../../cert/test.crt;
-
- location /t {
- content_by_lua_block {
- do
- local sock = ngx.socket.tcp()
-
- sock:settimeout(2000)
-
- local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
- -- local ok, err = sock:connect("127.0.0.1", 4433)
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
-
- ngx.say("connected: ", ok)
-
- local sess, err = sock:sslhandshake(nil, "test.com", true)
- if not sess then
- ngx.say("failed to do SSL handshake: ", err)
- return
- end
-
- ngx.say("ssl handshake: ", type(sess))
-
- local req = "GET /foo HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n"
- local bytes, err = sock:send(req)
- if not bytes then
- ngx.say("failed to send http request: ", err)
- return
- end
-
- ngx.say("sent http request: ", bytes, " bytes.")
-
- while true do
- local line, err = sock:receive()
- if not line then
- -- ngx.say("failed to receive response status line: ", err)
- break
- end
-
- ngx.say("received: ", line)
- end
-
- local ok, err = sock:close()
- ngx.say("close: ", ok, " ", err)
- end -- do
- -- collectgarbage()
- }
- }
-
---- request
-GET /t
---- response_body
-connected: 1
-ssl handshake: cdata
-sent http request: 56 bytes.
-received: HTTP/1.1 201 Created
-received: Server: nginx
-received: Content-Type: text/plain
-received: Content-Length: 4
-received: Connection: close
-received:
-received: foo
-close: 1 nil
-
---- error_log
-lua ssl server name: "test.com"
-ssl_client_s_dn: emailAddress=agentzh@gmail.com,CN=test.com,OU=OpenResty,O=OpenResty,L=San Francisco,ST=California,C=US
-
---- no_error_log
-[error]
-[alert]
---- grep_error_log eval: qr/ssl_client_hello_by_lua\(.*?,|\bssl client hello: connection reusable: \d+|\breusable connection: \d+/
---- grep_error_log_out eval
-# Since nginx version 1.17.9, nginx call ngx_reusable_connection(c, 0)
-# before call ssl callback function
-$Test::Nginx::Util::NginxVersion >= 1.017009 ?
-qr/reusable connection: 0
-ssl client hello: connection reusable: 0
-ssl_client_hello_by_lua\(nginx.conf:\d+\):1: ssl client hello by lua is running!,/
-: qr /reusable connection: 1
-ssl client hello: connection reusable: 1
-reusable connection: 0
-ssl_client_hello_by_lua\(nginx.conf:\d+\):1: ssl client hello by lua is running!,/
diff --git a/src/deps/src/lua-nginx-module/t/188-balancer_keepalive_pool_max_retry.t b/src/deps/src/lua-nginx-module/t/188-balancer_keepalive_pool_max_retry.t
deleted file mode 100644
index 679ee680f..000000000
--- a/src/deps/src/lua-nginx-module/t/188-balancer_keepalive_pool_max_retry.t
+++ /dev/null
@@ -1,89 +0,0 @@
-# vim:set ft= ts=4 sw=4 et:
-
-use Test::Nginx::Socket::Lua;
-use Cwd qw(cwd);
-
-log_level('info');
-repeat_each(1);
-
-plan tests => repeat_each() * (blocks() * 6);
-
-my $pwd = cwd();
-
-no_long_string();
-
-check_accum_error_log();
-run_tests();
-
-__DATA__
-
-=== TEST 1: sanity
---- http_config
- lua_shared_dict request_counter 1m;
- upstream my_upstream {
- server 127.0.0.1;
- balancer_by_lua_block {
- local balancer = require "ngx.balancer"
-
- if not ngx.ctx.tries then
- ngx.ctx.tries = 0
- end
-
- ngx.ctx.tries = ngx.ctx.tries + 1
- ngx.log(ngx.INFO, "tries ", ngx.ctx.tries)
-
- if ngx.ctx.tries == 1 then
- balancer.set_more_tries(5)
- end
-
- local host = "127.0.0.1"
- local port = $TEST_NGINX_RAND_PORT_1;
-
- local ok, err = balancer.set_current_peer(host, port)
- if not ok then
- ngx.log(ngx.ERR, "failed to set the current peer: ", err)
- return ngx.exit(500)
- end
-
- balancer.set_timeouts(60000, 60000, 60000)
-
- local ok, err = balancer.enable_keepalive(60, 100)
- if not ok then
- ngx.log(ngx.ERR, "failed to enable keepalive: ", err)
- return ngx.exit(500)
- end
- }
- }
-
- server {
- listen 127.0.0.1:$TEST_NGINX_RAND_PORT_1;
- location /hello {
- content_by_lua_block{
- local request_counter = ngx.shared.request_counter
- local first_request = request_counter:get("first_request")
- if first_request == nil then
- request_counter:set("first_request", "yes")
- ngx.print("hello")
- else
- ngx.exit(ngx.HTTP_CLOSE)
- end
- }
- }
- }
---- config
- location = /t {
- proxy_pass http://my_upstream;
- proxy_set_header Connection "keep-alive";
-
- rewrite_by_lua_block {
- ngx.req.set_uri("/hello")
- }
- }
---- pipelined_requests eval
-["GET /t HTTP/1.1" , "GET /t HTTP/1.1"]
---- response_body eval
-["hello", qr/502/]
---- error_code eval
-[200, 502]
---- no_error_log eval
-qr/tries 7/
diff --git a/src/deps/src/lua-nginx-module/t/StapThread.pm b/src/deps/src/lua-nginx-module/t/StapThread.pm
deleted file mode 100644
index e95886344..000000000
--- a/src/deps/src/lua-nginx-module/t/StapThread.pm
+++ /dev/null
@@ -1,282 +0,0 @@
-package t::StapThread;
-
-use strict;
-use warnings;
-
-our $GCScript = <<'_EOC_';
-global ids, cur
-global in_req = 0
-global alive_reqs
-
-function gen_id(k) {
- if (ids[k]) return ids[k]
- ids[k] = ++cur
- return cur
-}
-
-F(ngx_http_handler) {
- if (!alive_reqs[$r] && $r == $r->main) {
- in_req++
- alive_reqs[$r] = 1
-
- if (in_req == 1) {
- delete ids
- cur = 0
- }
- }
-}
-
-F(ngx_http_free_request) {
- if (alive_reqs[$r]) {
- in_req--
- delete alive_reqs[$r]
- }
-}
-
-F(ngx_http_terminate_request) {
- if (alive_reqs[$r]) {
- in_req--
- delete alive_reqs[$r]
- }
-}
-
-M(http-lua-user-thread-spawn) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("spawn user thread %x in %x\n", c, p)
-}
-
-M(http-lua-thread-delete) {
- t = gen_id($arg2)
- printf("delete thread %x\n", t)
-}
-
-M(http-lua-user-coroutine-create) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("create %x in %x\n", c, p)
-}
-
-M(http-lua-coroutine-done) {
- t = gen_id($arg2)
- printf("terminate %d: %s\n", t, $arg3 ? "ok" : "fail")
- #print_ubacktrace()
-}
-
-_EOC_
-
-our $StapScript = <<'_EOC_';
-global ids, cur
-global timers
-global in_req = 0
-global co_status
-global alive_reqs
-
-function gen_id(k) {
- if (ids[k]) return ids[k]
- ids[k] = ++cur
- return cur
-}
-
-F(ngx_http_handler) {
- if (!alive_reqs[$r] && $r == $r->main) {
- in_req++
- alive_reqs[$r] = 1
-
- printf("in req: %d\n", in_req)
-
- if (in_req == 1) {
- delete ids
- cur = 0
- co_status[0] = "running"
- co_status[1] = "suspended"
- co_status[2] = "normal"
- co_status[3] = "dead"
- }
- }
-}
-
-F(ngx_http_free_request) {
- if (alive_reqs[$r]) {
- in_req--
- println("free request")
- delete alive_reqs[$r]
- }
-}
-
-F(ngx_http_terminate_request) {
- if (alive_reqs[$r]) {
- in_req--
- println("terminate request")
- delete alive_reqs[$r]
- }
-}
-
-F(ngx_http_lua_post_thread) {
- id = gen_id($coctx->co)
- printf("post thread %d\n", id)
-}
-
-M(timer-add) {
- timers[$arg1] = $arg2
- printf("add timer %d\n", $arg2)
-}
-
-M(timer-del) {
- printf("delete timer %d\n", timers[$arg1])
- delete timers[$arg1]
-}
-
-M(timer-expire) {
- printf("expire timer %d\n", timers[$arg1])
- delete timers[$arg1]
-}
-
-F(ngx_http_lua_sleep_handler) {
- printf("sleep handler called\n")
-}
-
-F(ngx_http_lua_run_thread) {
- id = gen_id($ctx->cur_co_ctx->co)
- printf("run thread %d\n", id)
- #if (id == 1) {
- #print_ubacktrace()
- #}
-}
-
-probe process("/usr/local/openresty-debug/luajit/lib/libluajit-5.1.so.2").function("lua_resume") {
- id = gen_id($L)
- printf("lua resume %d\n", id)
-}
-
-M(http-lua-user-thread-spawn) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("spawn uthread %x in %x\n", c, p)
-}
-
-M(http-lua-thread-delete) {
- t = gen_id($arg2)
- uthreads = @cast($arg3, "ngx_http_lua_ctx_t")->uthreads
- printf("delete thread %x (uthreads %d)\n", t, uthreads)
- #print_ubacktrace()
-}
-
-M(http-lua-run-posted-thread) {
- t = gen_id($arg2)
- printf("run posted thread %d (status %s)\n", t, co_status[$arg3])
-}
-
-M(http-lua-user-coroutine-resume) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("resume %x in %x\n", c, p)
-}
-
-M(http-lua-thread-yield) {
- t = gen_id($arg2)
- printf("thread %d yield\n", t)
-}
-
-/*
-F(ngx_http_lua_coroutine_yield) {
- printf("yield %x\n", gen_id($L))
-}
-*/
-
-M(http-lua-user-coroutine-yield) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("yield %x in %x\n", c, p)
-}
-
-F(ngx_http_lua_atpanic) {
- printf("lua atpanic(%d):", gen_id($L))
- print_ubacktrace();
-}
-
-F(ngx_http_lua_run_posted_threads) {
- printf("run posted threads\n")
-}
-
-F(ngx_http_finalize_request) {
- printf("finalize request %s: rc:%d c:%d a:%d\n", ngx_http_req_uri($r), $rc, $r->main->count, $r == $r->main);
- #if ($rc == -1) {
- #print_ubacktrace()
- #}
-}
-F(ngx_http_lua_post_subrequest) {
- printf("post subreq: %s rc=%d, status=%d a=%d\n", ngx_http_req_uri($r), $rc,
- $r->headers_out->status, $r == $r->main)
- #print_ubacktrace()
-}
-M(http-subrequest-done) {
- printf("subrequest %s done\n", ngx_http_req_uri($r))
-}
-M(http-subrequest-wake-parent) {
- printf("subrequest wake parent %s\n", ngx_http_req_uri($r->parent))
-}
-M(http-lua-user-coroutine-create) {
- p = gen_id($arg2)
- c = gen_id($arg3)
- printf("create %x in %x\n", c, p)
-}
-
-F(ngx_http_lua_ngx_exec) { println("exec") }
-
-F(ngx_http_lua_ngx_exit) { println("exit") }
-F(ngx_http_lua_ffi_exit) { println("exit") }
-
-F(ngx_http_lua_req_body_cleanup) {
- println("lua req body cleanup")
-}
-
-F(ngx_http_read_client_request_body) {
- println("read client request body")
-}
-
-F(ngx_http_lua_finalize_coroutines) {
- println("finalize coroutines")
-}
-
-F(ngx_http_lua_ngx_exit) {
- println("ngx.exit() called")
-}
-
-F(ngx_http_lua_ffi_exit) {
- println("ngx.exit() called")
-}
-
-F(ngx_http_lua_sleep_resume) {
- println("lua sleep resume")
-}
-
-M(http-lua-coroutine-done) {
- t = gen_id($arg2)
- printf("terminate coro %d: %s, waited by parent:%d, child cocotx: %p\n", t, $arg3 ? "ok" : "fail", $ctx->cur_co_ctx->waited_by_parent, $ctx->cur_co_ctx)
- //print_ubacktrace()
-}
-
-F(ngx_http_lua_ngx_echo) {
- println("ngx.print or ngx.say")
-}
-
-F(ngx_http_lua_del_all_threads) {
- println("del all threads")
-}
-
-/*
-M(http-lua-info) {
- msg = user_string($arg1)
- printf("lua info: %s\n", msg)
-}
-*/
-
-M(http-lua-user-thread-wait) {
- p = gen_id($arg1)
- c = gen_id($arg2)
- printf("lua thread %d waiting on %d, child coctx: %p\n", p, c, $sub_coctx)
-}
-_EOC_
-
-1;
diff --git a/src/deps/src/lua-nginx-module/t/cert/dst-ca.crt b/src/deps/src/lua-nginx-module/t/cert/dst-ca.crt
deleted file mode 100644
index 7b714c60a..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/dst-ca.crt
+++ /dev/null
@@ -1,26 +0,0 @@
-# Comodo AAA Services root
------BEGIN CERTIFICATE-----
-MIIEMjCCAxqgAwIBAgIBATANBgkqhkiG9w0BAQUFADB7MQswCQYDVQQGEwJHQjEb
-MBkGA1UECAwSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHDAdTYWxmb3JkMRow
-GAYDVQQKDBFDb21vZG8gQ0EgTGltaXRlZDEhMB8GA1UEAwwYQUFBIENlcnRpZmlj
-YXRlIFNlcnZpY2VzMB4XDTA0MDEwMTAwMDAwMFoXDTI4MTIzMTIzNTk1OVowezEL
-MAkGA1UEBhMCR0IxGzAZBgNVBAgMEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UE
-BwwHU2FsZm9yZDEaMBgGA1UECgwRQ29tb2RvIENBIExpbWl0ZWQxITAfBgNVBAMM
-GEFBQSBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczCCASIwDQYJKoZIhvcNAQEBBQADggEP
-ADCCAQoCggEBAL5AnfRu4ep2hxxNRUSOvkbIgwadwSr+GB+O5AL686tdUIoWMQua
-BtDFcCLNSS1UY8y2bmhGC1Pqy0wkwLxyTurxFa70VJoSCsN6sjNg4tqJVfMiWPPe
-3M/vg4aijJRPn2jymJBGhCfHdr/jzDUsi14HZGWCwEiwqJH5YZ92IFCokcdmtet4
-YgNW8IoaE+oxox6gmf049vYnMlhvB/VruPsUK6+3qszWY19zjNoFmag4qMsXeDZR
-rOme9Hg6jc8P2ULimAyrL58OAd7vn5lJ8S3frHRNG5i1R8XlKdH5kBjHYpy+g8cm
-ez6KJcfA3Z3mNWgQIJ2P2N7Sw4ScDV7oL8kCAwEAAaOBwDCBvTAdBgNVHQ4EFgQU
-oBEKIz6W8Qfs4q8p74Klf9AwpLQwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQF
-MAMBAf8wewYDVR0fBHQwcjA4oDagNIYyaHR0cDovL2NybC5jb21vZG9jYS5jb20v
-QUFBQ2VydGlmaWNhdGVTZXJ2aWNlcy5jcmwwNqA0oDKGMGh0dHA6Ly9jcmwuY29t
-b2RvLm5ldC9BQUFDZXJ0aWZpY2F0ZVNlcnZpY2VzLmNybDANBgkqhkiG9w0BAQUF
-AAOCAQEACFb8AvCb6P+k+tZ7xkSAzk/ExfYAWMymtrwUSWgEdujm7l3sAg9g1o1Q
-GE8mTgHj5rCl7r+8dFRBv/38ErjHT1r0iWAFf2C3BUrz9vHCv8S5dIa2LX1rzNLz
-Rt0vxuBqw8M0Ayx9lt1awg6nCpnBBYurDC/zXDrPbDdVCYfeU0BsWO/8tqtlbgT2
-G9w84FoVxp7Z8VlIMCFlA2zs6SFz7JsDoeA3raAVGI/6ugLOpyypEBMs1OUIJqsi
-l2D4kF501KKaU73yqWjgom7C12yxow+ev+to51byrvLjKzg6CYG1a4XXvi3tPxq3
-smPi9WIsgtRqAEFQ8TmDn5XpNpaYbg==
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/equifax.crt b/src/deps/src/lua-nginx-module/t/cert/equifax.crt
deleted file mode 100644
index f30065261..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/equifax.crt
+++ /dev/null
@@ -1,19 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJV
-UzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2Vy
-dGlmaWNhdGUgQXV0aG9yaXR5MB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1
-MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0VxdWlmYXgxLTArBgNVBAsTJEVx
-dWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCBnzANBgkqhkiG9w0B
-AQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPRfM6f
-BeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+A
-cJkVV5MW8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kC
-AwEAAaOCAQkwggEFMHAGA1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQ
-MA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlm
-aWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoGA1UdEAQTMBGBDzIwMTgw
-ODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvSspXXR9gj
-IBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQF
-MAMBAf8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUA
-A4GBAFjOKer89961zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y
-7qj/WsjTVbJmcVfewCHrPSqnI0kBBIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh
-1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee9570+sB3c4
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/http3/http3.crt b/src/deps/src/lua-nginx-module/t/cert/http3/http3.crt
deleted file mode 100644
index 8683f41ad..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/http3/http3.crt
+++ /dev/null
@@ -1,29 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIFCTCCAvGgAwIBAgIUHLeNm7JwH368JWXBYJ1Dv+xcL6kwDQYJKoZIhvcNAQEL
-BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIxMTEwNTA2NTQxNVoXDTQxMDEw
-NDA2NTQxNVowFDESMBAGA1UEAwwJbG9jYWxob3N0MIICIjANBgkqhkiG9w0BAQEF
-AAOCAg8AMIICCgKCAgEAx5/M18tKWKfacgldf9gBguTdLA3JWiblRWM/38fSZGKL
-Mcb1vLErY/qQyLYxoLKBht0FUZAEZ08y/iheYFZT7H082b8bNvwY+v6bScOQOvcX
-hkTWNlSQORDH4qIFxVXq0soXga+0ukSZ2RQRcCUWeKUaZwhGCYNIj04/FB9Lef95
-Ku7LkNauTBmRGIwXgQWhfnoPM21o9D9i54R9L2RHU7fGeTGhiS0nCe1nPPB7KBgO
-s9rBHMXV9qHxCNMWWiVNsMX049S7aD9yvRrV7NAHssVQdaRR234IPJxb7BYSUPi8
-5U+8l43Ornd+cY/R/sXDQluFidlnZvHT+akdy0ObWDK0lMUweDWvFVLY3ZvMvsGR
-rQE8RR5/fy83y7w//0734EBk4ttEzlilmjA8UvnumOpK0UYaW8LkikvxB+48e89s
-NOEKZf3Mfw/fDRz0tO+cr4cIgUPQ4ru6KNVnGH/ZiD97AVMPXJO9nPOUIRVH9aXM
-wC74CSt5idWOwpTKy+sLg7anM235NvZ9bTiS+V5CTzBlqL/wKzEI0Injds3kBc1a
-Y8Lk/cIdNhuwlN01fYluA8XyB3DWoeQYbySEoHC5ksvaFLBM3yPomWrmyM5lJrj5
-QbWa46b0bONJQ2qmrQa5KREVvDthHQvKELsabHX1qbCShSxoG45aclqpmKy2AjcC
-AwEAAaNTMFEwHQYDVR0OBBYEFA2T9Sgv31hCl3INL5MB++NrMu0iMB8GA1UdIwQY
-MBaAFA2T9Sgv31hCl3INL5MB++NrMu0iMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZI
-hvcNAQELBQADggIBAJdxtUq4T/sh5Ww7pMOB4+JF5zsxEBpZiFMzT2hYZ+6a2mYh
-UTy7ff1lNfNl0BfslaOD404Qt0SSgI2TByLs838/sKpVk+QePcw6kl6IFIPERUBO
-uxq/+QXqsDHOXb6m4qpEBmrknUa65dThdUw5r4sHo0XD2l/y2/zEZtd4e3ZGAWts
-spdjPBk4UHPtG3p29eY/8ehw+zDXuWG4nlJYjn+6PRnLhvpgt2/E/Wr9PeYcv3IC
-UgavxXVtk9fnclg8BuKlnZYki7txn8+F9Rh03CVVZ9R16Q/aVALI2iTs8T4gCt7Z
-eexfLGfBkLBkLvpL7wpzxNsvOC2b5bJZCDUTprLVmdpmMQu75qLg1mOfubMo983H
-8G91V4XOokRoCRub/SLKA16/gpEwnE2aDsVMUVSxwpRu2Rjw4GpzbCNAHUzmblrh
-zYMSAsEuTcsZEAdZQrzmhGc1Yg5Q88V4o+qyywzkgd86O65QUozhnkCs+eS9ikMV
-cPLXoW5SDIsrrcoTR6bH5MdDjS7ILKUUC5+x0qo6EhK94Fx49TkRBNIYk3o0fG7j
-o/0YvozXjqTRnodYegL4LKoGZyfL4qbuh3t8ZGQ/Z0ECmvjcmJzPyObIiMe2InT3
-GRY+ypPTyeiumjHFFVO0zx+DAv+HFPtq1XaygWvxKY1DTP6FNN0BzQdzAgKm
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/http3/http3.key b/src/deps/src/lua-nginx-module/t/cert/http3/http3.key
deleted file mode 100644
index 5825540f5..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/http3/http3.key
+++ /dev/null
@@ -1,52 +0,0 @@
------BEGIN PRIVATE KEY-----
-MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDHn8zXy0pYp9py
-CV1/2AGC5N0sDclaJuVFYz/fx9JkYosxxvW8sStj+pDItjGgsoGG3QVRkARnTzL+
-KF5gVlPsfTzZvxs2/Bj6/ptJw5A69xeGRNY2VJA5EMfiogXFVerSyheBr7S6RJnZ
-FBFwJRZ4pRpnCEYJg0iPTj8UH0t5/3kq7suQ1q5MGZEYjBeBBaF+eg8zbWj0P2Ln
-hH0vZEdTt8Z5MaGJLScJ7Wc88HsoGA6z2sEcxdX2ofEI0xZaJU2wxfTj1LtoP3K9
-GtXs0AeyxVB1pFHbfgg8nFvsFhJQ+LzlT7yXjc6ud35xj9H+xcNCW4WJ2Wdm8dP5
-qR3LQ5tYMrSUxTB4Na8VUtjdm8y+wZGtATxFHn9/LzfLvD//TvfgQGTi20TOWKWa
-MDxS+e6Y6krRRhpbwuSKS/EH7jx7z2w04Qpl/cx/D98NHPS075yvhwiBQ9Diu7oo
-1WcYf9mIP3sBUw9ck72c85QhFUf1pczALvgJK3mJ1Y7ClMrL6wuDtqczbfk29n1t
-OJL5XkJPMGWov/ArMQjQieN2zeQFzVpjwuT9wh02G7CU3TV9iW4DxfIHcNah5Bhv
-JISgcLmSy9oUsEzfI+iZaubIzmUmuPlBtZrjpvRs40lDaqatBrkpERW8O2EdC8oQ
-uxpsdfWpsJKFLGgbjlpyWqmYrLYCNwIDAQABAoICAENb1qESRbn4matVIamb15a1
-ZzQQStsSuNZbERiPspyQ6+sV+aF8HuoTiHtRjxlsYmyBc+P7tqCthsVgFchoGNV5
-xOispaA+HKfE9d1EEgzzh4qU+7tFeYzn7qq4hT37KcuKybfG9DLOJyOqs9+lhBmd
-jHUrw4Y+OGOywXImxS8bV2V3QlVTO2kOT3l6/AtbPQ0SXsK5rmqMYPFCMYOmULMd
-FembJ6jEBaJB604Sz1vOElf5/qOY1gPszQpvP+GXKMn3YhTmmX4puqu4vGq2H4Lh
-Na8cjUqFEn5xPEtDf1a3N/Ygm8B/5zfTtmTXZMKVNLfVbg//vfZsr1xVBmqqG2Zk
-PUxZ9pyRn25zAYIgIC6DBgmM32S5Zl0axeoWIHdgOTAOwqLLF/ZFozdVSN+skJhl
-q1ndTw+MmVHi19HDUt8YfIICn8g+Dw9NRdX+VjXrRMBweCL41JzHzP6YKo73VJty
-WIVt/LwH2sxdGH0QeP6+Dajel3/ouXAcS31ZpeWZ0QUfa5I0DOn50mvZSuaC0m7Z
-baHBGqawq9EKdjbU5WN6popOCWCx23BZDorKmPGBQ4x54LxfUeet0HAYjsvzUZ0q
-a/AC6pMMHUjG4i5dPhOAhjxkpwfhLjIBTC8VrelGfap50Mlst5InCjClUsSKg43w
-tsRg0HQflxYsPXUGtBqxAoIBAQD29Q6gPNsd7JMzmVzK7fy5YaKq7aI/vOU/tp7U
-LQqhBfsy70U3UNsclsQQ/1RG2cgpFVctlpE8ITpFqSlUDRtlvrK9NaIPEYBV84Xn
-bWPqFjGiRowuXiCR8axbPnsEquO2+VHNuVD/PsCocvbpqtpbfEGmcuyWiO4uFMyW
-beOcRxEsn3U7ABZGDIhxYjpmkiVMu1pRjj+ddqtNMia398K86c3ETRg+zrHnpzio
-kuhxv6TjtnXT1ibI0yKzdQ5sKpa3DYUN/wJgeFVHsSuCZjCzufcMdjCjG3kTTljT
-FrMbweISSTJNs6KsbCqzmc6dmpwuU1ySX07F9sgdJ/7lBCXTAoIBAQDO7wy9Zr8C
-Ridte1EaMP04OSfqc2Jha/U2te47R1VDyHKzpFHvHwWHqFng6J181M9iubUsh/63
-d12uyjZoToMgT7AJ7PMwbEKJbMxpIjqF7Dp1aM11TjRq0mQbZ3wkeuYdK7jYc92j
-X4hF+tJpCYo/0lMA0UFYhMyUPbi33xqlJKLghVncBYmKHluf3k0g73eRg4MGlYHG
-tZ5qVdgwFTztpBb4ySJMOYmjb/OoYPdfoLC8P4ZoHiax4MU30R8b/oGCmYzwOsMC
-dNz9dZgeCFo3+lrzMUnIh3y+YcGo2JJ9ZW1LxGvEIU0aEQ7mSPV8k7m3QiH2MiPQ
-P0t17w1hQP+NAoIBAHJch1pi9CGGZaB2e8cpsGf0s8yt4P3dLthzbFfbR9nLmEk9
-DnOQSPeTRdaNNuzce1mzHTzqRfVvebm6nX3j1/Uk+0atqI+Lzj9/V1oViThk8LUy
-MEZkpnaPUP6sD3HY5TzddilrkPuyhqs7GeaZjSbigtBe1frcDFhgn2FmIApFysk8
-SqB46NelhCXllB/du9ItzKSJ2CHGS4ujFtUIsjCjoPsvrHOhajdZc950sZnDYstk
-umnP+QP06lPqeDRVAJhidWRG3EXqU6uwevKW+iSwkJw/u0Q9O7NaC74s++J1xYgs
-R1Q+RK3OJXQoXMsVRxAY4HyUEDmSj5cY52wMoKsCggEAQMXu9PJOY8XV3Z02G76t
-5IVviyGm79u9G+0Cryd69watcLHEu9a4AmieCZqGgWaTq9F5doDzKDaC6o19TlUV
-Em4fKlwzGzsn8KBPs7D1JKp2+f1eIpPiMHW+xB02bKzTjtn6uDY8cEEdBNqoNhy4
-W5XYSW82xyB6cQSI53U8f+jh2umi4Q4SqVsrTvVkqySKBtBlmQ//WVXMSniofRSI
-x9IPJry+saFpBfGrEU+Y3yQLbkFsLvcRIai70ubwl/CoVVr/FMsv83rlGalPfkcb
-Bl6lTW5mLBDM6ULsPY/c+sde2NKY8QGDgt9IDKlVvjL3dPeMbeXv8+V8F2RGieSw
-mQKCAQEA1n4t4CLKZMWZ4oonBEp8u9rjK23ObCSxANsfoIw94v2zHTFqLraFg9aH
-s+DIc6M/XWX+Ie55v1QuYt8LrMtc9/rtOJdISybAtnheSqjQ+IkTEvBab/8pqhYg
-Jhv/RxmBnCLwiIzRGVpxv9/5bbKXq1JKgdQKO3RBG53lcFFMO1O5srhKqj2KgAHv
-XCQxBmtj83e6gp6hvUOU4YC2aKyL9QqNVndGzPJikEguyvJPUFw6RoB0StVQnzLY
-UOgIH+8VTjzL90nQ/JitVT8uGdw1Ge5xJfCXDe/PEYpDsY65DKPrIMWFeQs6T/Mb
-nvNeBReQOuYYpcCc2GM96RMUz3iyoA==
------END PRIVATE KEY-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_ca.crt b/src/deps/src/lua-nginx-module/t/cert/mtls_ca.crt
deleted file mode 100644
index 1fe7e1f98..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_ca.crt
+++ /dev/null
@@ -1,78 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number:
- 32:ed:21:56:d8:4e:aa:03:89:a9:4a:a4:e2:85:2d:8a:3b:2b:89:22
- Signature Algorithm: sha256WithRSAEncryption
- Issuer: C = US, ST = California, O = OpenResty, CN = OpenResty Testing Root CA
- Validity
- Not Before: Mar 13 15:49:00 2022 GMT
- Not After : Mar 8 15:49:00 2042 GMT
- Subject: C = US, ST = California, O = OpenResty, CN = OpenResty Testing Root CA
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- RSA Public-Key: (2048 bit)
- Modulus:
- 00:e6:37:d2:c6:17:36:c7:b2:7f:7d:cf:d0:62:87:
- 99:d9:21:b8:de:ff:d8:e2:3a:1c:68:90:8f:ce:17:
- 68:22:b0:60:30:cc:29:e8:34:ee:ff:b2:25:de:6e:
- 1a:d4:df:10:19:11:4b:40:61:d3:a9:4d:80:ed:97:
- 81:4e:c5:74:e8:4d:63:e3:5f:21:bc:5a:6e:22:a0:
- 17:91:c1:cb:25:53:9b:9d:4e:e1:51:5b:f6:52:e7:
- 0a:27:f6:16:c2:31:cb:6c:47:f4:89:51:15:cc:06:
- be:31:3e:1c:ea:ee:81:9b:c4:97:96:fd:e5:1c:95:
- 9e:c0:65:cd:a9:9a:cb:68:67:f2:62:a0:21:eb:5a:
- c5:a1:92:ed:32:41:28:f9:47:34:eb:44:ae:d6:e7:
- 76:71:11:98:c9:2e:ce:6c:7c:10:1b:c7:4c:c3:14:
- 89:4e:d9:4c:d9:c7:43:e9:3c:29:ca:62:a9:91:b3:
- 87:e7:d7:b4:18:ab:65:f9:6b:ed:82:ca:a1:36:35:
- 18:05:cb:5c:24:26:13:13:f8:99:ac:99:be:9b:a6:
- 73:df:0d:16:95:b1:dc:be:fe:7a:c2:b6:dc:c8:93:
- cf:10:e0:29:03:0e:28:78:18:84:ee:14:92:ab:be:
- 5a:a0:14:a2:4a:2f:d3:d0:b8:0e:00:d2:5a:cd:e4:
- bd:a1
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Key Usage: critical
- Certificate Sign, CRL Sign
- X509v3 Basic Constraints: critical
- CA:TRUE
- X509v3 Subject Key Identifier:
- F0:D7:4B:14:73:E1:67:00:6B:54:B4:19:20:76:12:9F:9D:8E:C8:09
- Signature Algorithm: sha256WithRSAEncryption
- 6d:52:21:6d:6e:8c:e5:4a:28:07:65:6d:d8:7c:23:2e:c6:c1:
- d0:ec:27:b3:b0:c3:d3:e8:fa:72:b9:de:32:4e:ff:97:8d:86:
- a9:6d:b3:a9:b4:2d:77:ca:28:97:6a:3d:7b:a2:15:ed:34:dc:
- 72:9f:6f:e7:01:0c:d3:28:6a:80:1b:50:09:fd:d7:2c:d8:92:
- d5:10:c4:73:15:20:7d:99:dc:de:30:7b:3c:6e:e9:66:b2:0e:
- 4e:1a:c1:51:57:6e:5b:b0:a9:f6:ff:0b:8f:07:67:31:40:5b:
- 11:a9:06:d3:d3:76:c5:d2:56:95:9a:9e:4a:16:44:4b:32:e5:
- af:dd:4b:4d:5d:57:b8:85:69:36:93:2a:c6:0c:8f:e1:42:35:
- be:8e:f3:e7:35:d3:2c:3a:03:31:40:75:8e:e8:dd:57:35:20:
- 5e:18:a9:76:ce:85:be:7e:3a:cf:6e:08:58:5b:47:d5:e9:c4:
- ec:0e:e9:8e:3c:2d:5c:7b:59:20:5b:24:92:a0:e0:1e:a3:5a:
- 67:d8:ff:7f:a5:82:f1:df:db:05:65:79:88:b1:3c:e6:01:d1:
- 5a:c7:d2:6e:9a:e6:a2:da:4a:c7:19:78:d9:14:71:6e:1f:70:
- f3:41:e5:b3:78:31:d5:22:0e:7c:1a:b2:43:d9:86:ff:53:ea:
- 2b:ba:d2:27
------BEGIN CERTIFICATE-----
-MIIDhDCCAmygAwIBAgIUMu0hVthOqgOJqUqk4oUtijsriSIwDQYJKoZIhvcNAQEL
-BQAwWjELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExEjAQBgNVBAoT
-CU9wZW5SZXN0eTEiMCAGA1UEAxMZT3BlblJlc3R5IFRlc3RpbmcgUm9vdCBDQTAe
-Fw0yMjAzMTMxNTQ5MDBaFw00MjAzMDgxNTQ5MDBaMFoxCzAJBgNVBAYTAlVTMRMw
-EQYDVQQIEwpDYWxpZm9ybmlhMRIwEAYDVQQKEwlPcGVuUmVzdHkxIjAgBgNVBAMT
-GU9wZW5SZXN0eSBUZXN0aW5nIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IB
-DwAwggEKAoIBAQDmN9LGFzbHsn99z9Bih5nZIbje/9jiOhxokI/OF2gisGAwzCno
-NO7/siXebhrU3xAZEUtAYdOpTYDtl4FOxXToTWPjXyG8Wm4ioBeRwcslU5udTuFR
-W/ZS5won9hbCMctsR/SJURXMBr4xPhzq7oGbxJeW/eUclZ7AZc2pmstoZ/JioCHr
-WsWhku0yQSj5RzTrRK7W53ZxEZjJLs5sfBAbx0zDFIlO2UzZx0PpPCnKYqmRs4fn
-17QYq2X5a+2CyqE2NRgFy1wkJhMT+Jmsmb6bpnPfDRaVsdy+/nrCttzIk88Q4CkD
-Dih4GITuFJKrvlqgFKJKL9PQuA4A0lrN5L2hAgMBAAGjQjBAMA4GA1UdDwEB/wQE
-AwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTw10sUc+FnAGtUtBkgdhKf
-nY7ICTANBgkqhkiG9w0BAQsFAAOCAQEAbVIhbW6M5UooB2Vt2HwjLsbB0Owns7DD
-0+j6crneMk7/l42GqW2zqbQtd8ool2o9e6IV7TTccp9v5wEM0yhqgBtQCf3XLNiS
-1RDEcxUgfZnc3jB7PG7pZrIOThrBUVduW7Cp9v8LjwdnMUBbEakG09N2xdJWlZqe
-ShZESzLlr91LTV1XuIVpNpMqxgyP4UI1vo7z5zXTLDoDMUB1jujdVzUgXhipds6F
-vn46z24IWFtH1enE7A7pjjwtXHtZIFskkqDgHqNaZ9j/f6WC8d/bBWV5iLE85gHR
-WsfSbprmotpKxxl42RRxbh9w80Hls3gx1SIOfBqyQ9mG/1PqK7rSJw==
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_ca.key b/src/deps/src/lua-nginx-module/t/cert/mtls_ca.key
deleted file mode 100644
index d39b42f9d..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_ca.key
+++ /dev/null
@@ -1,27 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIEpAIBAAKCAQEA5jfSxhc2x7J/fc/QYoeZ2SG43v/Y4jocaJCPzhdoIrBgMMwp
-6DTu/7Il3m4a1N8QGRFLQGHTqU2A7ZeBTsV06E1j418hvFpuIqAXkcHLJVObnU7h
-UVv2UucKJ/YWwjHLbEf0iVEVzAa+MT4c6u6Bm8SXlv3lHJWewGXNqZrLaGfyYqAh
-61rFoZLtMkEo+Uc060Su1ud2cRGYyS7ObHwQG8dMwxSJTtlM2cdD6TwpymKpkbOH
-59e0GKtl+WvtgsqhNjUYBctcJCYTE/iZrJm+m6Zz3w0WlbHcvv56wrbcyJPPEOAp
-Aw4oeBiE7hSSq75aoBSiSi/T0LgOANJazeS9oQIDAQABAoIBAQDhH9+uNE8uUv/X
-MNvvLfklWpOlBf25o+fZ3NuzRjJgEafOsCee2fyI8FWVwIfeeE8OpFm5GLDZk1+r
-dwdM10xuSheO5Z1gyfF/TJwfvamA09SNrPArFkm3YhUNZNl2hykMtwSLL06oWEOu
-dbXjit4VS9aNIbTlEe7O5/6Ih0W3zmr1yvUua2swmAZMx3GFA4kbjZZ9vDs27sdu
-K+VY3DYRbq1HkiNFT0otfke5bObFBCG7Yp8JLyhYaIkGYFoBXuZ6JNY8EuU2+YyP
-6r40tJ7StR1Q6eZJh9/1leaYGZLCh5oFyKpilTuxHbRbr5A28RJKjKvPsdDgTtQn
-yHGg70FRAoGBAOhC3TQlFcT2WCCZHHql9JEEHnHVBWnL3Jg7VJuL1i6pEIz7qQkW
-AtBEIY/nnTcVNfJ6eXznYtutYvvRSgQTUsBNRoj3s1z9wKOo4uw4LoIUXDEmHCr+
-49DiQyIO21SNMHA+dVxvGRDDjLI9Uc+Scb64QOodoX75HLRZG++24mtdAoGBAP2/
-gCjga2p8Jx9UnhIcrEIIGANyxEQeBdhF56Nt9CJy/Iwi3a6qQ/GkbeoDm5FhXnXo
-xcBaHyv2lwi4uO/hONY8eRnYxAWMwAKMZe6VnU1hWI2Ytkh+OcMPMh7NIGQf6X1o
-JZrBtnTms060TuuDjLeIlaubDR/xDrMWTMKjKbsVAoGAVLuYAZ8J6xpIGlRhbGlA
-6OrMxJCHcgpahvsWKc0BLXKmRBjHmTX7fslsSRihZWgKj1SZH7U2fpgpxV6cFxKJ
-nPhUJEHhoKo+bjZ92tnANdqBq7iQjCsDJ8Bz52fuIlGD+1795+PsDA6bNKdkQkrV
-zlNf80kuEqmFDFJ5+6EHx00CgYAf+jkpbZa71aeMgDpnZ+uhaqm0DYuEVhBAgBa/
-9sRUbw86jc5IC7cCRcmAOzIosQ+ZZls9cV4KSUohVD4iJMzn2rkcM8AIPwOXjp/t
-4DbxoHnrZjpaimW3Gjwju5AAbjEbl7tddFoNA2HHYlurvGlIW9MYzDJsOxGyKfZE
-dRF2PQKBgQDUKNHgDYEjLJ99S5Fm5zN/64bKzzDtktGdqOxik5pBKcs/BvOdLM0i
-eCjGz/3qrEoenFIBwF/IRz3ug90Zr8bWOu6DudReflAKI/N13dZ2gOTAfaX4ljJF
-w0ohSi6xs+mu1GmtipGtNxHi/J3na2BeSnSRFSUg6Zd+oh8BZQKmNg==
------END RSA PRIVATE KEY-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/.gitignore b/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/.gitignore
deleted file mode 100644
index f375caaef..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-*.pem
-*.csr
-cfssl
-cfssljson
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/generate.sh b/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/generate.sh
deleted file mode 100644
index 46625fdd0..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/generate.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-rm *.pem *.csr cfssl cfssljson
-
-wget -O cfssl https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssl_1.6.1_linux_amd64
-wget -O cfssljson https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssljson_1.6.1_linux_amd64
-chmod +x cfssl cfssljson
-
-./cfssl gencert -initca -config profile.json mtls_ca.json | ./cfssljson -bare mtls_ca
-
-./cfssl gencert -ca mtls_ca.pem -ca-key mtls_ca-key.pem -config profile.json -profile=client mtls_client.json | ./cfssljson -bare mtls_client
-./cfssl gencert -ca mtls_ca.pem -ca-key mtls_ca-key.pem -config profile.json -profile=server mtls_server.json | ./cfssljson -bare mtls_server
-
-openssl x509 -in mtls_ca.pem -text > ../mtls_ca.crt
-mv mtls_ca-key.pem ../mtls_ca.key
-
-openssl x509 -in mtls_client.pem -text > ../mtls_client.crt
-mv mtls_client-key.pem ../mtls_client.key
-
-openssl x509 -in mtls_server.pem -text > ../mtls_server.crt
-mv mtls_server-key.pem ../mtls_server.key
-
-rm *.pem *.csr cfssl cfssljson
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/mtls_ca.json b/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/mtls_ca.json
deleted file mode 100644
index 0a4a7ab13..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/mtls_ca.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "CA": {
- "expiry": "175200h",
- "pathlen": 0
- },
- "CN": "OpenResty Testing Root CA",
- "key": {
- "algo": "rsa",
- "size": 2048
- },
- "names": [
- {
- "C": "US",
- "O": "OpenResty",
- "ST": "California"
- }
- ]
-}
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/mtls_client.json b/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/mtls_client.json
deleted file mode 100644
index 4d59f47a5..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/mtls_client.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "CN": "foo@example.com",
- "key": {
- "algo": "rsa",
- "size": 2048
- },
- "names": [
- {
- "C": "US",
- "O": "OpenResty",
- "ST": "California"
- }
- ],
- "hosts": [
- "foo@example.com",
- "bar@example.com"
- ]
-}
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/mtls_server.json b/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/mtls_server.json
deleted file mode 100644
index 655af54ef..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/mtls_server.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "CN": "example.com",
- "key": {
- "algo": "rsa",
- "size": 2048
- },
- "names": [
- {
- "C": "US",
- "O": "OpenResty",
- "ST": "California"
- }
- ],
- "hosts": [
- "example.com"
- ]
-}
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/profile.json b/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/profile.json
deleted file mode 100644
index d3b6ab16c..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_cert_gen/profile.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "signing": {
- "default": {
- "expiry": "175200h"
- },
- "profiles": {
- "server": {
- "usages": [
- "signing",
- "digital signing",
- "key encipherment",
- "server auth"
- ],
- "expiry": "175199h"
- },
- "client": {
- "usages": [
- "signing",
- "digital signature",
- "key encipherment",
- "client auth"
- ],
- "expiry": "175199h"
- }
- }
- }
-}
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_client.crt b/src/deps/src/lua-nginx-module/t/cert/mtls_client.crt
deleted file mode 100644
index dd0efdf7f..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_client.crt
+++ /dev/null
@@ -1,87 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number:
- 19:0a:a3:a8:9c:d4:0f:dc:c6:fa:23:7b:f8:fc:bd:f4:73:4e:7e:b1
- Signature Algorithm: sha256WithRSAEncryption
- Issuer: C = US, ST = California, O = OpenResty, CN = OpenResty Testing Root CA
- Validity
- Not Before: Mar 13 15:49:00 2022 GMT
- Not After : Mar 8 14:49:00 2042 GMT
- Subject: C = US, ST = California, O = OpenResty, CN = foo@example.com
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- RSA Public-Key: (2048 bit)
- Modulus:
- 00:be:5b:09:4c:94:71:d3:82:54:4a:42:6a:76:aa:
- 34:5d:28:d9:45:e6:44:9a:74:9f:a6:e6:78:49:9e:
- c6:20:75:32:5f:92:3b:ec:6e:4b:7b:b0:75:1c:75:
- 09:00:05:77:d6:59:ca:55:5b:13:b6:76:3a:c6:18:
- dc:37:6a:20:93:e6:26:56:5d:0b:96:8c:01:f2:96:
- 38:08:08:36:a2:64:12:21:a0:8d:48:cd:9a:26:78:
- 92:29:b6:63:eb:14:d9:b6:e5:87:f7:d5:55:a4:cc:
- 53:1c:a3:7c:b8:bd:ad:7c:a4:d4:86:1f:a7:1c:43:
- c5:1a:b5:f1:03:bd:fe:19:98:1d:b7:13:2b:93:a2:
- 2a:0e:21:7e:42:a9:bb:28:69:49:59:e7:89:0e:7d:
- 5a:ce:fb:d4:0c:20:6a:e1:db:b2:6a:e5:a7:55:e0:
- d0:58:4a:e2:08:78:82:b9:06:0c:65:f9:24:06:e6:
- 8a:13:b2:9a:ef:1b:4a:b2:3a:b4:98:7f:dd:3c:0e:
- 85:0b:a6:c6:47:2f:63:c2:73:52:41:db:7c:06:c3:
- 2a:b5:2d:d1:e1:30:d5:c4:79:c9:b9:35:68:46:ad:
- c4:45:57:ea:11:88:27:37:ed:ac:49:2d:c4:d6:c6:
- a6:74:8d:d3:bc:e0:d9:69:25:0c:0c:b0:e3:b7:cb:
- 8d:99
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Key Usage: critical
- Digital Signature, Key Encipherment
- X509v3 Extended Key Usage:
- TLS Web Client Authentication
- X509v3 Basic Constraints: critical
- CA:FALSE
- X509v3 Subject Key Identifier:
- 22:70:5E:30:8C:4D:66:39:E7:60:C9:29:A2:ED:95:32:34:63:5C:C0
- X509v3 Authority Key Identifier:
- keyid:F0:D7:4B:14:73:E1:67:00:6B:54:B4:19:20:76:12:9F:9D:8E:C8:09
-
- X509v3 Subject Alternative Name:
- email:foo@example.com, email:bar@example.com
- Signature Algorithm: sha256WithRSAEncryption
- 96:e7:2a:fc:2a:56:16:80:e2:d3:79:0c:46:db:c3:88:ab:d3:
- ef:39:66:4b:a9:ab:6c:0e:30:08:07:7c:fc:03:6c:f7:dd:fb:
- 3e:a8:c8:68:28:ab:4e:73:97:80:27:5d:c5:9d:52:00:aa:08:
- 25:c8:f9:dc:df:64:73:a4:58:5b:bd:5f:1a:53:a4:33:a3:b1:
- 45:38:2d:be:d7:f3:a4:c4:f4:7a:07:71:44:f1:a2:65:02:e4:
- 71:84:01:b5:83:4b:de:83:b5:ad:ac:b9:3c:17:42:0c:9a:7d:
- eb:7f:ab:26:dd:9b:3a:fd:95:37:55:cc:01:c3:3f:20:df:e5:
- ed:49:51:7a:42:ea:f3:8a:3f:da:6e:c1:1a:11:b9:45:4d:6e:
- c9:21:f4:e3:4f:31:72:5b:bb:01:92:b6:7f:f1:8a:9e:6c:d0:
- 7f:96:d7:eb:29:09:53:38:26:41:00:f2:33:04:77:bd:a9:ee:
- 60:9e:06:b7:7d:26:ae:1c:4f:56:bd:a5:b6:50:40:be:be:84:
- 2a:54:21:59:47:7d:a5:1e:63:6d:28:36:4d:a6:e4:62:69:9b:
- 9b:fa:2b:48:e8:64:d7:14:f4:62:a2:26:17:a5:05:58:4a:38:
- d2:44:e7:33:90:b9:c1:8c:85:02:99:b8:03:1a:03:d2:cf:ac:
- a5:6b:44:98
------BEGIN CERTIFICATE-----
-MIID3DCCAsSgAwIBAgIUGQqjqJzUD9zG+iN7+Py99HNOfrEwDQYJKoZIhvcNAQEL
-BQAwWjELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExEjAQBgNVBAoT
-CU9wZW5SZXN0eTEiMCAGA1UEAxMZT3BlblJlc3R5IFRlc3RpbmcgUm9vdCBDQTAe
-Fw0yMjAzMTMxNTQ5MDBaFw00MjAzMDgxNDQ5MDBaMFAxCzAJBgNVBAYTAlVTMRMw
-EQYDVQQIEwpDYWxpZm9ybmlhMRIwEAYDVQQKEwlPcGVuUmVzdHkxGDAWBgNVBAMM
-D2Zvb0BleGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
-AL5bCUyUcdOCVEpCanaqNF0o2UXmRJp0n6bmeEmexiB1Ml+SO+xuS3uwdRx1CQAF
-d9ZZylVbE7Z2OsYY3DdqIJPmJlZdC5aMAfKWOAgINqJkEiGgjUjNmiZ4kim2Y+sU
-2bblh/fVVaTMUxyjfLi9rXyk1IYfpxxDxRq18QO9/hmYHbcTK5OiKg4hfkKpuyhp
-SVnniQ59Ws771AwgauHbsmrlp1Xg0FhK4gh4grkGDGX5JAbmihOymu8bSrI6tJh/
-3TwOhQumxkcvY8JzUkHbfAbDKrUt0eEw1cR5ybk1aEatxEVX6hGIJzftrEktxNbG
-pnSN07zg2WklDAyw47fLjZkCAwEAAaOBozCBoDAOBgNVHQ8BAf8EBAMCBaAwEwYD
-VR0lBAwwCgYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUInBeMIxN
-ZjnnYMkpou2VMjRjXMAwHwYDVR0jBBgwFoAU8NdLFHPhZwBrVLQZIHYSn52OyAkw
-KwYDVR0RBCQwIoEPZm9vQGV4YW1wbGUuY29tgQ9iYXJAZXhhbXBsZS5jb20wDQYJ
-KoZIhvcNAQELBQADggEBAJbnKvwqVhaA4tN5DEbbw4ir0+85Zkupq2wOMAgHfPwD
-bPfd+z6oyGgoq05zl4AnXcWdUgCqCCXI+dzfZHOkWFu9XxpTpDOjsUU4Lb7X86TE
-9HoHcUTxomUC5HGEAbWDS96Dta2suTwXQgyafet/qybdmzr9lTdVzAHDPyDf5e1J
-UXpC6vOKP9puwRoRuUVNbskh9ONPMXJbuwGStn/xip5s0H+W1+spCVM4JkEA8jME
-d72p7mCeBrd9Jq4cT1a9pbZQQL6+hCpUIVlHfaUeY20oNk2m5GJpm5v6K0joZNcU
-9GKiJhelBVhKONJE5zOQucGMhQKZuAMaA9LPrKVrRJg=
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_client.key b/src/deps/src/lua-nginx-module/t/cert/mtls_client.key
deleted file mode 100644
index 7d77e5506..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_client.key
+++ /dev/null
@@ -1,27 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIEogIBAAKCAQEAvlsJTJRx04JUSkJqdqo0XSjZReZEmnSfpuZ4SZ7GIHUyX5I7
-7G5Le7B1HHUJAAV31lnKVVsTtnY6xhjcN2ogk+YmVl0LlowB8pY4CAg2omQSIaCN
-SM2aJniSKbZj6xTZtuWH99VVpMxTHKN8uL2tfKTUhh+nHEPFGrXxA73+GZgdtxMr
-k6IqDiF+Qqm7KGlJWeeJDn1azvvUDCBq4duyauWnVeDQWEriCHiCuQYMZfkkBuaK
-E7Ka7xtKsjq0mH/dPA6FC6bGRy9jwnNSQdt8BsMqtS3R4TDVxHnJuTVoRq3ERVfq
-EYgnN+2sSS3E1samdI3TvODZaSUMDLDjt8uNmQIDAQABAoIBACqRsUKu78WdH7x7
-ndNrvMoYmH5JQI5KBmoMoFnWZ/haPSmiSkRVZgwDKi1y/tBCaMpGyjjMZVwolHw4
-kwbRdPeeQHSP2keQh974OQ+SxqUKPAPJI89kK1TvIcCySSYJQ6bjLcT+sGhqSSve
-Y8XspR96vQxBh92KSknu5jcwBeMy/eG0mmszzP3y2R0BPztuZdE6dq/KxWQ/R4/P
-JG9V1rNkIY+1JZvIICIH1Ehn4UKjiE+FJmyDbDlPKEi7W4CpRnShMLOF4cCFnQLW
-RQds3Dj9GcVY+8Q/GLZF0ATjekIyEsKZEgrMAUF5ZSGRpjJQEHX7oseAiQGQxtHT
-nj5b1AECgYEAwewXbbd1MqRQ6ohfsQ8j5HSMY6ahvUzs1dZUckr2jw8B98tfi/uj
-a6Jq1KZe12+4dfwruRSaYdTsSVuvNiSJOxElY0C1p+lXdprFf7XfoQ6UNtg22jcH
-9f8cftnlJoV5whh3YKjqnnnAWUQZ61FTNJ258/t+x0ZgpBJvqBoHwDUCgYEA+0qp
-FZ5xS4FLJMc+Xf/hUeXo+04e4OD/se3atYqyuh1ghmQZfRRPOC110HG99H+rzq/x
-xPMvRFahkAMyi+/3oIcBEuXvoQyqscIsAhkWD/e9t3Qc9OsWe1hlAgWKZxr6oR2U
-KKR1FD7UVecOH+FKCKaL5UpEt4yEigc1NtSlTFUCgYBnV5agrIyzQSex5J0CMWxS
-Od362PkGdXEc/8we4F4GnNvSnrm7Uo2jNXmy+zo9mtb1YT43sogXLK4C5e44bz4G
-kTuYagqkgdBPb2lihpy3KprHo2+P2JXQfXRFEX9xiN37Fqi/hSUK8R0VNRqO8dbi
-ik9nexXzwkiMBxsjvUN2JQKBgFy62FpZ9YTfWVNhEuqtGgCWzrqtwUdKwBBwrVyA
-qiNz48Kz/ZPigrlATVF2J5qp4kSLOLRs6OxW65exFl39V2utZgALSbosanDeLk83
-4qRRz3h7KJRYjBtIKz3rvX7+va3mtF2rEmk+Jizs7pFlGWTH0Kf0GBeDiwVEU6bA
-IZ9hAoGAQTjnRGMjvyhq0aPYP+mRFiMKSkcL1nyXizYInfAnbfbL/uEODH7D+iMf
-kak+UgmeD9ce5d/APmZp3/FzYH/M8ivBgG+MnaI+MLVMhmQdLZyMtbSKKaDpiim7
-DdN1wCXYbur0HlO2t+wemMZPpQu7wybgEOLlIG7Yj/0OWDcal1c=
------END RSA PRIVATE KEY-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_server.crt b/src/deps/src/lua-nginx-module/t/cert/mtls_server.crt
deleted file mode 100644
index 7cbc2a804..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_server.crt
+++ /dev/null
@@ -1,87 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number:
- 2f:d5:41:13:5a:ff:c7:1c:5b:ce:28:cd:a6:f7:a5:5a:0d:c0:e2:d2
- Signature Algorithm: sha256WithRSAEncryption
- Issuer: C = US, ST = California, O = OpenResty, CN = OpenResty Testing Root CA
- Validity
- Not Before: Mar 13 15:49:00 2022 GMT
- Not After : Mar 8 14:49:00 2042 GMT
- Subject: C = US, ST = California, O = OpenResty, CN = example.com
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- RSA Public-Key: (2048 bit)
- Modulus:
- 00:d7:03:80:a7:42:7d:06:5a:7b:70:d8:11:96:dd:
- 63:35:53:07:28:71:52:05:40:55:83:61:a7:14:ac:
- cf:4b:9b:ab:b7:4e:9d:79:e9:13:3d:bc:c3:67:8f:
- dd:88:d9:8b:c2:31:aa:b8:28:9e:13:70:db:76:b0:
- 12:1c:f8:35:c6:2e:33:9c:b9:04:e3:47:e0:f9:e4:
- 7f:a5:55:03:0c:2d:b2:54:17:29:12:dd:61:6e:5c:
- 33:9f:e5:8f:8a:2b:41:53:dc:e1:98:49:63:df:e3:
- 00:30:2d:1b:bb:f0:8f:cb:04:ec:c9:98:c4:09:5b:
- b4:ba:a9:a0:0a:77:d2:42:76:7c:ac:64:c3:97:85:
- 50:5d:7d:02:61:2a:00:93:d0:69:5e:87:22:f0:c1:
- 1e:53:46:02:40:37:c9:55:77:99:7d:9d:3d:35:14:
- 74:84:e3:73:ca:e7:4a:ab:33:98:26:aa:41:4b:b5:
- e6:63:7c:a4:1e:25:6a:88:f4:56:d9:2c:63:dd:89:
- 19:fa:25:41:44:95:87:40:a7:9b:4e:3a:91:29:32:
- 79:66:05:f4:2f:68:2c:06:53:df:4d:60:be:ac:09:
- 20:61:9c:6f:1a:a6:07:5a:e7:41:91:9d:36:77:38:
- 18:3a:69:7b:67:29:9f:1d:e0:c2:d2:8f:16:5b:14:
- e8:e1
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Key Usage: critical
- Digital Signature, Key Encipherment
- X509v3 Extended Key Usage:
- TLS Web Server Authentication
- X509v3 Basic Constraints: critical
- CA:FALSE
- X509v3 Subject Key Identifier:
- 16:07:B5:C2:4C:B5:2D:4F:B8:E9:D6:FA:2F:3F:C0:1B:B6:4F:20:E6
- X509v3 Authority Key Identifier:
- keyid:F0:D7:4B:14:73:E1:67:00:6B:54:B4:19:20:76:12:9F:9D:8E:C8:09
-
- X509v3 Subject Alternative Name:
- DNS:example.com
- Signature Algorithm: sha256WithRSAEncryption
- d9:c0:c0:d6:8b:44:04:26:b3:98:24:2c:12:82:6d:15:79:92:
- 76:c9:77:94:c1:be:8f:8a:18:78:96:04:68:c9:0a:d1:84:c5:
- de:cd:ba:b5:a2:3b:d4:0a:70:be:00:49:19:c0:6e:ca:e9:e5:
- 8b:b6:e3:a2:39:0d:d8:ee:55:1a:08:73:39:19:d3:07:07:33:
- 8c:d8:1b:0f:1b:73:0e:84:72:cf:e6:c1:a1:da:39:aa:c0:2e:
- 3d:b9:a6:8f:ec:98:3a:07:58:34:c2:5e:4c:1a:6b:db:ce:51:
- 92:25:1d:ba:78:4b:11:b6:f1:69:02:cb:ac:32:bb:80:f9:15:
- 91:bf:4e:6a:ab:51:51:7c:7b:1a:72:80:96:eb:0c:fa:56:0e:
- f2:87:3c:16:8a:04:aa:8a:9d:0c:d9:e0:c4:2a:20:42:5a:12:
- 41:52:30:50:3d:85:f8:07:31:6b:af:a4:d2:44:38:69:ab:88:
- 05:d4:5b:68:34:02:dc:99:5a:6c:b7:ea:fc:79:76:fe:68:29:
- df:94:22:58:46:f2:40:cb:e1:92:17:d8:1e:3d:fa:a2:56:4f:
- ac:3c:3d:ae:f7:90:12:ac:3b:6c:1e:1f:26:48:08:87:9a:0e:
- 8d:9d:75:ef:86:1e:63:ac:e9:14:47:ad:3f:4f:10:57:2a:d1:
- 95:ec:6f:24
------BEGIN CERTIFICATE-----
-MIIDwzCCAqugAwIBAgIUL9VBE1r/xxxbzijNpvelWg3A4tIwDQYJKoZIhvcNAQEL
-BQAwWjELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExEjAQBgNVBAoT
-CU9wZW5SZXN0eTEiMCAGA1UEAxMZT3BlblJlc3R5IFRlc3RpbmcgUm9vdCBDQTAe
-Fw0yMjAzMTMxNTQ5MDBaFw00MjAzMDgxNDQ5MDBaMEwxCzAJBgNVBAYTAlVTMRMw
-EQYDVQQIEwpDYWxpZm9ybmlhMRIwEAYDVQQKEwlPcGVuUmVzdHkxFDASBgNVBAMT
-C2V4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1wOA
-p0J9Blp7cNgRlt1jNVMHKHFSBUBVg2GnFKzPS5urt06deekTPbzDZ4/diNmLwjGq
-uCieE3DbdrASHPg1xi4znLkE40fg+eR/pVUDDC2yVBcpEt1hblwzn+WPiitBU9zh
-mElj3+MAMC0bu/CPywTsyZjECVu0uqmgCnfSQnZ8rGTDl4VQXX0CYSoAk9BpXoci
-8MEeU0YCQDfJVXeZfZ09NRR0hONzyudKqzOYJqpBS7XmY3ykHiVqiPRW2Sxj3YkZ
-+iVBRJWHQKebTjqRKTJ5ZgX0L2gsBlPfTWC+rAkgYZxvGqYHWudBkZ02dzgYOml7
-ZymfHeDC0o8WWxTo4QIDAQABo4GOMIGLMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE
-DDAKBggrBgEFBQcDATAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBQWB7XCTLUtT7jp
-1vovP8Abtk8g5jAfBgNVHSMEGDAWgBTw10sUc+FnAGtUtBkgdhKfnY7ICTAWBgNV
-HREEDzANggtleGFtcGxlLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEA2cDA1otEBCaz
-mCQsEoJtFXmSdsl3lMG+j4oYeJYEaMkK0YTF3s26taI71ApwvgBJGcBuyunli7bj
-ojkN2O5VGghzORnTBwczjNgbDxtzDoRyz+bBodo5qsAuPbmmj+yYOgdYNMJeTBpr
-285RkiUdunhLEbbxaQLLrDK7gPkVkb9OaqtRUXx7GnKAlusM+lYO8oc8FooEqoqd
-DNngxCogQloSQVIwUD2F+Acxa6+k0kQ4aauIBdRbaDQC3JlabLfq/Hl2/mgp35Qi
-WEbyQMvhkhfYHj36olZPrDw9rveQEqw7bB4fJkgIh5oOjZ1174YeY6zpFEetP08Q
-VyrRlexvJA==
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/mtls_server.key b/src/deps/src/lua-nginx-module/t/cert/mtls_server.key
deleted file mode 100644
index f5b85d18d..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/mtls_server.key
+++ /dev/null
@@ -1,27 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIEowIBAAKCAQEA1wOAp0J9Blp7cNgRlt1jNVMHKHFSBUBVg2GnFKzPS5urt06d
-eekTPbzDZ4/diNmLwjGquCieE3DbdrASHPg1xi4znLkE40fg+eR/pVUDDC2yVBcp
-Et1hblwzn+WPiitBU9zhmElj3+MAMC0bu/CPywTsyZjECVu0uqmgCnfSQnZ8rGTD
-l4VQXX0CYSoAk9BpXoci8MEeU0YCQDfJVXeZfZ09NRR0hONzyudKqzOYJqpBS7Xm
-Y3ykHiVqiPRW2Sxj3YkZ+iVBRJWHQKebTjqRKTJ5ZgX0L2gsBlPfTWC+rAkgYZxv
-GqYHWudBkZ02dzgYOml7ZymfHeDC0o8WWxTo4QIDAQABAoIBAEnmZUiXnJsbbEPr
-r5f3vYptYA9xa2xsoTeHz8JWZuUouwtE1PE6v6c/grXMh6rqgpObOH8VTseFyZhw
-ibk1Ql48MPcTzG9FnDinZYvwvRxpdFpcn3xhZIRm4kN5xi0KEuj9CPireM1RmxXz
-2w1scC+qIKxlejNxNpvVgzE136mBqEFKJzecP+yZuH/A86MQCgwqqa3jSz5ApNg+
-1aJE34cGFieDbAN+9sdqWA3OkRrHoy8EakUf4JEvwX1AwUN832mj+N/LfmcCGMeD
-YhzybzlPBV2q2T1+pHIdNT99JVNPkgdTe1903EjnG5oSDGHt2i9MdnNkMsffDWNt
-pJiqSHECgYEA2hL6l8Py4oa5AJ2WXriuHRJykAs90K0akftQt4i4lWCbeRhaGh7h
-kPgpDS33RkE4SymVVr0c05abMCKabQBwbu4PNCqetCFtfmIQdQCTUbLbXjL8UuD2
-QnF7nbHiwyGBKRMU/F74oX3z7lXLgRtIiyyo5yYgIAQqpz3oJAaXNTUCgYEA/GhE
-Ziez8FXVAg3XwwrE3SexRFKv1JqipYE4mr+ouzfpn9yn8mttxbOORiAAEBl3ZPhd
-ZUBzLy19fdFZ8RJ0zPsqoZxsd09/XetaBU56C/g9u0fycj1L2elh9rQAlOW0Grus
-l8jBh01TGtlg0xobK0zjwdGPcbYkp1IzIqyD9n0CgYEAicBvVyrJ5FnhxwfEkrTq
-FycuAtt3Arg2DnzH8geFQaayzv2Y/OMA7Yg0tkSQ7GoKW0A7O31eFjIOeYuCLNSY
-MRpjtDov4e0zsx/S8XWZmYP3mjtutBOyuyngQi655TTm18FcAkcjmy9qxOShFj7b
-xj5BuzGUHWVEZDxwxUD8hvkCgYBnrcyqyZQ4HImqllUSYNIMpclC71QaWIqGwVWm
-+yMsBAOLDvBNu6MTmnXOiEZ+VnecmgiDFr45ms35aI0xYQtpR6JzT/Wd7KG8ynfn
-xhyL3iQ9UYhdNKB7mkoLNFUo1FHuyThUALq+AR0p4jDLheWzG5pSeuoZI2Ba+oDW
-tVZfYQKBgC5phtERR5LKU5Wkzm+uY2j+Nzh4kuKkdLosB9pUW8VnrwFDLZ+r1CxG
-L6CxOZ0AylCMIlrFeUXMa91kLDJYch0NUPHuGBkdIBDXi2kqN7GflTdV3Z8uev20
-uMjErA93yVOWHTR3Wo8WIHy5mdsNRQgGAPw1RVW7rnYIyXJW/mTs
------END RSA PRIVATE KEY-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/test.crl b/src/deps/src/lua-nginx-module/t/cert/test.crl
deleted file mode 100644
index 0abfa77ac..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/test.crl
+++ /dev/null
@@ -1,14 +0,0 @@
------BEGIN X509 CRL-----
-MIICGzCCAQMCAQEwDQYJKoZIhvcNAQELBQAwgZcxCzAJBgNVBAYTAlVTMRMwEQYD
-VQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNpc2NvMRIwEAYDVQQK
-DAlPcGVuUmVzdHkxEjAQBgNVBAsMCU9wZW5SZXN0eTERMA8GA1UEAwwIdGVzdC5j
-b20xIDAeBgkqhkiG9w0BCQEWEWFnZW50emhAZ21haWwuY29tFw0yMzEwMDYwNjM4
-MzlaFw0zMTEyMjMwNjM4MzlaMCcwJQIUImcuJ8MJpeNhvYBEoEGGz5oCBg4XDTIz
-MTAwNjA2MjkyNVqgDjAMMAoGA1UdFAQDAgEEMA0GCSqGSIb3DQEBCwUAA4IBAQBj
-FciorrAuXxn1ULW0XJ7PElwTxZtBrb838EHYvkZ5OdT5tZcucYR6XTZpfT1Up/Px
-rC9EZ1/aZ0wSQfYEQuctafyVCJoPN71IV9IWpPTWm8JyEvnE1W3SgHJujItanyZ3
-aMDihljxV9eKyEQnZPQZkaOjAKhj8d2/XZLQ3uIrjWy+/OxcaBQK4a8bDoSM3GZT
-J6YCD2UBVYKSiROMZZAj3m1thLAGm1RM7A6vjEcH7rPyoxhok5SdxXH5ERY94/ro
-McjNCv6zV8/Ue5/+ajz5pu/48T901mlIicHry8uImJvlnqAXlH8ReJ+hiSfGhbZ5
-WYNf0wN81NXwTxPIb+v2
------END X509 CRL-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/test.crt b/src/deps/src/lua-nginx-module/t/cert/test.crt
deleted file mode 100644
index 9fed1bc3b..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/test.crt
+++ /dev/null
@@ -1,22 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDtzCCAp8CFCJnLifDCaXjYb2ARKBBhs+aAgYOMA0GCSqGSIb3DQEBCwUAMIGX
-MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2Fu
-IEZyYW5jaXNjbzESMBAGA1UECgwJT3BlblJlc3R5MRIwEAYDVQQLDAlPcGVuUmVz
-dHkxETAPBgNVBAMMCHRlc3QuY29tMSAwHgYJKoZIhvcNAQkBFhFhZ2VudHpoQGdt
-YWlsLmNvbTAeFw0yMzA5MDUwNDE5MjhaFw0zMzA5MDIwNDE5MjhaMIGXMQswCQYD
-VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5j
-aXNjbzESMBAGA1UECgwJT3BlblJlc3R5MRIwEAYDVQQLDAlPcGVuUmVzdHkxETAP
-BgNVBAMMCHRlc3QuY29tMSAwHgYJKoZIhvcNAQkBFhFhZ2VudHpoQGdtYWlsLmNv
-bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJzRMFoLDuYOwJ8szrS4
-nOibtiimiXZJGx3I/RcFZxaH4nL/WcEb1fwftMQxx73IBJnqnDYkDOzUmzItPMn0
-t2WrNYesC5GqLNRm87m6PVt010tZvq/WxTn6+9qruiGm1PhFxzLQfrClpEeOshlG
-UeoQjPOMrhCmofDM2NQo3D4wIQT0kCJxIPq6wCZt22/Yqz1EmR0UnF/R3ZtiB8O+
-SQGcsUKy4se3919xq+ZkzBdMxLneO5sofUiDC9MgRfiU960tbHPGX9I9P+kLK89S
-yajPEYaRUkSBFjV5kdDK3+L6XckdMbY2pvwhAnVXSmd13Bf2V9XisUrX2Mr4YlnS
-sy0CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAVPY/z6Mvjg5EGHzU8bXyuXqxrx8Q
-GBwf3PY25aDF6ofRrTCzMdIhthv8eRtGwHinkpgaK34D7hI/dPB7aswQTzED5c+l
-S2au5OzzCj454oXdhSRA5Rt0mu/+pxmQ+iNk+7XJxgTN0mk1dYQqodyZ+vC4NIYb
-javMlU4zDm4JPtwDs0Mz/d7gf14MU60jppF2vl6AYFHKYBLMHBmqxjy6H9YHjRjQ
-oe4TNpn0zxJAPu5LqMkfB2+eLOe6ced7DcLLbbeVJ4Xtqj6Y5KsAyVojWQxrk4vW
-3WO/953pHofO5F2ricS/rsf+5ivTmfiP8mQYTtp7k3T11sIZ4DOmtNwO4A==
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/test.key b/src/deps/src/lua-nginx-module/t/cert/test.key
deleted file mode 100644
index 4c8c905b2..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/test.key
+++ /dev/null
@@ -1,28 +0,0 @@
------BEGIN PRIVATE KEY-----
-MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCc0TBaCw7mDsCf
-LM60uJzom7Yopol2SRsdyP0XBWcWh+Jy/1nBG9X8H7TEMce9yASZ6pw2JAzs1Jsy
-LTzJ9LdlqzWHrAuRqizUZvO5uj1bdNdLWb6v1sU5+vvaq7ohptT4Rccy0H6wpaRH
-jrIZRlHqEIzzjK4QpqHwzNjUKNw+MCEE9JAicSD6usAmbdtv2Ks9RJkdFJxf0d2b
-YgfDvkkBnLFCsuLHt/dfcavmZMwXTMS53jubKH1IgwvTIEX4lPetLWxzxl/SPT/p
-CyvPUsmozxGGkVJEgRY1eZHQyt/i+l3JHTG2Nqb8IQJ1V0pnddwX9lfV4rFK19jK
-+GJZ0rMtAgMBAAECggEABjaOkcllis1o/yrVZMPPabLpAHV6tZ5MuKfNiUOMSPr+
-HfF1OFQL7MxCdfyFQ1prqOp/9nAut+puMgp99wAfDQ7qanNGq7vgQKkfPSD+dy4V
-rUquELBJH6nh9SZqfpSqKaJgHlNe6vehHuRYikJRkrJwVzegGjuekm3B+y6Zl/gc
-e0p5Ha3MTLTFjocwYzgTjJlxD40wlbjpuVnmzKjo8AKNv1F1azMaqBmt1VfPiDn0
-Xyq4SPEsWKnEAl2kZdaIBR6zIx7Z3zNUwkfb32QwNoSyo8wS7lCgf2GVS7r1Eul6
-iiCE/Gd7w10alW4Pu96shVqkvKn7ROF2nBP9xOSPwQKBgQDCuD6mlNpA07iOX364
-aAzIAYookceVA0I9L/fbOQW7RgpvYpM8lxr31TQ3fBDkXSgjzMMYjnk4kz+xN+BB
-WFdjb4raUBtrvip8Q8QZ53DVQK/LodHh0XhipbOxZrDm+6o5nQD0fTqHCBIHSVFF
-tXX2Y90t1cxWMMleRhfNEuzkQQKBgQDOK0rs7mf04Xhc4ZIRIxOtNFnthGp4Kqp7
-SD8VQpbPOLV8iqZEtXIy/hvoTpfQW30c1931KgDQ3Pv5MZYpI7PLqrqkj4tGCQ91
-DJ03GWkSXcMwlPmJRbvgWIeCLgShU5PLxmQu3mH2DP+uGFUBq5/6miDDVjF9z6vb
-BwYlG66j7QKBgA0n/bOrowN2SqXz9c/n19U7pWYQU3fR/Iu9zfVV6Pk6RkI4WtJh
-M0VDdn+5Njr3wFqK3zOtjKsx57/FkrVXjq/9PVh6yR+CfcRfn8RQSuNdt4L+r/ud
-95BSuc1mrtUsc9for8PVIjs1ZGJxpbgcBphbLvqF04SPT0u7WKhWewMBAoGAcJO/
-RAUiitsbaExcADORKQDvIf0uThOuJ8dZevhzdQ/YOftTsy0JAMM05fMUfteWR8uw
-DZE0BNjGVlo3TpuKL+o4JGele0azRAzxRAcCEt9UGBEg+U40utpclD8glB8ZEypv
-xg/0mfCbJKtwr4rRvnuu7DsCp1pg0ybQui6VfDkCgYBXHwcrZwmv7kgr4pUG6oZj
-fzjFenQFqibvb2h7QESyCW13O885GxU13DKv4zg1yi6EqPIopz16qCiUNCvWr5Us
-6sI74wEVI3MzmzG0Htgl29q5yWpeY+7libC/fbZYG8GFgdINq58ko9be1u/8644S
-t2hoKM9/vrVFh9p9qGzckg==
------END PRIVATE KEY-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/test2.crt b/src/deps/src/lua-nginx-module/t/cert/test2.crt
deleted file mode 100644
index edc3b0df3..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/test2.crt
+++ /dev/null
@@ -1,16 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIChzCCAfACCQDjCkJpJUtZmjANBgkqhkiG9w0BAQUFADCBhjELMAkGA1UEBhMC
-VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28x
-EjAQBgNVBAoMCU9wZW5SZXN0eTESMBAGA1UEAwwJdGVzdDIuY29tMSIwIAYJKoZI
-hvcNAQkBFhNvcGVucmVzdHlAZ21haWwuY29tMCAXDTE0MDkxMzAwMTgxMFoYDzIx
-MTQwODIwMDAxODEwWjCBhjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3Ju
-aWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xEjAQBgNVBAoMCU9wZW5SZXN0eTES
-MBAGA1UEAwwJdGVzdDIuY29tMSIwIAYJKoZIhvcNAQkBFhNvcGVucmVzdHlAZ21h
-aWwuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDy+OVI2u5NBOeB2Cyz
-Gnwy9b7Ao4CSi05XtUxh2IoVdzYZz6c4PFb9C1ad52LDdRStiQT5A7+RKLj6Kr7f
-JrKFziJxMy4g4Kdn9G659vE7CWu/UAVjRUtc+mTBAEfjdbumizmHLG7DmnNhGl3R
-NGiVNLsUInSMGfUlJRzZJXhI4QIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAEMmRvyN
-N7uE24Tc6TR19JadNHK8g3YGktRoXWiqd/y0HY4NRPgvnK/nX7CY/wXa1j+uDO8K
-e6/Ldm5RZrjtvfHJmTSAu8zkqTJz8bqRDH7kzL5Ni2Ky2x8r9dtB0ImpOiSlwvZN
-snMvbrxEdwBiqlC9prV2f9aG+ACo1KnPL0j6
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/test2.key b/src/deps/src/lua-nginx-module/t/cert/test2.key
deleted file mode 100644
index 82ce6ce91..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/test2.key
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQDy+OVI2u5NBOeB2CyzGnwy9b7Ao4CSi05XtUxh2IoVdzYZz6c4
-PFb9C1ad52LDdRStiQT5A7+RKLj6Kr7fJrKFziJxMy4g4Kdn9G659vE7CWu/UAVj
-RUtc+mTBAEfjdbumizmHLG7DmnNhGl3RNGiVNLsUInSMGfUlJRzZJXhI4QIDAQAB
-AoGAEqBB83PVENJvbOTFiHVfUAjGtr3R/Wnwd4jOcjHHZB3fZ9sjVoxJntxfp3s1
-dwZir2rxlqVS6i3VAFiGiVTOGo2Vvzhw2J7f58twCECmnLb2f863AkGEYe4dAndD
-GHGD0WI0CBMD1sT18YCj561o0Wol5deWH0gM9pr2N3HkeIECQQD6hUKFlFhrpaHP
-WNJsl6BxgE6pB5kxLcMcpIQ7P+kHUvtyvCJl5QZJqPrpPGjRsAI5Ph92rpsp/zDp
-/IZNWGVjAkEA+Ele31Rt+XbV32MrLKZgBDBk+Pzss5LTn9fZ5v1k/7hrMk2VVWvk
-AD6n5QiGe/g59woANpPb1T9l956SBf0d6wJABTXOS17pc9uvANP1FGMW6CVl/Wf2
-DKrJ+weE5IKQwyE7r4gwIvRfbBrClSU3fNzvPueG2f4JphbzmnoxBNzIxwJAYivY
-mGNwzHehXx99/byXMHDWK+EN0n8WsBgP75Z3rekEcbJdfpYXY8Via1vwmOnwOW65
-4NqbzHix37PSNw37GwJBALxaGNpREO2Tk+oWOvsD2QyviMVae3mXAJHc6nLVdKDM
-q0YvDT6VdeNYYFTkAuzJacsVXOpn6AnUMFj0OBedMhc=
------END RSA PRIVATE KEY-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/test_der.crt b/src/deps/src/lua-nginx-module/t/cert/test_der.crt
deleted file mode 100644
index 273b98638..000000000
Binary files a/src/deps/src/lua-nginx-module/t/cert/test_der.crt and /dev/null differ
diff --git a/src/deps/src/lua-nginx-module/t/cert/test_der.key b/src/deps/src/lua-nginx-module/t/cert/test_der.key
deleted file mode 100644
index 14e9fa582..000000000
Binary files a/src/deps/src/lua-nginx-module/t/cert/test_der.key and /dev/null differ
diff --git a/src/deps/src/lua-nginx-module/t/cert/test_ecdsa.crt b/src/deps/src/lua-nginx-module/t/cert/test_ecdsa.crt
deleted file mode 100644
index b3e1e9fbc..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/test_ecdsa.crt
+++ /dev/null
@@ -1,12 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIBtDCCAVoCCQD0QJnL8zpA0jAKBggqhkjOPQQDAjBhMQswCQYDVQQGEwJVUzET
-MBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzESMBAG
-A1UECgwJT3BlblJlc3R5MREwDwYDVQQDDAh0ZXN0LmNvbTAgFw0xNTA3MTcyMTUx
-NDFaGA8yMTE1MDYyMzIxNTE0MVowYTELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNh
-bGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xEjAQBgNVBAoMCU9wZW5S
-ZXN0eTERMA8GA1UEAwwIdGVzdC5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC
-AAT/OtGmlIlbtvvJ3OP0dm5lyEMCrMnpDTDjwBPnUZ2f+16LCmNsdtEJ0r0Sd4GM
-o4Lss2JpwzPy2SLGEj3KwGKSMAoGCCqGSM49BAMCA0gAMEUCIQDbNwDkq1FiqcRD
-XdbP1MPAc33N2IK9EDIfMgJ0nTL82wIgNZiL4xvCQe9UA0zC+JqHLnVCQHYAM9kI
-BbvzNrt0hEM=
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/test_ecdsa.key b/src/deps/src/lua-nginx-module/t/cert/test_ecdsa.key
deleted file mode 100644
index 46eb72c5e..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/test_ecdsa.key
+++ /dev/null
@@ -1,5 +0,0 @@
------BEGIN PRIVATE KEY-----
-MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg0vwBPGgv1hE6RnQo
-3imyoceR+5dLsKegodOlBwnWtbuhRANCAAT/OtGmlIlbtvvJ3OP0dm5lyEMCrMnp
-DTDjwBPnUZ2f+16LCmNsdtEJ0r0Sd4GMo4Lss2JpwzPy2SLGEj3KwGKS
------END PRIVATE KEY-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/test_passphrase.crt b/src/deps/src/lua-nginx-module/t/cert/test_passphrase.crt
deleted file mode 100644
index f4d516ba9..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/test_passphrase.crt
+++ /dev/null
@@ -1,17 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICozCCAgwCCQDEutRdSs3vZjANBgkqhkiG9w0BAQUFADCBlDELMAkGA1UEBhMC
-Q04xEjAQBgNVBAgMCUd1YW5nZG9uZzERMA8GA1UEBwwIU2hlblpoZW4xEjAQBgNV
-BAoMCU9wZW5SZXN0eTESMBAGA1UECwwJT3BlblJlc3R5MREwDwYDVQQDDAh0ZXN0
-LmNvbTEjMCEGCSqGSIb3DQEJARYUZ3VhbmdsaW5sdkBnbWFpbC5jb20wIBcNMTYw
-NDI4MTQ0MzI4WhgPMjE1MTAzMjcxNDQzMjhaMIGUMQswCQYDVQQGEwJDTjESMBAG
-A1UECAwJR3Vhbmdkb25nMREwDwYDVQQHDAhTaGVuWmhlbjESMBAGA1UECgwJT3Bl
-blJlc3R5MRIwEAYDVQQLDAlPcGVuUmVzdHkxETAPBgNVBAMMCHRlc3QuY29tMSMw
-IQYJKoZIhvcNAQkBFhRndWFuZ2xpbmx2QGdtYWlsLmNvbTCBnzANBgkqhkiG9w0B
-AQEFAAOBjQAwgYkCgYEA2KZ+HdH9R2tarxD8PKqu5EYq2BNGlFRg1xJmrw0XZBRM
-UP/VPb+sIeioooz36uhiXfQjExlpBCA/0zNAN+HbFyqpPPTf1qLGrj/dqeE4MJaN
-Bwzxiv3fZnENT65u2qbiFWIY+ATNHgA20d50nxNNjPTzLbkx/nYXL92r4kuAGk0C
-AwEAATANBgkqhkiG9w0BAQUFAAOBgQCfMo0qbcs3kwl1tcNBO5hCcUUJRzyv041V
-ff/nZ/JPIMo/LSZd12K82G/dLRN7uRT9nzqtm+JRkHALHWWWFKi6bdg1vcdOTWqC
-08bCkJHQoXJQQLvvA6gNvnR+0b7L4CrCmrcyYgKDLXVGNP9Wv/PqSWWbxsmqngkA
-Mvy6CVytFw==
------END CERTIFICATE-----
diff --git a/src/deps/src/lua-nginx-module/t/cert/test_passphrase.key b/src/deps/src/lua-nginx-module/t/cert/test_passphrase.key
deleted file mode 100644
index b8fc97634..000000000
--- a/src/deps/src/lua-nginx-module/t/cert/test_passphrase.key
+++ /dev/null
@@ -1,18 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-Proc-Type: 4,ENCRYPTED
-DEK-Info: DES-EDE3-CBC,679ACC8E69ACAA92
-
-Ssrjp3VU4somCNPiXkWqcudDnvnwbyj/Q0pS07at3lXKbhQSgI1Tzhg9Pm3BXXj5
-mkLdeGG5ocrj1Q9dhtmZgZeHHQIiynZBhjBu1Y+HPef8jXOWLrCOi8EKiWkJ2qG3
-V1KFM/95CcDt0mRLykUXEL3IpUst05SFb9XwiLokB7ypeu3NhgNUHjL6G+ubB4ri
-TOUjCW4pEoNHjdC22IiqSncwCVhluYSGhr6ktHKehZMhYIXmL1wmSLdhTlsPXCQl
-xvYILQ2vJcKIR1BkeYYPD/OQC6zCZlXIErzfgeZiz2+NTudKYpb9VmsQKsO+R8L7
-tZ/fNaR0vk8bbimMHgStAV4acVsC/7WxsqOjMJ8VTq1iqhYPl6N7kRdR3H3kSSOm
-cN9T3SrOHDVaHbnWgToaOE4mKFjvFSLIOcWgus0iOHWXmY+SLG+Ndag3oVB6R9oB
-cAHX19mq99+GhzA8IV4I0En2UCKQhnGPvkM+9mcCDxhRETlwncDjlMGOHpQ65J9r
-eReVPIpnDkvHxPGTtsR3ZHTdWTZb+C0W2N3QIlJKrOzxFmfoj++yG3tMX42aDY0g
-DVkrXgcKobiWN0AVrJNAwfG7uObKSCFYgz/0RRMCO4cjXRW99nxdjVDZhyc6R0Te
-jzuF04okkOLNb25n2hP+yIULrn+6Nv/uHtFI0j0n3hOzcKh//dNbACSAKgkHni9g
-JKDFJXgLJxf+Wc3So0DF9gYMKJJ+WbcdVT9gkC7RyQHlC90Pn7kNXzHr0ZawUsNI
-ZxSkL4dMhYAfA4lUBJbOkwbSurv97LinOSRffpM0Nmf7VNw/Ue15eg==
------END RSA PRIVATE KEY-----
diff --git a/src/deps/src/lua-nginx-module/t/data/fake-delayed-load-module/config b/src/deps/src/lua-nginx-module/t/data/fake-delayed-load-module/config
deleted file mode 100644
index a5fa6fb48..000000000
--- a/src/deps/src/lua-nginx-module/t/data/fake-delayed-load-module/config
+++ /dev/null
@@ -1,3 +0,0 @@
-ngx_addon_name="ngx_http_lua_fake_delayed_load_module"
-HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_lua_fake_delayed_load_module"
-NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_lua_fake_delayed_load_module.c"
diff --git a/src/deps/src/lua-nginx-module/t/data/fake-delayed-load-module/ngx_http_lua_fake_delayed_load_module.c b/src/deps/src/lua-nginx-module/t/data/fake-delayed-load-module/ngx_http_lua_fake_delayed_load_module.c
deleted file mode 100644
index 2898255c2..000000000
--- a/src/deps/src/lua-nginx-module/t/data/fake-delayed-load-module/ngx_http_lua_fake_delayed_load_module.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * This fake_delayed_load delayed load module was used to reproduce
- * a bug in ngx_lua's function ngx_http_lua_add_package_preload.
- */
-
-
-#include
-#include
-#include
-#include
-
-
-#include "ngx_http_lua_api.h"
-
-
-static ngx_int_t ngx_http_lua_fake_delayed_load_init(ngx_conf_t *cf);
-static int ngx_http_lua_fake_delayed_load_preload(lua_State *L);
-static int ngx_http_lua_fake_delayed_load_function(lua_State * L);
-
-
-static ngx_http_module_t ngx_http_lua_fake_delayed_load_module_ctx = {
- NULL, /* preconfiguration */
- ngx_http_lua_fake_delayed_load_init, /* postconfiguration */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- NULL, /* create server configuration */
- NULL, /* merge server configuration */
-
- NULL, /* create location configuration */
- NULL, /* merge location configuration */
-};
-
-/* flow identify module struct */
-ngx_module_t ngx_http_lua_fake_delayed_load_module = {
- NGX_MODULE_V1,
- &ngx_http_lua_fake_delayed_load_module_ctx, /* module context */
- NULL, /* module directives */
- NGX_HTTP_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static ngx_int_t
-ngx_http_lua_fake_delayed_load_init(ngx_conf_t *cf)
-{
- ngx_http_lua_add_package_preload(cf, "ngx.delayed_load",
- ngx_http_lua_fake_delayed_load_preload);
- return NGX_OK;
-}
-
-
-static int
-ngx_http_lua_fake_delayed_load_preload(lua_State *L)
-{
- lua_createtable(L, 0, 1);
-
- lua_pushcfunction(L, ngx_http_lua_fake_delayed_load_function);
- lua_setfield(L, -2, "get_function");
-
- return 1;
-}
-
-
-static int
-ngx_http_lua_fake_delayed_load_function(lua_State * L)
-{
- return 0;
-}
diff --git a/src/deps/src/lua-nginx-module/t/data/fake-module/config b/src/deps/src/lua-nginx-module/t/data/fake-module/config
deleted file mode 100644
index 00cc8e865..000000000
--- a/src/deps/src/lua-nginx-module/t/data/fake-module/config
+++ /dev/null
@@ -1,3 +0,0 @@
-ngx_addon_name=ngx_http_fake_module
-HTTP_MODULES="$HTTP_MODULES ngx_http_fake_module"
-NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fake_module.c"
diff --git a/src/deps/src/lua-nginx-module/t/data/fake-module/ngx_http_fake_module.c b/src/deps/src/lua-nginx-module/t/data/fake-module/ngx_http_fake_module.c
deleted file mode 100644
index 650f4f7cc..000000000
--- a/src/deps/src/lua-nginx-module/t/data/fake-module/ngx_http_fake_module.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * This fake module was used to reproduce a bug in ngx_lua's
- * init_worker_by_lua implementation.
- */
-
-
-#include
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_int_t a;
-} ngx_http_fake_srv_conf_t;
-
-
-typedef struct {
- ngx_int_t a;
-} ngx_http_fake_loc_conf_t;
-
-
-static void *ngx_http_fake_create_srv_conf(ngx_conf_t *cf);
-static char *ngx_http_fake_merge_srv_conf(ngx_conf_t *cf, void *prev, void *conf);
-static void *ngx_http_fake_create_loc_conf(ngx_conf_t *cf);
-static char *ngx_http_fake_merge_loc_conf(ngx_conf_t *cf, void *prev, void *conf);
-
-
-/* flow identify module configure struct */
-static ngx_http_module_t ngx_http_fake_module_ctx = {
- NULL, /* preconfiguration */
- NULL, /* postconfiguration */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_http_fake_create_srv_conf, /* create server configuration */
- ngx_http_fake_merge_srv_conf, /* merge server configuration */
-
- ngx_http_fake_create_loc_conf, /* create location configuration */
- ngx_http_fake_merge_loc_conf /* merge location configuration */
-};
-
-/* flow identify module struct */
-ngx_module_t ngx_http_fake_module = {
- NGX_MODULE_V1,
- &ngx_http_fake_module_ctx, /* module context */
- NULL, /* module directives */
- NGX_HTTP_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-/* create server configure */
-static void *ngx_http_fake_create_srv_conf(ngx_conf_t *cf)
-{
- ngx_http_fake_srv_conf_t *fscf;
-
- fscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fake_srv_conf_t));
- if (fscf == NULL) {
- return NULL;
- }
-
- return fscf;
-}
-
-
-/* merge server configure */
-static char *ngx_http_fake_merge_srv_conf(ngx_conf_t *cf, void *prev, void *conf)
-{
- ngx_http_fake_srv_conf_t *fscf;
-
- fscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_fake_module);
- if (fscf == NULL) {
- ngx_conf_log_error(NGX_LOG_ALERT, cf, 0,
- "get module srv conf failed in merge srv conf");
- return NGX_CONF_ERROR;
- }
-
- return NGX_CONF_OK;
-}
-
-
-/* create location configure */
-static void *ngx_http_fake_create_loc_conf(ngx_conf_t *cf)
-{
- ngx_http_fake_loc_conf_t *flcf;
-
- flcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fake_loc_conf_t));
- if (flcf == NULL) {
- return NULL;
- }
-
- return flcf;
-}
-
-
-/* merge location configure */
-static char *ngx_http_fake_merge_loc_conf(ngx_conf_t *cf, void *prev, void *conf)
-{
- ngx_http_fake_loc_conf_t *flcf;
-
- flcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_fake_module);
- if (flcf == NULL) {
- ngx_conf_log_error(NGX_LOG_ALERT, cf, 0,
- "get module loc conf failed in merge loc conf");
- return NGX_CONF_ERROR;
- }
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/lua-nginx-module/t/data/fake-shm-module/config b/src/deps/src/lua-nginx-module/t/data/fake-shm-module/config
deleted file mode 100644
index 027452941..000000000
--- a/src/deps/src/lua-nginx-module/t/data/fake-shm-module/config
+++ /dev/null
@@ -1,3 +0,0 @@
-ngx_addon_name=ngx_http_lua_shm_fake_module
-HTTP_MODULES="$HTTP_MODULES ngx_http_lua_fake_shm_module"
-NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_lua_fake_shm_module.c"
diff --git a/src/deps/src/lua-nginx-module/t/data/fake-shm-module/ngx_http_lua_fake_shm_module.c b/src/deps/src/lua-nginx-module/t/data/fake-shm-module/ngx_http_lua_fake_shm_module.c
deleted file mode 100644
index ffc32f579..000000000
--- a/src/deps/src/lua-nginx-module/t/data/fake-shm-module/ngx_http_lua_fake_shm_module.c
+++ /dev/null
@@ -1,298 +0,0 @@
-#include
-#include
-#include
-#include
-
-
-#include
-#include
-#include
-
-
-#include "ngx_http_lua_api.h"
-
-
-static void *ngx_http_lua_fake_shm_create_main_conf(ngx_conf_t *cf);
-static ngx_int_t ngx_http_lua_fake_shm_init(ngx_conf_t *cf);
-
-static char *ngx_http_lua_fake_shm(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static ngx_int_t ngx_http_lua_fake_shm_init_zone(ngx_shm_zone_t *shm_zone,
- void *data);
-static int ngx_http_lua_fake_shm_preload(lua_State *L);
-static int ngx_http_lua_fake_shm_get_info(lua_State *L);
-
-
-typedef struct {
- ngx_array_t *shm_zones;
-} ngx_http_lua_fake_shm_main_conf_t;
-
-
-static ngx_command_t ngx_http_lua_fake_shm_cmds[] = {
-
- { ngx_string("lua_fake_shm"),
- NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2,
- ngx_http_lua_fake_shm,
- 0,
- 0,
- NULL },
-
- ngx_null_command
-};
-
-
-static ngx_http_module_t ngx_http_lua_fake_shm_module_ctx = {
- NULL, /* preconfiguration */
- ngx_http_lua_fake_shm_init, /* postconfiguration */
-
- ngx_http_lua_fake_shm_create_main_conf, /* create main configuration */
- NULL, /* init main configuration */
-
- NULL, /* create server configuration */
- NULL, /* merge server configuration */
-
- NULL, /* create location configuration */
- NULL, /* merge location configuration */
-};
-
-
-ngx_module_t ngx_http_lua_fake_shm_module = {
- NGX_MODULE_V1,
- &ngx_http_lua_fake_shm_module_ctx, /* module context */
- ngx_http_lua_fake_shm_cmds, /* module directives */
- NGX_HTTP_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-typedef struct {
- ngx_str_t name;
- size_t size;
- ngx_int_t isold;
- ngx_int_t isinit;
-} ngx_http_lua_fake_shm_ctx_t;
-
-
-static void *
-ngx_http_lua_fake_shm_create_main_conf(ngx_conf_t *cf)
-{
- ngx_http_lua_fake_shm_main_conf_t *lfsmcf;
-
- lfsmcf = ngx_pcalloc(cf->pool, sizeof(*lfsmcf));
- if (lfsmcf == NULL) {
- return NULL;
- }
-
- return lfsmcf;
-}
-
-
-static char *
-ngx_http_lua_fake_shm(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_http_lua_fake_shm_main_conf_t *lfsmcf = conf;
-
- ngx_str_t *value, name;
- ngx_shm_zone_t *zone;
- ngx_shm_zone_t **zp;
- ngx_http_lua_fake_shm_ctx_t *ctx;
- ssize_t size;
-
- if (lfsmcf->shm_zones == NULL) {
- lfsmcf->shm_zones = ngx_palloc(cf->pool, sizeof(ngx_array_t));
- if (lfsmcf->shm_zones == NULL) {
- return NGX_CONF_ERROR;
- }
-
- if (ngx_array_init(lfsmcf->shm_zones, cf->pool, 2,
- sizeof(ngx_shm_zone_t *))
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
- }
-
- value = cf->args->elts;
-
- ctx = NULL;
-
- if (value[1].len == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid lua fake_shm name \"%V\"", &value[1]);
- return NGX_CONF_ERROR;
- }
-
- name = value[1];
-
- size = ngx_parse_size(&value[2]);
-
- if (size <= 8191) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid lua fake_shm size \"%V\"", &value[2]);
- return NGX_CONF_ERROR;
- }
-
- ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_lua_fake_shm_ctx_t));
- if (ctx == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ctx->name = name;
- ctx->size = size;
-
- zone = ngx_http_lua_shared_memory_add(cf, &name, (size_t) size,
- &ngx_http_lua_fake_shm_module);
- if (zone == NULL) {
- return NGX_CONF_ERROR;
- }
-
- if (zone->data) {
- ctx = zone->data;
-
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "lua_fake_shm \"%V\" is already defined as "
- "\"%V\"", &name, &ctx->name);
- return NGX_CONF_ERROR;
- }
-
- zone->init = ngx_http_lua_fake_shm_init_zone;
- zone->data = ctx;
-
- zp = ngx_array_push(lfsmcf->shm_zones);
- if (zp == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *zp = zone;
-
- return NGX_CONF_OK;
-}
-
-
-static ngx_int_t
-ngx_http_lua_fake_shm_init_zone(ngx_shm_zone_t *shm_zone, void *data)
-{
- ngx_http_lua_fake_shm_ctx_t *octx = data;
-
- ngx_http_lua_fake_shm_ctx_t *ctx;
-
- ctx = shm_zone->data;
-
- if (octx) {
- ctx->isold = 1;
- }
-
- ctx->isinit = 1;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_lua_fake_shm_init(ngx_conf_t *cf)
-{
- ngx_http_lua_add_package_preload(cf, "fake_shm_zones",
- ngx_http_lua_fake_shm_preload);
- return NGX_OK;
-}
-
-
-static int
-ngx_http_lua_fake_shm_preload(lua_State *L)
-{
- ngx_http_lua_fake_shm_main_conf_t *lfsmcf;
- ngx_http_conf_ctx_t *hmcf_ctx;
- ngx_cycle_t *cycle;
-
- ngx_uint_t i;
- ngx_shm_zone_t **zone;
- ngx_shm_zone_t **zone_udata;
-
- cycle = (ngx_cycle_t *) ngx_cycle;
-
- hmcf_ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
- lfsmcf = hmcf_ctx->main_conf[ngx_http_lua_fake_shm_module.ctx_index];
-
- if (lfsmcf->shm_zones != NULL) {
- lua_createtable(L, 0, lfsmcf->shm_zones->nelts /* nrec */);
-
- lua_createtable(L, 0 /* narr */, 2 /* nrec */); /* shared mt */
-
- lua_pushcfunction(L, ngx_http_lua_fake_shm_get_info);
- lua_setfield(L, -2, "get_info");
-
- lua_pushvalue(L, -1); /* shared mt mt */
- lua_setfield(L, -2, "__index"); /* shared mt */
-
- zone = lfsmcf->shm_zones->elts;
-
- for (i = 0; i < lfsmcf->shm_zones->nelts; i++) {
- lua_pushlstring(L, (char *) zone[i]->shm.name.data,
- zone[i]->shm.name.len);
-
- /* shared mt key */
-
- lua_createtable(L, 1 /* narr */, 0 /* nrec */);
- /* table of zone[i] */
- zone_udata = lua_newuserdata(L, sizeof(ngx_shm_zone_t *));
- /* shared mt key ud */
- *zone_udata = zone[i];
- lua_rawseti(L, -2, 1); /* {zone[i]} */
- lua_pushvalue(L, -3); /* shared mt key ud mt */
- lua_setmetatable(L, -2); /* shared mt key ud */
- lua_rawset(L, -4); /* shared mt */
- }
-
- lua_pop(L, 1); /* shared */
-
- } else {
- lua_newtable(L); /* ngx.shared */
- }
-
- return 1;
-}
-
-
-static int
-ngx_http_lua_fake_shm_get_info(lua_State *L)
-{
- ngx_int_t n;
- ngx_shm_zone_t *zone;
- ngx_shm_zone_t **zone_udata;
- ngx_http_lua_fake_shm_ctx_t *ctx;
-
- n = lua_gettop(L);
-
- if (n != 1) {
- return luaL_error(L, "expecting exactly one arguments, "
- "but only seen %d", n);
- }
-
- luaL_checktype(L, 1, LUA_TTABLE);
-
- lua_rawgeti(L, 1, 1);
- zone_udata = lua_touserdata(L, -1);
- lua_pop(L, 1);
-
- if (zone_udata == NULL) {
- return luaL_error(L, "bad \"zone\" argument");
- }
-
- zone = *zone_udata;
-
- ctx = (ngx_http_lua_fake_shm_ctx_t *) zone->data;
-
- lua_pushlstring(L, (char *) zone->shm.name.data, zone->shm.name.len);
- lua_pushnumber(L, zone->shm.size);
- lua_pushboolean(L, ctx->isinit);
- lua_pushboolean(L, ctx->isold);
-
- return 4;
-}
diff --git a/src/deps/src/lua-nginx-module/t/lib/CRC32.lua b/src/deps/src/lua-nginx-module/t/lib/CRC32.lua
deleted file mode 100644
index 8ca0d5634..000000000
--- a/src/deps/src/lua-nginx-module/t/lib/CRC32.lua
+++ /dev/null
@@ -1,173 +0,0 @@
---Copyright (c) 2007-2008 Neil Richardson (nrich@iinet.net.au)
---
---Permission is hereby granted, free of charge, to any person obtaining a copy
---of this software and associated documentation files (the "Software"), to deal
---in the Software without restriction, including without limitation the rights
---to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
---copies of the Software, and to permit persons to whom the Software is
---furnished to do so, subject to the following conditions:
---
---The above copyright notice and this permission notice shall be included in all
---copies or substantial portions of the Software.
---
---THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
---IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
---FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
---AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
---LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
---OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
---IN THE SOFTWARE.
-
-module('CRC32', package.seeall)
-
-local max = 2^32 -1
-
-local CRC32 = {
- 0,79764919,159529838,222504665,319059676,
- 398814059,445009330,507990021,638119352,
- 583659535,797628118,726387553,890018660,
- 835552979,1015980042,944750013,1276238704,
- 1221641927,1167319070,1095957929,1595256236,
- 1540665371,1452775106,1381403509,1780037320,
- 1859660671,1671105958,1733955601,2031960084,
- 2111593891,1889500026,1952343757,2552477408,
- 2632100695,2443283854,2506133561,2334638140,
- 2414271883,2191915858,2254759653,3190512472,
- 3135915759,3081330742,3009969537,2905550212,
- 2850959411,2762807018,2691435357,3560074640,
- 3505614887,3719321342,3648080713,3342211916,
- 3287746299,3467911202,3396681109,4063920168,
- 4143685023,4223187782,4286162673,3779000052,
- 3858754371,3904687514,3967668269,881225847,
- 809987520,1023691545,969234094,662832811,
- 591600412,771767749,717299826,311336399,
- 374308984,453813921,533576470,25881363,
- 88864420,134795389,214552010,2023205639,
- 2086057648,1897238633,1976864222,1804852699,
- 1867694188,1645340341,1724971778,1587496639,
- 1516133128,1461550545,1406951526,1302016099,
- 1230646740,1142491917,1087903418,2896545431,
- 2825181984,2770861561,2716262478,3215044683,
- 3143675388,3055782693,3001194130,2326604591,
- 2389456536,2200899649,2280525302,2578013683,
- 2640855108,2418763421,2498394922,3769900519,
- 3832873040,3912640137,3992402750,4088425275,
- 4151408268,4197601365,4277358050,3334271071,
- 3263032808,3476998961,3422541446,3585640067,
- 3514407732,3694837229,3640369242,1762451694,
- 1842216281,1619975040,1682949687,2047383090,
- 2127137669,1938468188,2001449195,1325665622,
- 1271206113,1183200824,1111960463,1543535498,
- 1489069629,1434599652,1363369299,622672798,
- 568075817,748617968,677256519,907627842,
- 853037301,1067152940,995781531,51762726,
- 131386257,177728840,240578815,269590778,
- 349224269,429104020,491947555,4046411278,
- 4126034873,4172115296,4234965207,3794477266,
- 3874110821,3953728444,4016571915,3609705398,
- 3555108353,3735388376,3664026991,3290680682,
- 3236090077,3449943556,3378572211,3174993278,
- 3120533705,3032266256,2961025959,2923101090,
- 2868635157,2813903052,2742672763,2604032198,
- 2683796849,2461293480,2524268063,2284983834,
- 2364738477,2175806836,2238787779,1569362073,
- 1498123566,1409854455,1355396672,1317987909,
- 1246755826,1192025387,1137557660,2072149281,
- 2135122070,1912620623,1992383480,1753615357,
- 1816598090,1627664531,1707420964,295390185,
- 358241886,404320391,483945776,43990325,
- 106832002,186451547,266083308,932423249,
- 861060070,1041341759,986742920,613929101,
- 542559546,756411363,701822548,3316196985,
- 3244833742,3425377559,3370778784,3601682597,
- 3530312978,3744426955,3689838204,3819031489,
- 3881883254,3928223919,4007849240,4037393693,
- 4100235434,4180117107,4259748804,2310601993,
- 2373574846,2151335527,2231098320,2596047829,
- 2659030626,2470359227,2550115596,2947551409,
- 2876312838,2788305887,2733848168,3165939309,
- 3094707162,3040238851,2985771188,
-}
-
-local function xor(a, b)
- local calc = 0
-
- for i = 32, 0, -1 do
- local val = 2 ^ i
- local aa = false
- local bb = false
-
- if a == 0 then
- calc = calc + b
- break
- end
-
- if b == 0 then
- calc = calc + a
- break
- end
-
- if a >= val then
- aa = true
- a = a - val
- end
-
- if b >= val then
- bb = true
- b = b - val
- end
-
- if not (aa and bb) and (aa or bb) then
- calc = calc + val
- end
- end
-
- return calc
-end
-
-local function lshift(num, left)
- local res = num * (2 ^ left)
- return res % (2 ^ 32)
-end
-
-local function rshift(num, right)
- local res = num / (2 ^ right)
- return math.floor(res)
-end
-
-function Hash(str)
- local count = string.len(tostring(str))
- local crc = max
-
- local i = 1
- while count > 0 do
- local byte = string.byte(str, i)
-
- crc = xor(lshift(crc, 8), CRC32[xor(rshift(crc, 24), byte) + 1])
-
- i = i + 1
- count = count - 1
- end
-
- return crc
-end
-
-
---
--- CRC32.lua
---
--- A pure Lua implementation of a CRC32 hashing algorithm. Slower than using a C implementation,
--- but useful having no other dependencies.
---
---
--- Synopsis
---
--- require('CRC32')
---
--- crchash = CRC32.Hash('a string')
---
--- Methods:
---
--- hashval = CRC32.Hash(val)
--- Calculates and returns (as an integer) the CRC32 hash of the parameter 'val'.
-
diff --git a/src/deps/src/lua-nginx-module/t/lib/Memcached.lua b/src/deps/src/lua-nginx-module/t/lib/Memcached.lua
deleted file mode 100644
index 1f8c7f957..000000000
--- a/src/deps/src/lua-nginx-module/t/lib/Memcached.lua
+++ /dev/null
@@ -1,567 +0,0 @@
---Copyright (c) 2006-2008 Neil Richardson (nrich@iinet.net.au)
---
---Permission is hereby granted, free of charge, to any person obtaining a copy
---of this software and associated documentation files (the "Software"), to deal
---in the Software without restriction, including without limitation the rights
---to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
---copies of the Software, and to permit persons to whom the Software is
---furnished to do so, subject to the following conditions:
---
---The above copyright notice and this permission notice shall be included in all
---copies or substantial portions of the Software.
---
---THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
---IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
---FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
---AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
---LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
---OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
---IN THE SOFTWARE.
-
-module('Memcached', package.seeall)
-
-require('socket')
-require('CRC32')
-
-local SERVER_RETRIES = 10
-
-local STATS_KEYS = {
- malloc = true,
- sizes = true,
- slabs = true,
- items = true,
-}
-
-local FLAGS = {
- 'STORABLE',
- 'COMPRESSED',
- 'SERIALISED',
-}
-
-local function warn(str)
- io.stderr:write(string.format('Warning: %s\n', tostring(str)))
-end
-
-local function _select_server(cache, key)
- local server_count = #cache.servers
-
- local hashfunc = cache.hash or CRC32.Hash
-
- if server_count == 1 then
- return cache.servers[1].socket
- else
- local serverhash = hashfunc(key)
-
- for i = 0, SERVER_RETRIES do
- local index = (serverhash % server_count) + 1
- local server = cache.servers[index].socket
-
- if not server then
- serverhash = hashfunc(serverhash .. i)
- else
- return server
- end
- end
- end
-
- error('No servers found')
- return nil
-end
-
-local function _retrieve(cache, key, str)
- local server = _select_server(cache, key)
-
- server:send(str .. '\r\n')
-
- local function toboolean(value)
- if type(value) == 'string' then
- if value == 'true' then
- return true
- elseif value == 'false' then
- return false
- end
- end
-
- return nil
- end
-
- local function extract_flags(str)
- local num = tonumber(str)
- local flags = {}
-
- for i = table.maxn(FLAGS), 1, -1 do
- local bf = 2 ^ (i - 1)
-
- if num >= bf then
- flags[FLAGS[i]] = true
- num = num - bf
- end
- end
-
- return flags
- end
-
- local returndata = {}
- while true do
- local line, err = server:receive()
-
- if line == 'END' then
- break
- elseif string.sub(line, 1, 5) == 'VALUE' then
- local key,flagstr,size,cas = string.match(line, 'VALUE (%S+) (%d+) (%d+)')
- flags = extract_flags(flagstr)
-
- local data = server:receive(size)
-
- if flags.COMPRESSED and cache.compress_enabled then
- data = cache.decompress(data)
- end
-
- if flags.SERIALISED then
- returndata[key] = cache.decode(data)
- else
- local ldata = tonumber(data) or toboolean(data)
-
- if ldata == nil then
- if data == 'nil' then
- returndata[key] = nil
- else
- returndata[key] = data
- end
- else
- returndata[key] = ldata
- end
- end
- end
- end
-
- return returndata
-end
-
-local function _send(cache, key, str)
- local server = _select_server(cache, key)
-
- server:send(str .. "\r\n")
- local line, err = server:receive()
-
- if not err then return line end
-end
-
-local function _store(cache, op, key, value, expiry)
- local str
- local flags = 0
-
- if type(value) == 'table' then
- str = cache.encode(value)
- -- TODO lookup rather than hard code
- flags = flags + 4
- else
- str = tostring(value)
- end
-
- if cache.compress_enabled and string.len(str) > cache.compress_threshold then
- local cstr = cache.compress(str)
-
- if string.len(cstr) < (string.len(str) * 0.8) then
- str = cstr
-
- -- TODO lookup rather than hard code
- flags = flags + 2
- end
- end
-
- local len = string.len(str)
-
- expiry = expiry or 0
-
- local cmd = op .. ' ' .. key .. ' ' .. flags .. ' ' .. expiry .. ' ' .. len .. '\r\n' .. str
-
- local res = _send(cache, key, cmd)
-
- if res ~= 'STORED' then
- return false, res
- end
-
- return true
-end
-
-local function set(cache, key, value, expiry)
- return _store(cache, 'set', key, value, expiry)
-end
-
-local function add(cache, key, value, expiry)
- return _store(cache, 'add', key, value, expiry)
-end
-
-local function replace(cache, key, value, expiry)
- return _store(cache, 'replace', key, value, expiry)
-end
-
-local function get(cache, key)
- local dataset = _retrieve(cache, key, 'get ' .. key)
- return dataset[key]
-end
-
-local function delete(cache, key)
- local res = _send(cache, key, 'delete ' .. key)
-
- if res == 'NOT_FOUND' then
- return false
- end
-
- if res ~= 'DELETED' then
- return false, res
- end
-
- return true
-end
-
-local function incr(cache, key, val)
- val = val or 1
-
- local res = _send(cache, key, 'incr ' .. key .. ' ' .. val)
-
- if res == 'ERROR' or res == 'CLIENT_ERROR' then
- return false, res
- end
-
- return res
-end
-
-local function decr(cache, key, val)
- val = val or 1
-
- local res = _send(cache, key, 'decr ' .. key .. ' ' .. val)
-
- if res == 'ERROR' or res == 'CLIENT_ERROR' then
- return false, res
- end
-
- return res
-end
-
-local function stats(cache, key)
- local servers = {}
-
- key = key or ''
-
- if string.len(key) > 0 and not STATS_KEYS[key] then
- error(string.format("Unknown stats key '%s'", key))
- end
-
- for i,server in pairs(cache.servers) do
- server.socket:send('stats ' .. key .. '\r\n')
-
- local stats = {}
-
- while true do
- local line, err = server.socket:receive()
-
- if line == 'END' or line == 'ERROR' then
- break
- end
-
- local k,v = string.match(line, 'STAT (%S+) (%S+)')
-
- if k then
- stats[k] = v
- end
- end
-
- servers[server.name] = stats
- end
-
- return servers
-end
-
-local function get_multi(cache, ...)
- local dataset = nil
-
- if table.maxn(cache.servers) > 1 then
- dataset = {}
-
- for i,k in ipairs(arg) do
- local data = _retrieve(cache, k, 'get ' .. k)
- dataset[k] = data[k]
- end
- else
- local keys = table.concat(arg, ' ')
- dataset = _retrieve(cache, keys, 'get ' .. keys)
- end
-
- return dataset
-end
-
-local function flush_all(cache)
- local success = true
-
- for i,server in ipairs(cache.servers) do
- server.socket:send('flush_all\r\n')
- local res = assert(server.socket:receive())
-
- if res ~= 'OK' then
- success = false
- end
- end
-
- return success
-end
-
-local function disconnect_all(cache)
- while true do
- local server = table.remove(cache.servers)
-
- if not server then
- break
- end
-
- server.socket:close()
- end
-end
-
-local function set_hash(cache, hashfunc)
- cache.hash = hashfunc
-end
-
-local function set_encode(cache, func)
- cache.encode = func
-end
-
-local function set_decode(cache, func)
- cache.decode = func
-end
-
-local function set_compress(cache, func)
- cache.compress = func
-end
-
-local function set_decompress(cache, func)
- cache.decompress = func
-end
-
-function Connect(hostlist, port)
- local servers = {}
-
- if type(hostlist) == 'table' then
- for i,host in pairs(hostlist) do
- local h, p
-
- if type(host) == 'table' then
- h = host[1]
- p = host[2]
- elseif type(host) == 'string' then
- h = host
- elseif type(host) == 'number' then
- p = host
- h = nil
- end
-
- if not h then
- h = '127.0.0.1'
- end
-
- if not p then
- p = 11211
- end
-
- local server = socket.connect(h, p)
-
- if not server then
- warn('Could not connect to ' .. h .. ':' .. p)
- else
- table.insert(servers, {socket = server, name = string.format('%s:%d', h, p)})
- end
- end
- else
- local address = hostlist
-
- if type(address) == 'number' then
- port = address
- address = nil
- end
-
- if address == nil then
- address = '127.0.0.1'
- end
-
- if port == nil then
- port = 11211
- end
-
- local server = socket.connect(address, port)
-
- if not server then
- warn('Could not connect to ' .. address .. ':' .. port)
- else
- servers = {{socket = server, name = string.format('%s:%d', address, port)}}
- end
- end
-
- if table.maxn(servers) < 1 then
- error('No servers available')
- end
-
- local cache = {
- servers = servers,
-
- set_hash = set_hash,
- set_encode = set_encode,
- set_decode = set_decode,
- set_decompress = set_decompress,
- set_compress = set_compress,
-
- compress_enabled = false,
- enable_compression = function(self, on)
- self.compress_enabled = on
- end,
-
- hash = nil,
- encode = function()
- error('No encode function set')
- end,
-
- decode = function()
- error('No decode function set')
- end,
-
- compress = function()
- error('No compress function set')
- end,
-
- decompress = function()
- error('No decompress function set')
- end,
-
- -- 10K default
- compress_threshold = 10240,
- set_compress_threshold = function(self, threshold)
- if threshold == nil then
- self:enable_compression(false)
- else
- self.compress_threshold = threshold
- end
- end,
-
- set = set,
- add = add,
- replace = replace,
- get = get,
- delete = delete,
- incr = incr,
- decr = decr,
-
- get_multi = get_multi,
- stats = stats,
- flush_all = flush_all,
- disconnect_all = disconnect_all,
- }
-
- return cache
-end
-
-function New(hostlist, port)
- return Connect(hostlist, port)
-end
-
---
--- Memcached.lua
---
--- A pure Lua implementation of a simple memcached client. 1 or more memcached server(s) are currently supported. Requires the luasocket library.
--- See http://www.danga.com/memcached/ for more information about memcached.
---
---
---
--- Synopsis
---
--- require('Memcached')
---
--- memcache = Memcached.Connect('some.host.com', 11000)
--- OR
--- memcache = Memcached.New('some.host.com', 11000)
---
--- memcache:set('some_key', 1234)
--- memcache:add('new_key', 'add new value')
--- memcache:replace('existing_key', 'replace old value')
---
--- cached_data = memcache:get('some_key')
---
--- memcache:delete('old_key')
---
---
---
--- Methods:
---
--- memcache = Memcached.Connect()
--- Connect to memcached server at localhost on port number 11211.
---
--- memcache = Memcached.Connect(host[, port])
--- Connect to memcached server at 'host' on port number 'port'. If port is not provided, port 11211 is used.
---
----memcache = Memcached.Connect(port)
--- Connect to memcached server at localhost on port number 'port'.
---
--- memcache = Memcached.Connect({{'host', port}, 'host', port})
--- Connect to multiple memcached servers.
---
--- memcache:set(key, value[, expiry])
--- Unconditionally sets a key to a given value in the memcache. The value for 'expiry' is the expiration
--- time (default is 0, never expire).
---
--- memcache:add(key, value[, expiry])
--- Like set, but only stores in memcache if the key doesn't already exist.
---
--- memcache:replace(key, value[, expiry])
--- Like set, but only stores in memcache if the key already exists. The opposite of add.
---
--- value = memcache:get(key)
--- Retrieves a key from the memcache. Returns the value or nil
---
--- values = memcache:get_multi(...)
--- Retrieves multiple keys from the memcache doing just one query. Returns a table of key/value pairs that were available.
---
--- memcache:delete(key)
--- Deletes a key. Returns true on deletion, false if the key was not found.
---
--- value = memcache:incr(key[, value])
--- Sends a command to the server to atomically increment the value for key by value, or by 1 if value is nil.
--- Returns nil if key doesn't exist on server, otherwise it returns the new value after incrementing. Value should be zero or greater.
---
--- value = memcache:decr(key[, value])
--- Like incr, but decrements. Unlike incr, underflow is checked and new values are capped at 0. If server value is 1, a decrement of 2 returns 0, not -1.
---
--- servers = memcache:stats([key])
--- Returns a table of statistical data regarding the memcache server(s). Allowed keys are:
--- '', 'malloc', 'sizes', 'slabs', 'items'
---
--- success = memcache:flush_all()
--- Runs the memcached "flush_all" command on all configured hosts, emptying all their caches.
---
--- memcache:disconnect_all()
--- Closes all cached sockets to all memcached servers.
---
--- memcache:set_hash(hashfunc)
--- Sets a custom hash function for key values. The default is a CRC32 hashing function.
--- 'hashfunc' should be defined receiving a single string parameter and returning a single integer value.
---
--- memcache:set_encode(func)
--- Sets a custom encode function for serialising table values. 'func' should be defined receiving a single
--- table value and returning a single string value.
---
--- memcache:set_decode(func)
--- Sets a custom decode function for deserialising table values. 'func' should be defined receiving a
--- single single and returning a single table value
---
--- memcache:enable_compression(onflag)
--- Turns data compression support on or off.
---
--- memcache:set_compress_threshold(size)
--- Set the compression threshold. If the value to be stored is larger than `size' bytes (and compression
--- is enabled), compress before storing.
---
--- memcache:set_compress(func)
--- Sets a custom data compression function. 'func' should be defined receiving a single string value and
--- returning a single string value.
---
--- memcache:set_decompress(func)
--- Sets a custom data decompression function. 'func' should be defined receiving a single string value and
--- returning a single string value.
diff --git a/src/deps/src/lua-nginx-module/t/lib/Redis.lua b/src/deps/src/lua-nginx-module/t/lib/Redis.lua
deleted file mode 100644
index 8bc28048d..000000000
--- a/src/deps/src/lua-nginx-module/t/lib/Redis.lua
+++ /dev/null
@@ -1,1120 +0,0 @@
---[[
-Copyright (c) 2009-2011 Daniele Alessandri
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-]]
-
-module('Redis', package.seeall)
-
-local commands, network, request, response = {}, {}, {}, {}
-
-local defaults = {
- host = '127.0.0.1',
- port = 6379,
- tcp_nodelay = true,
- path = nil
-}
-
-local protocol = {
- newline = '\r\n',
- ok = 'OK',
- err = 'ERR',
- queued = 'QUEUED',
- null = 'nil'
-}
-
-local lua_error = error
-local function default_error_fn(message, level)
- lua_error(message, (level or 1) + 1)
-end
-
-local function merge_defaults(parameters)
- if parameters == nil then
- parameters = {}
- end
- for k, v in pairs(defaults) do
- if parameters[k] == nil then
- parameters[k] = defaults[k]
- end
- end
- return parameters
-end
-
-local function parse_boolean(v)
- if v == '1' or v == 'true' or v == 'TRUE' then
- return true
- elseif v == '0' or v == 'false' or v == 'FALSE' then
- return false
- else
- return nil
- end
-end
-
-local function toboolean(value) return value == 1 end
-
-local function fire_and_forget(client, command)
- -- let's fire and forget! the connection is closed as soon
- -- as the SHUTDOWN command is received by the server.
- client.network.write(client, command .. protocol.newline)
- return false
-end
-
-local function zset_range_request(client, command, ...)
- local args, opts = {...}, { }
-
- if #args >= 1 and type(args[#args]) == 'table' then
- local options = table.remove(args, #args)
- if options.withscores then
- table.insert(opts, 'WITHSCORES')
- end
- end
-
- for _, v in pairs(opts) do table.insert(args, v) end
- request.multibulk(client, command, args)
-end
-
-local function zset_range_byscore_request(client, command, ...)
- local args, opts = {...}, { }
-
- if #args >= 1 and type(args[#args]) == 'table' then
- local options = table.remove(args, #args)
- if options.limit then
- table.insert(opts, 'LIMIT')
- table.insert(opts, options.limit.offset or options.limit[1])
- table.insert(opts, options.limit.count or options.limit[2])
- end
- if options.withscores then
- table.insert(opts, 'WITHSCORES')
- end
- end
-
- for _, v in pairs(opts) do table.insert(args, v) end
- request.multibulk(client, command, args)
-end
-
-local function zset_range_reply(reply, command, ...)
- local args = {...}
- local opts = args[4]
- if opts and (opts.withscores or string.lower(tostring(opts)) == 'withscores') then
- local new_reply = { }
- for i = 1, #reply, 2 do
- table.insert(new_reply, { reply[i], reply[i + 1] })
- end
- return new_reply
- else
- return reply
- end
-end
-
-local function zset_store_request(client, command, ...)
- local args, opts = {...}, { }
-
- if #args >= 1 and type(args[#args]) == 'table' then
- local options = table.remove(args, #args)
- if options.weights and type(options.weights) == 'table' then
- table.insert(opts, 'WEIGHTS')
- for _, weight in ipairs(options.weights) do
- table.insert(opts, weight)
- end
- end
- if options.aggregate then
- table.insert(opts, 'AGGREGATE')
- table.insert(opts, options.aggregate)
- end
- end
-
- for _, v in pairs(opts) do table.insert(args, v) end
- request.multibulk(client, command, args)
-end
-
-local function mset_filter_args(client, command, ...)
- local args, arguments = {...}, {}
- if (#args == 1 and type(args[1]) == 'table') then
- for k,v in pairs(args[1]) do
- table.insert(arguments, k)
- table.insert(arguments, v)
- end
- else
- arguments = args
- end
- request.multibulk(client, command, arguments)
-end
-
-local function hash_multi_request_builder(builder_callback)
- return function(client, command, ...)
- local args, arguments = {...}, { }
- if #args == 2 then
- table.insert(arguments, args[1])
- for k, v in pairs(args[2]) do
- builder_callback(arguments, k, v)
- end
- else
- arguments = args
- end
- request.multibulk(client, command, arguments)
- end
-end
-
-local function parse_info(response)
- local info = {}
- response:gsub('([^\r\n]*)\r\n', function(kv)
- local k,v = kv:match(('([^:]*):([^:]*)'):rep(1))
- if (k:match('db%d+')) then
- info[k] = {}
- v:gsub(',', function(dbkv)
- local dbk,dbv = kv:match('([^:]*)=([^:]*)')
- info[k][dbk] = dbv
- end)
- else
- info[k] = v
- end
- end)
- return info
-end
-
-local function parse_info_new(response)
- local info, current = {}, nil
- response:gsub('([^\r\n]*)\r\n', function(kv)
- if kv == '' then return end
-
- local section = kv:match(('^# (%w+)'):rep(1))
- if section then
- current = section:lower()
- info[current] = {}
- return
- end
-
- local k,v = kv:match(('([^:]*):([^:]*)'):rep(1))
- if (k:match('db%d+')) then
- info[current][k] = {}
- v:gsub(',', function(dbkv)
- local dbk,dbv = kv:match('([^:]*)=([^:]*)')
- info[current][dbk] = dbv
- end)
- else
- info[current][k] = v
- end
- end)
- return info
-end
-
-local function load_methods(proto, methods)
- local redis = setmetatable ({}, getmetatable(proto))
- for i, v in pairs(proto) do redis[i] = v end
- for i, v in pairs(methods) do redis[i] = v end
- return redis
-end
-
-local function create_client(proto, client_socket, methods)
- local redis = load_methods(proto, methods)
- redis.network = {
- socket = client_socket,
- read = network.read,
- write = network.write,
- }
- redis.requests = {
- multibulk = request.multibulk,
- }
- return redis
-end
-
--- ############################################################################
-
-function network.write(client, buffer)
- local _, err = client.network.socket:send(buffer)
- if err then client.error(err) end
-end
-
-function network.read(client, len)
- if len == nil then len = '*l' end
- local line, err = client.network.socket:receive(len)
- if not err then return line else client.error('connection error: ' .. err) end
-end
-
--- ############################################################################
-
-function response.read(client)
- local res = client.network.read(client)
- local prefix = res:sub(1, -#res)
- local handler = protocol.prefixes[prefix]
- if not handler then
- client.error('unknown response prefix: '..prefix)
- end
- return handler(client, res)
-end
-
-function response.status(client, data)
- local sub = data:sub(2)
-
- if sub == protocol.ok then
- return true
- elseif sub == protocol.queued then
- return { queued = true }
- else
- return sub
- end
-end
-
-function response.error(client, data)
- local err_line = data:sub(2)
-
- if err_line:sub(1, 3) == protocol.err then
- client.error('redis error: ' .. err_line:sub(5))
- else
- client.error('redis error: ' .. err_line)
- end
-end
-
-function response.bulk(client, data)
- local str = data:sub(2)
- local len = tonumber(str)
- if not len then
- client.error('cannot parse ' .. str .. ' as data length')
- end
-
- if len == -1 then return nil end
- local next_chunk = client.network.read(client, len + 2)
- return next_chunk:sub(1, -3);
-end
-
-function response.multibulk(client, data)
- local str = data:sub(2)
- local list_count = tonumber(str)
-
- if list_count == -1 then
- return nil
- else
- local list = {}
- if list_count > 0 then
- for i = 1, list_count do
- table.insert(list, i, response.read(client))
- end
- end
- return list
- end
-end
-
-function response.integer(client, data)
- local res = data:sub(2)
- local number = tonumber(res)
-
- if not number then
- if res == protocol.null then
- return nil
- end
- client.error('cannot parse '..res..' as a numeric response.')
- end
-
- return number
-end
-
-protocol.prefixes = {
- ['+'] = response.status,
- ['-'] = response.error,
- ['$'] = response.bulk,
- ['*'] = response.multibulk,
- [':'] = response.integer,
-}
-
--- ############################################################################
-
-function request.raw(client, buffer)
- local bufferType = type(buffer)
-
- if bufferType == 'table' then
- client.network.write(client, table.concat(buffer))
- elseif bufferType == 'string' then
- client.network.write(client, buffer)
- else
- client.error('argument error: ' .. bufferType)
- end
-end
-
-function request.multibulk(client, command, ...)
- local args = {...}
- local args_len = #args
- local buffer = { true, true }
- local proto_nl = protocol.newline
-
- if args_len == 1 and type(args[1]) == 'table' then
- args_len, args = #args[1], args[1]
- end
-
- buffer[1] = '*' .. tostring(args_len + 1) .. proto_nl
- buffer[2] = '$' .. #command .. proto_nl .. command .. proto_nl
-
- for _, argument in pairs(args) do
- s_argument = tostring(argument)
- table.insert(buffer, '$' .. #s_argument .. proto_nl .. s_argument .. proto_nl)
- end
-
- request.raw(client, buffer)
-end
-
--- ############################################################################
-
-local function custom(command, send, parse)
- return function(client, ...)
- local has_reply = send(client, command, ...)
- if has_reply == false then return end
- local reply = response.read(client)
-
- if type(reply) == 'table' and reply.queued then
- reply.parser = parse
- return reply
- else
- if parse then
- return parse(reply, command, ...)
- else
- return reply
- end
- end
- end
-end
-
-function command(command, opts)
- if opts == nil or type(opts) == 'function' then
- return custom(command, request.multibulk, opts)
- else
- return custom(command, opts.request or request.multibulk, opts.response)
- end
-end
-
-local define_command_impl = function(target, name, opts)
- local opts = opts or {}
- target[string.lower(name)] = custom(
- opts.command or string.upper(name),
- opts.request or request.multibulk,
- opts.response or nil
- )
-end
-
-function define_command(name, opts)
- define_command_impl(commands, name, opts)
-end
-
-local undefine_command_impl = function(target, name)
- target[string.lower(name)] = nil
-end
-
-function undefine_command(name)
- undefine_command_impl(commands, name)
-end
-
--- ############################################################################
-
-local client_prototype = {}
-
-client_prototype.raw_cmd = function(client, buffer)
- request.raw(client, buffer .. protocol.newline)
- return response.read(client)
-end
-
-client_prototype.define_command = function(client, name, opts)
- define_command_impl(client, name, opts)
-end
-
-client_prototype.undefine_command = function(client, name)
- undefine_command_impl(client, name)
-end
-
--- Command pipelining
-
-client_prototype.pipeline = function(client, block)
- local requests, replies, parsers = {}, {}, {}
- local socket_write, socket_read = client.network.write, client.network.read
-
- client.network.write = function(_, buffer)
- table.insert(requests, buffer)
- end
-
- -- TODO: this hack is necessary to temporarily reuse the current
- -- request -> response handling implementation of redis-lua
- -- without further changes in the code, but it will surely
- -- disappear when the new command-definition infrastructure
- -- will finally be in place.
- client.network.read = function() return '+QUEUED' end
-
- local pipeline = setmetatable({}, {
- __index = function(env, name)
- local cmd = client[name]
- if not cmd then
- client.error('unknown redis command: ' .. name, 2)
- end
- return function(self, ...)
- local reply = cmd(client, ...)
- table.insert(parsers, #requests, reply.parser)
- return reply
- end
- end
- })
-
- local success, retval = pcall(block, pipeline)
-
- client.network.write, client.network.read = socket_write, socket_read
- if not success then client.error(retval, 0) end
-
- client.network.write(client, table.concat(requests, ''))
-
- for i = 1, #requests do
- local reply, parser = response.read(client), parsers[i]
- if parser then
- reply = parser(reply)
- end
- table.insert(replies, i, reply)
- end
-
- return replies, #requests
-end
-
--- Publish/Subscribe
-
-do
- local channels = function(channels)
- if type(channels) == 'string' then
- channels = { channels }
- end
- return channels
- end
-
- local subscribe = function(client, ...)
- request.multibulk(client, 'subscribe', ...)
- end
- local psubscribe = function(client, ...)
- request.multibulk(client, 'psubscribe', ...)
- end
- local unsubscribe = function(client, ...)
- request.multibulk(client, 'unsubscribe')
- end
- local punsubscribe = function(client, ...)
- request.multibulk(client, 'punsubscribe')
- end
-
- local consumer_loop = function(client)
- local aborting, subscriptions = false, 0
-
- local abort = function()
- if not aborting then
- unsubscribe(client)
- punsubscribe(client)
- aborting = true
- end
- end
-
- return coroutine.wrap(function()
- while true do
- local message
- local response = response.read(client)
-
- if response[1] == 'pmessage' then
- message = {
- kind = response[1],
- pattern = response[2],
- channel = response[3],
- payload = response[4],
- }
- else
- message = {
- kind = response[1],
- channel = response[2],
- payload = response[3],
- }
- end
-
- if string.match(message.kind, '^p?subscribe$') then
- subscriptions = subscriptions + 1
- end
- if string.match(message.kind, '^p?unsubscribe$') then
- subscriptions = subscriptions - 1
- end
-
- if aborting and subscriptions == 0 then
- break
- end
- coroutine.yield(message, abort)
- end
- end)
- end
-
- client_prototype.pubsub = function(client, subscriptions)
- if type(subscriptions) == 'table' then
- if subscriptions.subscribe then
- subscribe(client, channels(subscriptions.subscribe))
- end
- if subscriptions.psubscribe then
- psubscribe(client, channels(subscriptions.psubscribe))
- end
- end
- return consumer_loop(client)
- end
-end
-
--- Redis transactions (MULTI/EXEC)
-
-do
- local function identity(...) return ... end
- local emptytable = {}
-
- local function initialize_transaction(client, options, block, queued_parsers)
- local coro = coroutine.create(block)
-
- if options.watch then
- local watch_keys = {}
- for _, key in pairs(options.watch) do
- table.insert(watch_keys, key)
- end
- if #watch_keys > 0 then
- client:watch(unpack(watch_keys))
- end
- end
-
- local transaction_client = setmetatable({}, {__index=client})
- transaction_client.exec = function(...)
- client.error('cannot use EXEC inside a transaction block')
- end
- transaction_client.multi = function(...)
- coroutine.yield()
- end
- transaction_client.commands_queued = function()
- return #queued_parsers
- end
-
- assert(coroutine.resume(coro, transaction_client))
-
- transaction_client.multi = nil
- transaction_client.discard = function(...)
- local reply = client:discard()
- for i, v in pairs(queued_parsers) do
- queued_parsers[i]=nil
- end
- coro = initialize_transaction(client, options, block, queued_parsers)
- return reply
- end
- transaction_client.watch = function(...)
- client.error('WATCH inside MULTI is not allowed')
- end
- setmetatable(transaction_client, { __index = function(t, k)
- local cmd = client[k]
- if type(cmd) == "function" then
- local function queuey(self, ...)
- local reply = cmd(client, ...)
- assert((reply or emptytable).queued == true, 'a QUEUED reply was expected')
- table.insert(queued_parsers, reply.parser or identity)
- return reply
- end
- t[k]=queuey
- return queuey
- else
- return cmd
- end
- end
- })
- client:multi()
- return coro
- end
-
- local function transaction(client, options, coroutine_block, attempts)
- local queued_parsers, replies = {}, {}
- local retry = tonumber(attempts) or tonumber(options.retry) or 2
- local coro = initialize_transaction(client, options, coroutine_block, queued_parsers)
-
- local success, retval
- if coroutine.status(coro) == 'suspended' then
- success, retval = coroutine.resume(coro)
- else
- -- do not fail if the coroutine has not been resumed (missing t:multi() with CAS)
- success, retval = true, 'empty transaction'
- end
- if #queued_parsers == 0 or not success then
- client:discard()
- assert(success, retval)
- return replies, 0
- end
-
- local raw_replies = client:exec()
- if not raw_replies then
- if (retry or 0) <= 0 then
- client.error("MULTI/EXEC transaction aborted by the server")
- else
- --we're not quite done yet
- return transaction(client, options, coroutine_block, retry - 1)
- end
- end
-
- for i, parser in pairs(queued_parsers) do
- table.insert(replies, i, parser(raw_replies[i]))
- end
-
- return replies, #queued_parsers
- end
-
- client_prototype.transaction = function(client, arg1, arg2)
- local options, block
- if not arg2 then
- options, block = {}, arg1
- elseif arg1 then --and arg2, implicitly
- options, block = type(arg1)=="table" and arg1 or { arg1 }, arg2
- else
- client.error("Invalid parameters for redis transaction.")
- end
-
- if not options.watch then
- watch_keys = { }
- for i, v in pairs(options) do
- if tonumber(i) then
- table.insert(watch_keys, v)
- options[i] = nil
- end
- end
- options.watch = watch_keys
- elseif not (type(options.watch) == 'table') then
- options.watch = { options.watch }
- end
-
- if not options.cas then
- local tx_block = block
- block = function(client, ...)
- client:multi()
- return tx_block(client, ...) --can't wrap this in pcall because we're in a coroutine.
- end
- end
-
- return transaction(client, options, block)
- end
-end
-
--- ############################################################################
-
-local function connect_tcp(socket, parameters)
- local host, port = parameters.host, tonumber(parameters.port)
- local ok, err = socket:connect(host, port)
- if not ok then
- default_error_fn('could not connect to '..host..':'..port..' ['..err..']')
- end
- socket:setoption('tcp-nodelay', parameters.tcp_nodelay)
- return socket
-end
-
-local function connect_unix(socket, parameters)
- local ok, err = socket:connect(parameters.path)
- if not ok then
- default_error_fn('could not connect to '..parameters.path..' ['..err..']')
- end
- return socket
-end
-
-local function create_connection(parameters)
- local perform_connection, socket
-
- if parameters.scheme == 'unix' then
- perform_connection, socket = connect_unix, require('socket.unix')
- assert(socket, 'your build of LuaSocket does not support UNIX domain sockets')
- else
- if parameters.scheme then
- local scheme = parameters.scheme
- assert(scheme == 'redis' or scheme == 'tcp', 'invalid scheme: '..scheme)
- end
- perform_connection, socket = connect_tcp, require('socket').tcp
- end
-
- return perform_connection(socket(), parameters)
-end
-
-function connect(...)
- local args, parameters = {...}, nil
-
- if #args == 1 then
- if type(args[1]) == 'table' then
- parameters = args[1]
- else
- local uri = require('socket.url')
- parameters = uri.parse(select(1, ...))
- if parameters.scheme then
- if parameters.query then
- for k, v in parameters.query:gmatch('([-_%w]+)=([-_%w]+)') do
- if k == 'tcp_nodelay' or k == 'tcp-nodelay' then
- parameters.tcp_nodelay = parse_boolean(v)
- end
- end
- end
- else
- parameters.host = parameters.path
- end
- end
- elseif #args > 1 then
- local host, port = unpack(args)
- parameters = { host = host, port = port }
- end
-
- local socket = create_connection(merge_defaults(parameters))
- local client = create_client(client_prototype, socket, commands)
-
- client.error = default_error_fn
-
- return client
-end
-
--- ############################################################################
-
-commands = {
- -- commands operating on the key space
- exists = command('EXISTS', {
- response = toboolean
- }),
- del = command('DEL'),
- type = command('TYPE'),
- rename = command('RENAME'),
- renamenx = command('RENAMENX', {
- response = toboolean
- }),
- expire = command('EXPIRE', {
- response = toboolean
- }),
- pexpire = command('PEXPIRE', { -- >= 2.6
- response = toboolean
- }),
- expireat = command('EXPIREAT', {
- response = toboolean
- }),
- pexpireat = command('PEXPIREAT', { -- >= 2.6
- response = toboolean
- }),
- ttl = command('TTL'),
- pttl = command('PTTL'), -- >= 2.6
- move = command('MOVE', {
- response = toboolean
- }),
- dbsize = command('DBSIZE'),
- persist = command('PERSIST', { -- >= 2.2
- response = toboolean
- }),
- keys = command('KEYS', {
- response = function(response)
- if type(response) == 'string' then
- -- backwards compatibility path for Redis < 2.0
- local keys = {}
- response:gsub('[^%s]+', function(key)
- table.insert(keys, key)
- end)
- response = keys
- end
- return response
- end
- }),
- randomkey = command('RANDOMKEY', {
- response = function(response)
- if response == '' then
- return nil
- else
- return response
- end
- end
- }),
- sort = command('SORT', {
- request = function(client, command, key, params)
- --[[ params = {
- by = 'weight_*',
- get = 'object_*',
- limit = { 0, 10 },
- sort = 'desc',
- alpha = true,
- } --]]
- local query = { key }
-
- if params then
- if params.by then
- table.insert(query, 'BY')
- table.insert(query, params.by)
- end
-
- if type(params.limit) == 'table' then
- -- TODO: check for lower and upper limits
- table.insert(query, 'LIMIT')
- table.insert(query, params.limit[1])
- table.insert(query, params.limit[2])
- end
-
- if params.get then
- if (type(params.get) == 'table') then
- for _, getarg in pairs(params.get) do
- table.insert(query, 'GET')
- table.insert(query, getarg)
- end
- else
- table.insert(query, 'GET')
- table.insert(query, params.get)
- end
- end
-
- if params.sort then
- table.insert(query, params.sort)
- end
-
- if params.alpha == true then
- table.insert(query, 'ALPHA')
- end
-
- if params.store then
- table.insert(query, 'STORE')
- table.insert(query, params.store)
- end
- end
-
- request.multibulk(client, command, query)
- end
- }),
-
- -- commands operating on string values
- set = command('SET'),
- setnx = command('SETNX', {
- response = toboolean
- }),
- setex = command('SETEX'), -- >= 2.0
- psetex = command('PSETEX'), -- >= 2.6
- mset = command('MSET', {
- request = mset_filter_args
- }),
- msetnx = command('MSETNX', {
- request = mset_filter_args,
- response = toboolean
- }),
- get = command('GET'),
- mget = command('MGET'),
- getset = command('GETSET'),
- incr = command('INCR'),
- incrby = command('INCRBY'),
- incrbyfloat = command('INCRBYFLOAT', { -- >= 2.6
- response = function(reply, command, ...)
- return tonumber(reply)
- end,
- }),
- decr = command('DECR'),
- decrby = command('DECRBY'),
- append = command('APPEND'), -- >= 2.0
- substr = command('SUBSTR'), -- >= 2.0
- strlen = command('STRLEN'), -- >= 2.2
- setrange = command('SETRANGE'), -- >= 2.2
- getrange = command('GETRANGE'), -- >= 2.2
- setbit = command('SETBIT'), -- >= 2.2
- getbit = command('GETBIT'), -- >= 2.2
-
- -- commands operating on lists
- rpush = command('RPUSH'),
- lpush = command('LPUSH'),
- llen = command('LLEN'),
- lrange = command('LRANGE'),
- ltrim = command('LTRIM'),
- lindex = command('LINDEX'),
- lset = command('LSET'),
- lrem = command('LREM'),
- lpop = command('LPOP'),
- rpop = command('RPOP'),
- rpoplpush = command('RPOPLPUSH'),
- blpop = command('BLPOP'), -- >= 2.0
- brpop = command('BRPOP'), -- >= 2.0
- rpushx = command('RPUSHX'), -- >= 2.2
- lpushx = command('LPUSHX'), -- >= 2.2
- linsert = command('LINSERT'), -- >= 2.2
- brpoplpush = command('BRPOPLPUSH'), -- >= 2.2
-
- -- commands operating on sets
- sadd = command('SADD', {
- response = toboolean
- }),
- srem = command('SREM', {
- response = toboolean
- }),
- spop = command('SPOP'),
- smove = command('SMOVE', {
- response = toboolean
- }),
- scard = command('SCARD'),
- sismember = command('SISMEMBER', {
- response = toboolean
- }),
- sinter = command('SINTER'),
- sinterstore = command('SINTERSTORE'),
- sunion = command('SUNION'),
- sunionstore = command('SUNIONSTORE'),
- sdiff = command('SDIFF'),
- sdiffstore = command('SDIFFSTORE'),
- smembers = command('SMEMBERS'),
- srandmember = command('SRANDMEMBER'),
-
- -- commands operating on sorted sets
- zadd = command('ZADD', {
- response = toboolean
- }),
- zincrby = command('ZINCRBY'),
- zrem = command('ZREM', {
- response = toboolean
- }),
- zrange = command('ZRANGE', {
- request = zset_range_request,
- response = zset_range_reply,
- }),
- zrevrange = command('ZREVRANGE', {
- request = zset_range_request,
- response = zset_range_reply,
- }),
- zrangebyscore = command('ZRANGEBYSCORE', {
- request = zset_range_byscore_request,
- response = zset_range_reply,
- }),
- zrevrangebyscore = command('ZREVRANGEBYSCORE', { -- >= 2.2
- request = zset_range_byscore_request,
- response = zset_range_reply,
- }),
- zunionstore = command('ZUNIONSTORE', { -- >= 2.0
- request = zset_store_request
- }),
- zinterstore = command('ZINTERSTORE', { -- >= 2.0
- request = zset_store_request
- }),
- zcount = command('ZCOUNT'),
- zcard = command('ZCARD'),
- zscore = command('ZSCORE'),
- zremrangebyscore = command('ZREMRANGEBYSCORE'),
- zrank = command('ZRANK'), -- >= 2.0
- zrevrank = command('ZREVRANK'), -- >= 2.0
- zremrangebyrank = command('ZREMRANGEBYRANK'), -- >= 2.0
-
- -- commands operating on hashes
- hset = command('HSET', { -- >= 2.0
- response = toboolean
- }),
- hsetnx = command('HSETNX', { -- >= 2.0
- response = toboolean
- }),
- hmset = command('HMSET', { -- >= 2.0
- request = hash_multi_request_builder(function(args, k, v)
- table.insert(args, k)
- table.insert(args, v)
- end),
- }),
- hincrby = command('HINCRBY'), -- >= 2.0
- hincrbyfloat = command('HINCRBYFLOAT', {-- >= 2.6
- response = function(reply, command, ...)
- return tonumber(reply)
- end,
- }),
- hget = command('HGET'), -- >= 2.0
- hmget = command('HMGET', { -- >= 2.0
- request = hash_multi_request_builder(function(args, k, v)
- table.insert(args, v)
- end),
- }),
- hdel = command('HDEL', { -- >= 2.0
- response = toboolean
- }),
- hexists = command('HEXISTS', { -- >= 2.0
- response = toboolean
- }),
- hlen = command('HLEN'), -- >= 2.0
- hkeys = command('HKEYS'), -- >= 2.0
- hvals = command('HVALS'), -- >= 2.0
- hgetall = command('HGETALL', { -- >= 2.0
- response = function(reply, command, ...)
- local new_reply = { }
- for i = 1, #reply, 2 do new_reply[reply[i]] = reply[i + 1] end
- return new_reply
- end
- }),
-
- -- connection related commands
- ping = command('PING', {
- response = function(response) return response == 'PONG' end
- }),
- echo = command('ECHO'),
- auth = command('AUTH'),
- select = command('SELECT'),
- quit = command('QUIT', {
- request = fire_and_forget
- }),
-
- -- transactions
- multi = command('MULTI'), -- >= 2.0
- exec = command('EXEC'), -- >= 2.0
- discard = command('DISCARD'), -- >= 2.0
- watch = command('WATCH'), -- >= 2.2
- unwatch = command('UNWATCH'), -- >= 2.2
-
- -- publish - subscribe
- subscribe = command('SUBSCRIBE'), -- >= 2.0
- unsubscribe = command('UNSUBSCRIBE'), -- >= 2.0
- psubscribe = command('PSUBSCRIBE'), -- >= 2.0
- punsubscribe = command('PUNSUBSCRIBE'), -- >= 2.0
- publish = command('PUBLISH'), -- >= 2.0
-
- -- redis scripting
- eval = command('EVAL'), -- >= 2.6
- evalsha = command('EVALSHA'), -- >= 2.6
- script = command('SCRIPT'), -- >= 2.6
-
- -- remote server control commands
- bgrewriteaof = command('BGREWRITEAOF'),
- config = command('CONFIG', { -- >= 2.0
- response = function(reply, command, ...)
- if (type(reply) == 'table') then
- local new_reply = { }
- for i = 1, #reply, 2 do new_reply[reply[i]] = reply[i + 1] end
- return new_reply
- end
-
- return reply
- end
- }),
- client = command('CLIENT'), -- >= 2.4
- slaveof = command('SLAVEOF'),
- save = command('SAVE'),
- bgsave = command('BGSAVE'),
- lastsave = command('LASTSAVE'),
- flushdb = command('FLUSHDB'),
- flushall = command('FLUSHALL'),
- shutdown = command('SHUTDOWN', {
- request = fire_and_forget
- }),
- slowlog = command('SLOWLOG', { -- >= 2.2.13
- response = function(reply, command, ...)
- if (type(reply) == 'table') then
- local structured = { }
- for index, entry in ipairs(reply) do
- structured[index] = {
- id = tonumber(entry[1]),
- timestamp = tonumber(entry[2]),
- duration = tonumber(entry[3]),
- command = entry[4],
- }
- end
- return structured
- end
-
- return reply
- end
- }),
- info = command('INFO', {
- response = function(response)
- if string.find(response, '^# ') then
- return parse_info_new(response)
- end
- return parse_info(response)
- end
- }),
-}
diff --git a/src/deps/src/lua-nginx-module/t/lib/ljson.lua b/src/deps/src/lua-nginx-module/t/lib/ljson.lua
deleted file mode 100644
index 108472493..000000000
--- a/src/deps/src/lua-nginx-module/t/lib/ljson.lua
+++ /dev/null
@@ -1,89 +0,0 @@
-local ngx_null = ngx.null
-local tostring = tostring
-local byte = string.byte
-local gsub = string.gsub
-local sort = table.sort
-local pairs = pairs
-local ipairs = ipairs
-local concat = table.concat
-
-local ok, new_tab = pcall(require, "table.new")
-if not ok then
- new_tab = function (narr, nrec) return {} end
-end
-
-local _M = {}
-
-local metachars = {
- ['\t'] = '\\t',
- ["\\"] = "\\\\",
- ['"'] = '\\"',
- ['\r'] = '\\r',
- ['\n'] = '\\n',
-}
-
-local function encode_str(s)
- -- XXX we will rewrite this when string.buffer is implemented
- -- in LuaJIT 2.1 because string.gsub cannot be JIT compiled.
- return gsub(s, '["\\\r\n\t]', metachars)
-end
-
-local function is_arr(t)
- local exp = 1
- for k, _ in pairs(t) do
- if k ~= exp then
- return nil
- end
- exp = exp + 1
- end
- return exp - 1
-end
-
-local encode
-
-encode = function (v)
- if v == nil or v == ngx_null then
- return "null"
- end
-
- local typ = type(v)
- if typ == 'string' then
- return '"' .. encode_str(v) .. '"'
- end
-
- if typ == 'number' or typ == 'boolean' then
- return tostring(v)
- end
-
- if typ == 'table' then
- local n = is_arr(v)
- if n then
- local bits = new_tab(n, 0)
- for i, elem in ipairs(v) do
- bits[i] = encode(elem)
- end
- return "[" .. concat(bits, ",") .. "]"
- end
-
- local keys = {}
- local i = 0
- for key, _ in pairs(v) do
- i = i + 1
- keys[i] = key
- end
- sort(keys)
-
- local bits = new_tab(0, i)
- i = 0
- for _, key in ipairs(keys) do
- i = i + 1
- bits[i] = encode(key) .. ":" .. encode(v[key])
- end
- return "{" .. concat(bits, ",") .. "}"
- end
-
- return '"<' .. typ .. '>"'
-end
-_M.encode = encode
-
-return _M