mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
c47084b5d bumped version to 0.10.25. 6d0a2c184 bugfix: used after free when encountering invalid http IF-Match header. 6e9948dcd bugfix: ssl_client_hello_by_lua generating chunk cache key and chunk name 68acad14e bumped the lua version to 0.10.24. ec6df3249 bugfix: windows also need to support ngx_http_lua_ffi_worker_pids. 9bee7e789 bugfix : comparison of integer expressions of different signedness. 1953052a0 bugfix: fixed warning of signed and unsigned. 74786af95 bugfix: windows does not support ngx_http_lua_ffi_worker_pids. ce30e2fb0 Revert "bugfix: doesn't set flags for Darwin arm64. (#2071)" (#2163) 644b98faa feature: introduced ngx_http_lua_get_lua_http10_buffering. 6f7a9a330 feature: add four new apis to manipulate the coctx. 14be60380 doc: setoption is already available now. 6dbc4e1bd tests: use the specified perl to execute cpanm. (#2157) 5e05fa3ad tests: cross requests cosocket can only be use one time. a6ee03aba bugfix: cleanup of http request will not be callled for the request created by ngx_http_lua_create_fake_request. 992bfc352 style: use forward declaration. 1a4859924 bumped the lua version to 0.10.23. 47f0a3676 bugfix: cosocket did not exit when worker_shutdown_timeout handler is called. 81bc96401 tests: fixed some test cases in t/129-ssl-socket.t t/162-socket-tls-handshake.t t/186-cosocket-busy-bufs.t. f488965b8 feature: added HTTP 3.0 support to ngx.req.http_version(). 3f4005fa8 bugfix: fix receiveuntil rest bytes count. 4045ea8eb tests: test failed when running in randmonize mode. 6e3b1c4fd bugfix: define busy_bufs per cosocket (#2119) 56347d174 tests: upgrade openssl to 1.1.1s. (#2117) 0499e8443 doc: add link to pre-defined Nginx variables (#2116) a31e9cf33 bugfix: avoid buf double free in ngx.print if lua body filter enabled (#2115) eb977111b bugfix: add a timed recycling child process as a last resort. (#2112) b754786bb feature: add new ffi api ngx_http_lua_ffi_msec. (#2108) 3207da152 chore: add assertion to make linter happy (#2107) a318d250f doc: add detail on explanation of a running timer (#2105) 4bbb57aa4 doc: add release description for ngx.worker.pids(). (#2104) d518adcac Merge tag 0.10.22 into master. 8d9032298 bumped the lua version to 0.10.22. 4add94239 bugfix: did not wakeup coroutine when worker thread finished. cff86dd7f doc: fix the version in README (#2089) edfa0f984 feat: add ngx_http_lua_ffi_worker_pids to get all workers pid map 3e2a7f459 bugfix: run_worker_thread arg is self-reference. eb6d6cbf0 tests: build with DDEBUG=1. (#2084) 5eb7101d3 doc: complete md5.lua example in run_worker_thread api (#2085) a7e67a596 doc: add more explanation for premature in ngx.timer.at. 73f2b3f6f bugfix: typo in the debug message. (#2081) 9b7bde2e7 feature: added new API bind. 44486a45f feature: add shdict APIs into worker thread (#2074) 99b29cd16 doc: clarify the ngx.req.set_uri_args api when using Lua table as the 'arg' argument. (#2073) 1fd1e83c8 bugfix: doesn't set flags for Darwin arm64. (#2071) 1c43f1c4f ci: bumped OpenSSL to 1.1.1p. (#2070) 74b8d4b4f chore: update the PR types (#2069) c55fceb5c ci: add a way to check PR title automatically (#2067) b6d167cf1 bugfix: update handling of multiple headers changed in nginx 1.23.0 (#2063) c8597eda0 tests: change the running phase to cover the bug reported in google group. (#2064) 9a0a8968c bugfix: did not wakeup coroutine when worker thread finished. 3fe8d9dde change: can not receive udp datagram greater 8192. (#2057) 2c60e8966 optimize: destroy pipe proc when freeing the request. (#2052) e7660d75a doc: revised English grammar in ngx_http_lua_timer.c. (#2053) 9c6478b08 Merge branch '0.10.21.x' 0ac2ab279 bugfix: tctx.pool is double freed. (#2049) b6db2e741 optimize: add error log when closing the pipe failed. (#2050) b91221bd6 optimize: fix potential null pointer dereference found by coverity (#2051) 381e9b3a6 bugfix: wrong memory size for the pernding timers array. (#2048) af130ae89 fix dead code found by coverity 8a8e710cb fix potential null pointer dereference found by Coverity (#2043) 86e1a6446 feature: content_by_lua_file return 503 if read err and file is existed #1992 (#1995) 653d6a36f bugfix: Apple Silicon FFI ABI limitation workaround bc2ecdae2 ci: add util/build-without-ssl.sh. (#2035) f0c04dbf6 bugfix: failed to compile when nginx https is disabled. (#2034) 6c0cc5c45 doc: did not generate README.markdown from doc/HttpLuaModule.wiki. (#2029) c1d378824 feature: add `server_rewrite_by_lua*`. (#2004) 3d1431790 travis: update openssl to 1.1.1n. (#2028) 8df296c47 travis: fixe the uri of lua-resty-core. 2b902657f cosocket: add function `tcpsock:setclientcert`, reimplemented `tcpsock:sslhandshake` with FFI 1fea11712 tests: use random port numbers instead of fixed port number to prevent conflict. (#2025) a7444abe8 tests: 160-disable-init-by-lua.t: prevent the test process from overwriting the original pid file. (#2024) 247086ed3 doc: describe the second argument of get_uri_args (#2023) d959374e0 optimize: use ngx_hash_t to optimize the built-in header look-up process for ngx.header.HEADER. 974d5d163 feature: add FFI implementation for ngx.arg getter (#2021) bd92edf3b doc: modify openssl patch requirements. (#2022) 496d98533 tests: change the count of the record after adding ngx.get_raw_phase. (#2019) 97d1b704d bugfix: ngx.pipe waits until timeout because child process forgot to close pipe after dup2. d001dea77 bugfix: posted event handler was called after event memory was freed. (#1982) 7d585bd53 bugfix: fixed size of the array when initialized in the init_worker_by* phase. (#2017) 66294b9d0 bugfix: ambiguous error message 'connection in dubious state' when connection is closed. (#2016) 77540f78c doc: change description for ssl_client_hello_by_lua. cee06592f doc: fixed link to lua-resty-core 15b693b33 bugfix: passing the wrong chunkname argument to luaL_loadbuffer. (#2010) 70a50e66c optimize: change lua chunkname to config filename and line number for (init/header_filter/body_filter)_by_lua_block and so on. (#2008) 907d1d9ad doc: modified the todo section. we now have exit_worker_by_lua (#2009) 297e73cde bugfix: the error message should use the first line rather than the last line of the code block when load lua code block failed. (#2005) 2615bafa3 bugfix: segment fault when get header via ngx.req.raw_header with malformed requests. 8cf9c632d travis-ci: upgraded openssl to 1.1.1m, pcre to 8.45. (#2002) 8b497f5a5 change: delete useless code for get old_cpath. (#2000) ce8405c73 bugfix: ngx.run_worker_thread injected api into the wrong table.(#1996) fa5982c63 tests: t/140-ssl-c-api.t failed because got wrong libssl.so. a41fdcea4 feature: add api to fetch raw nginx ssl pointer of the downstream request. 5f02311a9 feature: ssl/tls: support for passphrase protected key. (#1991) 7eb8ad025 bugfix: ngx.pipe waits until timeout because child process forgot to close pipe after dup2. 30debf674 doc: mentioned OpenResty. 320f03078 doc:move all the discouraged *_by_lua documentation to *_by_lua_block 1637b3534 tests: travis.yml: ngx-releng depends on ack. (#1986) f36fe2982 feature: expose the 'Last-Modified' response header as ngx.header["Last-Modified"]. (#1983) 75c68b225 bugfix: posted event handler was called after event memory was freed. (#1982) de09fc6cc tests: removed duplicated c declaration in t/140-ssl-c-api.t. 2fce8ca38 optimize: don't calculate hash when clearing the request header. 85388f4ef feature: check the number of parameters for ngx.thread.wait d0e56ca14 optimize: don't calculate hash when clearing the header. a27647626 change: use nil instead of false when lpush&rpush overflow. Co-authered-by: lijunlong<lijunlong@openresty.com> b67b22af8 feature: prevent calling ngx.exit() with invalid values. 0b6da3b6c feature: added ffi-based function 'ngx_http_lua_ffi_req_is_internal'. e98f5c508 doc: Clarify ngx.req.set_header usage for proxies. 5483b9157 feature: added http const HTTP_NOT_IMPLEMENTED, fixes #1466. Co-authored-by: lijunlong <lijunllong@openrestycom> 37ec9f756 doc: Readme: completed the Installation part, with add lua-resty-core and lua-resty-lrucache. 94fa662bc style: removed extra space. (#1981) 6302d4740 tests: NGINX_TEST_CHECK_LEAK detects memoryleak because nginx can not free resolver ctx quickly. This was introduce in commit acd53645754ce which is use to resovle double free of resolver ctx. This issue happens only when nginx can not get any reply from the dns server until timeout. 94dd3ac94 style: updated the indentation of .travis.yml according to the yaml specification. (#1976) 3229945a2 bugfix: prevent illegal memory access in ngx_http_lua_util.c. (#1974) ce8fd0268 tests: fixed test plan for 129-ssl-socket.t and 162-exit-worker.t. (#1972) 0b98a58ad tests: 132-lua-blocks.t and 158-global-var.t: use RegExp instead of strict character match. (#1971) 91907a0f3 bugfix: forgot to clean up the cached thread contexts when worker process exits. (#1968) 892ed514f tests: skip test cases for unsupported event types. (#1967) 9a93a3a0b travis-ci: bumped the NGINX core to 1.21.4. (#1964) 9e692e29c travis-ci: updated ftp.pcre.org to sourceforge mirror. (#1965) e68213328 tests: wrong pid path when running jobs greater than 1. (#1961) 751667913 style: changed the comment a bit. 931f62799 bugfix: ngx_http_lua_assert failure in ngx_http_lua_worker_thread.c. (#1960) 3f33dd862 optimization: removed superfluous code from shdict_store. (#1956) 560461e1f tests: updated the test cases in t/104-req-raw-header.t to reflect the changes in nginx. 913b5583b tests: updated the test cases in t/020-subrequest.t to reflect the changes in nginx. 0dffd1227 travis-ci: bumped the NGINX core to 1.21.3. 73181ca90 bumped the API version to 0.10.21. 617cb5dad style: removed extra space. (#1952) 557e0097d tests: remove workflows/label.yml since it is not working properly. (#1950) 59d39ca2f doc: fixed spelling errors in the docs and code. (#1947) ccc748eaf bugfix: fix nginx crash caused by a bad format specifier. a6e9e11f1 doc: fixed code style and test case style found by ngx-releng. aeaecd652 tests: added the missing test case which should be added in commit 5f47838e600. 5f47838e6 doc: clearify the missing the closing long bracket may due to the lua code is too long. 3f1c6834e bugfix: fixed memcpy param overlap detected by asan. c4d5ae71e feature: allowed some ngx APIs to be used in worker thread. 421a8da81 chore: fix possible null pointer dereference found by Coverity. c4a3e34fc bugfix: we should use luaL_typename() with lua stack index. 07e11f316 SSL: fixed potential leak on memory allocation errors. similar to https://hg.nginx.org/nginx/rev/8981dbb12254 If ngx_pool_cleanup_add() fails, we have to clean just created SSL context manually, thus appropriate call added. 7c60431a0 tests: travis failed due to the cetificat of Let's Encrypt expired. (#1939) acd536457 bugfix: nginx crash when resolve an not exist domain in thread create by ngx.thread.spawn.(#1931) c4ca52032 tests: ca-certificates of Let's Encrypt has expired. (#1937) 1ea5b09f1 feature: auto assign pr to project (#1772) 250f31d01 tests: the certificate of the Let's Encrypt has expired. (#1929) a3ec1565e bugfix: should reset the value_len to 0 when reuse the expired list type key in shared dict. (#1928) 5095da4a5 change: do not need to create the Lua request ctx data table from C (#1926) 5425d6d8e bugfix: we should ignore match limit in DFA mode. (#1924) fef25815f feature: implemented the ssl_client_hello_by_lua_block and ssl_client_hello_by_lua_file directives for controlling the NGINX downstream SSL handshake dynamically with Lua. 776f82910 style: fixed some of the code style issues and add code style checking for the ci. (#1916) 3820d0e11 bugfix: buffer bloat and CPU 100% when download large file was filtered by body_filter_by_lua. (#1909) 86514c1e4 bugfix: fixed missing 'const' qualifier causing compilation failure on freebsd. (#1914) a9cd21e94 travis-ci: upgraded openssl to 1.1.1l. c297cf69f tests: improve test cases robustness. 89818721f feature: implement the new ngx.run_worker_thread API to run Lua function in a seperated worker thread. 263bd0ca7 bugfix: should not allow to create timer in the exit process phase (#1907) b721656a9 bugfix: add nginx version condition for privileged agent connections. (#1903) 66a4d417d add privileged agent connections 53bd82199 travis-ci: remove clang compiler mode from travis. ccb0f8cc1 change: removed the openssl 1.0.2 in CI since it has been EOL ove a year, fix #1897. (#1899) bdd48a154 bugfix: we didn't exclude the ssl_verify_callback when compiling with LibreSSL (#1894) 223139d20 chore: fix typos introduced by PR #1890 (#1892) 6c1a2e95b bugfix: fixed typo introduced by 276f16af. (#1891) 276f16af4 feature: add lua_ssl_conf_command directive for setting arbitrary Ope… (#1890) f1b97e450 feature: support environ in ngx.pipe on mac (#1882) 6ed8e4b0f feature: allow to be compiled with LibreSSL 3.0+ (#1888) f72792234 doc: stripped line trailing whitespaces. (#1881) 68f6a1498 travis-ci: upgraded openssl from 1.1.1i to 1.1.1k. (#1868) 9007d673e bumped the API version to 0.10.20. dabc8e881 change: changed from graceful shutdown to abort when lua_resume return LUA_ERRMEM. d3a862642 tests: suspected memory leak of 160-disable-init-by-lua.t when test with TEST_NGINX_CHECK_LEAK=1 because forgot to close the file. (#1877) 14ef2cb25 doc: added sample config directives for internal redirects, as reported by Jason Hoch. b8d5b379f tests: added a new rule about 'ngx_pass_open_channel()' to valgrind suppression file. (#1874) dcc77fae7 doc: documented the scope of ngx.ctx for timer handlers. thanks Jason Hoch for the suggestion. 5b90b1fae doc: recommend to renew ngx.timer.at regularly (#1876) a43cc398a doc: sync doc from README to ensure wiki2markdown.pl is work (#1875) 1c1bcfeb9 travis-ci: bumped the NGINX core to 1.19.9. (#1870) eb944dedd bugfix: correct the way to handle invalid quote in ngx.escape_uri/ngx.req.get_{uri,post}_args (#1862) 2abb142d2 tests: fixed typo in 162-exit-worker.t. (#1866) 88a52c44a chore: fix possible null pointer dereference found by Coverity (#1846) 9a3176e93 chore: fix possible null pointer dereference found by Coverity (#1844) 4d2d47ce5 chore: fix possible null pointer dereference found by Coverity (#1845) 23e40f3fd docs: fix spelling (#1841) 138c1b964 src/ngx_http_lua_ssl_certby.c: fix possible null pointer dereference found by coverity 7bba6d195 bugfix: fixed memory leak in debug log. 8f12a28e2 updated openssl to 1.1.1i. (#1836) 60e95eff3 doc: added new youtube video on luajit bytecode precompilation. b9b39645f doc: added 1 more video. 99ea68a13 bugfix: we closed listener's fd which was closed. (#1832) d59afff27 doc: added our tutorial videos. 7105adaa5 bumped the API version to 0.10.19. (#1824) 83a61d6b4 optimize: post zombie thread: avoided the linear search. (#1823) 15197e7bb bugfix: accessed memory out of range when calling lua_pushfstring with none zero-terminated string introduced in commit 7367a231. 26809e75b tests: 106-timer.t: fixed test plan count. 98f482bfb bugfix: process may crash when a timer run failed and a function with arguments run inside this timer. (#1819) e497ffc68 bugfix: ngx.resp.set_headers(): may cause an error when Content-Length field is larger than 2^32. 411a9aed7 tests: 124-init-worker.t: made the test robust by changing the match pattern for TEST 22. (#1817) 4653f2182 bugfix: fixed segfault caused by an incorrect format token introduced in commit 3e24a95a. 65d875074 bugfix: wrong pipelined request body length when request body is parent's request body. (#1814) 8b9d7fdae travis: openssl: enable threads. 50de32e85 travis: upgraded openssl 1.1.1 to 1.1.1h. 843e20301 bugfix: ngx.flush never blocks on http v2. ea6b07cd6 feature: implemented the new tcpsok:setoption() function for setting options for the TCP socket. 8ae3e73f2 tests: --- shutdown_error_log should be excluded from repeat_each() when counting plans. 7bccbbff6 tests: skip t/163-signal.t under hup reload test mode. de1c3c63b bugfix: entry threads would leak when exceeding the lua_max_running_timers limit. this regression had appeared in commit 4de59f5da or v0.10.18rc2. e16d217a1 optimize: removed useless code for luajit without the lua_resetthread API. 186c84738 debug: added more debug info to monitor the main lua stack size in timer creation code. fdf752daf feature: added undocumented API for attaching arbitrary key-value pair data to a cosocket TCP connecton, which can survive connection pool reuse. 7367a2314 bugfix: ngx.resp.get_headers(): may return a wrong (like: negative) value of the Content-Length field when it is larger than 2^32. 57ebdd343 bugfix: should still use timer instead of delayed_events when worker process is exiting, otherwise the new created 0 delay timer may have no chance to run. ff8163423 optimize: added the "ev" to ngx_posted_delayed_events instead of the rbtree for 0 delay timer, so that we can save an epoll wait in such case. df4033d13 travis-ci: bumped the NGINX core to 1.19.2. (#1793) 0bccfb30f style: added "static" for the "ngx_http_lua_module_ctx" (#1794) 2c5b18933 feature: implemented the new ngx.ssl.server_port() API to get server port. d8b408a7f bugfix: build error with nginx 1.7.4 or older version 2d82f078a bugfix: we now only recycle light threads which are "entry threads" otherwise it is not safe to recycle user created threads since we have no idea whether the user may still hold refs to them. b28112130 optimize: now we make use of the new lua_getexdata2 and lua_setexdata2 to attach coctx to the Lua thread objects directly which save the lookup overhead which can become the bottleneck when there are many Lua light threads around in a single request handler. 021b75b88 travis: fixed the luajit branch. 4de59f5da feature: now we recycle lua thread GC objects for our "light threads" and added lua_thread_cache_max_entries directive to configure the cache size. 4695419bd bumped the API version to 0.10.18. ce30a0886 feature: added new C API ngx_http_lua_pcre_version to wrap the pcre_version() C API in libpcre. ef9e7507a updated .gitignore a bit. ac9836f97 bugfix: double values larger than int32_t were incorrectly printed out as 64-bit integers. 85fb9b839 test: make the 030-uri-args.t more robust since there is no fixed order in lua table. (#1797) 4d2a04a08 test: increased time unit to make test less error-prone db1999816 bugfix: the format in argerror messages are incorrect (#1787) 97b91899c bugfix: when recreating balancer buffer, remove existing buffers first (#1770) 172c2145e doc: fixed broken links. 9416eadfa doc: minor link tweaks. b1a3b5d16 style: removed a line-trailing space found by ngx-releng. 2db0e8246 doc: minor link tweaks. b4f464a90 doc: added a link to new blog post "Introduction to Lua-Land CPU Flame Graphs". e86d41f50 bugfix: added missing SSL feature macro (#1776) 218af5ee9 feature: shared ngx.ctx among SSL_* phases and the following phases. (#1514) d6a29d261 feature(socket.tcp): enhance the logic of parameter verification in connect 21cfd8ab2 doc: ported recent changes in mardkown to the wiki file. b0875fa8f doc: added more blog post links. 3e24a95a2 bugfix: the body size may overflow since the size_t is only int32 in 32-bit system (#1756) eeee4069e doc: ngx.var.VARIABLE is available in the balancer_by_lua* context (#1761) 49937fb69 doc: removed the useless semicolon in the example lua code 83bfe9157 doc: added a blog post link. f6b486b24 doc: fixed the wrong phase for lua_need_request_body (#1758) bdfc4bfc0 doc: removed the useless semicolon in the example lua code (#1757) e526caeeb feature: added the `ngx_http_lua_ffi_balancer_recreate_request` FFI function to allow recreation of request buffer in balancer phase. (#1734) c0e460a53 feature: add FFI interface to verify SSL client certificate (#1666) fd2547491 test: use official repo instead of third pard repo 393c95470 feature: added exit_worker_by* to run Lua code upon nginx worker process exit. (#1682) 1669904d5 * optimize: avoided use of lua_tolstring in ngx_http_lua_calc_strlen_in_table, ngx_http_lua_copy_str_in_table, ngx_http_lua_socket_udp_send, log_wrapper and ngx_http_lua_ngx_echo. b050e1c94 sytle: added blank line after code block. (#1752) af7484201 test: fix: add lua-resty-string to lua_package_path (#1748) 4368a8ea2 bugfix: macro contains operator should be wrapped inside a bracket. 635b6e864 feature: supported receiveany on ngx.req.socket(true?) socks (#1623) a4d63f7f7 refactor: used 'yieldable context' to simpify the context list. c366f3a9b doc: fixed an unclosed <code> tag breaking the markup. c48eeed50 tests: 161-load-resty-core.t: added vim mode line. 2d23bc4f0 bumped version to 0.10.17. 9ab38e8ee bugfix: prevented request smuggling in the ngx.location.capture API. 6913b1b1e doc: updated the Version section to reflect the release date. c2565fe79 tests: added test cases for sending HUP signal to nginx processes without the master process. aa548f538 tests: fixed an error message to reflect new changes in lua-resty-core. bb045f2d8 feature: ngx.escape_uri: added new optional 'type' argument not_component argument for pure URI escaping (still defauls to URI component escaping). 5d1517268 feature: ngx.req.set_uri(): added the 'binary' optional boolean arg to allow arbitrary binary data in the unencoded URI. 8746f6405 doc: ngx.req.set_uri_args: fixed byte ranges for automatic escaping. e1e335fd7 security: ngx.req.set_header(): now we always escape bytes in header names and header values which are prohibited by RFC 7230. be3531827 doc: more typo fixes. 2a6c9a63e doc: minor typo fixes. c6ffcfbf3 tests: added test cases for the nginx core patch static_mod_escape_loc_hdr. 785fb5709 feature: ngx.req.set_uri_args() now automatically escapes control and whitespace characters if the query-string is provided directly. 99a5a6bcb test: used the iptable -I option to insert rule to the head of the filter chain. f655b0e19 feature: add mergify.yml to manage our pr c86819f0b doc: updated the docs on the limits of subrequests to reflect recent changes in the nginx core. 8ac6cc728 doc: made the code examples more realistic (better for direct copy&paste use). d278043fb doc: added docs for working around memory fragmentation issues to the shdict:set() method. 23d2bc10a bugfix: ngx.req.set_uri_args() threw an exception with wrong argument info. 678988696 bugfix: set_by_lua_block allowed more than one arg (in addition to the block). 8c9968bd4 doc: fixed a few typos/wording issues in readme. (#1712) febd73006 travis-ci: bumped OpenSSL to 1.1.1g. 50c1912ef misc: ngx_http_lua_logby.c: removed duplicate headers. 6e48a804f style: ngx_http_lua_socket_tcp.c: ensured two blank lines between functions. 896638287 style: fixed a minor styling issue in 'ngx_http_lua_initworkerby.c'. efd284106 travis-ci: bumped OpenSSL to 1.1.1f and fixed older versions downloads. beb5c6ba0 bugfix: allow the use of spaces in 'ngx.req.set_uri()'. 6d270c32f doc: fixed the return value name in 'ngx.worker.id()' documentation. 66026039d doc: clarify ngx.timer.every callback argument conventions, #1409. f991f3e10 travis: fixed the warnings from build config validation. f45d4e999 bugfix: overrided the input header only for the first time f6ff2890c misc: avoided warnings with old gcc versions due to incorrect inline definition and renamed functions for clarity. 3908769d3 travis: upgraded pcre to 8.44. ada56de57 updated .gitignore. 79b3bd3cf config: more followup fixes in autoconf feature tests. 3a37c9c61 bugfix: FFI availability feature test was broken on Windows. 38f587a35 bugfix: ensured arguments of APIs mutating uri or request/response headers do not contain unsafe characters. (#1654) be864c2af travis-ci: upgraded OpenSSL to 1.1.1e. 43220429e tests: fixed numbering thanks to the reindex script. ec3b219e6 tests: fixed a newly failing test due to changes in openresty.org accepted ciphers. 4c4bb0fcb bugfix: fixed use of uninitialized cache_key in ngx_http_set_by_lua_file. 52f0d95fa doc: sync the minor change (in the last commit) to README.markdown from the HttpLuaModule.wiki file. 6b79cd441 doc: minor grammar typo fix (#1642) (#1643) 9259e7a34 tests: 139-ssl-cert-by.t: relaxed timing test cases for tvw test mode. 8669e0985 bugfix: ngx.pipe: ensured reading while a process died returns the "closed" error. 743773bfb tests: fixed a newly failing test due to openresty.org now rejecting TLSv1 connections. 1d9298d64 bugfix: fixed use of an uninitialized value in ngx_http_lua_set_by_lua_file. 028c0d495 doc: mentioned that 1.17.8 is the latest NGINX core version tested. c06793c3e travis-ci: bumped the NGINX core to 1.17.8. d328e5620 tests: 025-codecache.t: updated a test case to avoid error logs in stderr. c2390abb5 Revert "bugfix: ensured 'init_worker_by_lua*' does not mutate another NGINX module's main_conf." e32864543 change: we now ignore 'lua_regex_*' directives when NGINX is compiled without PCRE support. 8f518e7d9 travis-ci: bumped OpenSSL to 1.0.2u. 760f7073d feature: implemented the FFI interface for the 'ngx_req.add_header()' API. 7c5b11d73 tests: 124-init-worker.t: fixed a few failing test cases. a3ac3f557 style: updated 'nginx_version' guard macros assuming it is always defined. 771eb231e misc: ngx_http_lua_util.h: removed 'ngx_str_set' definition as it is defined in NGINX 1.6.0+ d1e55394e misc: removed dead code, guard non-OpenResty LuaJIT definitions, and fixed styling issues. 478bae6fc doc: readme: mentioned that the latest tested NGINX core is 1.17.4. 4e593c335 travis-ci: bumped the NGINX core to 1.17.4. 69780f676 bugfix: config: fallback to '--undefined' option for ld 2.25 and below. d062170e9 feature: implemented the 'ngx.crc32_short' and 'ngx.crc32_long' C FFI APIs. 50dabbc3a travis-ci: bumped OpenSSL versions to 1.0.2t, 1.1.0l, and 1.1.1d. fd1e0f89e feat: config: added a check for Lua language version 5.1. 9b224957f doc: readme: minor updates to align with the ngx_stream_lua module README. 4c943b944 tests: 087-udp-socket.t: removed a duplicated test case. 70484bcbe tweaks: ported adjustments and missing test cases from the ngx_stream_lua module. 315330ac0 bugfix: config: ensured LuaJIT FFI check and static PCRE builds succeed on all platforms. 2a190736a change: removed error logging on coroutine runtime errors. 9a892b8d5 bugfix: coroutine.wrap: propagate errors to the parent coroutine. c658e2260 tests: 139-ssl-cert.t: added test cases asserting support for 'ngx.thread.kill()' and 'ngx.socket.udp' in 'ssl_certificate_by_lua*'. 97f0101e5 feature: enabled the 'ngx.thread' and 'ngx.socket.udp' APIs in ssl_session_fetch_by_lua*. 97431d814 bugfix: fixed compilation with NGINX cores < 1.11.11 189ba24ef feature: when a timer fails to run we now log the location of its function's definition. 4b9e53f74 feature: ngx.pipe: allowed for calling resty.core 'ngx_pipe.shutdown()' on a sub-process when a light thread is waiting on it. 8573c1c5d feature: ngx.pipe: allowed for specifying timeouts in resty.core 'ngx_pipe.spawn()'. d154e5a7c doc: readme: removed all mentions of PUC-Rio Lua and fixed styling and grammatical issues. c5135a051 change: removed compatibility code for unsupported NGINX versions (< 1.6.0). 947fa0088 change: retired the old CFunction API when newer FFI implementations are available. 60736e686 change: 'resty.core' is now mandatorily loaded, and the 'lua_load_resty_core' directive is deprecated. a96e99ab1 change: we now prevent compilation with PUC-Rio Lua; only LuaJIT 2.x is supported. 2f270642b bugfix: fixed file cache key size allocation. 6b3822b18 bugfix: added missing arguments to an 'ngx_log_error()' call in ngx_http_lua_pipe.c. 9fa316f50 tweak: updated the debug log in 'ngx_http_lua_socket_tcp_conn_op_ctx_cleanup()' to align with the meta_lua module. ba182dd59 style: fixed some minor styling issues to align with the meta_lua module. eed28fca8 optimize: fixed the pre-allocated number of keys in the 'ngx.socket.tcp' table. 6c25b7bea optimize: removed declaration of obsolete 'ngx_http_lua_inject_logby_ngx_api' function. d313bf8de bugfix: ensured the 'pcre_version' symbol is also preserved on Darwin platforms. c618d0d23 bugfix: fixed compilation errors encountered with ngx_stream_lua due to a recent commit. 881bf91da bugfix: ensured arguments of APIs mutating response headers do not contain '\r' and '\n' characters. 246ec8ac4 refactor: simplified Lua chunk and file cache key generation. f45908cd3 refactor: reduced cache key size by removing unnecessary chunkname component. bd83c656d tests: codecache.t: moved and reinforced a test case ensuring *by_lua directives with identical Lua chunks produce distinct cache keys. 0c755ed89 bugfix: ensured set_by_lua_file with nginx variables re-computes closures code cache key. 39c2ead3c optimize: improved code cache lookup performance by using 'luaL_ref()' to avoid the costly 'lj_str_new()'. bf11f67d8 tests: codecache.t: added tests for code cache behavior with *_by_lua_file directives containing NGINX variables. e42f9b5f6 doc: updated the section on OpenSSL and NGINX patches in the 'ssl_certificate_by_lua*' documentation. 09484e8fd bugfix: ensured 'init_worker_by_lua*' does not mutate another NGINX module's main_conf. b6875300b doc: mentioned that we support NGINX 1.17.x. cf77a42c4 doc: removed TODO items that have been taken care of. de60e555a travis: added OpenSSL 1.1.1c to the tests matrix. 467f0134d tests: added tests asserting that 'ssl_certificate_by_lua*' and 'ssl_session_fetch_by_lua*' can yield when reading early data. d3dbc0c81 bugfix: skipped 'ssl_session_store_by_lua*' and 'ssl_session_fetch_by_lua*' when using TLS 1.3. 2014dd80f bugfix: ensured the 'pcre_version' symbol is preserved as undefined when PCRE is statically linked. 277d382f5 api: bumped API version to 0.10.16. 2524330e5 travis-ci: bumped the NGINX core version to 1.17.1. 65bdd4a83 tests: 139-ssl-cert-by.t: downgraded error log level of SSL handshake failures from 'crit' to 'info'. 4e974ba96 doc: updated ssl_session_fetch_by_lua_block documentation around OpenSSL and NGINX core patches. b0c737391 Revert "feature: added OpenSSL 1.1.1 support to ssl_session_fetch_by_lua*." 81344434a doc: fixed a mistake in ngx.location.capture() example in README.md. 32dd6a34a style: fixed a minor alignment issue in ngx_http_lua_ssl_certby.c. 59b6430f7 bugfix: LuaJIT sets currentline to -1 if it is unavailable. a38d90667 feature: added OpenSSL 1.1.1 support to ssl_session_fetch_by_lua*. 3a5872969 travis-ci: bumped OpenSSL to 1.0.2s and 1.1.0k. 33a5517c9 tweak: fixed some warnings from the clang static code analyzer. 4102b82cd tests: 161-load-resty-core.t: added a test asserting the directive honors 'lua_package_path'. 1882c30a0 doc: we now work with nginx 1.14.x and 1.15.x. a7afd56c6 feature: added support for specifying environment variables in ngx.pipe spawn() FFI API. 1c756b385 doc: fixed a mistake in tcpsock:receiveany() example in README.md. 30678fd5b tests: ssl-socket.t: fixed a failing test case due to openresty.org's default cipher. 441c7f626 tests: re-enabled a test case for using ngx.re.match in init_by_lua*. 28cf5ce3b feature: added the FFI API for 'str_replace_char()'. f87d1f165 bugfix: ngx.pipe: cleared the pending event after aborting the uthread. 86941a706 tests: 123-lua-path.t: fixed a few test cases failing in EC2 to-ngx_lua suite. 7be0a4dc9 doc: fixed a typo in README.md. 61e4d0aac tests: fixed a few failing test cases due to loading resty.core. fccf383ae tests: fixed default lua path to load resty.core from many test cases. 87f0a09a6 feat: implemented the lua_load_resty_core directive which loads resty.core by default. 7ac6f3f67 doc: fixed a typo in a comment from ngx_http_lua_common.h. 95a2e59bf tests: removed obsolete drizzle upstream block in init.t. 12d991e18 api: bumped API version to 0.10.15. afeeb84b0 bugfix: ngx.pipe: fixed a segfault when error_log is configured with syslog. 2bc20ccb0 travis-ci: switch to xenial image 15b01c66f tests: fixed the tests using iscribblet.org which would time out now. a92cf7255 tests: fixed failures due to recent CDN changes. 83ca6b57a doc: bumped version to 0.10.14. ee47e55eb bugfix: ngx.pipe: proc:wait() returns false only when the sub-process exited abnormally. c368af2f0 tests: 159-sa-restart.t: avoided sending SIGWINCH to the test nginx worker process. 761ddca72 bugfix: ensured we cleanup up aborted queued connect operations. 8edb21abc bugfix: only update connections count when cosockets are truly associated with the socket pool. fd90f4e82 doc: one followup tweak. 4ebab2b8a doc: emphasized that this module is a core component of OpenResty. cf887654a tests: switched to 127.0.0.2 instead of agentzh.org for timeout-related tests. 01735c27f tests: hardened a few flaky test cases from recent CI runs. 70dd0bee4 tests: fixed a test case in 068-socket-keepalive.t which always fails when a local dns server is running. 9750a8173 tests: fixed new test failure due to openresty.org server changes. b2af4d369 bugfix: inlined Lua code snippets in nginx.conf failed to use the Lua source checksum as part of the Lua code cache key. thanks Oleg A. Mamontov for the report in #1428. f627f4c54 tests: t/160-disable-init-by-lua.t: hardened test suite to prevent false positives. 055bb17c6 bugfix: fixed a segfault introduced in 7c2b58e when testing an nginx configuration containing 'lua_shared_dict' directive(s). aef03eb33 feature: added the C API to support the 'ngx.pipe' module provided by lua-resty-core. 2c8984934 travis: bumped the nginx core version to 1.15.8. bd9964e7f tests: fixed some test cases failing with the 1.15.8 nginx core. c2940c132 feature: added backlog queueing to cosocket connection pools. 2fb8f120c feature: added support for the Nginx builtin Link header. 248060b81 feature: errors are now logged when timers fail to run. 7c2b58ee7 change: we now avoid running init_by_lua* in signaller processes and when testing the nginx configuration. e76292dee tests: reindexed the t/158-global-var.t suite. fbb891930 change: we now avoid generating the Content-Type response header when getting all response headers. cec2a09de bugfix: ensured Content-Type header gets generated when other headers get set. 637a4c645 doc: updated the copyright year to 2019. 017e00462 bugfix: we now avoid generating a Content-Type header when getting/setting other response headers. ab2e2718b tests: updated the test suite so that it can be run in parallel mode. 5d924cc63 tests: require: hardened lua_path and lua_cpath regexes. f63af5dc0 travis-ci: upgraded openssl to 1.0.2q and 1.1.0j. 11a31b540 tests: increased the timeouts of some ssl cosocket tests. ec0d5768b doc: noted that ngx.req.get_method can be used in the body_filter_by_lua* and log_by_lua* phases. 60225ad19 bugfix: the lightuserdata mask was broken in WIN64. b4ade7887 bugfix: we now only apply the lightuserdata mask on platforms that are at least 64bits. 1c72f57ce feature: added an FFI API for retrieving env 'directives' values. 2f7c65009 feature: implemented a new 'lua_sa_restart' directive, which sets the SA_RESTART flag on nginx workers signal dispositions. c65f5738a bugfix: the 'dd' calls in ngx_http_lua_util.h are now guarded by '#ifdef DDEBUG' . 3754757be change: we now print an alert when a non openresty-specific version of LuaJIT is detected since many optimizations would be missing. 1a73e0ab7 doc: ported the Lua 5.1 interpreter removal to the wiki document. 08a9baa92 bugfix: ngx.process: process.type() didn't return 'master' in master process. 09a365460 tests: declared many variables as local to avoid triggering the new _G write guard. 5efd95d79 doc: updated the docs to reflect the change that we now no longer support the standard Lua 5.1 interpreter in this module. also recommended OpenResty's LuaJIT branch version instead of the stock LuaJIT. c9eca03eb misc: updated _G write guard message to be more accurate. 84338ab85 typo: fixed a debug log in access and rewrite handlers. ebfa66ceb misc: rename a test file to be properly ordered. d067594ca bugfix: silenced -Wcast-function-type warnings. 728681211 feature: added support for ARM64 (Aarch64). f64ec8c90 bugfix: tcpsock:setkeepalive: worker processes might take too long to gracefully shut down when the keep alive connections take a long max idle time. e94f2e5d6 bugfix: fixed segfault in NGINX core >= 1.15.0 when init_worker_by_lua* is used. 576a10d24 doc: mention that ngx.req.set_body_data() and ngx.req.set_body_file() must read the request body. 8ba33dac0 optimize: removed a duplicated include directive in ngx_http_lua_regex.c. 55743aeba bugfix: when variable is cacheable and indexed, setting the request "Host" header should clear any existing cached $host variable value so that subsequent reads return the expected result. 70b843f82 tests: upgraded openssl version to 1.1.0h. 6bbfffdec tests: we failed to enable master process when configuring multiple workers. 9112536b1 api: bumped API version to 0.10.14. b5ffb11fe feature: implemented the receiveany() upstream cosocket method. 5a3c48d23 doc: fixed the links to ssl_session_store_by_lua_block. 15e93a11e restored the change in commit 4ff3dd14ed since it only changed the auto-generated README.markdown. alas. 612931c0f doc: bumped version to 0.10.13. 0605709c3 bugfix: fixed compatibility regressions on Win32. this regression had appeared in commit 012f3163e. f341daa26 api: bumped API version to 1.10.13. 52af63a5b feature: ngx.req.get_post_args(), ngx.req.get_uri_args(), ngx.req.get_headers(), ngx.resp.get_headers(), and ngx.decode_args() now would return an error string, "truncated", when the input exceeds the max_args/max_headers limits. 19cc6bf8f tests: fixed a test case that cannot be run in parallel test jobs. 4ff3dd14e doc: fix the link to ngx.ocsp's docs. 288ebdb93 doc: bumped version to 0.10.12. 91a0ad236 optimize: switched exptime argument type to 'long' in the shdict FFI API to mitigate potential overflows. 5196e6551 tests: remove google.com relevant ssl certificate test cases. 9ea1c06a6 feature: ngx_http_lua_ffi_set_resp_header(): now add an override flag argument to control whether to override existing resp headers. 53519cd7a feature: allowed sending boolean and nil values in cosockets. 6d4475ae3 tests: increased timeouts to avoid failing in mockagain writing test mode. 809192c96 feature: api.h: exposed the ngx_http_lua_ffi_str_t type for other Nginx C modules. 23e69fb20 bugfix: ngx_http_lua_ffi_ssl_set_serialized_session(): avoided memory leak when calling it repeatly. 5cd103b1f optimize: avoided the string copy in ngx_http_lua_ffi_req_get_method_name(). 80fa32c8d feature: added support for the 308 status code in ngx.redirect(). 439a02ab9 typo: fixed an error message typo in set_der_priv_key(). bb76eb123 change: switched to SSL_version() calls from TLS1_get_version(). feae6e775 doc: mentioned that OpenResty includes its own version of LuaJIT which is specifically optmized and enhanced for OpenResty. 3cde1d8aa doc: fixed some code comment typo. a698cb098 doc: updated the NDK repo URL to github.com/simplresty. 3078ca613 bugfix: we now throw a Lua exception when ngx.location.capture* Lua API is used inside an HTTP2 request since it is known to lead to hanging. df1b0198f optimize: corrected the initial table size of req socket objects. 988756924 tests: removed duplicate entries in valgrind.supress. 00b92b3d0 style: fixed minor coding style issues found by ngx-releng. fcd0deaff ssl: support enabling TLSv1.3 via lua_ssl_protocols. 9e5cc6e23 bugfix: nginx rewrite directive may initiate internal redirects without clearing any module ctx and rewrite_by_lua* handlers might think it was re-entered and thus it might lead to request hang. thanks twistedfall for the report in #1235. 90d752234 doc: added the new 'init_ttl' argument to the shdict:incr() documentation. a46862afe doc: updated the copyright years in markdown as well. 11aa4636b bugfix: avoided sharing the same code object for identical Lua inlined code chunks in different phases due to chunk name conflicts. e343b3a14 tests: updated valgrind.suppress for latest glibc. c2b6ae2ae doc: updated the copyright years. d125123f8 tests: updated more uses of the server IP addr for agentzh.org to reflect recent changes. 051f35240 doc: setting ngx.header.HEADER no longer throws out an exception when the header is already sent out; it now just logs an error message. 9a3bbb6f2 tests: updated the server IP for agentzh.org to reflect recent changes. 071bb0ff6 doc: typo fix: fix core constants "NGX_XX" to "ngx.XX". 468403e37 feature: added the "init_ttl" argument to the pure C function for the shdict:incr() API. 5f6e74061 feature: added pure C APIs for the remaining time related Lua APIs (for lua-resyt-core). 6d0ecd617 doc: typo fix: fix "\d+" to [[\d+]]. cf5fb9823 tests: corrected the No SNI, No verify case in 129-ssl-socket.t. 01b314522 travis-ci: enabled openssl-1.1.0g builds. 7c8c50300 bugfix: fixed compatibility with older OpenSSL versions like 0.9.8 and 0.9.7. this regression had appeared in commit 7f108923b. 858753bb0 travis: upgraded pcre to 8.41 and openssl to 1.0.2n. 7f108923b feature: added support for OpenSSL 1.1.0. e51a4739a doc: typo fix: fix constrolled to controlled. 34d929857 bugfix: ngx.req.raw_header(): the first part of the header would be discarded when using single LF as delimiter and the number of headers is large enough. c2f68a48e style: minor coding style fixes suggested by our ngx-releng tool. 99a5ba212 feature: added a pure C API function ngx_http_lua_ffi_raw_log for ngx.errlog module's rawlog() function in the lua-resty-core library. 51b7d649a feature: added pure C API function ngx_http_lua_ffi_master_pid() for the get_master_pid() Lua FFI API in ngx.process of lua-resty-core. 20ffd853e feature: implemented pure C function for the pure FFI version of the ngx.get_phase() API function in lua-resty-core. b1b1504ac tests: fixed broken SSL tests due to switch in CA for openresty.org. d6aa6ea1c tests: fixed typos in test tiles in t/124-init-worker.t. 81e140c59 bugfix: pure C API for ngx.var assignment: we failed to output the error message length. 18b5de576 bugfix: the upper bound of port ranges should be 65535 instead of 65536. 9de3dc7ef tests: updated the expected debugging log message for freeing cosocket connection pools. de3b7def1 feature: added pure C API for fetching client address in the SSL handshake phase. 4577a6fbc bugfix: freed all connections when cleaning up socket pools. 4e1a9e1d4 tests: relaxed the checks to account for timing races in error logs from multiple cache helper processes. 927961250 bugfix: use of lua-resty-core's ngx.re API in init_by_lua* might lead to memory issues during nginx HUP reload when no lua_shared_dict directives are used and the regex cache is enabled. 012f3163e optimize: destroy the Lua VM and avoid running any init_worker_by_lua* code inside cache helper processes. 7c7b2e0b1 api: bumped version to 0.10.12. 91d2cd61a bugfix: fixed a compilation error with nginx cores older than 1.11.2 due the lack of the ngx_inet_get_port() C API function (which was first added to nginx 1.11.2). thanks sumantdas for the report. 4f76a377e feature: logged the tcp cosocket's remote end address when connect() times out and lua_socket_log_errors is on. 54135a03e travis: always find out the external IP address of the current travis ci node to help debugging network issues. 7dc97df41 change: fixed a typo in a comment in ngx_http_lua_rewriteby.c. b2aae31a8 tests: use larger timeout threshold values for more openresty.org ssl tests. 3eb1d2f64 tests: use longer timeout threshold. 8af77d3ca doc: we should also work with nginx 1.12.x. ba2b60593 doc: we now work with nginx cores as new as 1.13.6. ed2c9f8e4 release 0.10.11. c6089171d tests: added full GC cycle operations to avoid false positives in the "check leak" test mode. 4b871b45e tests: made one stap-based test case less possible to fail due to timing error. 38780280c updated valgrind suppressions for the hv test mode. 5f766faf0 tests: added new valgrind false positives in the latest nginx core. fd5201c57 tests: valgrind.suppress: removed too aggressive suppressions in nginx mem pools and luajit lj_str_new. 201f7c051 travis: bumped nginx core version to 1.13.6. 7730490c1 dev: util/build.sh: now we require ngx_stream_lua_module to build (for testing and development). 56d309881 bugfix: add fallthrough comment to silence GCC 7's -Wimplicit-fallthrough. 5900df4a6 doc: added "413 Request Entity Too Large" to the possible short circuit response list. 8dd4bdef6 doc: fixed strike-through in shdict.free_space. f829065b7 feature: shdict: added pure C API for getting free page size and total capacity for lua-resty-core. 59dff5eec tests: suppressed one more false positive. 97fbeb0be bugfix: the ssl connections might be drained and reused prematurely when ssl_certificate_by_lua* or ssl_session_fetch_by_lua* were used. this might lead to segmentation faults under load. thanks guanglinlv for the report and the original patch in #1162. bf14723e4 tests: fixed a test case that might fail due to timing errors. 0c8df2fa6 Revert "tests: try to make a test case less possible to fail on slow machines." e5d7fc9fd tests: try to make a test case less possible to fail on slow machines. 93d1f30c3 bugfix: a followup fix for the previous commit. afbfe4cf7 bugfix: the timeout overflow checks did not work on 32-bit systems. aee660bdf bugfix: suppressed the gcc warning "comparison between signed and unsigned integer expressions". 4bbf39928 travis-ci: fixed the IPC::Run dep for Test::Nginx and also added nginx 1.13.5 to the matrix. 3266b40c7 doc: typo fix from dongbeiouba in #1158. 1d01a6d66 doc: documented the shdict:ttl() and shdict:expire() API functions. 37cbafe4e tests: minor tweaks for the http2 test mode. 9a81a6864 feature: added pure C functions for shdict:ttl() and shdict:expire() API functions. c338c7b3f api: bumped version to 0.10.11. ac7615a28 dev: util/build.sh: specify --with-pcre-jit for the nginx build. 837cecb64 tests: fixed ssl ciphers to reflect recent changes in openresty.org's mini CDN network. 1626aaa78 bugfix: *_by_lua_block might break nginx config dump (-T switch). c97473b5e bugfix: segmentation faults might happen when pipelined http requests are used in the downsteram connection. thanks Gao Yan for the report. 36d6ef406 bugfix: tcpsock:connect(): when the nginx resolver's send() immediately fails without yielding, we didn't clean up the coroutine ctx state properly. 77a285163 bugfix: tcpsock: settimeout/settimeouts: throw an error when the timeout argument values overflow. 3fc5aea08 doc: simplified a Lua function call a bit. aee499ac2 doc: minor fixes. e96aec767 doc: fixed the stale Lua module preloading docs as reminded by Denis. b87ad242d tests: skipped a test case which is known to leak memory when lua_code_cache is off. e9609d25c valgrind: suppressed a known false positive inside the nginx core. cdd2ae921 bumped version to 0.10.10. 7b7178a95 bugfix: fixed a compilation error on Windows. this regression had appeaered in 0.10.9. 89de78022 doc: bumped version to 0.10.9. 82b218871 tests: made 2 test cases less possible to fail on slower machines. 691370ec2 Revert "bugfix: ngx.escape_uri: we did not escape URI reserved chars. #1124" f17050518 bugfix: ngx.escape_uri: we did not escape URI reserved chars. #1124 0f0af5094 doc: fixed a typo in a code example for `ngx.re.match`. 51c14a898 bugfix: segmentation fault might happen when a stale read event happens after the downstream cosocket object is closed. thanks Dejiang Zhu for the report. 2fd469d46 refactor: removed the duplicate C function decelaration for ngx_http_lua_socket_read_handler. c26854856 tests: added a test case to make sure $proxy_add_x_forwarded_for is accessible on the Lua land. 1e71ff2cb tests: fixed the vim mode line in a test file. a50947667 bugfix: ngx.semaphore: when nginx workers exit, the harmless error message "semaphore gc wait queue is not empty" might be logged. cc0a793a2 ocsp: removed a useless line of code, which unbreak the libressl build. thanks Kyra Zimmer for the original patch. ef4a0b1db tests: skipped the test case for lua_code_cache off + ngx.timer.every in the "check leak" test mode since there is a known memory leak in this case. 720bd5dbb bugfix: the fake requests/connections might leak when memory allocations fail. c372e1cc0 optimize: made ngx_http_lua_log_ringbuf_header_t have the same size on linux i386 and x64. 67664fef0 minor coding style fixes. e84d69b26 tests: made a slow test less possible to time out on slow machines. 81b8e4823 tests: made a test less possible to fail due to timing error. 4527ec0bb tests: relaxed the expected ouptut constraint in tests for testing ssl host name mismatch. 8827a7f83 bugfix: segmentation fault would occur when several server {} blocks listen on the same port or unix domain socket file path *and* some of them are using ssl_certificate_by_lua* configurations while some are not. thanks petrovich-ua for the report and original patch in #1055. bb30f6d8b bugfix: ngx.escape_uri() did not escape "|", ",", "$", "@", and "`". 3294b1dfd bugfix: ngx.encode_args() did not escape "|", ",", "$", "@", and "`". 66f073128 bugfix: fixed several bugs in ngx_http_lua_log_ringbuf.c. 20d6558b0 feature: balancer_by_lua*: now the user Lua code can terminate the current request with arbitrary HTTP response status codes via ngx.exit(). df708216c feature: errlog capture: now we also record the UNIX timestamp (in sec with msec precision through the decimal part) for each error log entry. 031e00004 doc: use the .ljbc file extension instead of .luac for LuaJIT bytecode files. 9cb970978 tests: updated tests on ssl cosockets to reflect recent changes in our CDN network. 6f49242a8 fixed tests to reflect recent changes. 2360565f5 doc: fixed some typos detected by misspell. 69d995513 bugfix: the running timer counter might go out of sync when non-timer handlers using fake requests are involved (like ssl_certficate_by_lua* and ssl_session_fetch_by_lua*). 7a8798437 feature: added pure C API function +ngx_http_lua_ffi_errlog_get_sys_filter_level for ngx.errlog module's get_sys_filter_level() function in the lua-resty-core library. e80d29257 tests: ssl: avoided those domains using startcom ssl certificates. 993aec8eb refactor: removed the obsolete util/gdbinit script script. we have much better tools in openresty-gdb-utils already. 0c2979399 doc: made it explicit that shdict methods are all atomic. c1317e412 travis-ci: we no longer want to cover nginx 1.9.15. 2dd44623d feature: ngx.sleep(0) now always yield the control to the nginx event loop. 9b16e254e feature: implemented the ngx.timer.every() API function for creating recurring timers. 2a8770493 feature: added new pure C API ngx_http_lua_ffi_process_signal_graceful_exit() for the signal_graceful_exit() function of the ngx.process module in lua-resty-core. 76e213897 change: renamed the C API function ngx_http_lua_ffi_errlog_get_logs to ngx_http_lua_ffi_errlog_get_msg. eb0bb2853 lua_capture_error_log: various documentation fixes and API name changes. ab63ba8df change: renamed lua_intercept_error_log directive to lua_capture_error_log. 4ed1f9605 doc: added more material on capturing error log filtering. 8d8f2c24a doc: documented the lua_intercept_error_log directive. 1a5a33e61 feature: added new config directive lua_intercept_error_log for capturing nginx error logs on Lua land. 6a2b4ff55 doc: a typo fix from Oleg Abrosimov. edbded405 change: bumped API version to 0.10.9. 23cb8e832 travis-ci: enable -msse4.2 when building luajit2. b98da9a19 feature: added pure C functions ngx_http_lua_ffi_worker_type() & ngx_http_lua_ffi_worker_privileged(). f5633cacc feature: added pure C API for tuning the jit_stack_size option in PCRE. c03462637 change: removed util/reindex. put it into the openresty/openresty-devel-utils repo instead. ca8ed0e8c doc: minor tweaks. 39bec7f40 doc: minor tweaks. 6c7ac361f doc: more tweaks in the Installation section. c7d9691e5 doc: more tweaks in the Installation section. 398db9517 doc: more fixes in the Installation section for OpenResty. 55f91d782 doc: updated the Installation section to reflect recent changes. e39e44291 bugfix: fixed typos in error messages. 0459a285c feature: nginx 1.11.11+ can now build with this module. 4b7249342 tests: added passing test cases for testing Lua errors thrown in init_by_lua*. 975c3f838 bumped version to 0.10.8. 385ae4cd1 tests: a followup fix for the previous commit (2ba183d3). 2ba183d3c tests: made a test for duplex cosockets less sensitive to timing error. 94248d64e tests: added valgrind suppression rules for false positives in nginx 1.11.11+ and pcre 3.40+'s JIT compiler. 844e842cb change: removed the use of luaL_getn() macro as it is no longer available in the latest LuaJIT v2.1. fixes #1029. 113d13809 bugfix: lacking the fix from #936 in the C API for lua-resty-core. #1031 6b01840dc change: disabled the mmap(sbrk(0)) memory trick since glibc leaks memory when it is forced to use mmap to fulfill malloc(). 743a10ab0 travis-ci: avoided installing the Test::Nginx perl module; just use it right away. 312bf3ed1 tests: avoided flooding google dns servers in the check leak test mode. 8a6448a39 travis-ci: upgraded pcre to 8.40. 38dd154a7 doc: ngx.exit() also returns immediately in the balancer_by_lua* context. thanks Jinhua Tan for the patch in #1012. 2fd7daa69 bugfix: typo fix in C POST args handler debug log. fdbfdaecf semaphore: fixed a typo in a code comment. e86dd9662 doc: added more hints as comments to installation commands. 11495c28a util/reindex: tweaked the regex to avoid useless substitutions. this is a followup fix for commit 772e6fd. 3217a0781 util/reindex: fixed the shebang line. 2e7031f01 util/reindex: fixed the author and copyright notice. 772e6fdaa tests: removed superfluous empty lines at the end of the test files. 32fea9e66 util/reindex: trims the extra newline characters at the end of the test file. 7f9387ced doc: fixed a typo. a14b9cd37 doc: various wording tweaks and more code examples. e73cd4b90 tweak: guarded SSL related function declarations with the macro NGX_HTTP_SSL. 4fb510f5f fixed a function parameter name. e958cb2ca tests: fixed a bug in testing the nullness of cdata pointers. 827a5d6f8 feature: fixed build compatibility with BoringSSL. 5ae4aba83 travis-ci: upgraded openssl to 1.0.2k. 1028333e4 travis-ci: added checks for use of tabs and source lines exceeding 80 cols. 0c3706298 fixed a coding style issue in the previous commit. 5c54198a3 bugfix: tcp cosockets: sslhandshake(): typo in the error message. 1ada6d0e5 tests: require PCRE 8.39 instead of 8.33 to run our test suite. 39783100f feature: tcpsock:connect(): allows the options_table argument being nil. 5fdbb56ad bugfix: setting response headers would change the Content-Type response header. b3c872e12 added a passing test for #853. da11870db bugfix: balancer_by_lua*: the number of retres might exceed the limit of proxy_next_upstream_tries or alike. 5028d6353 doc: updated copyright notice. 3cf706236 travis-ci: cosmetic "wget" improvement. e7031127e feature: added support for the 303 status code in ngx.redirect(). 6e38c11eb tests: disable IPv6 in resolver. 9ed76a732 travis-ci: several improvements. 26be99def tests: t/090-log-socket-errors.t: avoided connecting to 8.8.8.8:80. 7c9503493 tests: added a passing test for ngx.re.find + \G regexes. db28ece8e doc: a typo fix from Andrei Belov. aa43ca063 doc: stripped line trailing whitespaces. 793531df5 doc: removed ngx.re.split() from TODO section since it is already implemented in ngx.re. 5e59e8c89 bugfix: compilation failures with nginx cores older than 1.9.0. 4bc904222 tests: fixed a perl warning "Unescaped left brace in regex is deprecated, passed through in regex". a24db2cb9 tests: ngx_http_fake_module: removed the coyyright notice since the copyright is already granted. 38dfb174a tests: fixed a bug in the example ngx_fake_delayed module. thanks Dejiang Zhu. also removed the copyright notice in this module since it is already granted. 0a83639f1 tests: avoided solving IPv6 addresses in more tests. 3b42b8bb8 tests: avoided solving IPv6 addresses. 0a1de31ff bugfix: C API: ngx_http_lua_add_package_preload() might not take effect when lua_code_cache is off. ce525fb50 tests: made tests less likely to fail due to bad network. 75b03949c doc: added a note about the LRU regex cache used in the ngx.re.* implementation of lua-resty-core. 006432488 doc: bumped version to 0.10.7. 3cbe5be4a tests: skipped the newly added test case that cannot run in check leak test mode. 7bd68906b doc: log level constants are also available in init_by_lua* and init_worker_by_lua* contexts. ea92f7ea8 doc: documented the support of 307 status argument value in ngx.redirect. 5134a9c82 bugfix: segmentation faults might happen when ngx.exec() was fed with unsafe URIs (#905) 397f3663e bugfix: ngx.req.set_header: skips setting multi-value headers for bad requests to avoid segfaults. 37e536208 change: ssl_session_fetch_by_lua* and ssl_session_store_by_lua* are now only allowed in the http {} context. cf0623c64 tests: 147-tcp-socket-timeouts.t was failing in mockeagain read/write test modes. 521d802aa tests: updated a shdict test case for i386 to reflect our recent optimizations in shdict storage layout. 6b2c9a3bf tests: updated the IP address of our own test server. 73bd64dbc feature: added public C API for 3rd-party NGINX C modules to register their own shm-based data structures for the Lua land usage (that is, to create custom siblings to lua_shared_dict). 40b61f40b doc: fixed the version number since which settimeouts() was first introduced. 28df10b16 feature: added a new api function tcpsock:settimeouts(connect_timeout, send_timeout, read_timeout). 66405877d bumped the API version to 0.10.7; also documented that lua_malloc_trim was first introduced in ngx_lua 0.10.7. 1173cc7c9 feature: added new config directive "lua_malloc_trim N" to periodically call malloc_trim(1) every N requests when malloc_trim() is available. 91fc078c4 doc: use *_by_lua_block {} in the examples. 74bad01b2 travis-ci: cache openssl-1.0.2h-sess_set_get_cb_yield.patch f7a0d58a4 travis-ci: upgraded openssl to 1.0.2j 5c491a59c travis-ci: add nginx-1.11.2 (supported by openresty) d26ca9052 fixed a hard-coded IP address in a test case. da08f59ae optimize: optimized the shdict node struct memory layout which can save 8 bytes for every key-value pair on 64-bit systems, for example. 3bd4227ce made a resolver test case more tolerante. 7ecba5377 travis-ci: use openssl 1.0.2i. 61621e0d3 doc: fixed the link to qa.openresty.org. 8bfa895c3 fixed a code comment. d52116753 doc: fixed a typo. 92d188425 doc: documented how to easily test the ssl_session_fetch_by_lua* and ssl_session_store_by_lua* locally with a modern web browser. 7d242ff79 doc: bumped version to 0.10.6. 4b8f26285 bugfix: *_by_lua_file: did not support absolute file paths on non-UNIX systems like Win32. thanks Someguynamedpie for the report and the original patch in #835. d802dbd87 tests: fixed more shdict list test cases that could fail on i386. 8d0ca5881 tests: fixed a shdict list test case that failed on i386. 8f1608495 tests: wait longer for CPU-intensive test cases for shdict lists for valgrind test mode. addfb0a80 bugfix: shdict lists: fixed new compilation warnings from the Microsoft C compiler. thanks itpp16 for the report in #836. 5dcf4e19e travis-ci: removed the env LUA_CMODULE_DIR=/lib which caused problems. f0687d94c doc: typo fix from Shuxin Yang. 65ccb5644 bugfix: ngx.exit() did not work at all in ssl_session_fetch_by_lua* and ssl_session_store_by_lua* when the FFI API is used (e.g., via lua-resty-core). 1de58835a feature: added new shdict methods: lpush, lpop, rpush, rpop, llen for manipulating list-typed values. d6258dae4 bugfix: build would fail when the http ssl module is disabled. ac89f23f5 travis-ci: disables caching the drizzle7 tarball. f714417ab Merge pull request #829 from doujiang24/doc aad493987 doc: sync the change from README.markdown to wiki c5ada9947 doc: ngx.worker.count() is available in the init_worker_by_lua* context. b9bd8028f feature: shdict:incr(): added the optional "init" argument to allow intializing nonexistent keys with an initial value. dbb48e33a bugfix: segmentation fault might happen in ssl_session_fetch_by_lua*, caught by the clang static analyzer. 5b2e1d20e tests: fixed a typo in the t/143-ssl-session-fetch.t test file. 5bcc53cab feature: implemented ssl_session_fetch_by_lua* and ssl_session_store_by_lua* config directives for doing (distributed) caching of SSL sessions (via SSL session IDs) for downstream connections. a5ac9fa2e bugfix: fake connections did not carry a proper connection number. thanks Piotr Sikora for the patch. b4609c10f bugfix: ngx_http_lua_ffi_ssl_create_ocsp_request: we did not clear the openssl stack errors in the right place. 3f4eba7aa skipped check leak mode for two test cases using malformed requests. 7c69ccdf7 renamed macro HAVE_UPSTREAM_TIMEOUT_FIELDS to HAVE_NGX_UPSTREAM_TIMEOUT_FIELDS. e90e0c1dd bugfix: ngx.sha1_bin() was always disabled with nginx 1.11.2+ due to incompatible changes in nginx 1.11.2+. thanks manwe for the report in #819. 522d2d58c tests: 070-sha1.t: checks error messages in nginx error logs. 8a4328a3e feature: added pure C API for setting upstream request connect/send/read timeouts in balancer_by_lua* on a per session basis. thanks Jianhao Dai for the original patch. 347bb2fba added the PULL_REQUEST_TEMPLATE file. 83c07bd22 minor fixes in ISSUE_TEMPLATE. d51903995 tests: added a passing test case for github #816 where ngx.log() is used in balancer_by_lua*. 93f9f6036 feature: allow tcpsock:setkeepalive() to receive nil args. a27c11f9f travis-ci: moved package management under travis-ci "apt" plugin, also cached apt packages. 349ad466e feature: ssl: add FFI functions to parse certs and private keys to cdata. b63ccaf31 bugfix: "lua_check_client_abort on" broke HTTP/2 requests. 473f7fa28 doc: documented that ngx.req.raw_header() does not work in HTTP/2 requests. 177946446 removed the obsolete Changes file. d14871950 spelling corrections found via github.com/client9/misspell 8e6456e56 bugfix: specifying the C macro NGX_LUA_NO_FFI_API broke the build. thanks jsopenrb for the report in #802. b092aa675 bumped the API version to 0.10.6. e7f6de01a bugfix: segfaults might happen when calling ngx.log() in ssl_certificate_by_lua* and error_log was configured with syslog. thanks Jonathan Serafini and Greg Karékinian for the report in #723. 6fb8a0e99 bugfix: fixed a typo in the error handling of the SSL_get_ex_new_index() call for our ssl ctx index. thanks Jie Chen for the report in #798. cb0923041 fixed various spelling errors in docs, source code, and tests. ff7e6a7a3 bugfix: fixed crashes in ngx.req.raw_header() for HTTP/2 requests. bcecaa07e tests: added a regression test for buffer split in block parsing (#687) e21d9b55e bugfix: when the nginx core does not properly initialize r->headers_in.headers (due to 400 bad requests and etc), more_set_input_headers might lead to crashes. thanks Marcin Teodorczyk for the report. 3010caded added an issue template for github. 1d3d441dc doc: bumped version to 0.10.5. 3b4a96363 bugfix: ngx.flush(true) calls right after ngx.send_header() was broken due to the previous commit. 547c961ef bugfix: ngx.flush() might lead to the "zero-size buf" alerts when ngx.print("") was called before. this regression had appeared in the previous commit. 53e78f5df bugfix: ngx.print("") did not trigger response header sending. be133bca5 bumped the API version to 0.10.5. 5de1b1fac bugfix: use of ssl_certificate_by_lua* in the http {} scope might lead to process crashes. thanks Andreas Lubbe for the report in openresty/lua-resty-core#42. d4f71ad08 doc: bumped version to 0.10.4. 69818f459 bumped the API version to 0.10.4. 816be0073 bugfix: only do the mmap(sbrk(0)) trick on Linux since it may cause problems on other operating systems. c7d5cbdf4 travis-ci: various improvements. b38aefeb7 travis-ci: enables clang builds. thanks Ilya Shipitsin for the patch in #769. 6b8b06060 release 0.10.3. 9f319e956 travis-ci: supress some unuseful output. 91c429a6d travis-ci: cache pcre-8.33 downloads and make sure we "exit 1" on any build failure. 61e2d3a49 travis-ci: use dig to warm-up the DNS servers a bit before testing. dce236188 feature: added Travis CI support. thanks Ilya Shipitsin for the patch in #766. c0efcd3bd fixed a udp test case. 54719b6f7 doc: util/build2.sh is now util/build.sh. thanks Ilya Shipitsin for the patch in #766. c92e71bfe doc: updated the directive execution order diagram. thanks Emil Stolarsky again. c28e17221 util/build.sh: use nginx's builtin ngx_http_auth_request module instead. thanks Ilya Shipitsin for the report in #765. 7352fe869 doc: added diagram of the order of directive execution to README. thanks Emil Stolarsky for the contribution. e7cdb4efd made a shdict test case less likely to fail in slow testing modes. 22566ed9b bugfix: ngx.exit() could not be used in the context of balancer_by_lua* when lua-resty-core was used. 7e6445ef8 bugfix: a follow-up fix for commit 93321acd in the FFI implementation of ngx.status. 70f708071 bugfix: *_by_lua_block: fixed Lua long bracket parsing at buffer boundaries. thanks Maxim Ivanov and Tom Thorogood for the report in #762. 7886a0810 style: fixed lines exceeding 80 cols. 37b476578 fixed a test case. a6b960fe0 refactorings in the semaphore implementation. 9a96f9e85 adjusted the test case for ngx.worker.id() for slow testing modes like valgrind. 0b2093d2b removed useless nginx logs from the nginx fake module in the test suite. 97a6a169a made the test case for ngx.worker.id() more reasonable. 766cde61c tests: made a test less possible to get timed out on resolvers. a0ed1bf29 bugfix: ngx.req.append_body() might enter infinite loops when ngx.req.init_body() has not specified a buffer size and the request header Content-Length is 0 (or client_body_buffer_size is configured to 0). cda5f872c bugfix: ngx.re.match: the 5th argument hid the 4th one. thanks iorichina for the report in #719 and rako9000 for the original patch in #727. ebb648c19 try harder to get the ngx.worker.id() test pass. alas. b90d7ad01 bugfix: wait a bit longer in the test case for ngx.worker.id(). 1967998b0 further tweaks in the test case for ngx.worker.id(). alas. 64499675d tests: ensured all the helper workers are indeed run in the test case for ngx.worker.id(). 05ffc6e9d tests: wait a bit longer for helper processes to start up in the worker.id() test case. a6e4e4583 ngx.worker.id() should still return something when the master process is off. 92d2d44ac simplified the test case in commit 57d034f. c9b02aa19 tests: avoided a memory leak in the test case itself. 57d034f89 bugfix: ngx.worker.id() should return nil in non-worker processes like nginx's cache managers. 8ec587aa7 tests: skip tests using local IPv6 addresses if it is not supported. 0fddb590b feature: now we try limiting the growth of the data segment of the nginx processes to preserve as much lowest address space for LuaJIT as possible. thanks Shuxin Yang for the help. 51d63b41c fixed dtrace static probes for systems other than Linux. b60f53f97 bugfix: fixed a memory leak in ssl.cert_pem_to_der(), caught by valgrind. 6683a8b25 refactor: simplifies the fix in commit 473926654a. df5bf1d62 bugfix: ignore unexpected closing long-brackets in '*_by_lua_block' directives. e6771593b minor coding style fixes. 473926654 bugfix: changing peers in balancer_by_lua* might lead to stale values of $upstream_addr. 559243b2c bugfix: clear errors in pem_to_der functions to avoid flooding nginx error logs (#695). b88ed7fb5 bugfix: ssl: clear stacked errors in some of our Lua APIs to avoid flooding nginx error logs. 1d9b530f7 removed a useless assignment in the timer impl caught by cppcheck and reported by Ilya Shipitsin in #745. b0fbce322 bugfix: sslhandshake() accepts up to 5 arguments now (including the object itself). 256a59c36 added a test case for the previous commit. 99866b50d bugfix: cosocket: sslhandshake() did not correctly check argument count. d44f8e04d Merge pull request #725 from ctrochalakis/typo-fixes a67957d07 Typo fixes 93321acd0 bugfix: assignment to ngx.status might not affect subsequent ngx.status reads when error_page had already taken place. thanks wangwei4514 for the report. 21231a443 bumped API version to 0.10.3. 92c6b8d42 bugfix: init_worker_by_lua* did not honor http {} top-level configurations like lua_ssl_verify_depth and lua_ssl_trusted_certificate. thanks Vladimir Shaykovskiy for the report in #709. 3d61bf4ed doc: bumped version to 0.10.2. b68d7b4bd bugfix: fixed compilation warnings when http ssl module is disabled in the nginx build. this regression had appeared in commit c226a00567. a22a40984 doc: release 0.10.1. bf339b0f6 Merge pull request #699 from othree/patch/readme-typo 493eaa784 Fix conf sample syntax error in README c226a0056 bugfix: balancer_by_lua* might crash the nginx worker when SSL (https) is used for upstream connections. thanks Alistair Wooldrige for the report in #696. e9b437160 minor doc updates. 60ebb5c00 bugfix: hot loop might happen when balancer_by_lua was used with the "keepalive" directive. thanks GhostZch for the report in #693. 6a422b6a4 fixed a test formatting issue. fe96cf835 ngx.req.get_post_args: return error message instead of raising an exception when request body is in temp file. 78426ffa6 bugfix: fixed the compiler warning "unused variable" when compiling with nginx cores older than 1.7.5 (exclusive). thanks Marc Neudert for the patch in #684. 4b063c93d Merge pull request #683 from thibaultCha/docs/get-phase-balancer 9c603e3ff docs: add get_phase() result in "balancer" context c6c905d8a tests: added a (passing) test case proposed by Mathew Heard in #681. 2aa42d572 tests: added passing tests for using ngx.worker.count() in the context of init_by_lua*. 5231d5fb6 doc: updated the markdown version accordingly. d2cedd838 doc: updated the TODO list to reflect recent changes. 20f2e889a tests: increased the waiting time of a test case. b1a326eed bugfix: fixed compilation errors with LibreSSL by disabling ssl_certificiate_by_lua* and some ngx.ssl API functions that are not supported by LibreSSL. thanks George Liu for the report in #654 and Bret for the report in openresty/openresty#148. 3b46731e9 doc: updated the docs of get_phase() for the "ssl_cert" context. 74103392e doc: typo fix from Prayag Verma in #675. 01727a39c feature: added HTTP 2.0 support to ngx.req.http_version(). 4f2954302 feature: this module can now be built as a "dynamic module" with NGINX 1.9.11+ via the --add-dynamic-module=PATH option of ./configure. 91c65907b config: more adjustments. 5adcbefd2 config: refactoring. 5abc7b6bb bugfix: fixed compatibility issues with other nginx modules loaded as "dynamic modules" in NGINX 1.9.11+. 64866bcf4 bugfix: fixed compilation errors with nginx 1.9.11+. thanks Charles R. Portwood II and Tomas Kvasnicka for the report in #669 and #668, respectively. b28eefa2e tests: made two test cases less agreesive in allocations. 320641adf optimize: use lua_pushliteral for string-literal. db206ab85 doc: a follow-up fix for commit 4d77caeb8. b6f5877d1 Merge pull request #671 from typhonius/docos-error-fix 4d77caeb8 Small documentation fix to sample code b98a7f7bb bugfix: stream-typed cosockets: we did not set the "error" field of the ngx_connection_t object which MIGHT lead to socket leaks. d7d454734 bugfix: avoided a potential memory issue when the request handler is aborted prematurely (via ngx.exit, for example) while a light thread is still waiting on ngx.flush(true). 740552fa7 doc: updated the doc for ngx.req.discard_body() to reflect recent changes. now ignoring request bodies indeed trigger disgarding the body upon request finalization. 8d7549fe7 feature: added new API, ngx.config.subsystem, which always takes the Lua string value "http" in this module. fcec9744c made the tests more robust. 43ec78432 renamed util/build2.sh to util/build.sh. e920600f6 doc: mentions ngx_stream_lua_module. 0dabb560c doc: updated the copyright year to 2016. da30ad60a Merge pull request #667 from bjoe2k4/master c16e1e4c0 doc: log_by_lua runs after nginx access log 3bb11aa51 Merge pull request #665 from doujiang24/doc 2a53bb483 doc: add balancer_by_lua*, ssl_certificate_by_lua* to the context of some api da16f8d71 doc: fixed an error in ngx.encode_base64 regarding streaming generation. 5ee9b0dad feature: added new API function ngx.socket.stream() which is an alias to ngx.socket.tcp(). 8961c4943 change: shdict: throws a Lua error when the exptime arg is invalid. bb91590fa feature: ngx.log() and print() now accept tables with the __tostring metamethod. 60bd1b1aa bugfix: support non-RSA private keys as well. a43bc0a1b bugfix: ngx.re: memory over-reads might happen in DFA mode when the regex has submatch capturing groups. 34985cc61 fixed coding style issues introduced in the previous commit. 49d525626 optimize: ngx.re: we always preserve the array part for the 0-indexed capture to avoid (expensive) lua table auto growth. cfd4f904d change: unmatched captures are set to false in the captures table. 701efd5ca bumped API version number to 0.10.1. 753b0a2f8 minor tweaks in a test file. 2c4984f0b a followup fix for the previous commit. e5992f7e4 bugfix: we might not respond to client abort events when lua_check_client_abort is on. cd3c6bd2a minor style fixes. bcdcd85b2 added more bytecode tests that can work with LuaJIT 2.1 and beyond without hard-coding bytecodes in the tests. d44e90dcb added a passing tests using balancer_by_lua* inside a lua subrequest. 6ba92a674 bugfix: balancer_by_lua* did not respect "lua_code_cache off". thanks XI WANG for the report and Dejiang Zhu for the patch in #663. 4c0bf0911 minor tweaks in tests. 36403c160 doc: ngx_openresty -> OpenResty. 4bc2e2d9f doc: documented that ngx.req.get_body_data() is available in the context of log_by_lua*. thanks YuanSheng Wang for the patch in #660. a5a6a12b3 Merge pull request #661 from doujiang24/style f4db0b71e style fix: variable name align with the previous line 93ca1cb75 minor tweaks. 489cc2457 various minor tweaks. dc5ad6019 SSL: remove leading white space from error messages 9de7841ee SSL: set error message on i2d_X509() failure as well f86335b53 minor coding style fixes. 1645a5f0d doc: fixed the year. my brain still lived in 2015. alas. thanks leemingtian for the report. 09644c46a doc: bumped version to 0.10.0. 17621837e bugfix: semaphore: memory invalid reads might happen when using ngx.semaphore in init_by_lua*. 8ac6fe795 made a test case less possible to fail on slow machines due to timing errors. b7fac12c4 Revert "tests: $TEST_NGINX_HTML_DIR might be too long for unix domain socket names." 79527af67 tests: skipped tests for ssl_certificiate_by_lua* if OpenSSL is too old. df130559f tests: $TEST_NGINX_HTML_DIR might be too long for unix domain socket names. 514e6d611 doc: added a note to ssl_certificate_by_lua_block for the use of ssl_certificate and ssl_certificate_key directives. thanks eagle-china for the suggestion. 832dcd1b9 doc: improved the docs for ngx.ctx a bit more. 2293dd228 doc: made clear the ngx.ctx scoping issues. thanks Robert Paprocki for asking. 08c32bc08 now we require at least NGINX 1.6.0. 813d743cc bugfix: fixed compilation errors with nginx cores older than 1.7.5 (exclusive). thanks Mejar Singh for the report. 1fac98574 optimize: saved the event_posted flag maintained by ourselves since ngx_event_t already has such a flag. also moved all the event initialization code to the semaphore initializer. 9f3eb280c bugfix: semaphore: always zero the whole ngx_event_t struct to avoid forward compatibility risks. 3c3cca76e bugfix: fixed compilation failures with nginx cores older than 1.7.12. this regression had appeared in the semaphore commit. 55d28401c bugfix: we should cleanup the current light thread and run the static dtrace probe in ngx.exit() even for fake requests (used by ngx.timer.at and ssl_certificiate_by_lua*, for example). f95d7b0b1 bugfix: remove a line of unreacheable code found by the Microsoft C compiler (via a warning). thanks itpp16 for the patch in #640. 988041615 util/build2.sh: added support for the OPENSSL_INC and OPENSSL_LIB environments. 4fbd5da4c minor doc typo fixes. 6667cb959 doc: updated the links to reflect recent changes. 0d470871e bugfix: ngx.get_phase() did not work in the context of balancer_by_lua*. 6c9d2585a feature: better SSL/TLS handshake control. 884f24eef doc: fixed the literal asterisk escaping in the correct way. a46c07a2a doc: markdown: escaped the literal asterisks properly. e44c9d889 added even more nginx debugging logs to the ngx.semaphore API implementation. 9799d2724 added more nginx debugging logs to the ngx.semaphore API implementation. 295744eaa minor fixes. b84801c48 updated .gitignore to reflect recent changes. 9c3e3cf04 bugfix: balancer_by_lua*: fixed a warning from the Microsoft C compiler. thanks itpp16 for the report in #636. 8c53a0d2d feature: implemented the balancer_by_lua_block and balancer_by_lua_file directives to allow NGINX load balancers written in Lua. e5bf7d69f the next version will be 0.10.0. 822341d8d doc: moved the document section "ngx.semaphore" to a better place. 18551f7c9 doc: fixed the link to the ngx.semaphore module documentation. #584. 9db3f54f4 feature: added pure C API for the ngx.semaphore Lua module implemented in lua-resty-core. d6fa8dbbd minor coding style tweak. 04b05ff2a bumped API version to 0.9.21. 9693828e7 doc: typo fix for the contexts of ngx.worker.id. thanks RocFang for the patch in #634. c655905eb style: various coding style fixes from Dejiang Zhu (found by his enhanced version of ngx-releng) via #630. b21f7993b updated a test case that fail in recent versions. 6a664c839 doc: minor typo fixes. 524be2ea8 fixed a C compiler warning on FreeBSD introduced in the previous commit. 35ba732be bugfix: fixed a compiler warning on type mismatch when dtrace USDT is enabled in the build. 0aa08037d doc: bumped version to 0.9.20. feb634ab8 doc: stated that we work with nginx cores as far as 1.9.7. 87a20d124 tests: fixed SSL cosocoket test cases for server configuration changes. 1d9a77169 refactor: lua code cache: make load functions take a log directly. 2c4045576 bugfix: we lacked detailed context info in error messages due to use of disabled Lua APIs in body_filter_by_lua*. thanks Dejiang Zhu for the patch in #623. 97890587c documented that ngx.worker.id() requires nginx 1.9.1+. fced532fe removed the empty .gitmodules file. ed96fef21 bugfix: compilation failed with nginx <= 1.9.0. thanks huangzihao for the patch in #622. 1ca69efbf a follow-up fix for the previous commit. f54438b6a bugfix: fixed compiler warnings "comparison between signed and unsigned integer expressions" on Windows. c040f1591 improved the tests added in commit 3e086ed3. 2bf771011 fixed the initial table sizes for the tables "ngx" and "ngx.req" to reflect recent changes. 7befc2c5f added one more test case (for ngx.req.clear_header) for commit f48aef50. c9b629ad9 doc: added a note about the full-buffering nature of the ngx.location.capture* API. thanks cmaion for the original patch in #607. 00f62a5ad feature: added new API function ngx.req.is_internal() for testing if the current request is an internal request. c3ac14e23 feature: added many more HTTP status constants as ngx.HTTP_XXX. thanks Vadim A. Misbakh-Soloviov for the patch in #425. f48aef50f bugfix: setting the built-in header X-Forwarded-For via ngx.req.set_header() or ngx.req.clear_header() might not take effect in some parts of the nginx core (like $proxy_add_x_forwarded_for). thanks aviramc for the patch in #491. 932584be2 feature: added new constant ngx.HTTP_TEMPORARY_REDIRECT (307) and support for 307 in ngx.redirect(). thanks RocFang for the patch in #416. b75aa9342 feature: added new config directive "access_by_lua_no_postpone". thanks Delta Yeh for the patch in #580. 7c2801702 doc: documented the minimum size threshold in lua_shared_dict. thanks mlr3000 for the original patch in #616. 3e086ed32 optimize: reduce memory allocations in stream cosockets. f2228aef4 feature: added new API functions ngx.timer.pending_count() and ngx.timer.running_count(). thanks Simon Eskildsen for the patch in #550. 1dee38920 feature: added new API functions ngx.worker.count() and ngx.worker.id() for returning the total count of nginx worker processes and the ordinal number (0, 1, 2, and etc) of the current worker. thanks YuanSheng Wang for the patch in #531. 91f9846c0 bugfix: ngx.req.get_uri_args/ngx.req.get_post_args: avoided allocating a zero-size buffer in the nginx memory pool since it might cause problems. thanks Chuanwen Chen for the report and patch in #605. 91bd1e4e3 optimize: avoid allocating in the nginx request memory pool in stream cosockets' receive*() methods. thanks Lourival Vieira Neto for the patch in #519. 72244ea07 bugfix: fixed a potential data alignment issue in the ngx.var setter API. 87bdfc1a1 bugfix: we had data alignment issues in the subrequest API which can explode on systems like ARMv6. thanks Stefan Parvu for providing the test environment. openresty/ngx_openresty#131. 9fc3a1f2d style: fixed a line exceeding 80 columns in the previous commit. 8b1861679 bugfix: there was a data alignment issue in the tcpsock:setkeepalive() implementation which might lead to crashes on ARM systems. thanks Stefan Parvu for the report in openresty/ngx_openresty#130. fd76e196a bumped the ABI version to 0.9.20. 049feaffd a follow-up fix for #611. 94f68befa bugfix: bogus nginx.conf parse failure "Lua code block missing the "}" character" might happen when there are many Lua code blocks inlined. thanks Andreas Lubbe for the report and test case in #611. 2b9308721 bugfix: bogus "subrequests cycle" errors might occur with nginx 1.9.5+ due to the recent changes in the nginx core. 1fae28928 Revert "tweaked .gitattributes a bit more." 4ab399199 develper build script: disabled the spdy module since it is already removed. fe50cff38 tweaked .gitattributes a bit more. 2fa55e863 added a .gitattributes file to correct GitHub's language tag. 7b1ff62c2 bumped version to 0.9.19. 905d7d0f0 bugfix: using quotes inside a pair of long brackets might lead to parse failures. this is similar to the issue reported by Dejiang Zhu in #596. c31774274 doc: ngx.var: documented the values for undefined and uninitialized nginx variables. thanks Sean Johnson for asking for this explanation in #595. ea3343502 doc: bumped version to 0.9.18. f8e1a7ae7 doc: emphasized that we target NGINX's HTTP subsystem in this module. 4e897529d bugfix: use line comments inside a pair of long brackets might lead to parse failures. thanks Dejiang Zhu for the patch in #596. 809c67432 bugfix: fixed errors and warnings with C compilers without variadic macro support. ec86ade22 bumped the API version to 0.9.18. 9fb2948c4 feature: now we support LuaJIT 2 on Windows (in the form of lua51.dll). 4a9d4b11f bugfix: subrequest response status codes between the range 100 .. 299 (inclusive) might get lost in the return values of ngx.location.capture*() calls. thanks Igor Clark for the report. 2f65b0fff bugfix: we might return the wrong shm zone in the public C API function ngx_http_lua_find_zone(). thanks qlee001 for the report in #589. 2cbeb0c5a doc: bumped version to 0.9.17. 04a57a1d3 doc: fixed a typo. e5c01f3dc doc: use *_by_lua_block {} in the examples in Synopsis; also updated the TODO and Special Escaing Sequeneces sections to reflect recent changes. 9afe2066a documented the log_by_lua_block {} directive. acc823991 documented the body_filter_by_lua_block {} directive. d76317b62 documented the header_filter_by_lua_block {} directive. 51be770ac documented the access_by_lua_block {} directive. 2ba17fd19 documented the rewrite_by_lua_block {} directive. 37167ce58 documented the content_by_lua_block {} directive. def5d5500 documented the init_worker_by_lua_block {} directive. 8daa9a672 doc: use proper wiki syntax. 0025a9827 documented the init_by_lua_block {} directive. 95dd9cd61 documented the set_by_lua_block directive. bf9436ade tests: removed a bogus test case for set_by_lua_block. 195baff55 feature: implemented the set_by_lua_block directive. effd1d1d5 fixed the test serial numbers in t/028-req-header.t. 62e31a3f2 bugfix: fixed typos due to copy&paste mistakes in some error messages. cecc0e789 bugfix: setting builtin request header Upgrade via ngx.req.set_header and etc might not take effect with some bultin nginx modules. 1d640d6e8 a followup fix for commit c96625866. b948841c0 bugfix: setting builtin request headers Depth, Destination, Overwrite, and Date via ngx.req.set_header() and etc might not take effect at least with ngx_http_dav_module. thanks Igor Clark for the report. c96625866 refactor: reordered the request header entries in the ngx_http_lua_set_handlers array to match ngx_http_headers_in in the nginx core. da089df2d doc: updated the wiki file to reflect recent changes. 311539270 tests: removed the useless "use lib" directives from the Perl test files. thanks Markus Linnala for the report in #464. 8b32f3616 feature: initial fixes when being used with the new ngx_http_v2 module since nginx 1.9.5. thanks itpp16 for the patch in #569 and #570. 8a0a3e470 doc: nginx 1.9.3 is compatible. bccf4dab2 bugfix: the user specified ./configure's --with-cc-opt and --with-ld-opt might override the LUAJIT_INC/LUAJIT_LIB and LUA_INC/LUA_LIB environment settings. thanks Julian Gonggrijp for the report in openresty/ngx_openresty#117. ec4076ef3 reverted the last commit. e80109795 skipped test cases that do not make sense for the "check leaks" testing mode. bec51155f fixed line numbers in 132-lua-blocks.t. a688d5a06 doc: a code example misses a "return". thanks YuanSheng Wang for the patch in #572. 6b558cd4b feature: implemented the *_by_lua_block {...} directives that do not require extra escaping when inlining Lua code in nginx.conf. b5de0c2f9 bugfix: fixed one -Wmaybe-uninitialized warning when compiling with gcc -Os. 7e415bbbd optimize: fixed the hash-table initial sizes of the cosocket metatables. c93567d70 doc: more typo fixes from Lance Li in #565. 74aecfe72 doc: typo fixes from Lance Li in #564. 1885b4d29 doc: typo fixes from Lance Li in #562. 826988303 doc: added links to more lua-resty-* libraries. a05e1eb54 bugfix: use of shared dicts resulted in (unwanted) registrations of shared dict metatables on all the lightuserdata in the Lua space. thanks helloyi for the report in #548 and patch in #557. 14f2b88b5 bumped the API version to 0.9.17. b6189f87f fixed the test plan. 69d1a6988 bugfix: if a 3rd-party module calls ngx_http_conf_get_module_srv_conf to fetch its current srv_conf construct in its merge_srv_conf callback, then use of init_worker_by_lua might lead to segmentation faults (the same also applied to merge_loc_conf). thanks chiyouhen for the report and patch in #554. ee30b7ce0 doc: updated the wiki format to reflect recent changes. 73bdb5391 Merge pull request #546 from doujiang24/doc 3043b7163 doc fix: ngx.exit is not disabled within header_filter_by_lua ea195bd81 typo fixes in recently added test cases. b661ff10e bugfix: the if_unmodified_since "shortcut" field in ngx_http_headers_in_t was first added in nginx 0.9.2. 2979422c4 Merge branch 'master' of github.com:openresty/lua-nginx-module bc0d61924 bugfix: ngx.req.clear_header/ngx.req.set_header: we did not update the shortcut fields in ngx_http_headers_in_t added since nginx 1.3.3 which may confuse other nginx modules accessing them. 5e4584312 doc: typo fix from Lance Li. cc2df46d4 minor doc tweaks. 5399898ea bugfix: setting Content-Type response values including "; charset=xxx" via the ngx.header API might bypass the MIME type checks in other nginx modules like ngx_gzip. thanks Andreas Fischer for the report. a22bfb94a Merge branch 'master' of github.com:openresty/lua-nginx-module 7087978d1 fixed SSL cosocket tests with google https in non-US regions. a7857abf1 Merge pull request #538 from tatsuyafw/fix-typo 6d45420d4 Fix typo: use a double quote instead of a single quote b8fc6c589 tests: disabled the test cases exercising multiple http {} blocks since this undocumented feature has been disabled since nginx 1.9.3. 7e201d750 Merge pull request #535 from doujiang24/typofix 336ed3f51 typo fix in debug log 1bf0757a3 Merge branch 'master' of github.com:openresty/lua-nginx-module 289d86b37 valgrind.suppress: suppressed a false positive in the latest version of glibc on Amazon Linux. 51a311c04 removed the old util/build.sh script and also added notes as comments to util/build2.sh #527. f67aefc96 bugfix: we might miss the linker option -ldl when we shouldn't. 91ff51faf bugfix: access nonexistent fields in the "ngx" table in init_by_lua* could lead to the exception "no request object found" because of the overreacting __index metamethod of the "ngx" table. ec3f150cc doc: bumped version number to 0.9.16. b59129ff6 doc: fixed a bug in an example where both rewrite_by_lua and content_by_lua produce response outputs. thanks fengidri for the report in #460. 721fff24f bugfix: fixed compiler warnings at least with gcc 4.7 and clang 3.5. this regression had appeared in commit 9e0503b035. 601044eb3 bugfix: ngx.resp.get_headers(): some built-in headers were not accessible via lowercase. thanks Nick Muerdter for the patch in #529. 9e0503b03 bugfix: raw downstream cosockets did not support full-deplexing. thanks aviramc for the bug report in #478 and the original patch in #481. 0be132078 fixed buggy test cases stuck on request body reading, which were exposed by the previous commit. 6fa6e97cc bugfix: we did not always discard the request body if the user Lua handlers don't, which might cause 400 error pages for keep-alive or pipelined requests. thanks Shuxin Yang for the original patch in #493. 255d40b12 fixed a test case for Mac OS X. 5b35451cd doc: fixed the context for the lua_need_request_body directive. thanks Tatsuhiko Kubo for the patch in #492. f4e131118 feature: fixed compilation failures with nginx 1.9.0. thanks Charles R. Portwood II for the original patch in #500. 847bc0f47 minor fixes in doc. 76dc20d4d Merge pull request #486 from itpp16/patch-3 1db65c105 Update ddebug.h 42d62e4b7 doc: mentioned the "auth_request", "add_before_body", and "add_after_body" directives in the section "Locations Configured by Subrequest Directives of Other Modules". 0fff5888f more coding style fixes in function declarations. edad9bb06 fixed a test case to reflect recent changes in lua-resty-core. 3eadb55c1 more coding style fixes. 65b65bfd9 minor coding style fixes. c9f2b8656 follow-up fix for the previous commit. thanks Tatsuhiko Kubo for the patch in #475. 9531e5e75 bugfix: removed the dead code for the old NGX_THREADS mode which breaks the new nginx (1.7.11+) with thread pool support. thanks Tatsuhiko Kubo for the patch in #475. e7a7079cb add no_padding option to ngx_http_lua_ffi_encode_base64 bbc64d40c removed the git submodule deps/ngx_devel_kit because this is just an optional dependency and it is painful to maintain submodule pointers. ac48bd2b6 doc: added new section "Obsolete Sections" to hold renamed or removed documentation sections so as to keep links valid over the web. thanks Dayo Akanji for the suggestion. 5fa6ff1b6 Updated docs. e3cda9cb8 bugfix: fixed compilation failures with very old versions of PCRE, like 4.5. 054f80f6a bugfix: we might still pick up Lua/LuaJIT headers/libraries in the paths specified by nginx ./configure's --with-cc-opt=OPTS and --with-ld-opt=OPTS optons even when the LUAJIT_INC/LUAJIT_LIB or LUA_INC/LUA_LIB environments are explicitly specified. 6222f0c53 feature: ngx.encode_base64: added support for the "no_padding" boolean argument to disable padding when a true value is specified. thanks Shuxin Yang for the patch. 0f0c2f814 bugfix: we should never automatically set Content-Type on 304 responses. thanks Simon Eskildsen for the patch in #468. e086440cb bumped the API version to 0.9.16. 7c37b4bbd bugfix: use of ngx_http_image_filter_module might lead to request hang due to duplicate header filter invocations. thanks Antony Dovgal for the report. 3dbb2b00e tests: fixed nondeterminism due to unordered Lua table iterations. thanks Markus Linnala for the patch in #465. b2b061d32 Merge pull request #466 from maage/env_lua ff23175f0 fix env tests 8f6790de7 doc: fixed the code sample for ngx.redirect() to reflect recent changes there. thanks Zi Lin for the report. 4388b1e48 doc: bumped version to 0.9.15; also stated that we work with nginx 1.7.10. f88d4a9fb tests: fixed the test plan in 041-header-filter.t. dde606203 Revert "bugfix: header_filter_by_lua*: now we ensure we always forward the exact return value of the ngx_http_filter_finalize_request() calls." e9fa313ff bugfix: header_filter_by_lua*: now we ensure we always forward the exact return value of the ngx_http_filter_finalize_request() calls. 82d0c265b bugfix: using error codes (ngx.ERROR or >=300) in ngx.exit() in header_filter_by_lua* might lead to Lua stack overflow. d427d9a1d feature: improved the debugging event logging for timers created by ngx.timer.at(). 6f63b9730 optimize: fixed padding holes in our struct memory layouts for 64-bit systems to save a little memory. 31265f783 bumped the API version number to 0.9.15. 05a4a7143 bugfix: the value of the Location response header set by ngx.redirect() might get overwritten by nginx's header filter to the fully qualified form (with the scheme and host parts). 8f908775c bugfix: the value of the Location response header set by the ngx.header.HEADER API might get overwritten by nginx's header filter to the fully qualified form (with the scheme and host parts). 23afdc0b1 bugfix: lua_shared_dict: use of Lua numbers as the value in shared dict might lead to unaligned accesses which could lead to crashes on architectures sensitive to address alignment (like ARMv6). thanks Shuxin Yang for the fix and thanks Stefan Parvu and Brandon B for the report in openresty/ngx_openresty#84. a02467304 optimize: header_filter_by_lua*: removed a piece of useless code. thanks Zi Lin for the report. 23c2ceae4 doc: emphasized the capability of using nginx variables in the Lua file path in content_by_lua_file/rewrite_by_lua_file/access_by_lua_file. cea0699a5 updated the copyright years. 20d968bc8 doc: bumped version to 0.9.14. 93a056c84 doc: typo fix from lneto in #451. fe0e22d35 bugfix: tcpsock:setkeepalive(): we did not check NULL connection pointers properly. thanks Yang Yue for the report. a05073d71 doc: typo fix from Harold via #446. 8e79804e0 bugfix: ngx.quote_str_str() incorrectly escaped "\026" to "\z" while "\Z" is expected. thanks laodouya for the original patch in #447. bd51d8196 added passing test cases for #445. 39ff3e697 added tests for using the ngx. API functions in the user callback functions for ngx.re.gsub's replacement. these tests exposed a bug in lua-resty-core. 521e4f454 reindexed the tests in t/036-sub.t. bc120f9a2 bugfix: fixed a compiliation error in the timer module when the DDEBUG macro is set to 1 or a C compiler without variadic macro support (like the Microsoft Visual C++ compiler) is used. thanks itpp16 for the patch in #443. 4cd7644ac bugfix: ngx.timer.at: fixed a small memory leak in case of running out of memory (which should be extremely rare though). c317feeae optimize: save our own log ctx for timers. c6930f018 tests: fixed a test case which expects 127.0.0.1:53 has nothing to listen on, which is not true when a local DNS caching server is enabled. ac009a248 bugfix: ngx.re.gsub/ngx.re.sub incorrectly swallowed the character right after a 0-width match that happens to be the last match. thanks Guanlan Dai for the patch in #442. af16d1f99 feature: added the Lua global __ngx_cycle which is a lightuserdata holding the current ngx_cycle_t pointer. f24a96b80 doc: added two more TODO items. cd01e7b98 doc: updated our TODO list. f9709b6dd api: bumped the version number to 0.9.14. 452640db9 doc: ngx.var: named more readonly nginx builtin variables, as per adamonduty's request in #440. b3a3e5ea2 doc: fixed some formatting issues in markdown. 4c633dd34 doc: added a warning for the "share_all_vars" option for ngx.location.capture*. 7a97d0902 doc: bumped version to 0.9.13 and also claimed the compatibility with nginx cores up to 1.7.7. 5d063412e Merge branch 'master' of github.com:openresty/lua-nginx-module 4720940e8 fixed some new test failures according to the Amazon EC2 report. 3085f32e7 Various improvements in ngx.timer and fake connections/requests. e6132eab9 feature: added nginx configuration file names and line numbers to the rewrite/access/content/log_by_lua directives' Lua chunk names in order to simplify debugging. e22684511 Various downstream writing fixes. bda5b9795 style: minor fixes. 60c64cc14 doc: documented the 0-delay timer workaround for contexts where cosockets are not available (yet). also documented the "connection in dubious state" error message for tcpsock:setkeepalive(). 20bbbfbe4 bugfix: compilation failed when http ssl is not enabled in the nginx build. this regression had appeared in commit 5eb3f8c6f. 3c1918df8 bugfix: ngx.get_phase() does not work in the context of init_worker_by_lua*. 5eb3f8c6f bugfix: tcpsock:sslhandshake(): memory invalid read and/or bogus "lua ssl ceritficate does not match host" errors might happen when checking certificates with the SNI name. da31a5e65 doc: documented that ngx.exit() is enabled in the context of ngx.timer.* callbacks. 0846f2766 tests: increased the timeout threshold for the test cases involved with expensive SSL handshakes to prevent them from getting timed out on slow boxes. 75eaf0784 feature: ngx.flush(true) now returns the "timeout" and "client aborted" errors to the Lua land for the cases that writing to the client is timed out or the client closes the connection prematurely, respectively. 0c33b9e0a feature: ngx.flush(true) can now wait on delayed events due to nginx's limit_rate config directive or "$limit_rate" variable settings. thanks Shafreeck Sea for the original patch in #432. a4f8b8ad0 bugfix: use of "ngx.flush(true)" with the "limit_rate" config directive or the $limit_rate variable may hang the request forever for large volumn of output data. thanks Shafreeck Sea for the report in #430. db428bfc6 doc: added a new section, "Cocockets Not Available Everywhere", under the "Known Issues" section. 1506812af updated valgrind.suppress to suppress a false positive on Amazon Linux i386. 2fe0d8dda more fixes in the tests regarding the resolver. bba7058e7 tests: avoid using hard-coded DNS nameserver address but the TEST_NGINX_RESOLVER environment. d42751731 suppressed a warning in the libc resolver. c2f88f8df bugfix: compilation error when PCRE is disabled in the nginx build. thanks Ivan Cekov for the report in #428. 9ea909bae doc: typo fix from e路相扶. 0162afd71 doc: fixed some broken in-page links, as reported by smallfish in #421. cc9e738a7 doc: various wording improvements and link fixes from Dayo Akanji. c135f05f2 tests: use larger timeout limit for a test case revolved with external DNS resolving. 5c8957b2d tests: fixed a failure due to recent changes in the nginx core. 05e8499c8 tests: fixed a test failure due to the misuse of the $TEST_NGINX_PORT variable. 0d736bf22 tests: suppressed a warning from the test scaffold for a timer test case. 6706ec214 bugfix: when syslog was enabled in the "error_log" directive for nginx 1.7.1+, use of init_worker_by_lua or ngx.timer.at() would lead to segmentation faults. thanks shun.zhang for the report in #426. 8a4e8a72d minor test file format fixes. 25c4bdd6b tests: suppressed a warning from the test scaffold due to an expected [crit] error log message in 2 test cases. c9128e50f tests: added a passing test case for connecting to IPv6 addresses via cosockets. 4323f3bc1 tests: 129-ssl-socket.t: use limited timeout threshold for the cosockets. 0c4528e50 bugfix: fixed compilation error with nginx 1.7.5+ because nginx 1.7.5+ changes the API in the events subsystem. thanks Charles R. Portwood II and Mathieu Le Marec for the report in #422. 14fbf4031 doc: made clarification about ngx.exec() requested by Dayo Akanji. e9139a954 doc: typo fix from tianchaijz in #419. 227a5f0e5 api: bumped version to 0.9.13. 334979177 bugfix: ngx.req.raw_header(): buffer overflow and the "buffer error" exception might happen for massively pipelined downstream requests. thanks Dane Knecht for the report. ddb363625 refactor: ngx.req.raw_header(): simplified the implementation. 62fd4c5f7 bugfix: ngx.req.raw_header(): we might change nginx's internal buffer pointers, which might cause bad side-effects. 73884588f doc: bumped version to 0.9.12. ffe7b34de doc: added more discussions for the potential race conditions in worker-level changeable data sharing to the "Data Sharing within an Nginx Worker" section. thanks Jon Keys for asking. d7378122d tests: fixed a small bug in a test case. be1655d23 bugfix: added extra delays to some of the test cases with systemtap involved. 8e6aa11dc tests: updated test suite according to the latest changes in Test::Nginx::Socket. 9688c645b doc: documented the behavior in the case that one does not call close() nor setkeepalive() in a cosocket object's lifetime. thanks Bogdan Irimia for asking. eb128df04 bugfix: added allocation failure check for ngx_array_init(). thanks Tatsuhiko Kubo for the patch in #414. 0e49fe746 tests: fixed a case with expired CRL. 5662ddd9b bumped internal code version to 0.9.12. 7e4f1af7f bugfix: init_worker_by_lua*: memory corruptions would happen when no server {} is defined in nginx.conf. this regression had appeared in v0.9.11. df70a5e7e bugfix: fixed build failures with OpenSSL older than 0.9.8f. thanks FFCZ for the report in #413. 044f86188 bugfix: create_loc_conf did not return NULL on error. 96d4608ef tests: fixed a case for raw req socket to reflect recent changes in the debugging logs for tcp_nodelay. 3acb8dd90 bugfix: the "tcp_nodelay" directive configuration was not honored by upstream TCP cosockets, which could lead to extra delays for small messages. thanks Shun Zhang for reporting this issue. 947f82d1b bugfix: compilation failed with nginx 1.3.6 or older. this regression had appeared in the v0.9.11 release. 1565a068e bugfix: compilation failed with nginx 0.9.x. e2aef6d03 doc: bumped version to 0.9.11; also claimed that we work with nginx 1.7.4. 4c19852c0 doc: typo fix. da0ced8a4 bugfix: init_worker_by_lua* would conflict with some other nginx C modules (like ngx_proxy) when their merge_loc_conf callbacks (or alike) produce side-effects in cf->cycle. thanks Ruoshan Huang for the report. d4dbba59d config: now we also explicitly check the Lua ABI/language version in our feature test for a Lua lib. 90bdd9744 fixed the build failure introduced in commit 109fd454a. b6978cde6 Merge pull request #409 from cubicdaiya/feature/vim e4691cb5c Merge pull request #410 from cubicdaiya/feature/use_macro 99cc06d0f Merge pull request #411 from cubicdaiya/feature/ues_luapushliteral2 109fd454a use lua_pushliteral for string-literals. 8e464f9ae Style: use macro instead of magic-number. 7f739a983 Style: added vim modeline. d957eefee tests: made a test case for ngx.on_abort() more tolerant. e0cd3ccf1 bugfix: ngx.resp.get_headers(): sometimes we might omit the builtin-headers Content-Type, Content-Length, Connection, and Transfer-Encoding. thanks Jon Keys for the report. 75cc29ea6 bugfix: ngx.req.socket(true): it incrrectly returned the error "chunked request bodies not supported yet" for *raw* request sockets with chunked request bodies. thanks Xiaofei Yang for the report. 5f62a5584 tests: fixed a test case that could fail randomly. 3ffe48cce bugfix: tcpsock:sslhandshake() incorrectly returned failures when the SSL handshake operation succeeded immediately. 03a74d445 tests: fixed a test case to reflect latest change in ngx_set_misc. ad3364515 Merge pull request #408 from cubicdaiya/issues/use_luapushliteral 06652edb1 bugfix: we did not check allocation failures while compiling the pattern for tcpsock:receiveuntil(). thanks Tatsuhiko Kubo for the patch in #407. 141725f4c use lua_pushliteral for string-literals. 05e2ad61f doc: removed the SSL cosocket item from the TODO list. 92d92fbff style: fixed tab indentation. thanks Tatsuhiko Kubo for the patch in #406. e482cdab3 doc: more clarification in the docs for the res.truncated flag returned by ngx.location.capture(). thanks Jon Keys for asking. 2b40b44dc doc: documented the new SSL cosocket feature. fd3f4ee25 bugfix: tcpsock:sslhandshake(): the "host" parameter did not accept the nil value. 45cb4feb1 doc: added missing method name "get_keys" under "ngx.shared.DICT" and also fixed the method order. thanks George Bashi for the patch in #404. e7d89c043 bugfix: builds without --with-http_ssl_module were broken. this regression had appeared in commit a6a0ed5. b55d0ecf5 feature: tcpsock:sslhandshake(): when the "session" argument is a boolean "false", then no SSL session userdata will be returned and only a boolean "true" value is returned when successful. 207865762 tests: use iscribblet.org instead of agentzh.com in tests because the latter is currently served by Chinese name servers, which are not quite stable. 90751a071 tests: fixed a case regarding ngx.on_abort(). 82188a1e8 tests: made a test regarding ngx.re.sub less possible to fail in slow testing modes. 937dfb35e tests: a minor style fix in a case. a844a13ce bugfix: we did not set the c->pool->log properly where c is an upstream stream-typed cosocket connection. this regression had appeared in the ssl cosocket patch, i.e., commit 5aed1966. 3f9ab4bf6 tests: suppressed a valgrind false positive in the nginx core. a6a0ed520 bugfix: memory leak cound happen when both cosocket connection pools and "lua_code_cache off" were used. this regression had appeared in the ssl cosocket patch, i.e., commit 5aed1966. 531fb5a08 tests: one minor Perl code style fix. 348d359dd tests: fixed the test case added in commit 6ef948150. 5aed1966c feature: SSL/TLS cosocket API 6ef948150 added a test case to exercise a bug in ngx_proxy's ssl handshake timeout handling (see http://mailman.nginx.org/pipermail/nginx-devel/2014-July/005627.html ). 8acc73f2c bugfix: stream-typed cosocket might read uninitialized memory bytes when logging errors due to sending to or receiving from a closed socket. 766ab667c tests: fixed a test case regarding unix domain cosockets. 353563226 optimize: we now cache the userdata metatable (for the __gc metamethod) in the lua registry for the datagram-typed cosockets. 3fd3234f3 optimize: we now cache the userdata metatable (for the __gc metamethod) in the stream-typed cosocket implementation. 58f916f13 bugfix: the datagram-typed cosocket resolver handler did not handle some special errors correctly. 2cc788b42 improved the fix in commit 48e48305. 48e483050 bugfix: the stream-typed cosocket resolver handler did not handle some special errors correctly. c2f4dda29 trivial optimizations. 66c45338c doc: markdown: fixed the "Back to TOC" links for the sections ("Nginx API for Lua" and "Directives") with inlined TOC. thanks Pierre-Yves Gérardy and Simon Eskildsen for the reports in #370 and #399, respectively. 92e22bc43 bugfix: body_filter_by_lua*: reading ngx.arg[1] after clearing ngx.arg[1] (by assigning nil or "") could lead to segmentation faults. this regression had appeared in v0.9.10. thanks Jason Stangroome for the report in #398. f3870f6a7 bugfix: ngx.req.raw_header() would return garbled data when LF instead of CRLF is used as the line terminator in the original header. b5d23b9e4 bugfix: ngx.req.raw_header() could lead to buffer overflow and the "userdata length overflow" error due to misuse of r->header_end while modules like ngx_fastcgi and ngx_proxy can change r->header_end to point to buffers of their own. thanks sadmedved for the report. e4e0f4b37 doc: improved the wording in the "Lua Coroutine Yielding/Resuming" section. thanks Hungpu DU for the report in #394. dfb61faeb bugfix: we did not use lua_checkstack() to prevent Lua stack overflow in our own C-land Lua backtrace generator. e1b24308a refactor: removed a piece of duplicate code from the stream-typed cosocket implementation. 35e174b4f optimize: reading ngx.header.HEADER: eliminated dynamic allocations and data copying when there is no need to ransform "_" to "-" in the header name. ee2a206b2 feature: added pure C API function for FFI-based implementation of reading ngx.header.HEADER. b6e991ba9 tests: improved the test cases for the ngx.header API a little bit. d380c975b doc: improved the wording of the documentation for ngx.req.clear_header() to prevent ambiguity. thanks Christophe-Marie Duquesne for the report in #393. ed096adaf style: fixed coding style in the header files consts.h and args.h. thanks Tatsuhiko Kubo for the report in #392. f83fa0d4d bugfix: fixed an incorrect error message. thanks aviramc for the patch in #290. 4969b87a2 style: preserved a blank line after the goto labels. 790e57dee optimize: reading ngx.header.HEADER: reduce allocations in the nginx request memory pool. c37e6a6e5 change: use the type ngx_http_lua_ffi_str_t instead of ngx_str_t in the pure C function ngx_http_lua_ffi_req_get_headers. cee6659f6 doc: documented that the standard coroutine API is now available in the context of header_filter_by_lua* and body_filter_by_lua*. 1238bdd9f doc: documented the NGX_LUA_NO_FFI_API C macro. 7ff3ef1f1 renamed the NGX_HTTP_LUA_NO_FFI_API macro to NGX_LUA_NO_FFI_API. e94a4f371 feature: added pure C API functions for FFI-based implementations of ngx.worker.pid() and ngx.worker.exiting(). a2e53c4f5 bumped the code version to 0.9.11. 17c28f1ac feature: the standard coroutine API is now enabled in the context of header_filter_by_lua* and body_filter_by_lua*. thanks ngo for the request in #389. 0778f2b04 feature: for content/rewrite/access_by_lua_file directives, we now return 404 status code instead of 500 in case that the specified .lua file cannot be opened. thanks Sam Lee for the suggestion. 76c70010b doc: fixed a wrong statement regarding require() in the "Lua Variable Scope" section. thanks Hungpu DU for the report in #390. 34ecd2f13 bugfix: ngx.escape_uri() now uses uppercase hexadecimal digits for percent-encoding according to the recommendation in RFC 3986. thanks Piotr Sikora for the suggestion. 5e9446378 bugfix: for statically linked luajit, we need to pass -ldl to the linker. thanks cf2012 for the report in openresty/ngx_openresty#40. 6929e7de9 doc: documented the behavior of init_by_lua* when lua_code_cache is off. cea9ee2cd doc: bumped version to 0.9.10. f3102fef3 minor fixes in the NGX_LUA_ABORT_AT_PANIC macro. de46d204b bugfix: fixed a compilation error regression when using the Microsoft Visual C/C++ compiler. thanks itpp16 for the patch in #388. 1e07b1ead bugfix: we should use "c->buffered & NGX_HTTP_LOWLEVEL_BUFFERED" instead of "c->buffered" for testing if the downstream connection is busy writing. aa6054a13 change: throw out the "no memory" Lua error consistently (instead of "out of memory") when failing to allocate on the nginx side. 9c79180b7 bugfix: we did not handle an out-of-memory case in ngx.req.set_body_data(). 5ad9b3fbb bugfix: rewrote the buggy patch in commit 4c215c556 for #386 because it did not handle flush bufs correctly and had other issues. bda34bb09 fixed 2 minor lua stack manipulation mistakes. 88be20583 bugfix: ngx_http_lua_chain_get_free_buf(): avoided returning zero-sized memory bufs. fd8af73d2 refactor: renamed ngx_http_chains_get_free_buf() to ngx_http_lua_chain_get_free_buf(). also omitted the buf tag argument which is a constant anyway. 6b8ca4a35 doc: typo fix. c29f33adf doc: documented the NGX_LUA_USE_ASSERT and NGX_LUA_ABORT_AT_PANIC C macros. 4c215c556 bugfix: body_filter_by_lua*: we might incorrectly pass zero-size bufs (in the form of "special sync bufs") at the beginning of a chain, which could get stuck in the buffer of ngx_http_writer_filter_module (or in other words, being "busy") while could still get recycled in the content handler (like content_by_lua), leading to buffer corruptions. thanks westhood for the report and patch in #386. 26fd00704 bugfix: we did not clear all the fields in ngx_buf_t when recycling chain link buffers. fdd10bf3a tests: use larger timeout threshold for test cases involved with external resolvers. b106ccdb4 fixed the test plan in 014-bugs.t. 8613ed6e9 bugfix: the *_by_lua_file directives failed to load .lua files of exactly the size n*LUAL_BUFFERSIZE bytes with the error "'end' expected (to close 'function' at line 1) near '<eof>'". thanks kworr for the report in #385. db9fe7ab9 bumped version to 0.9.10. 745a7107b optimize: now we turn off our C-land assertions by default unless the user explicitly specifies the C compiler option -DNGX_LUA_USE_ASSERT. 3abfb1fc6 bugfix: when the ngx.on_abort() user thread was created but never run *and* some other pending user thread was aborted prematurely, the latter thread might get leaked. thanks Dane Knecht for the report. this regression had appeared in the v0.9.9 release. 1250c5bf4 tests: use larger resolver_timeout settings. 09e0944d6 change: now we always iterate through all the user light threads to ensure all threads are de-anchored even when the "uthreads" counter gets out of sync. also added an assertion on the "uthreads" counter. 24953436f doc: documented the new full-duplex stream cosocket feature. f408dd51a doc: documented the ngx.thread.kill() API function. 0950973ad doc: bumped version to 0.9.9. also states that we work with nginx 1.7.2. f40e371be Revert "refactor: we no longer call ngx_pfree() in our own pcre_free hook." fcbbf523d tests: fixed timing issues in some of the test cases for full-duplex cosockets. d56a2af52 bugfix: fixed the initial size of the ngx.worker table and the misleading comment due to a copy&paste mistake. thanks Suraj Jaiswal for the report. 934e33e6d feature: cosockets are now full duplex: a reader "light thread" and a writer "light thread" can operate on the same cosocket simultaneously. thanks shun zhang and aviramc for the original patches in #367 and #290, respectively. 6885462e9 feature: added new API function ngx.thread.kill() for killing a user "light thread". thanks aviramc for the original patch in #288. 52b76a719 removed some dead code from the stream cosocket implementation. d6bc02eb3 bugfix: the coroutine API table introduced by require("coroutine") was not working in the context of ngx_lua. thanks Paul K and Pierre-Yves Gérardy for the report (in #381). c2e29483d a minor coding style fix. 9f0f9eaf1 tests: made a test case in 124-init-worker.t less possible to fail in slow testing mode. b773bcabc bumped version number to 0.9.9. fd41af2d0 bugfix: we incorrectly overrode coctx->data before calling coctx->cleanup, which could lead to memory corruptions. this regression had appeared in the previous commit, f19e27e777. f19e27e77 bugfix: the coctx cleanup handler might not be called before being overidden by other operations. this could happen when failing to yield in an error handler (for xpcall). 053f40e79 bugfix: fixed an incorrect error message. thanks doujiang for the patch in #373. 75c98cb5f fixed the test plan in 058-tcp-socket.t. 8fd50ad87 ensured that the resolver handler will not call into the dead request context. 06b7476b2 doc: added performance notes to the sections for ngx.var and ngx.ctx. 7a20b0770 doc: fixed a typo. ab8bd1b02 doc: documented the values can be passed to the timer callback function. 73e831f04 bumped version to 0.9.8. 2b721c7fd doc: markdown format: inlined the TOC for the long sections "Directives" and "Nginx API for Lua" as per Pierre-Yves Gérardy's suggestion in #370. c91e1f525 doc: moved the "Directives" and "Nginx API for Lua" sections to the end because they are too long and kinda boring :) thanks Pierre-Yves Gérardy for the patch in #371. a9e0111fe doc: moved important sections to the front. thanks Pierre-Yves Gérardy for the patch in #371. 91e3307fb use ngx_http_lua_assert() instead of plain assert() across the code base. ec2498a81 added assertions to the coroutine scheduler to ensure that we do not pop or push the wrong number of stack slots for yielded coroutines. 5318f3a69 resolved merge conflicts. d3ab0edd4 bugfix: ngx.req.set_method(): we incorrectly modified r->method when the method ID was wrong. 31e001557 feature: added a pure C API function for FFI-based implementations of ngx.req.set_header() (single-value only) and ngx.req.clear_header(). 3a01812d8 feature: added a pure C API function for FFI implementations of shdict:flush_all(). 62b2ac5cb feature: added pure C API function for FFI-based implementations of ngx.req.set_method(). f9ce770d7 feature: added pure C API functions for FFI-based implementations of ngx.req.get_method(). 1c3a84162 Revert "optimize: use lua_pushinteger instead of lua_pushnumber in ngx_http_lua_ngx_time()." 9bb1f3586 the "int" return type of ngx_http_lua_ffi_time might lead to data loss. thanks itpp16 for the report. e9b8563c3 optimize: use lua_pushinteger instead of lua_pushnumber in ngx_http_lua_ngx_time(). 99e5171c6 renamed ngx_http_lua_ffi_ngx_now to ngx_http_lua_ffi_now. d9fff3b70 feature: added pure C API function ngx_http_lua_ffi_time for FFI-based implementations of ngx.time(). 8666424db fixed the wrong return type of the ngx_http_lua_ffi_req_start_time function in the previous commit. 50dbfcefd feature: added pure C API function ngx_http_lua_ffi_req_start_time for FFI-based implementations of ngx.req.start_time(). 34ab51f89 updated tests to reflect recent changes in rewrite_by_lua* and access_by_lua*. 4f0be44f7 doc: added more explanation for some user FAQs. ec78bf101 fixed a source line exceeding 80 cols. 32960150f minor doc love. 938323644 change: rewrite_by_lua* will now terminate the current request if the response header has already been sent (via calls like ngx.say and ngx.send_headers) at that point. a1ea105f4 change: access_by_lua* will now terminate the current request if the response header has already been sent (via calls like ngx.say and ngx.send_headers) at that point (otherwise nginx might crash when other modules try to generate their own response). thanks yaronli and Sophos for the report in #364. c478f41e1 change: access_by_lua* will now terminate the current request if the response header has already been sent (via calls like ngx.say and ngx.send_headers) at that point (otherwise nginx might crash when other modules try to generate their own response). thanks yaronli and Sophos for the report in #364. b438f972d feature: now we save the original pattern string pointer value into our ngx_http_lua_regex_t struct, to help runtime regex profiling and debugging. 7f184ec4c feature: now we save the original pattern string pointer value into our ngx_http_lua_regex_t struct, to help runtime regex profiling and debugging. fb5f97541 feature: attempt to allow use of 3rd-party pcre bindings in init_by_lua*. thanks ikokostya for the feature request in #368. cae725928 added a fix for the leftover cases in commit b57d60d4c9d c178302bd updated the test index in 109-timer-hup.t. 0a11b402a feature: added pure C API function, ngx_http_lua_ffi_ngx_now, for FFI-based implementation for ngx.now() like lua-resty-core. 0a845986a 126-shdict-frag.t: force a full GC cycle at the end of the Lua handler to help the "check leaks" testing mode. a43bca8d1 fixed the wait time for slow testing mode. eb4f98676 126-shdict-frag.t: increased the timeout threshold. 0f68763de bugfix: nginx does not guarentee the parent pointer of the rbtree root is meaningful, which could lead to inifinite loops when ngx_lua tried to abort pending timers prematurely (upon worker exit). thanks pengqi for the patch in #362. a2dee0c62 added more code comments to the timer implementation. af2d3570b added a (passing) fuzz testing for aborting many pending timers. 3b3239c22 added (passing) tests for yielding failures in cosocket DNS resolving. 5d614b094 added a (passing) fuzz test case for shdict. b57d60d4c bugfix: we did not call our coroutine cleanup handlers right after our coroutine completes (either successfully or unsuccessfully) otherwise segmentation fault might happen when the Lua VM throws out unexpected exceptions like "attempt to yield across C-call boundary". thanks Lipin Dmitriy for the report in #361. 509bb9819 removed an obsolete code comment. ed1eb4f7f bugfix: the ngx.ctx table might be released prematurely when ngx.exit() was used to generate the response header. thanks Monkey Zhang for the report. now we release ngx.ctx in a request pool cleanup handler. f7443edc1 fixed the test index in 126-shdict-frag.t. 373376ce0 try to make a test case for shdict fragmentation pass on i386. fa83bb5fd added tests for exercising the memory fragmentation issue in nginx's built-in allocator for blocks larger than the page size d8c45b872 feature: make use of the new shm API in nginx 1.5.13+ to suppress the "no memory" error logging when the shared dicts run out of memory. ae2207bf8 bumped version to 0.9.8. 125586404 feature: added C macro NGX_LUA_ABORT_AT_PANIC to allow generating a core dump when the Lua VM panics. 506728da2 doc: fixed the links to ngx_rewrite in the "set_by_lua" section. 39d3e74cb updated docs to reflect recent changes. 6c555ed50 bugfix: bugs in the error handling for pure C API functions for shared dict. thanks Xiaochen Wang for the patch in #365. c11ceb40a updated the tests to reflect the new openresty server at agentzh.org. b111180c1 added a (passing) test case for reading ngx.header in the context of log_by_lua. c1ee08e8a Merge pull request #359 from cubicdaiya/issues/use_ngx_str_null 0d48124c9 added a (passing) test for timeout error on tcpsock:receive(N). 0375856d8 use ngx_str_null e52a2631e doc: now we have tested with nginx 1.5.12; also put the 0.9.7 release date. 40691f409 Revert "added assertions for the pcre pool management." 1117f043c Merge pull request #355 from lhmwzy/master 8192b9745 Update ngx_http_lua_string.c 4e284f73c bumped version to 0.9.7. 5c2718004 added assertions for the pcre pool management. 5c788b8b9 refactor: we no longer call ngx_pfree() in our own pcre_free hook. 988ac5d84 bugfix: when lua_code_cache was off, cosocket:setkeepalive() might lead to segmentation faults. thanks Kelvin Peng for the report. f08bddccd suppressed a false positive in libdl. 3f7e04cf8 made a test case less likely to fail on slow machines. cbf054f12 made a test case less likely to fail on slow machines. 01cd00c40 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 8542d4365 refactor: improved the error handling and logging in the Lua code loader and closure factory. 5719c60cf Merge pull request #351 from cubicdaiya/issues/use_luapushliteral f07a55b28 use lua_pushliteral instead of lua_pushlstring bbb7e05d9 added stronger assertions to the stream-typed cosocket implementation. 5d4afab7a optimize: we no longer clear "ctx->user_co_ctx" in ngx_http_lua_reset_ctx. bec802ea9 bumped version to 0.9.6. e5eefed32 updated docs to reflect the change in commit 382c7201. f9917b93e skipped 2 test cases that are nonderterministic. 4cb8dda8b bugfix: accessing a datagram cosocket object from a request which does not create it could lead to segmentation faults. now we throw out a Lua error "bad request" properly in this case. 414db1a80 bugfix: accessing a cosocket object from a request which does not create it could lead to segmentation faults. now we throw out a Lua error "bad request" properly in this case. thanks Ross Timson for the report. 382c72010 change: it is now the user's responsibility to clear the captures table for ngx.re.match(). a4db3e1b2 bugfix: we should prefix our chunk names for from-string lua source (which also leads to nicer error messages). thanks Mike Pall for the catch. 6c56337d7 bugfix: init_worker_by_lua should honor the lua_socket_log_errors directive's configuration in the http {} block. 9b18ca311 bugfix: the "resolver" directive's toplevel configuration in the http {} block was not respected by init_worker_by_lua. thanks Heero Zhang for the report. 37c86d67f bumped version to 0.9.6. be08630ba bugfix: subrequests initiated by ngx.location.capture* with the HEAD method did not result in responses without response bodies. thanks Daniel for the report in #347. 97d916233 updated docs for the 0.9.5 release. cfc593bb9 test: skipped two invalid test cases that use cosockets beyond the creating request boundary. 3898993eb fixed a bad regressoin in commit 1b615c46. fb06f3958 fixed a test case that could fail in the "check leak" mode due to GC delays. 1b615c46e bugfix: segfault might happen in the FFI API for destroying compiled pcre regexes, which affects libraries like lua-resty-core. c6e28fdc0 fixed the waiting time for a test case that could fail on slow machines. e0c5d58f2 doc: typo fix in a code sample for ngx.req.get_post_args(). thanks Evan for the patch in #344. 880a1c85b refactor: adjusted the globals table handling a little bit. 911c39553 increased the waiting time in two ngx.abort test cases that might fail on slow boxes. dc8e88cc2 feature: explicitly check Lua langauge version mismatch; we only accept the Lua 5.1 language (for now). 9ef3ca51e removed the spdy mode check from ngx.location.capture*() to renable this API again for SPDY requests. d74878969 bugfix: an attempt to fix subrequests initiated by ngx.location.capture*() in the SPDY mode. 48af6433b doc: documented the new ngx.config.nginx_configure() function. 1916d0c2f renamed ngx.config.ngx_configure to ngx.config.nginx_configure. 441d9c28b feature: added new API function ngx.config.ngx_configure() to return the NGINX ./configure arguments string to the Lua land. thanks Tatsuhiko Kubo for the patch in #339. f86291583 doc: documented the ngx.resp.get_headers() API function. 887f0f99d feature: added new API function ngx.resp.get_headers() for fetching all the response headers. thanks Tatsuhiko Kubo for the patch in #335. 4a0036c07 optimize: coroutine status string look-up is now a bit more efficient by specifying the string lengths explicitly. thanks Tatsuhiko Kubo for the patch in #338. eab56942a doc: fixed a typo in the doc for coroutine.yield(). thanks Ruoshan Huang for the report. f7db5fddb doc: fixed linkrot of mod_lua. thanks Tatsuhiko Kubo for the patch in #336. ec368b46f refactor: removed an unused parameter, "len", in ngx_http_lua_ffi_script_eval_data. df7bf56af doc: documented the new ngx.worker.pid() API. 7460a8d16 adjusted a test case that could fail on slow machines. e5c1105be bugfix: fixes for small string buffer arguments in the C API for FFI-based implementations of shdict:get(). 4112e749d bugfix: fixed the error message buffer overwrite in the C API for FFI-based ngx.re implementations. 766896378 skipped tests that could fail in the "check leak" testing mode. 3eafa8df1 better context info in the error messages for init_by_lua* and init_worker_by_lua*. a1c15f46b fixed an erorr message in ngx_http_lua_report. 92219bba5 feature: added new API function ngx.worker.pid() for retrieving the current nginx worker process's pid. a6e0f512e reindexed the tests in t/058-tcp-socket.t. 6525ec0d0 change: turned off lua_socket_log_errors in init_worker_by_lua*. 2c4534ab2 test: now we require the ngx_lua_upstream module for the test suite. 096e2ff8e doc: updated the "TODO" section to reflect recent changes. 870b9a7f1 test: use smaller port numbers to reduce the chance of conflicting with local ports. 2079446fa bugfix: use of the public C API in other nginx C modules (extending ngx_lua) lead to compilation errors and warnings when the Microsoft C compiler is used. thanks Edwin Cleton for the report. 47836cec1 bugfix: segmentation faults might happen when multiple "light threads" in the same request manipuate a stream cosocket object in turn. thanks Aviram Cohen for the report. c00535402 bugfix: timers created by ngx.timer.at() might not be aborted prematurely upon nginx worker exit. thanks Hamish Forbes for the report. 1d85a61f6 doc: mentioned ngx.timer.at for doing background jobs in ngx.eof's documentation. c5c8a1281 doc: markdown formatting fixes from Peter Cawley in #326. d633e34a3 added a test case to exercise a bug in $args (it requires the setting_args_invalidates_uri patch for the nginx core to pass). 7e96a2dda doc: typo fix from Zheng Ping. c07aac16e bugfix: fixed some new warnings when using Microsft's C compiler. thanks Edwin Cleton for the patch. bbaa57d2a doc: added a code example for init_worker_by_lua. 484e7df2f doc: documented init_worker_by_lua and init_worker_by_lua_file. also updated the copyright years. 9fc675f68 added more (passing) tests for init_worker_by_lua*. 356661d6b feature: added new configuration directive, init_worker_by_lua, to run Lua code upon nginx worker process startup. 81daa5356 updated .gitignore a bit. 6ba574878 minor label name fixes. 50f5b1b92 bugfix: the return value sizes of the C functions ngx_http_lua_init_by_inline and ngx_http_lua_init_by_file were wrong. 8c74fb922 bumped version number to 0.9.5. c18e03c5c refactor: made C functions ngx_http_lua_report and ngx_http_lua_do_call global. 238ace2f7 refactor: abstracted out the ngx_http_lua_create_fake_request function from the ngx.timer code base. b90bb2a57 refactor: abstracted out the ngx_http_lua_create_fake_connection function from the ngx.timer code base. 6169a191d documented the 5th optional argument, "res_table", for ngx.re.match(). eb43c9c7d doc: fixed the year. it is 2014 now :) 388094027 updated docs to reflect recent changes. b4fe8acdd bugfix: when ngx_http_lua_get_co_ctx returns NULL, it no longer means that the coroutine is dead. 5581dedcb added a test to exercise the bug in nginx's resolver that domain names with a trailing dot is rejected. c27f65b2b updated tests to reflect the changes in commit 60999efe3. 60999efe3 bugfix: segmentation fault might happen when the downstream cosocket objects were GC'd. this regression had appeared in commit e768e151ab3. 2444f32db ngx.shared: improved the error handling in incr() a bit. e768e151a bugfix: segfault might happen when aborting a "light thread" pending on downstream cosocket writes. thanks Aviram Cohen for the report. 594830073 ngx.re: added the whole regex flags string to the error message when there is an unknown regex flag. b8efc2749 added a (passing) test for error status to improve code coverage. 01f3cef14 reindexed the test file 043-shdict.t. f6d309ffd shdict: improved the error handling a bit and also added more (passing) tests. 5bf928ede ngx.var: added a (passing) test for writing to a non-changeable nginx variable. c3d8da376 ngx.var: improved the error handling a bit. 4c1d0bd10 feature: ngx.escape_uri() and ngx.unescape_uri() now accept a nil argument, which is equivalent to an empty string. a4323aab8 shdict: improved the error handling a bit and also increased the tests' code coverage. 0afaeec3d added (passing) tests for using lua numbers in response header names and values for the ngx.header.HEADER API. 76fc8a7c8 feature: added new pure C API, ngx_http_lua_ffi_max_regex_cache_size, for FFI-based implementations like lua-resty-core. dce53afc6 feature: added the optional 5th argument to ngx.re.match() which is the user-supplied result table for the captures. ed3e68fc0 added a (passing) test for providing the resulting match table to ngx.re.match(). 73d74a094 added (passing) tests for feeding lua numbers to ngx.md5(), ngx.md5_bin(), and ngx.sha1_bin(). 2d0f587ec ngx_http_lua_ffi_set_ctx_ref: return the error code NGX_HTTP_LUA_FFI_NO_REQ_CTX properly. 52dfc3fbf refactor: avoided the magic error code -3 in ngx_http_lua_ffi_get_ctx_ref. 7e7b944ad change: ngx.decode_base64() now only accepts string arguments. fc52e157e Merge pull request #322 from zh-ang/master 1b96235e5 reduce compiling warning(avoid halting compiling) c50f3cd3c doc: documented that the coroutine.* API can be used in init_by_lua since 0.9.2. thanks Ruoshan Huang for the reminder. 26c1accef tweaked a test case that could fail randomly on slow machines. eafad2990 bugfix: we did not set the shortcut fields in r->headers_in for request headers in our subrequests created by ngx.location.capture*(). thanks Aviram Cohen for the original patch in #318. f64993565 optimize: we no longer clear the lua_State pointers for dead "light threads" such that their coroutine context structs could be reused by other "light threads" and user coroutines. 8f4c48532 bugfix: coroutines might incorrectly enter the "dead" state even right after creation with coroutine.create(). thanks James Hurst for the report. 8d1459812 minor debugging log tweaks. 80c8bc0aa reindexed test file t/041-header-filter.t. 3f8a592ac feature: allow use of ngx.exit() in the context of header_filter_by_lua*. but in this context ngx.exit() returns immediately. 9b76f74de updated the tests to reflect recent changes in ngx.exit(). f364c8203 fixed incompatiblities in nginx 1.5.8 which breaks the resolver API in the nginx core. 5a4199bb9 bugfix: we might try sending the response header again in ngx.exit() when the header was already sent. 20c41e1ad version bump. 779702a17 fixed issues in the test suite exposed by nginx 1.5.7. 0787f2c2a fixed the tests for truncated subrequests to reflect the changes in nginx 1.5.3+. 685f5eaf7 bugfix: subrequests initiated by ngx.location.capture() might send their own response headers more than once. this issue might also lead to the alert message "header already sent" and request aborts when nginx 1.5.4+ was used. 4f2b35ddb doc: bumped version to 0.9.3 and also stated that we work with nginx 1.4.4. 31e221279 doc: documented the new behavior regarding zero-delay timers upon nginx worker process exiting. 6e4a22b52 doc: documented the ngx.worker.exiting() API. 3c5e109e3 bugfix: ngx.req.set_header() did not completely override the existing request header with multiple values. thanks Aviram Cohen for the report in #314. 0b9558cb1 bugfix: fixed compilation warnings when ngx_devel_kit is missing in the build. 02abcec8a doc: minor formatting fixes in the markdown version. d11dda108 added test cases for commit 2a121317. 04a7a2cca use Test::Nginx::Socket::Lua from the test-nginx project in our test suite. de86661c6 fixed the test plan in 025-codecache.t. af1b72ec1 bugfix: when lua_code_cache was off and timers created by ngx.timer.at() was exceeding the lua_max_running_timers limit, memory leak would happen. this bug had appeared in the new per-request Lua VM refactoring. 1de82ab6e bugfix: memory leak would happen in the pure C API function ngx_http_lua_ffi_destroy_regex for FFI-based ngx.re implementations. 2a121317d bugfix: when lua_code_cache is off, per-request Lua VMs should inherit package.path and package.cpath from the global Lua VM because the LUA_PATH and LUA_CPATH environments might not be inherited by nginx worker processes. thanks leaf corcoran for the report. 182042386 refactor: introduced the type ngx_http_lua_ffi_str_t for FFI-based APIs. 5ed4aa8b8 bugfix: modifying request headers in a subrequest could lead to assertion failures and crashes. thanks leaf corcoran for the report and test cases. d37d7475f refactor: removed the useless "conf" field from ngx_http_lua_socket_pool_t. 69b0e98dc refactor: cleaned up the code for Lua VM instance management. f61d7ba10 bugfix: turning off lua_code_cache and using cosocket connection pools might lead to memory issues (like segfaults). this regression had appeared in commit 5fc80b5b0. thanks Zheng Ping for the report. 77fb07257 better debugging logs for "lua_code_cache off" and better test cases. 4eade0689 doc: tweaked the wording for lua_code_cache a bit more. 26e148a0a removed an unimportant subtest from 025-codecache.t. 80944815a doc: updated the docs for lua_code_cache to reflect recent changes. 9a9c511fe added more tests for "lua_code_cache off". 250ab0892 added more debugging logs to the (global) Lua VM instance managing code. 5fc80b5b0 bugfix: turning off lua_code_cache could lead to memory issues (segfaults and LuaJIT assertion failures) when Lua libraries using LuaJIT FFI were loaded. now we always create clean separate lua VM instances for every Nginx request when the Lua code cache is disabled. thanks Ron Gomes for the report. 8acecfef6 refactor: introduce the ngx_http_lua_get_main_lua_state function to abstract away where the global lua state is stored. f07a73ef5 refactor: made the main Lua VM state creation and initialization code detached from the configuration loading phase. bb9b2b341 feature: added pure C API for FFI-based implementations of the ngx.header.HEADER API (the write part). d87ded2fe fixed an issue in commit 8e6b4e3cb7: cygwin linker only issues a warning about the use of -E rather than an error, so our previous feature test for -E always succeeds. thanks Heero Zhang for the report. 9dd88ffcd bugfix: fixed compiler warnings and errors when using the Microsoft Visual C++ compiler. thanks Edwin Cleton for the report. 5a9a6f1cc feature: added pure C API functions for FFI-based implementations for ngx.req.get_uri_args(). 8e6b4e3cb bugfix: the linker option -E is not support in Cygwin's linker; we should test --export-all-symbols when -E is unavailable. thanks Heero Zhang for the report. 5d7e08ce0 documented the new "nth" argument for ngx.re.find. 6213b040c bugfix: ngx.re.find: fixed the case when "nth" is greater than or equal to "rc" but not exceeds the number of captures. a8c0b5f2b bugfix: ngx.re.find: we incorrectly returned negative indexes for nil submatch captures; also we returned the "nth out of bound" when there was a trailing nil submatch capture. 27b804d4c bugfix: ngx.re.find() did not return an error when the "nth" argument is out of bound. 55adcc6b0 feature: ngx.re.find() now accepts the optional 5th argument "nth" to control which submatch capture's indexes are returned. thanks Lance Li for the feature request in agentzh/lua-resty-core#1. 590ac5c94 updated the test suite to reflect recent changes in Test::Nginx. 5e0db0e9a fixed the "ngx" table preallocation space. 014de9d9b doc: typo fix from Zheng Ping. 77f24ba4a fixed a test case in t/014-bugs.t. 513051779 bugfix: 0-delay timers created after the worker starts shutting down should not always expire prematurely. 002b68ec7 feature: added new API function ngx.worker.exiting() for testing if the current worker process is exiting. 4d6dc5804 feature: allow creating 0-delay timers upon worker process existing. e5f63816b doc: more formatting tweaks. 55623aca7 doc: fixed regressions in the markdown version. f5b78fc80 doc: markdown: removed unnecessary indentation from code samples. 159be4c9b doc: documented how to link against a static library (or object file archive) consisting of (many) compiled Lua module files. 736fce1ad doc: added new section "Statically Linking Pure Lua Modules". 5cb9d9d48 doc: mention LuaJIT 2.1 wherever we mention LuaJIT 2.0. 98f9420bf added ljson.lua for the test suite so that we can have sorted keys in the JSON encoded output. 9401a60cb fixed the table pre-allocation space for the ngx.config table. 86a08bab4 documented the new ngx.config.nginx_version and ngx.config.ngx_lua_version API. 797fa5cac feature: added new API for version numbers of both nginx and the ngx_lua module itself: ngx.config.nginx_version and ngx.config.ngx_lua_version. thanks smallfish for the patch. 3748896d6 minor debugging log message tweaks. e4e085f73 Merge branch 'master' into ffi 93bc3c505 updated docs to reflect the new support for loading LuaJIT 2.1 bytecode directly. 358f9a590 feature: added support for loading LuaJIT 2.1 bytecode files directly in *_by_lua_file directives. 11dee4a44 feature: added pure C API for FFI-based implementations of ngx.req.get_headers. 3e63ceba3 feature: added pure C API for FFI-based implementations for storing operations in the shared dictionaries. 6e0a5c528 bugfix: the FFI API for ngx.var incorrectly used the storage of the input buffer. 15e53e3a1 Merge branch 'master' into ffi 1523ab0ac removed the plain text README file. 622f12aad feature: added pure C API for implementing ngx.var writes via LuaJIT FFI. 6c1e4d621 optimized the default implementation of ngx.headers_sent a bit. 97d6a8c94 feature: added pure C API for FFI-based implementations of ngx.headers_sent. 12920fffb feature: added pure C API for FFI-based implementations of ngx.is_subrequest. a7a41fd0c feature: added pure C API for FFI-based API for ngx.status. 7358557db feature: added pure C API for FFI-based implementations of ngx.ctx. 7b9d88656 Merge branch 'master' into ffi d516e4e31 bumped version to 0.9.2. 229a22142 documented the new ngx.config.prefix() API function. 8228e9844 bugfix: reading ngx.header.HEADER could result in Lua string corruptions. thanks Dane Knecht for the report. 1bedc5d4c ngx.re.find now returns a single nil value when no match is found. 2d6cf5c7f documented the new ngx.re.find API function. d577a63e8 merged branch "master" into "ffi". 87dd3cf15 updated valgrind.suppress a bit. e454b0b1c Merge branch 'master' into ffi a44298037 updated .gitignore a bit. e6db9d3ae added tests for ngx.re.find. 279da4d09 feature: added new API function ngx.re.find, which is similar to ngx.re.match, but only returns the beginning index and end index of the whole match. 91d701d19 updated tests to reflect the fix in commit ccb0cbe0d. d333a369e minor coding style fixes. f5944933b updated docs to reflect recent changes. ccb0cbe0d bugfix: ngx.re.match: the ctx table's "pos" field should start from 1 instead of 0. 8fe00e8fc fixed a test title. 3c0a9d90b add debugging logs for the Lua VM initialization and shutdown. 0c85bec1b removed valgrind suppression rules for LuaJIT. f4af449f6 updated valgrind.suppress when the sysmalloc is used. 93493ea7d no longer set RPATH for luajit lib in the developer build script; also updated valgrind.suppress for luajit using system malloc. 0bd56bb8c updated valgrind.suppress when the sysmalloc is used. 483a3a9d7 no longer set RPATH for luajit lib in the developer build script; also updated valgrind.suppress for luajit using system malloc. df91a47b6 bugfix: compilation errors with nginx older than 1.0.0. 642db29e5 Merge branch 'master' into ffi 22f4c67a1 fixed the test plan for 119-config-prefix.t. 5536b8540 merged branch "master" to "ffi". 014c6b51b bugfix: localizing the coroutine.* API functions in init_by_lua* for future use in contexts like content_by_lua* might hang the Lua code. thanks James Hurst for the report in #304. cd52bd369 feature: added new API function ngx.config.prefix() to return the nginx server prefix path. c99ebeb4d documented the new lua_use_default_type directive. a95851bb1 doc: updated the docs for ngx.req.socket(raw) to reflect the recent change that allows reading raw request body data directly. b6715395c doc: bumped version to 0.9.1; also added a new section "System Environment Variable Support". 594f55bcb added a test case to exercise a bug in ngx_gunzip module with which ngx.flush(true) could hang forever. thanks Maxim Dounin for the catch. to make this test pass, we need the gzip_flush_bug patch applied to the nginx core. 4615fd591 bugfix: use of ngx.exit() to abort pending subrequests in other "light threads" might lead to segfault or request hang when HTTP 1.0 full buffering is in effect. 4ec0347d9 Merge branch 'master' into ffi b1ec27548 optimize: made ngx.re.match and ngx.re.gmatch faster for LuaJIT 2.x when there is no submatch captures. 9f134736c added a test for accessing $proxy_host and $proxy_port in Lua. this test requires the proxy_host_port_vars patch for the nginx core to pass. thanks saravsars for the report in #301. b361a101f updated valgrind.suppress to reflect recent changes. db87600eb doc: added language syntax highlighting to the markdown version. 647706f5b added a test case that exercises a bug in nginx's cache lock, which could lead to infinite request hang when cache_lock_timeout is exceeded. this test requires the cache_lock_hang_in_subreq patch to pass. thanks Akos Gyimesi for the report in #298. a8396e505 bugfix: downstream write events might interfere with upstream cosockets that are slow to write to. thanks Aviram Cohen for the report. 1f65751fc bugfix: removing a request header might lead to memory corruptions. thanks Bjørnar Ness for the report. 82ba941d2 bugfix: reading the value of ngx.status might get different values than ngx.var.status. thanks Kevin Burke for the report. 1c0a9e831 added a test for using ngx.flush(true) with the standard ngx_gzip module. it could hang in mainline nginx cores older than 1.5.3. 350e38a34 bugfix: the bookkeeping state for already-freed user threads might be incorrectly used by newly-created threads that are completely different. thanks Sam Lawrence for the report. 0f3c249a9 bugfix: calling ngx.thread.wait() on a user thread object that is already waited (i.e., already dead) would hang forever. thanks Sam Lawrence for the report. dad8ba3ab doc: fixed the context for the lua_package_path and lua_package_cpath directives. thanks duhoobo for the report in #297. 22ba5b114 fixed the test plan in 082-body-filter.t. 9e39cfd62 bugfix: the alert "zero size buf" could be logged when assigning an empty Lua string ("") to ngx.arg[1] in body_filter_by_lua*. 9bae5adf3 refactor: eliminated introducing NULL chain link in body_filter_by_lua*, which simplied the implementation a lot. 45319bfe5 doc: markdown: added lots of "Back to TOC" links to each sections but the beginning ones. 71d42c6d9 doc: markdown: added a "Table of Contents". b22569669 docs: markdown: made the module name more readable. d8c8e86c0 docs: markdown: fixed more external links that still point to wiki.nginx.org. f026151f0 docs: markdown: fixed links that were pointing to wiki.nginx.org, wherever possible. 70ecf928f docs: fixed the links in the markdown source. now they no longer point to the (broken) nginx wiki site. 82cbbd833 bugfix: subrequests initiated by ngx.location.capture* could trigger unnecessary response header sending actions in the subrequest because our capturing output header filter did not set "r->header_sent". f17fc0941 bugfix: the Lua error when ngx.sleep() was used in log_by_lua* was not friendly. thanks Jiale Zhi for the report. 39ac6421a bugfix: ngx.req.set_header("Host", value) would overwrite the value of $host with bad values. thanks aviramc for the patch in #293 (and issue #292). 335ad8cc9 added a code comment regarding the "active_connections" field in ngx_http_lua_socket_pool_t. b41f546c7 fixed the preallocation size for the "coroutine" Lua table. 9a986c9f9 Merge branch 'master' into ffi ca90ef434 optimize: pre-allocate space for the resulting Lua tables in ngx.location.capture*. 054444dd4 optimize: preallocate some space in our Lua registry tables to reduce the initial requests' "warm-up" time a bit. 0b3c47a3b optimize: preallocate the space for the metatable for the global environment table for header_filter_by_lua*, body_filter_by_lua*, and log_by_lua*. 101f8d9ed optimize: preallocate 4 hashtable slots in the ngx.ctx tables. ace93e66f optimize: preallocate space for the "ngx.thread" lua table during API initialization. d7e8ff8ca resolved a merge conflict. 136087f32 optimize: preallocate space for the "coroutine" lua table. bc8496447 optimize: preallocate space for the "coroutine" lua table. 330fe6e59 merged "master" into "ffi". c304f3592 bugfix: when there were no existing Cache-Control response headers, "ngx.header.cache_control = nil" would (incorrectly) create a new Cache-Control header with an empty value. thanks jinglong for the patch. 01bf02aa0 bugfix: the original lettercase of the header name was lost when creating the Cache-Control response header via the ngx.header.HEADER API. 487618a80 bugfix: header_filter_by_lua*, body_filter_by_lua*, and ngx.location.capture* might not work properly with multiple http {} blocks in nginx.conf. thanks flygoast for the report in #294. bc43c4367 docs: added more explanation on subrequests' request body handling. thanks Jędrzej Nowak for the suggestion. cd669b556 made a test case in 024-access/client-abort.t less possible to fail due to timing errors. fc03bfec3 bugfix: now ngx.req.socket(raw) returns proper error when there is some other "light thread" reading the request body. ebf9cc867 feature: now the raw request cosocket returned by ngx.req.socket() no longer requires the request body to be read already, which means that one can use this cosocket to read the raw request body data as well. thanks aviramc for the original patch. 374096296 added tests for the new lua_use_default_type directive. e5d47c448 bugfix: we always printed the "lua hit request header limit" debug log message even when the limit is not hit at all. this regression had appeared in commit d8a266497a. 789e36b49 feature: added the new configuration directive "lua_use_default_type" for controlling whether to send out a default Content-Type response header (as defined by the "default_type" directive). default on. thanks aviramc for the patch in #286. d8a266497 optimize: now we pre-calculate the exact size of the resulting Lua table and preallocate the table space, which makes it 8%+ faster for a request with a dozen request headers and 40%+ faster for a hundred request headers. f99825624 reindexed the 025-codecache.t test file. 2063a94b2 docs: bumped version to 0.9.0 and mentioned lua-resty-websocket and lua-resty-lock. eabadd9b2 docs: documented the new ngx.req.socket(true) API, upon which fancy protocols like WebSocket can be implemented. 04e53ee37 bugfix: Lua VM might run out of memory when lua_code_cache is off; now we always enforce a full Lua GC cycle right after unloading most of the loaded Lua modules when the Lua code cache is turned off. 8e6c9a312 change: raised the "lua_code_cache is off" warning to an alert. c4657a35b feature: now we allow use the raw request cosocket returned by ngx.req.socket(true) to send the raw HTTP response header. thanks aviramc for requesting this in #242. also we now always enable "lingering close" in the nginx core when raw req sockets are used. 42567bd24 docs: made the "Test Suite" section up to date (I hope). 7720bc7d9 removed the ngx_upstream_keepalive module from the developer build script because it has been included in the official nginx distribution. 5dfd54714 tests: removed the "single" option from the "keepalive" directive because it is not a public feature. 095ed4a23 bugfix: compilation regressions with nginx older than 1.3.13, introduced recently by the ngx.req.socket(true) API. 0387a89e7 bugfix: Windows compatibility issue in the Lua/LuaJIT bytecode file loader: it assumed that ngx_fd_info accepts integral fd as the 1st argument. thanks Edwin Cleton for the report (#283) and thanks jinglong for the original patch in #284. a41567b64 bugfix: the standard Lua coroutine API was not available in the context of init_by_lua* and threw out the "no request found" error. thanks Wolf Tivy for the report. c6b6b315d more warning fixes for the Microsoft Visual C++ compiler. thanks Edwin Cleton for the report. 585e7af92 bugfix: fixed most of the compiler warnings from the MinGW C compiler, some of which are real overflow issues. thanks Edwin Cleton for the report. 33832b1f7 fixed bad request header lines in the tests in 116-raw-req-socket.t, which caused test bailout in the "check leak" testing mode. a0ff19221 bugfix: memory invalid reads might happen when ngx.flush(true) was used: the "ctx" struct could get freed in the middle of processing and we should save the state explicitly on the C stack. 19f6f2f36 Merge branch 'master' into websocket add6df63b Merge branch 'master' into ffi e78dea9e0 bumped version to 0.8.10. 1d4c76d17 bugfix: we did not declare the "level" local variable of ngx_http_lua_ngx_log at the beginning of the code block. thanks Edwin Cleton for the report. db35efd18 docs: documented more limitations in the current implementation. a98ff5f80 docs: avoided using module() and also recommended the lua-releng tool to locate misuse of Lua globals. c218ed706 testing: fixed the stap probes for the new ffi implementation. 8fdfc7983 bugfix: use of the ctx->headers_sent field that was already removed. ca27b9e36 Merge branch 'master' into ffi 6597dc591 Merge branch 'master' into websocket a641101a5 bumped version to 0.8.9. 235875b5c refactor: removed our own ctx->headers_sent field because we should used r->header_sent instead. 4256020e4 Merge branch 'master' into websocket 95e293160 bugfix: the "pool" option value could not be nil in tcpsock:connect(). 7b726b32c change: we now temporarily disable the Lua API functions ngx.location.capture, ngx.location.capture_multi, and ngx.req.socket that are known to have problems with the SPDY requests for now. we will fix them eventually in the near future. 0557e44aa Merge branch 'master' into websocket 22e09118b bugfix: the nginx core does not send a default status line for 101 status code. now we construct one for 101. 8bbd6aae2 bugfix: the nginx core does not send a default status line for 101 status code. now we construct one for 101. 876beeef5 Merge remote-tracking branch 'origin/master' into websocket 36157b4cd bugfix: tcpsock:receive(0) could hang when no data arrived; now it always returns an empty string immediately. this new behavior diverges from LuaSocket though. aa2104931 Merge remote-tracking branch 'origin/master' into websocket 38ebe9a31 bugfix: we did not honor the tcp_nodelay config directive in the raw downstream cosockets. 5b7c567cb documented the "always_forward_body" option for ngx.location.capture() and ngx.location.capture_multi(). 4c6dc4f7a updated docs to reflect recent changes. 410930fa3 feature: added support for raw downstream cosocket via the ngx.req.socket(true) API, upon which http upgrading protocols like WebSocket can be implemented with pure Lua. 55776b7b5 tests: use larger timeout settings to account for slow DNS servers. ba7c1766b fixed those recently-added test cases that could fail in slow testing modes on slow machines. 0f7948d52 bugfix: we did not escape \z, \t, and \b properly in ngx.quote_sql_str(). 6e4b5745a bugfix: the null character ('\0') was not escaped in ngx.quote_sql_str() according to the MySQL quoting rules. thanks Siddon Tang for the report. fe3c318fa change: we now limit the number of nested coroutines in the backtrace dump for uncaught Lua exceptions by 5. 7c5e3548a bugfix: Lua backtrace dumps upon uncaught Lua exceptions did not work with the standard Lua 5.1 interpreter when the backtrace was deeper than 22 levels. now we just dump the top 22 levels in the backtrace for simplicity. also optimized the Lua string concatenation operations when constructing the backtrace string. 2926596a2 feature: now timeout errors in tcpsock:receive() and the reader returned by tcpsock:receiveuntil() no longer close the current cosocket object automatically. thanks Aviram Cohen for the original patch. 1a9f044dc now we allow application of the mockeagain reading mode to the test files that require the mockegain writing mode. 438bbca78 added a (passing) test for recalling the send() method on the same tcp cosocket object right after a send timeout error happens. 75d2524ba added a (passing) test for recalling the connect() method on the same tcp cosocket object right after a connecting timed out error happens. 45f430a00 feature: added new option "always_forward_body" to ngx.location.capture(), which controls whether to always forward the parent request's request body to the subrequest. 9d5bb2aa5 refactor: made the "processing flushing coroutines" process a separate C function. 37a502108 minor code refactoring to make the ngx_http_lua_wev_handler function shorter. 29a253b55 Revert "bugfix: ngx.flush(true) might hang when there was a buggy output body filter. now we only test the condition "r->connection->buffered & NGX_LOWLEVEL_BUFFERED"." 4ed6e7a54 bugfix: ngx.flush(true) might hang when there was a buggy output body filter. now we only test the condition "r->connection->buffered & NGX_LOWLEVEL_BUFFERED". 539a3021f one minor optimization in ngx.req.socket(). 138bc9d91 documented the new ngx.config.debug API and also updated docs to reflect other recent changes. db7a8c90c feature: added new FFI C API function ngx_http_lua_ffi_var_get for reading ngx.var.VARIABLE. b6d19752e feature: added new FFI C API ngx_http_lua_ffi_shdict_incr for shdict:incr(). 6473e2242 minor coding style fixes. e7f3b0264 feature: added new FFI C API for shdict:get(). also we use double instead of lua_Number when storing Lua numbers into shdict. b68729345 bugfix: the FFI C API function ngx_http_lua_ffi_compile_regex could leak memory when pcre failed to compile the regex pattern argument. d9400dc43 skipped the regex tests for checking bad data types, which cannot pass with lua-resty-core. 6227668ef bugfix: the FFI version of the PCRE API did not generate debug logs indicating the result of PCRE JIT compilation. 65010dd09 feature: added support for lua_regex_match_limit in the FFI C API function for PCRE. 527009f21 Merge remote-tracking branch 'origin/master' into ffi c75204927 optimize: fixed the initial table sizes for "ngx", "ngx.config", and "ngx.re". 9577e5fc5 feature: added new API ngx.config.debug to indicate whether this is a debug build of nginx. 021645c5e Merge remote-tracking branch 'origin/master' into ffi fdec27035 fixed test cases that tried to send the response header twice, which were caught by nginx 1.5.4. 3e049c594 minor cleanup in a recently added test case. 1e13a16b3 minor refactoring in the closure factory. c9a04a9c2 bugfix: when a Lua line comment was used in the last line of the inlined Lua code chunk, a bogus Lua syntax error would be thrown. d9a48d86c bugfix: the error message for failures in loading inlined Lua code was misleading. a0343434b bugfix: ngx.exit(204) could try to send the response header for twice. nginx 1.5.4 caught this issue. f4c4667b5 fixed a potential test failure in a recently added test case in 025-codecache.t. 3abd78b2f Merge branch 'master' into ffi e549fc2df feature: log_by_lua now always runs before the standard ngx_http_log_module (for access logging). thanks Calin Don for the suggestion in #254. 334afb35d fixed a test case index number in 025-codecache.t. b3734f002 bugfix: the global Lua state's _G table was cleared when lua_code_cache was off, which could confuse the setup in init_by_lua. thanks Robert Andrew Ditthardt for the report in #257. 4042f7bd6 bugfix: ngx.flush() triggered response header sending when the header was not sent yet. now it just returned the error string "nothing to flush" for this case. thanks linbo liao for the report. 940429a5c bumped version to 0.8.6. 2db5028ad bugfix: segfaults would happen in ngx.req.set_header() and ngx.req.clear_header() for HTTP 0.9 requests. thanks Bin Wang for the report in agentzh/headers-more-nginx-module#14. 65d4b419b minor test fixes. e72ab1dba minor coding style fixes. c7237efd8 made the test for shdict:get_stale less possible to fail. 7dbd2a511 bugfix: reading ngx.header.location did not work when auto-redirect was in action. this is a further fix for #260. 547d29946 bugfix: segfault might happen when reading or writing to a response header via the ngx.header.HEADER API in the case that the nginx core initiated a 301 redirect. this issue was caused by an optimization in the nginx core where ngx_http_core_find_config_phase, for example, does not fully initialize the "Location" response header after creating the header. thanks Vladimir Protasov for the report in #260. e0626c312 added tests to improve the code coverage in file ngx_http_lua_headers_out.c. 87a4f346b documented the new "get_stale" method for shdict objects. 424232deb updated docs to reflect recent changes. 124f50fd4 feature: added new method "get_stale" to shared dict objects, which returns the value (if not freed yet) even if the key has already expired. thanks Matthieu Tourne for the patch in #249. 2f5ebebcd bugfix: the "connect() failed" error message was still logged even when lua_socket_log_errors was off. thanks Dong Fang Fan for the report. 52f48e076 bugfix: we incorrectly returned 500 in our output header filter, body filter, and log-phase handlers upon inlined Lua code loading errors. bugfix: Lua stack overflow might happen when we failed to load inlined Lua code from the code cache. c7a52824a more coding style fixes. abaa7f427 more coding style fixes. e4641a3c7 more coding style fixes. 5edc4b3fc one minor coding style fix. thanks Guanlan Dai. c6426fb5e fixed the test plan in t/033-ctx.t. 0aa9332f5 bugfix: we incorrectly returned 500 in our output header filter, body filter, and log-phase handlers upon errors. bugfix: Lua stack overflow might happen when we failed to load Lua code from the code cache. 629330431 bugfix: memory leak would happen when using ngx.ctx before another nginx module (other than ngx_lua) initiates an internal redirect. 32aadb76d fixed a test case. e24ffb751 bugfix: use of the ngx.ctx table in the context of ngx.timer callbacks would leak memory. ffe89f226 refactor: abstracted the ngx.ctx releasing logic to eliminate code duplication. 00c5fb411 one minor coding style fix. 6859f6f8b minor error message fixes in the Lua code cache. 197332049 added a (passing) test for using .lua files with a shebang line in the content_by_lua_file directive. d1c654b3e bugfix: the error message was misleading when the *_by_lua_file directives failed to load the Lua file specified. fb38e4b27 various coding style fixes in the closure factory. 1db1e71f1 refactor: removed the useless code for reading Lua code from stdin. fadd28a11 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 918f9a239 refactor: removed the unused C function ngx_http_lua_clfactory_loadstring. df35583dd Merge pull request #262 from cubicdaiya/issues/traditional_definition 60902726d give the argument of 'void' to function definitions which has no arguments eecb52bc4 bugfix: when our atpanic handler for Lua VM gets called, the Lua VM is not recoverable for future use. so now we try to quit the current nginx worker gracefully so that the nginx master can spawn a new one. 0d8143091 bumped version to 0.8.5. 4516e5adf docs: documented the memory freeing behavior of shdict:flush_all and shdict:flush_expired. f36a35d39 documented the lua_regex_match_limit directive. 9d017a21e feature: added new directive lua_regex_match_limit for setting PCRE match_limit for regex matching. 0aca2046f bugfix: when compiling with -DDDEBUG=1, there was a compilation error in ngx_http_lua_uthread.c. thanks tigeryang for the report in #259. 8708f604f docs: typo fixes in the code sample for body_filter_by_lua. thanks cyberty for reporting this issue as #261. fe467e52b bugfix: the ngx.ctx tables would leak memory when ngx.ctx, ngx.exec()/ngx.req.set_uri(uri, true), and log_by_lua were used together in a single location. thanks Guanlan Dai for writing the gdb utils to catch this. a184a9111 util/build2.sh: default to nginx 1.4.1 now. 76c2427ac test: made the resolver less possible to time out in two test cases. 4656a290b docs: bumped version to 0.8.4; also mentioned Nginx Systemtap Toolkit. 4d27348cc bugfix: tcpsock:send("") resulted in the error log alert message "send() returned zero". 6977e9518 bugfix: setting ngx.var.VARIABLE could lead to stack buffer over-read in luaL_error when an error happened. 25ef1f942 feature: added pure C API for ngx.exit, which is expected to be used with LuaJIT FFI (or lua-resty-core in particular). also added coroutine._yield for the original std version of coroutine.yield. d86d3dc6f Merge remote-tracking branch 'origin/master' into ffi 5e256f8bf refactor: now we store the nginx request object as a named Lua global variable __ngx_req to help FFI-based Lua code access it. d82196f7f bugfix: t::TestNginxLua: env TEST_NGINX_INIT_BY_LUA would break existing init_by_lua_file directive in the test case. 0e5d1a892 Merge branch 'master' into ffi 569cabe17 refactor: no longer store cf->log into the lua registry table because we can directly access the global ngx_cycle->log thing. d9e3e8fee refactor: added inline functions ngx_http_lua_get_req and ngx_http_lua_set_req to eliminate code duplication when storing or fetching the nginx request object from the lua global variable table. fe27fc2a4 updated README.markdown to reflect recent changes in docs. f05ef37b9 optimize: avoided use of the nginx request objects in ngx.encode_args. 5a0bb76e6 optimize: avoided use of the nginx request objects in ngx.escape_uri, ngx.unescape_uri, ngx.quote_sql_str, ngx.decode_base64, ngx.encode_base64, and ngx.decode_args. 488ab67c0 Merge branch 'master' into ffi d8aa2feda updated docs to reflect recent changes. ff9580dd3 bugfix: ngx.flush(true) might not return 1 on success. 5a880aea9 change: made ngx.say/ngx.print/ngx.eof/ngx.flush/ngx.send_headers return nil and a string describing the error in case of most of the common errors (instead of throwing out an exception), and return 1 for success. cf4f62a62 updated .gitignore a bit. b07a3d3c5 fixed failing test cases to reflect the multi-value header change in nginx 1.4.1. f40a50427 tests: replaced the domain name "direct.agentzh.org" with "agentzh.org". 34f4042f2 Revert "bugfix: use of LuaJIT FFI when disabling the Lua code cache would lead to LuaJIT GC assertion failures like "g->gc.total == sizeof(GG_State)" because we unloaded the standard "ffi" module. thanks Ron Gomes for reporting this issue." b3218be26 bugfix: use of LuaJIT FFI when disabling the Lua code cache would lead to LuaJIT GC assertion failures like "g->gc.total == sizeof(GG_State)" because we unloaded the standard "ffi" module. thanks Ron Gomes for reporting this issue. 48067c830 feature: added pure C API for ngx.re.sub and ngx.re.gsub, which is expected to be used by lua-resty-core and etc. ef8779b18 Merge remote-tracking branch 'origin/master' into ffi 39151875d updated docs to reflect recent changes. 63a9915d3 added (passing) tests for use of the $invalid_referer variable in Lua. this requires the patch invalid_referer_hash for the nginx core (for now). thanks Fry-kun for reporting this issue as github #239. f50c7789b bugfix: a test case would fail when TEST_NGINX_PORT was set to port numbers other than 1985. 9e4f9272d Merge remote-tracking branch 'origin/master' into ffi 603c7a479 refactor: made the error messages for replacement template compilation failures less verbose in ngx.re.sub and ngx.re.gsub. 52bc57345 Merge remote-tracking branch 'origin/master' into ffi bd679f20e refactor: save the ngx_log_t pointer instead of the ngx_http_request_t pointer in ngx_http_lua_script_engine_t. this will make the new FFI-based Lua API easier to implement. f20bc6610 added custom test scaffold t::TestNginxLua which subclasses Test::Nginx::Socket. it supports the environment TEST_NGINX_INIT_BY_LUA which can be used to add more custom Lua code to the value of the init_by_lua directive in the nginx configuration. 300b167bd fixed a test that may time out unexpectedly. 5cd82926f bugfix: no longer automatically turn underscores (_) to dashes (-) in header names for ngx.req.set_header and ngx.req.clear_header. thanks aviramc for the report. 9cfcb06ba bugfix: segmentation fault might happen in nginx 1.4.x when calling ngx.req.set_header on the Cookie request headers because recent versions of nginx no longer always initialize r->headers_in.cookies. thanks Rob W for reporting this issue as #237. 06da40f9b style: fixed one line's indentation. 71e16c46d added custom test scaffold t::TestNginxLua which subclasses Test::Nginx::Socket. it supports the environment TEST_NGINX_INIT_BY_LUA which can be used to add more custom Lua code to the value of the init_by_lua directive in the nginx configuration. 1f1a31c7b feature: added pure C API for ngx.re.match, which is expected to be used by lua-resty-core and etc. 170d8f9d7 bugfix: ngx_http_lua_ffi_escape_uri did URI unescaping instead of URI escaping. 1bf2344ca Merge remote-tracking branch 'origin/master' into ffi 31a80431c fixed some expected error messages in the ngx.re test cases for Lua implementations of the ngx_lua API like lua-resty-core. e8ec21e9a Merge remote-tracking branch 'origin/master' into ffi 9b8a7b5e0 change: made more error messages for regex exec failures less verbose. a80d4e1d6 Merge remote-tracking branch 'origin/master' into ffi 5c5a0a87b change: made the error messages for regex exec failures less verbose. ece37a98e Merge remote-tracking branch 'origin/master' into ffi 35e6a65f9 change: made the error messages for regex compilation failures less verbose. 0e9fbdfb7 Merge remote-tracking branch 'origin/master' into ffi 4806fc2ee bugfix: fixed the warning "argument 'nret' might be clobbered by 'longjmp' or 'vfork'" when compiling with Ubuntu 13.04's gcc 4.7.3. thanks jacky and Rajeev's reports. 41e3c2f5b docs: documented the new WebDAV request methods; also fixed a small typo. b4c2ad1f8 feature: added ngx.HTTP_MKCOL, ngx.HTTP_COPY, ngx.HTTP_MOVE, and other WebDAV request method constants; also added corresponding support to ngx.req.set_method and ngx.location.capture. thanks Adallom Roy for the patch. 601ddff37 optimize: ngx.escape_uri now runs faster when the input string contains no special chars to be escaped. b7b728926 bugfix: temporary memory leaks might happen when using ngx.escape_uri, ngx.unescape_uri, ngx.quote_sql_str, ngx.decode_base64, and ngx.encode_base64 in tight Lua loops because we allocated memory in nginx's request memory pool for these methods. f442858bb minor coding style fixes and micro optimizations in ngx.md5, ngx.encode_base64, and ngx.decode_base64. 1cc76f597 feature: allow injecting new APIs into the "ngx" table. c04c51a23 bugfix: ngx.req.set_body_file() always enabled Direct I/O which caused the alert message "fcntl(O_DIRECT) ... Invalid argument" in error logs on file systems lacking the Direct I/O support. buffer corruption might happen in ngx.req.set_body_file() when nginx upstream modules are used later because ngx.req.set_body_file() incorrectly set r->request_body->buf to the in-file buffer which could get reused by ngx_http_upstream for its own purposes. thanks Matthieu Tourne for reporting this issue. 5cb2b4946 feature: added pure C API for ngx.escape_uri and ngx.unescape_uri, which is expected to be used by lua-resty-core and etc. 0ab77f964 feature: added pure C API for ngx.encode_base64 and ngx.decode_base64, which is expected to be used by lua-resty-core and etc. c355f0b5b bugfix: failed to compile when SHA1 support is missing. this regression had appeared in cea321f7f9e2614c9e0932e367d15502507fa7e9. 6ef7cef0d feature: allow injecting new APIs into the "ngx" table. cea321f7f added pure C API for ngx.md5, ngx.md5_bin, ngx.sha1_bin, which is expected to be used with LuaJIT FFI (or lua-resty-core in particular). such API can be excluded by specifying the C macro NGX_HTTP_LUA_NO_FFI_API. 34411875f added error log checks to the bytecode tests. e7dff1b30 updated the docs in plain text and markdown format to reflect recent changes. c558c4347 bumped version to 0.8.1. 04c81b1f8 minor coding style fixes. 65ff8d86d fixed a test case that may behave slighly differently on slow machines. 790a74e04 bugfix: when lua_http10_buffering is on, for HTTP 1.0 requests, ngx.exit(N) would always trigger the nginx's own error pages when N >= 300. thanks Matthieu Tourne for reporting this issue. 3052bcd8a updated .gitignore a bit. f41226883 refactor: removed the unused parameter, "no_create", from the ngx_http_set_header_helper function. 30cbc3307 fixed several places in the header API where we should return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR. d1eca0c72 fixed one test case's title. 7695a31e0 documented the new "U" regex option for the ngx.re API. 7e515f189 bugfix: modifying the Cookie request headers via ngx.req.set_header or ngx.req.clear_header did not update the Nginx internal data structure, r->headers_in.cookies, at the same time, which might cause issues when reading variables $cookie_COOKIE, for example. thanks Matthieu Tourne for the patch. 0ac676f65 feature: added the "U" regex option to the ngx.re API to mean enabling the UTF-8 matching mode but disabling UTF-8 validity check on the subject strings. thanks Lance Li for the patch in #227. 766563fba one minor coding style fix. b90e7dd1a bugfix: modifying the Via request header with ngx.req.set_header/ngx.req.clear_header did not update the special field r->headers_in.via when the ngx_gzip module was enabled. 97425f8dc bugfix: ngx.req.set_header/ngx.req.clear_header did not update the special field r->headers_in.x_real_ip when the ngx_realip module was enabled. thanks Matthieu Tourne for the patch. a07df6151 bugfix: modifying the Connection request header via ngx.req.set_header or ngx.req.clear_header did not update the special internal flags in the Nginx core, "r->headers_in.connection_type" and "r->headers_in.keep_alive_n". Thanks Matthieu Tourne for the patch. 55555a78a bugfix: modifying the User-Agent request header via ngx.req.set_header or ngx.req.clear_header did not update those special internal flags in the Nginx core, like "r->headers_in.msie6" and "r->headers_in.opera". Thanks Matthieu Tourne for the patch. 2aa12ab3d bumped version to 0.8.0. 656551e61 documented ngx.timer.at, lua_max_pending_timers, lua_max_running_timers, and other recent changes. 6afcc17ff feature: ngx.get_phase() now returns the string "timer" when being invoked within a user callback function for ngx.timer.*. d98a193d4 added a (passing) test for using ndk.set_var.* in the context of ngx.timer callbacks. d997f7401 refactor: replaced "ngx_lua_" with "ngx_http_lua_" in the identifiers used in ngx_http_lua_regex.c. d43a39c59 bugfix: setting ngx.header.etag could not affect other things reading the ETag response header (like the "etag" directive introduced in nginx 1.3.3+). thanks Brian Akins for the patch in #213. e2d299e50 Merge branch 'timer' f081f212d bumped version to 0.7.21. b2ae68b7a merged "master" into "timer". 6717d1153 feature: added support for user arguments to the user callback function specified in ngx.timer.add(); the user callback function has the prototype "function(premature, user_arg1, user_arg2, ...)". 26d679f8d bugfix: ngx.req.raw_header() would return an empty string value when the default header buffer (c->buffer) can hold the request line but not the whole header. thanks KDr2 for reporting this issue in #229. 10edc8cb0 added a passing test for calling ngx.timer.at() after HUP reload. 069f07541 feature: when the nginx worker process is quitting (as in server shutdown or HUP reload), all the pending ngx.timer timers expire immediately and their Lua callbacks get called with a true value as the first argument (to indicate whether it is a premature expiration or not). f820e5476 Merge branch 'master' into timer 4e8c4bfcb bugfix: boolean values in an array table were rejected with the exception "attempt to use boolean as query arg value" while encoding a lua (hash) table as URL arguments. thanks Calin Don for reporting this issue. 5df2ec9fa Merge branch 'master' into timer a414691b8 updated docs to reflect recent changes. 71bf29a2f merged "master" branch to "timer". 7c6484dc2 updated tests to reflect recent changes in the upstream_truncation patch for the nginx core. 59fe204e9 added error log checks in 000--init.t. 4eeb47626 removed too short proxy read timeout settings in two cases that are expected to pass. 9e3b32f90 fixed a test case that might fail in slow testing modes. b408d5be9 feature: ngx.location.capture and ngx.location.capture_multi now return a lua table with the boolean field "truncated", which indicates whether the subrequest response body is truncated. bugfix: we no longer override the subrequest response status code later when error happens. e9f9fdd3a bugfix: request hung when rewrite cycled in ngx.req.set_uri(uri, true) instead of throwing out an error log message and a 500 page properly. thanks Calin Don for the report. 74617ac4c bugfix: the debug log message "lua set uri jump to <uri>" generated by ngx.req.set_uri(uri, true) was wrong for <uri> was the old URI. 8dc910197 tests: made two systemtap-based test cases less possible to fail in slow testing mode. 40bc1bb0f tests: ensure that TEST_NGINX_USE_STAP is unset when TEST_NGINX_USE_HUP is set. 3c6379264 Merge remote-tracking branch 'origin/master' into timer c7a0cf5f2 Merge remote-tracking branch 'origin/master' into timer 2ac8d8943 feature: added new Lua API, ngx.timer.at(time, callback), for defining timers that can run the user callback as a Lua "light thread" (detached from the current request) after the time (in seconds) specified. also added new configure directives lua_max_pending_timers and lua_max_running_timers for limiting the number of pending timers and "running" timers. a352e1fd6 feature: now we allow zero time argument in ngx.sleep(). 66e2ccbfa bugfix: assignment to ngx.status did not take effect when the response status line had already been generated (by ngx_proxy or others). thanks eqiuno for reporting this issue in #221. d4b8c7d84 bumped version to 0.7.19. f203b5f46 ngx.req.raw_header: added a buffer size assertion and two more (passing) tests regarding some special cases. 664d74ed7 bugfix: ngx.req.raw_header() would return the first part of the request body when request body was read before the call. thanks Matthieu Tourne for reporting this issue. bugfix: ngx.req.raw_header() might not work properly in a subrequest. 5193cff29 updated docs to reflect recent changes. c7879f30f raised the error log level back to "warn" for 087-udp-socket.t, which contains test cases that can flush error logs a lot which may lead to timeouts. 168eb3878 typo fixes in the tests for udp cosockets. 357f25d10 added a (passing) test for ensuring the resolver gets shut down properly when it fails to resolve a domain. 84c4d1833 bugfix: ngx.socket.udp: memory leaks or invalid memory accesses might happen when the DNS resolver failed to resolve. 7f94cb208 fixed some test cases which may fail in slow testing modes. 16db13b88 eliminated the use of the cjson library in a recently-added test case. a38ceeb00 optimize: we now use the bind() call to do autobind for datagram unix domain sockets in ngx.socket.udp() on Linux instead of abusing the side effect of SO_PASSCRED. thanks Dirk Feytons for the suggestion. 57e3a3a9f added a test case for github issue #218, which requires the run_posted_requests_in_resolver patch for the nginx core to get passed. dbde4c390 optimize: fixed the initial size of the ngx.shared table and also updated the tests accordingly. 4751625f8 Merge branch 'ngx-re-no-exceptions' 3ad47790e Merge branch 'shdict-safe-store' d52ed6c2a Merge branch 'master' into subreq-body-in-file f4ffb4f93 one minor coding style fix. b582064ec bugfix: when a non-table value was specified for the "args" option in the ngx.location.capture or ngx.location.capture_multi call, memory invalid access might happen, which resulted in garbage data at least. thanks Siddon Tang for reporting this issue. 182f2e08b Merge branch 'master' of github.com:chaoslawful/lua-nginx-module dfc7a4cd7 feature: datagram unix domain sockets created by ngx.socket.udp() can now receive data from the other endpoint via "autobind" on Linux. thanks Dirk Feytons for the patch. d3c549e9f bugfix: (large) in-file request bodies could not be inherited correctly by multiple subrequests issued by ngx.location.capture. thanks Matthieu Tourne for reporting this issue. 0c8fb04d6 one minor coding style fix. 3ea32c969 api-change: the ngx.re.match, ngx.re.gmatch, ngx.re.sub, and ngx.re.gsub functions used to throw Lua exceptions aggressively for all the error conditions; now they return an additonal string describing the error for almost all common errors instead of throwing exceptions, including pcre compile-time and exec-time failures. thanks Matthieu Tourne for requesting this change. 17b349e97 feature: added new methods safe_set and safe_get to ngx.shared.DICT objects, which never override existing unexpired items but immediately return nil and a "no memory" string message when running out of storage. thanks Matthieu Tourne for requesting this. 835aea95f bugfix: invalid memory access might happen when the UDP cosockets were used. this regression had appeared in the commit f84ca22c30091c75955d44bd790a714b1ef0bbe9. a62eadd49 bugfix: invalid memory access might happen when the TCP cosockets were used. this regression had appeared in the commit 04775502b2e348181282345320b727ab1a5a8808. 5c4c4e429 tests: avoided using taobao.com in the test suite; also decreased the resolver_timeout setting. f84ca22c3 bugfix: when the Lua code using UDP cosockets + resolver was run in a subrequest, the subrequest could hang due to missing calls to ngx_http_run_posted_requests in the UDP cosocket resolver handler. thanks Lanshun Zhou for reporting this issue in #215. 04775502b bugfix: when the Lua code using TCP cosockets + resolver was run in a subrequest, the subrequest could hang due to missing calls to ngx_http_run_posted_requests in the TCP cosocket resolver handler. thanks Lanshun Zhou for reporting this issue in #215. a768a65b2 updated docs to reflect recent changes; also bumped the version number to 0.7.17. 88b4fda41 fixed the timeout settings for large header test cases in 104-req-raw-header.t. d86bb1713 bugfix: rewrite_by_lua_no_postpone can only work globally and did not reject contexts like "server" and "location" configuration blocks. thanks Matthieu Tourne for reporting this issue. ba594765f fixed ill-formed HTTP requests in a recently-added test case, which caused issues under the "check leaks" testing mode. 545b03fd5 fixed tests to reflect output format changes in agentzh/echo-nginx-module@2adcf59ec5. cf568da59 fixed tests to reflect the typo fix in 4927e75b0507477f425a7296cf44119453363b2d. 53a46aaef docs: made it explicit that redirecting to external domains is also supported in ngx.redirect(). thanks Ron Gomes for asking. c95456c87 feature: implemented the ngx.req.raw_header() function for returning the original raw HTTP protocol header string received by Nginx. thanks Matthieu Tourne for requesting this. 4927e75b0 fixed a typo in an error message. thanks Matthieu Tourne for reporting it. 89861df1c feature: implemented ngx.req.http_version() that returns the HTTP version number for the current request. thanks Matthieu Tourne for requesting this. 5361c9529 bugfix: ngx.req.get_headers(limit, true) would still return header names in the all-lower-case form when the "limit" argument was an integer. thanks Matthieu Tourne for reporting this issue. 76910a32d fixed tests that may fail in slow testing modes. eff99d5db bugfix: use of ngx.req.socket() could make socket reading hang infinitely when the request did not take a request body at all (that is, when the Content-Length request header is missing). thanks Matthieu Tourne for reporting this issue. 40fabb23b bugfix: ngx.re.match: when the "D" regex option was specified, an empty Lua table would always be created even when the named capture was actually empty. thanks Matthieu Tourne for reporting this issue. e30ea025c updated docs to reflect recent changes. eb2d84631 fixed test cases in uthread-spawn.t for slow testing modes. 85841a721 refactor: renamed ngx_http_lua_script_copy_capture_code_t to ngx_http_lua_script_capture_code_t. 5d114acb4 optimize: removed the unsed "size" field and related computatins from the script engine. 4beec04ba added (passing) tests for using $0 in the replacement template when no capturing parenthese are used in the regexes. e9dd32848 minor optimizations in the script engine to save a little memory. 57a6471bf updated docs to reflect recent changes; also bumped version to 0.7.15. 96a18a054 fixed more test cases using systemtap that could fail expectedly in slow testing modes. 414c6605a added a (passing) test for github issue #208: coroutine as iterator doesn't work 6f3471615 fixed a test case that may fail expectedly in slow testing mode. 49eab61c2 bugfix: the original Lua VM error messages might get lost in case of Lua code crashes when user coroutines were used. thanks Dirk Feytons for the report in github issue #208. b5492eedb fixed test cases using the deprecated math.mod() method. 6d4150994 added more info about r->main->count to the debugging logs. e82955676 massive coding style fixes. d931db457 bumped version to 0.7.14. 85bab3a9e added a (passing) test to ensure that ngx.req.get_body_data can handle request body bufs more than 2. 7c37f8530 updated valgrind.suppress a bit. c0f62e590 bugfix: for nginx 1.3.9+, rewrite_by_lua* or access_by_lua* handlers might hang if the request body was read there, because the nginx core now overrites r->write_event_handler to ngx_http_request_empty_handler in its ngx_http_read_client_request_body API. 58506f762 added a (passing) test for chunked request body + ngx.req.read_body (for nginx 1.3.9+). bbdb69568 bugfix: for nginx 1.3.9+ compatibility, we return an error while using ngx.req.socket() to read the chunked request body (for now), because chunked support in the downstream cosocket API is still a TODO. af944b179 fixed the style in t/044-req-body.t. 5af60191e updated docs to reflect recent changes. e37b58e37 bugfix: for nginx 1.3.9+ compatibility, we now throw an error in ngx.req.init_body(), ngx.req.set_body_data(), and ngx.req.set_body_file() when calling them without calling ngx.req.read_body() or after calling ngx.req.discard_body(). 480ff8858 removed most of the leak false positives from valgrind.suppress because we now pass the option --show-possibly-lost=no to valgrind by default. 742213977 bugfix: recent versions of ngx_lua failed to compile with old PCRE versions like 6.6 due to the "D" and "J" regex options; now these two regex options require at least PCRE 8.12. thanks Wenhua Zhang for reporting this issue. a1fe49f43 optimize: we no longer traverse the captured body chain everytime we append a new link to it. 22cf24c3f minor documentation tweaks. 07d487396 feature: implemented the "J" regex option for the PCRE Javascript compatible mode in the ngx.re API. thanks lhmwzy for requesting this. b8af0b925 fixed the missing bits for commit 0d120033. a6d8faf2b feature: implemented named subpatterns for ngx.re.match, ngx.re.gmatch, ngx.re.sub, and ngx.re.gsub; also added new regex option "D" to allow duplicate named subpatterns. thanks Ray Bejjani for the patch in github pull #182. e46baf0ad bugfix: commit 2875695b was incomplete. c8c568839 docs: documented the ngx.quote_sql_str API. also updated the docs for body_filter_by_lua* regarding the "eof" argument in subrequests. 2875695b7 bugfix: setting the "eof" argument (i.e., ngx.arg[2]) in body_filter_by_lua for a subrequest could truncate the main request's response data stream. 329907fd0 tests: stopped hitting Google's open DNS server's 12345 port. 0d1200331 tests: eliminated hitting Google's web servers (but we still make use of its public DNS servers). 2603780dd added a test case for a segfault in the nginx core when using ngx_poll_module + ngx_resolver together. ab02c1203 bugfix: failed to compile with the SPDY patch 58_1.3.11 because that patch removed the field from the Nginx core. thanks Chris Lea for reporting this in github issue \#203. bc53e62bc fixed those recently-added tests for 100 continue that may fail expectedly. b9ac4139d refactor: when the nginx core fails to send the "100 Continue" response in case of the "Expect: 100-continue" request header (or just running out of memory), ngx.req.read_body() will no longer throw out a "failed to read request body" Lua error but will just terminate the current request and returns the 500 error page immediately, just as what the Nginx core does in this case. 00bd9a4c3 added (passing) tests for using ngx.req.read_body in the "rewrite" and "access" phases when nginx fails to send the "100 Continue" response. 6398a9048 updated tests to reflect recent changes in the DNS settings for my agentzh.org domain. fec300b73 bugfix: we did not get the request reference counter right when lua_need_request_body was turned on and nginx versions older than 1.2.6 or 1.2.9 were used. f71e4700f fixed a failing test case in normal testing mode. 7786f978e bugfix: because of the recent API behaviour changes in nginx 1.2.6+ and 1.3.9+, the "http request count is zero" alert might happen when ngx.req.read_body() was called to read the request body and nginx failed to send out the "100 Continue" (short) response (like client connection early abortion and etc). thanks stonehuzhan for reporting this issue. 1a52a5819 feature: setting ngx.header.HEADER after sending out the response headers now only produced an error message in the nginx error logs and does not throw out a Lua exception. this should be handy for Lua development. thanks Matthieu Tourne for suggesting this. f6e62d563 bugfix: in body_filter_by_lua, the "eof" flag (i.e., ngx.arg[2]) was not set in subrequests. 7837e433e Merge pull request #200 from chipitsine/master 4b1adde52 OpenBSD-5.2 93e0e2929 docs: bumped version to 0.7.13. e059eac04 bugfix: using a key with underscores in ngx.header.KEY resulted in Lua string storage corruption. thanks rkearsley for reporting this as github issue #199. 87d109fce docs: bumped version to 0.7.12. 935474048 bugfix: ngx.decode_args() might modify (read-only) Lua strings in-place, which could lead to bad Lua string values. thanks Xu Jian for the report and Kindy Lin for the patch. d3280ab61 docs: typo in the code sample for tcpsock:receiveuntil. thanks Yecheng Fu for the patch in github pull #196. 58e14a62f bumped version to 0.7.11. d3c0f2546 docs: fixed a typo in the Lua code sample for ngx.re.gmatch (we forgot to add "do" there). thanks Guo Yin for reporting this issue. 3f69addea Merge branch 'master' of github.com:chaoslawful/lua-nginx-module a78ee7561 bugfix: removed the unnecessary dot from the "config" file. thanks Rafael Souza for reporting this regression. b802870d7 docs: declared compatibility with nginx 1.2.6; also bumped version to 0.7.10. 6e162fd01 minor coding style fixes in ngx_http_lua_variable.c. eabefc797 bugfix: accessing ngx.var.VARIABLE allocated tempory memory buffers in the request memory bool, which could lead to unnecessarily large memory footprint. not it allocates such bufferes via Lua GC. 508486684 updated the tests in 005-exit.t for nginx 1.2.6+. d1613a647 feature: automatically detect LuaJIT 2.0 on FreeBSD by default. thanks rkearsley for the patch. cf18fcbbb docs: explained why "local foo = require 'foo'" is required to load a Lua module. thanks rkearsley for asking. 362fcfe46 documented the request body automatic inheritance behavior in ngx.location.capture; also bumped version to 0.7.9. 6eeb8fb81 minor coding style fixes. 59fc4aea8 bugfix: ngx.status assignment would always be overridden by the later ngx.exit() calls for HTTP 1.0 requests if lua_http10_buffering is on (the default setting). thanks chenshu for reporting this in github issue #193. 543169dfb bugfix: typo in the error message when accessing an nginx variable that has not been defined. eb3a36bb4 updated docs to reflect recent changes. 515658747 Merge pull request #186 from mizzy/fix-date-format-in-readme 457cdf79e Fix date format d4eb39b40 bumped version to 0.7.8. d54a03ebd made the tests in uthread-exec.t less possible to fail the systemtap subtest on slow machines. 477f82efc made the tests for ngx.on_abort() less possible to fail due to random timing issues. d270ade76 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 46e32a291 bugfix: ngx.req.set_body_file() might lead to memory issues because it directly used the storage of lua strings allocated by the lua GC (we should allocate a new memory block on the nginx side and copy the string data over). 94d950eed bumped version to 0.7.7. b39743aa5 bugfix: when a user coroutine or user "light thread" dies with an error, our Lua backtrace dumper written in C may access one of its dead parent threads which could lead to segmentation faults. fd7b70de6 refactor: now we use the TEST_NGINX_SERVER_PORT env consistently in the test suite. fd51c766c fixed a test case that uses the hard-coded port 8888 which may not be available especially in the "check leak" testing mode that often runs into port shortage. c400c3115 minor coding style fixes in ngx_http_lua_regex.c. 614d6a6ef updated the docs for ngx.req.start_time and ngx.now a bit. 4a4bdd950 Merge remote-tracking branch 'origin/master' into req-start-time 5768a6824 feature: added ngx.req.start_time() to return the request starting time in seconds (the milliseconds part is the decimal part just as in ngx.now). thanks Matthieu Tourne for the patch. f85899f50 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 696951852 fixed an english typo in the error message for init_by_lua*. e83fabb0e attempted to fix a test that may fail unexpectedly in the "hup reload" testing mode. 50e41da5d fixed a test case in 020-subrequest.t for slow testing modes. e3d3ec3f5 added more docs regarding using ngx.exit() to abort pending subrequests in other "light threads" and setting ngx.status after sending out the response headers. 3583cb08d added tests for the "ngx_slab_alloc() failed: no memory" error message. these require the patch https://github.com/agentzh/ngx_openresty/blob/master/patches/nginx-1.2.4-slab_alloc_no_memory_as_info.patch 15fac2963 feature: setting ngx.status after sending out response headers no longer yield a Lua exception but only leave an error message in the error.log file, which is useful for Lua-land debugging. thanks Matthieu Tourne for requesting this. 930b938d4 fixed several test cases which may fail unexpectedly due to timing errors. 2b48ef43c Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 442b45333 bugfix: when the user callback function registered by ngx.on_abort() discarded the client abort event, the request would be aborted by force when the next client abort event happened. 164ef98f4 feature: the user can now call ngx.exit(444) to abort pending subrequests in other light threads from within a light thread. 780b82686 refactor: we did not need to reset the on_abort_co_ctx field in reset_ctx. cc57703fb updated docs to reflect recent changes. 5feda1fee Merge branch 'master' of github.com:chaoslawful/lua-nginx-module e1dd6ff66 added a test case for a regression introduced by the upstream_pipeline patch of openresty. 857ed86f0 increased the timeout threshold for the slow tests in slow testing modes. 4f7eb4f05 made a test case less possible to fail in slow testing modes like "mockeagain w + valgrind memcheck". 3986c4787 Merge pull request #181 from smallfish/patch-1 4bd074408 Update src/ngx_http_lua_log.c ff1949b07 bugfix: the "light thread" object created by ngx.thread.spawn() might be prematurely collected by the Lua GC because we did not correctly register its coroutine object into the Lua regsitry table. this bug may crash the Lua VM and nginx workers under load. thanks Zhu Dejiang for reporting this issue. 7b0d7daca bugfix: the "light thread" object created by ngx.on_abort() might be prematurely collected by the Lua GC because we did not correctly register its coroutine object into the Lua regsitry table. this bug may crash the Lua VM and nginx workers under load. thanks Zhu Dejiang for reporting this issue. 2ecf5afa8 bugfix: ngx.thread.wait() might hang infinitely when more than 4 user "light threads" are created in the same request handler due to the incorrect use of ngx_array_t for ngx_list_t. thanks Junwei Shi for reporting this issue. 5abd74c3d minor test file style fixes. e6b20cb2e feature: added new dtrace static probe http-lua-user-thread-wait. d3214ca9c bugfix: subrequests with error status code did not trigger output header filtering any more. this bad had appeared in the last commit. 6d7e0c0a5 bugfix: ngx.location.capture/ngx.location.capture_multi might hang infintely because the parent request might not be waken up right after the first time the post_subrequest callback was called. now we also always skip the special response handler altogether for our subrequests. 9ad04360c ported all the documentation tweaks from the nginx wiki site. a9d1383bd minor test case style formatting. 0b838944d fixed various issues in the test suite. 15a5793b5 ngx.exit(N) now no longer throws out a Lua exception when N >= 300 and a response header with a different status code has already been sent (but an error message will still be printed into the error.log file). this change makes Lua code debugging based on ngx.say/ngx.print much easier. thanks Matthieu Tourne for the suggestion. 35b86cd53 bugfix: ngx.exit(N) threw out exceptions when N was 408, 499, or 444 and the response header was already sent. thanks Kindy Lin for reporting this issue. ca262cb46 bumped version to 0.7.5. 8d92e6c67 bugfix: ngx.log() would truncate the log messages with a null character (\0) in it. thanks Wang Xi for reporting this issue. 7c0948a08 bugfix: ngx.req.clear_header() would result in memory invalid reads when removing the 21st request headers. thanks Umesh Sirsiwal for reporting this issue in github issue #176. 1a44b73fa updated docs to eliminate use of package.seeall in code samples and also to explicitly discourage the use of it. a55fd2506 documented the special case that client closes the connection before ngx.req.socket() finishes reading the whole body. fc4391e07 documented lua_check_client_abort and ngx.on_abort; also bumped version to 0.7.4. e06f7e3a2 polished the test cases that could expectedly fail. 0990bdef7 ported the tests for ngx.on_abort() to access_by_lua and rewrite_by_lua. 75be85db6 made the tests less possible to fail in slow testing modes. 1d5b18a81 bugfix: calling ngx.on_abort() twice in a single handler will result in memory leaks; now it returns an error upon subsequent calls. b3a778702 bugfix: request might hang when a callback function is registered via ngx.on_abort() and there was no client abort event at all. also ensured that the on_abort callback will not get called when the request is already done. 0b9466ac1 feature: ngx.exit(N) can now abort pending subrequests when N = 408 (request time out) or N = 499 (client closed request) or N = -1 (error). feature: added ngx.on_abort() for registering user Lua function callback which will get called automatically when client abortion happens. 52e971cb0 renamed the config directive "lua_on_client_abort stop|ignore" to "lua_check_client_abort on|off". ec5214cfc added a test case for testing the kqueue-specific bug in the ngx_http_upstream_test_connect function of the nginx core. 5ba9195e5 fixed a test case regarding cosocket set_keepalive on FreeBSD. 8ed15a432 tweaked the test cases for one-way shutdown for the mockegain writing testing mode because nginx does not really support the one-way shutdown on the client side. 8f8cb23f3 bugfix: using "lua_on_client_abort stop" and doing internal redirects might lead to segmentation faults. 9649c8ba6 bugfix: fixed the -Werror=unused-variable gcc warning on systems without kqueue, which was introduced by commit 9205848. 92058483d bugfix: ngx_lua cosocket's connect() method could not detect errors like "connection refused" when kqueue was used. tests: fixed the compatibilty issues in those test cases that were failing on non-Linux systems like FreeBSD. 31089a419 bugfix: we could not compile on FreeBSD due to the recent work on lua_on_client_abort. 1937d5811 updated --- stap_wait to --- wait in the test suite to reflect the new changes in Test::Nginx::Socket. c5dc5dc14 bugfix: reading on ngx.req.socket() now returns the error "client aborted" in case request body truncation even when lua_on_client_abort is "ignore". bugfix: for edge-triggered events, use of ngx.req.socket() might prevent "lua_on_client_abort stop" from detecting the connection shutdown event. 83f8f9554 bugfix: receiving data on ngx.req.socket() did not return any errors when the request body got truncated; now we return the "closed" error (or "client aborted" when lua_on_client_abort is not configured as "ignore"). feature: implemented new config directive lua_on_client_abort which (atm) takes two possible values, "ignore" (the default) and "stop". 642e54112 Merge branch 'master' into client-abort 5cc8de8e7 code refactoring in the module configuration part. 41243bfa8 code refactoring in the module configuration part. 7b1f3323a documented the new shdict:get_keys() API. also bumped version to 0.7.3. f928feae8 feature: added the "get_keys" method for the shared dictionaries for fetching all the (or the specified number of) keys (default to 1024 keys). thanks Brian Akins for the patch in pull \#170. e607b639b bumped version to 0.7.2. b5531ff5b feature: now we can automatically detect the vendor-provided LuaJIT-2.0 package on Gentoo. thanks Il'ya V. Yesin for the patch in github pull #167. it is still recommended, however, to explicitly set the environments LUAJIT_INC and LUAJIT_LIB. db2d5310b docs: massive wording improvements from Dayo. also bumped version to 0.7.1. 3875a3397 bugfix: ngx.re.gsub() might throw out the "attempt to call a string value" exception when the "replace" argument is a Lua function and the subject string is large. thanks Zhu Maohai for reporting this issue. 7ee528b20 docs: documented the new ngx.thread API. also fixed the __newindex metamethod definition for catching writes to undeclared global varaibles in a Lua module. 1690add7f docs: added a warning for ngx.var.VARIABLE that memory is allocated in the per-request memory pool. also made it clear why "return" is recommended to be used with ngx.exit(). thanks Antoine. 4d8cbe95c fixed those test cases using the UDP cosockets to be prepared for data read in a single run (without EAGAIN, that is). 5d0fb9fea bugfix: the lua light threads would leak in case of nginx filter finalization. this issue was caught by the "check leak" testing mode provided by Test::Nginx while running on Amazon EC2. 2694d7758 bugfix: older gcc versions might issue warnings like "variable 'nrets' might be clobbered by 'longjmp' or 'vfork'", like gcc 3.4.3 for Solaris 11. thanks Wenhua Zhang for reporting this issue. bfcb77b12 resolved conflicts while merging "master" into "thread". 73d8dd231 bumped version to 0.6.10. d3f55d7a7 bugfix: ffi.copy() was used incorrectly in the test cases in 099-c-api.t: it might write out of the buffer. this issue was caught by valgrind on linux i386. 95b276174 fixed a test case using shdict for the "use hup" testing mode. cc5d928cb renamed ngx_http_lua_shared_dict_lookup to ngx_http_lua_shared_dict_get; fixed various issues in this public C function. also added tests for it. ea456890a feature: added public C API ngx_http_shared_dict_get and ngx_http_lua_find_zone as per Piotr Sikora's request. 7fc1dc720 fixed a compilation warning in the cosocket code from some old gcc. thanks Dirk Feytons for reporting this issue as as #162. 0f66b1b33 bumped version to 0.6.9. a30c2d831 made a test case less possible to fail unexpectedly in slow testing mode. beb2bfff4 updated docs to reflect recent changes in ngx.req.get_headers(). a90cc0d99 feature: now ngx.req.get_headers() will return a table with keys in all lowercase by default. made the second argument be "raw". when the "raw" argument is true, the header names will be the original form. b09f15784 feature: when the lowercase argument to ngx.req.get_headers() is true, then any keys like "My-Header-Name" and "my_header_name" will be able to index the "my-header-name" entry in the Lua table returned. (behind the scene, we ngx.req.get_headers() just adds a __index metamethod to the resulting table when the lowercase argument is true.) thanks Matthieu Tourne for the proposal. 0263ef747 feature: ngx.req.get_headers() now takes a second (optional) boolean argument that can be used to convert all header names into the lowercase form. thanks James Hurst and Matthieu Tourne for proposing this feature. 661c261bc refactor: disabled ngx_http_lua_probe_info by default. fe4130e0f feature: ngx.thread.spawn(f, ...) can now take multiple arguments for the "light thread" coroutine's first resume. 56b9b8a46 polished the test for ngx.thread.wait a bit. 0ef27947a bugfix: ngx.thread.wait() did not croak when the argument coroutine is not a user thread at all. also added more tests for bad arguments to ngx.thread.wait(). 009911b4e enabled all the test cases in 098-uthread-wait.t. d680b6b2e added (passing) tests for ngx.thread.wait(a, b) and the slower thread is aborted. 4d0e77f5d feature: ngx.thread.wait() can now take multiple user threads as its arguments and wait on all of them at the same time. it will return the first terminated user thread's result as soon as possible (that is, without waiting for other pending user threads to finish). b842f16a1 refactor: removed the ctx->fatal field and just used ctx->no_abort instead. 5d5edcf02 feature: implemented ngx.thread.wait() for synchronously waiting on a child user thread, which also returns the final results of the last implicit call of coroutine.resume() on the user thread coroutine. so now an non-captured Lua exception in a user thread will not abort other running threads in the same nginx request. a40832732 Merge remote-tracking branch 'origin/master' into thread 97f4474a9 bumped version to 0.6.8. 171de5a7c refactor: renamed ngx_http_lua_uthread_create to ngx_http_lua_uthread_spawn for consistency with the Lua API name. b051763cc refactor: renamed t/*uthread.t to t/*uthread-spawn.t. bcfa39984 Merge branch 'master' into thread 1ff7288eb added a (passing) test for empty pattern in ng.re.match. d37c193a9 bugfix: ngx.re.gsub might enter infinet loops because it could not handle patterns matching emptry strings properly. bugfix: ngx.re.gsub incorrectly skipped matching altogether when the subject string was empty. 4b9100c1d bugfix: pattern matching an empty substring in ngx.re.gmatch did not match at the end of the subject string. ad5e7f7c3 bugfix: ngx.re.gmatch might loop infinitely when the pattern matches an empty string. thanks Lance Li and xingxing for tracking this issue down. 0b6685c20 bumped version to 0.6.7. 8589412e8 Merge branch 'master' into thread 15d8550b6 minor coding style fixes in the lua/luajit bytecode loader. e6297a5db Merge pull request #152 from jinglong/bytecode 00e99d519 bugfix: the ngx.thread API did not work in access_by_lua*. f4e8894e2 api: renamed ngx.thread.create() to ngx.thread.spawn(). 7ba928b52 bugfix: the ngx.thread API did not work in rewrite_by_lua*. 3a30a00ff added some (passing) tests for ngx.redirect + ngx.thread. 3b48d03d1 bugfix: aborting ngx.thread coroutines with pending subrequests caused problems and now we just prohibit this by raising Lua exceptions and aborting the main request. 8f2f149c2 updated t::StapThread to reflect recent changes. c25f2df8a bugfix: ngx.thread abortion did not abort ngx.flush(true) in time. de36decd7 Merge remote-tracking branch 'origin/master' into thread 2bea02618 bugfix: the write event timer might not be removed in time in ngx.flush(true) when ngx_handle_write_event failed. f30e42d94 Merge remote-tracking branch 'origin/master' into thread d3e2e646b bugfix: ngx.flush(true) might not return immediately when it should. 33756e1cd bugfix: ngx.thread abortion did not abort tcpsock:send() in time. 7c65ad1b9 bugfix: ngx.thread abortion did not abort ngx.req.read_body() in time. 73cd491de Merge remote-tracking branch 'origin/master' into thread 51b5421fe refactor: changed the way ngx.req.read_body() handles r->main->count, which opens the door for abortion in the middile. 94e623f6f added a (passing) test for aborting the receive() invocation on the ngx.req.socket() object. 1d74cad19 Merge remote-tracking branch 'origin/master' into thread 9e127b09a bugfix: always remove the read event timer during downstream cosocket finalization if it is not removed yet. 198e48d16 bugfix: NULL pointer access might happen on u->co_ctx in *handle_success and *handle_error functions. this bug had appeared in the previous commits. 1d05ac614 bugfix: ngx.thread abortion did not abort udpsock:receive() in time. c60ea6817 bugfix: ngx.thread abortion did not abort the reading iterators returned by tcpsock:receiveuntil() in time. 0e54fcd7a bugfix: ngx.thread abortion did not abort tcpsock:receive() in time. be896210d bugfix: ngx.thread abortion did not abort tcpsock:connect() in time. 05d4a3b7e refactor: now we use ngx_http_lua_request_cleanup for complete cleanups in all the places. c22c625ec bugfix: ngx.thread abortion did not abort the nginx resolver for ngx.socket.udp in time. ee02a8ca0 updated .gitignore a bit. cd5522dce Merge remote-tracking branch 'origin/master' into thread 9fdf63663 bugfix: the nginx resolver might not be destroyed in time when it was used by ngx.socket.tcp and ngx.socket.udp. 5c22e1d4b bugfix: ngx.thread abortion did not abort the nginx resolver for ngx.socket.tcp in time. 3a916d1e9 Merge remote-tracking branch 'origin/master' into thread b771a2e40 bugfix: when a coroutine aborts with errors, its status might not be updated to "dead". 535edec69 renamed t/094-uthread-exit to t/094-uthread-exit.t. 9e28c48a3 resolved conflicts when merging "master" into "thread". 3b5dc53b8 refactor: removed unnecessary code from the sleep handler for ngx.sleep(). 5e6a5b3e7 bugfix: ngx.thread abortion did not clean up the ngx.sleep timer in time. also refactored the uthread tests a bit. b63c3156a refactor: now we introduce an explicit is_uthread flag for each user thread. b6cb3a136 resolved conflicts while merging "master" into "thread". 07b9b3b6c bugfix: when the entry coroutine was yielded by coroutine.yield() then after it was resumed automatically its status would still be "suspended". 889a24afd refactor: ensure that we always bypass ngx_http_postpone_filter_module when we generating downstream outputs. also removed all the legacy code handling postponed outputs. c1f40cd90 added (passing) tests for ngx.req.socket() + ngx.thread and ngx.req.read_body() + ngx.thread. b4e6bf174 added (passing) tests for UPD/TCP cosockets + ngx.thread. 985c4a5e9 added (passing) tests for ngx.flush(true) + ngx.thread. 518c94eaa feature: added support for manual time-slicing between lightweight threads via the coroutine.yield() API. 3b0d04b95 added a (passing) test for creating user threads in a user coroutine. also tracked user coroutine creation in the test cases for user threads. 428217646 added (passing) tests for the "coroutine status" of user threads. c0ac11978 added (passing) tests for nested user threads. 10c7a0739 Merge remote-tracking branch 'origin/master' into thread 377bcd378 updated docs to reflect recent changes. f02a7323d added several (passing) tests for ngx.thread + ngx.location.capture. 12903c20d test: enabled repeat_each(2) in 093-uthread.t. 6d854044c feature: first prototype for the ngx.thread API (aka the lightweight thread API for ngx_lua) that passes the first bunch of tests. 903a3e55c refactor: even more coding style fixes. 681f0dd61 refactor: massive coding style fixes. 639cc398f refactor: removed the unused function ngx_http_lua_has_inline_var. 946e90741 bugfix: the "resume_handler" field of the subrequest ctx was not properly initialized. 3a7075dcd added comments to the ngx_http_lua_run_thread function; also fixed a coding style issue. 51a68ac94 bugfix: better error handling in ngx_http_lua_wev_handler. cf474bcb9 refactor: improved status code handling in content/access/rewrite_by_lua*. 213acb96f refactor: removed the ctx->entry_co field and also made the coctx->co_status and coctx->flushing fields smaller. 1fc023b26 removed the declaration of the non-existent function ngx_http_lua_resume; also fixed a warning from clang. 7d5d92340 docs: fixed the documenation for ngx.req.set_header and made it explicit that the modified request headers will be inherited by the subrequests. thanks James Hurst for reporting this nit. d0d9140e1 optimize: tcpsock:send() now calls c->send() instead of ngx_output_chain(), which gives about 4src/tcp.c ~ 5src/tcp.c performance boost for a simple test case accessing redis for several times. 67f8bbbde removed the valgrind suppression rules for sendmsg/ngx_channel_write since we already fix these issues via the channel-uninit-params patch: https://github.com/agentzh/ngx_openresty/blob/master/patches/nginx-1.2.3-channel-uninit-params.patch 2e50b1943 updated valgrind.suppress for valgrind 3.8.0. 66e2d98b0 docs: bumped version number to 0.6.5 and also documented the trick for doing background async jobs by using ngx.eof() + keepalive_timeout 0. 0c14852af suppressed the warnings reported by valgrind 3.8.0. 5b5a02dbe fixed a test case in 068-socket-keepalive.t by properly flushing the redis store first. 62a0b6960 updated docs to reflect recent changes. b1289817d added (passing) tests for using parallel subrequests after ngx.eof(). e0adfe5ec bugfix: the UDP and TCP cosockets could not keep track of the current Lua coroutine. now we also explicitly clear the current Lua coroutine context in the main request context to ensure that the I/O scheduler can indeed keep track of the current Lua coroutine itself. e49622d8b added a (passing) test case for using ngx.flush(true) in a user coroutine. fe8d7be13 optimize: we now skip processing in the default write event handler when the write event is not ready. 79dee2697 coding style fixes and also fixed a warning in clang. 2fbb4ada9 refactor: removed the "cur_co" field from ngx_http_lua_ctx_t because it is not necessary at all. 644b0b15c cleaned up the code a bit in ngx_http_lua_wev_handler. 240caaa72 refactor: made ngx.flush(true) keep track of the current Lua coroutine automatically. 59c5231b8 refactor: renamed the confusing "waiting" field of ngx_http_lua_co_ctx_t to "pending_subreqs". 9155f9400 refactor: made ngx.req.read_body() keep track of the current Lua coroutine automatically. 6fba5e1bf refactor: made ngx.req.socket() use the existing req_body_reader_co_ctx field in the context struct. 12981c904 refactor: made the ngx.req.socket() objects keep track of the current Lua coroutine themselves. also disabled the ngx.req.socket() API in subrequests to prevent potential problems. 357d4d761 refactor: made the UDP/datagram cosockets schedule their I/O automatically on the Lua coroutine level. b88aa3eaf refactor: removed the unused "socket_busy" flag from ngx_http_lua_co_ctx_t. 9cb0d829d refactor: made TCP/stream cosockets schedule their I/O automatically on the Lua coroutine level. e2f8b2a6b enabled the http-lua-info static probes in ngx_http_lua_wev_handler. 2f884b83e refactor: made ngx.location.capture() and ngx.location.capture_multi schedule themselves at the coroutine level (instead of the request level). 27dd2bab8 minor cleanup in ngx.sleep(). 7134d428a refactor: made ngx.sleep() schedule itself at the coroutine level. 4abd896cd fixed a test case in 020-subrequest.t for slow machines. 85c658475 made the new subrequest test cases less possible to fail unexpectedly on slow machines. 9fe21af57 use google.com instead of taobao.com in the test suite. a7d6962c2 upgraded version to 0.6.4. e572d8772 fixed the test cases for the mockeagain (W) testing mode. 73faa581d added more tests for bad upstream in subrequests. b3255acda bugfix: reset the subrequest status code when the non-buffered ngx_http_upstream request in the subrequest fails due to timeout errors or premature connection close and etc. this requires the patch for the nginx core to fix an issue in ngx_http_upstream: https://raw.github.com/agentzh/ngx_openresty/master/patches/nginx-1.2.3-nonbuffered-upstream-truncation.patch d06e26018 made a test case requires DNS resolving less possible to fail in slow testing modes. c56a98cd8 bugfix: we should not always return NGX_OK in our post_subrequest handler even if rc >= 300 because it will prevent response headers from being sent. 865cb1981 added a (passing) test for returning NGX_ERROR in the output body filter for the subrequest issued by ngx.location.capture(). 46a3c3d52 updated .gitignore a bit. 9728454af bugfix: the main request might be prematurely terminated if a subrequest issued by ngx.location.capture (or its friends) was finalized with error codes. 75c8c3098 updated valgrind.suppress for i386. 3a90b5740 bugfix: we did not compile with nginx cores without the allow_request_body_updating patch. thanks Dirk Feytons. 3b6f584be tweaked a test case to make it less possible to fail in slow testing modes. fd0a8fb18 refactor: now ngx_lua issues subrequests without updating r->postponed at all so as to allow the parent requests flush outputs immediately without waiting for its running subrequests. this will pave a way for subrequest integration with the upcoming lightweight thread model. 7819b4284 fixed typos in the test titles. ce1bcd53c bugfix: when a user coroutine died with an error, its parent coroutine's status was still 'normal'. thanks jinglong for reporting this issue. 62d67ad2f optimize: removed a duplidate ngx_memzero invocation in ngx_http_lua_reset_ctx. thanks jinglong. 35c1fcd04 docs: removed the note for the issues regarding "normal" state user coroutines in coroutine.resume() and coroutine.status() because we have already fixed them. 50f20351b merged "master" into "thread". 5cb6e9fa5 refactor: now every lua coroutine takes its own context state for its nginx-side activities. bugfix: coroutine.status() returned "suspended" for "normal" coroutines. bugfix: coroutine.resume() did not return an error immediately when operating on "normal" coroutines. feature: added new dtrace static probes http-lua-user-coroutine-yield and http-lua-entry-coroutine-yield. a819a192e docs: documented the new shdict:flush_expired() method. bumped the version to 0.6.3. also mentioned lua-resty-dns in the SEE ALSO section. f09867d91 feature: implemented shdict:flush_expired(max_count) for flushing out expired items up to max_count (or unlimited when max_count == 0). thanks Brian Akins for the patch. b771643db bumped version number to 0.6.2. e650dd118 bugfix: the dtrace static probes did not compile on non-Linux systems like FreeBSD. e64d60bd2 increated the timeout threshold for a test case requires resolving three domain names. 52018289b bugfix: tcpsock:send() might send garbage if it was not the first call: we did not properly initialize the chain writer ctx for every send() call. thanks Zhu Dejiang for reporting this issue. 28317770f feature: added new dtrace static probes http-lua-socket-tcp-send-start, http-lua-socket-tcp-receive-done, and http-lua-socket-tcp-keepalive-buf-unread. ccc4af2a1 bugfix: ngx_http_lua_probe.h was not listed in the NGX_ADDON_DEPS list in the "config" file. e46e4907a bugfix: the send timeout timer for downstream output was not deleted in time in our write event handler, which might result in request abortion for long running requests. thanks Demiao Lin (ldmiao) for reporting this issue. e282c1c6c bumped version to 0.6.1. 936653cbd removed the req_header_cached field from ngx_http_lua_ctx_t because it is not used at all. 43de06a0c merged merge conflicts. c2f3cffd5 bugfix: removed unnecessary code that was for the old coroutine abortion mechanism based on Lua exceptions. we no longer need that at all because we have switched to using coroutine yield to abort the current coroutine for ngx.exec, ngx.exit, ngx.redirect, and ngx.req.set_uri(uri, true). 912707780 bumped version to 0.6.0. ce791df20 documented the limitation in the current coroutine.resume() implementation. 2b560d359 documented the limitation in the current coroutine.status implementation and also included other documentation updates. 7feb3f4f0 fixed a source line exceeding 80 cols. 5c1603354 style: renamed ctx->cc to ctx->cur_co, ctx->cc_ref to ctx->entry_ref, and ctx->cc_op to ctx->co_op. c52320f5f Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 4e5cb2449 bugfix: there was no proper error messages when we tried to resume running coroutines. bugfix: there was error logs for resuming dead user coroutines, which was too chatty. bed05ac93 fixed the developer build script for FreeBSD. c4d796260 avoided using qq.com, taobao.com, and baidu.com in the test cases because the "check leak" testing mode will flush these 3rd-party sites which is very very bad. d6c32ea39 feature: yielding entry coroutines from within the user Lua code will make them resume immediately. 506519492 added a comment. 347214c05 documented the new user coroutine API and claimed that we work with nginx 1.3.4. also updated the TODO list to reflect recent changes. 9228475a5 removed the unused ngx_http_lua_dump_postponed function that was used for subrequest debugging. thanks Dirk Feytons. 47f0bf193 properly handled the errors when the user coroutine does not have a parent. 1c2cae9c7 Merge branch 'master' into coroutine 7b363ee7b bumped version to 0.5.14. 1462d9650 resolved conflicts while merging "master" into "coroutine". afb26d284 more fixes in the dtrace provider file. f7858fffb fixed the argument type again in the dtrace provider. f9dc0dc01 fix strict-aliasing warnings in ngx_http_lua_clfactory_bytecode_prepare c9d779e47 avoided declaring new C types in our dtrace provider. 8e5ebad47 bugfix: redeclared the ngx_http_request_t type in our dtrace provider file. 2c6a88c42 Merge branch 'master' into coroutine a70c1e4c7 bumped version to 0.5.13. 592d24f5a Merge branch 'master' into coroutine 1acd7e93c fixed a source line exceeding 80 cols. a39408060 bugfix: reads of unitialized memory might happen when variadic macros is defined and logging socket errors is enabled: when NGX_HAVE_VARIADIC_MACROS is defined, ngx_log_error_core does not take a va_list typed argument which disallows C function wrappers. bcaf634a2 bugfix: segmentation faults might happen when 1. the nginx worker was shutting down (i.e., the Lua VM is closing), 2. ngx.re.gmatch was used, and 3. regex cache is enabled via the "o" flag. this bug had appeared in ngx_lua 0.5.0rc30 (and ngx_openresty 1.0.15.9). d010f0143 bugfix: pcre_pool_resumed should be initialized to 1. 9043e7af9 bugfix: the pcre pool might not be properly resumed when lua panic happens in the lua coroutine scheduler. 8e3ee4b1e renamed 090-coroutine.t to 091-coroutine.t. f77dffbf3 Merge branch 'master' into coroutine de65585f3 optimize: make the coroutine scheduler faster for the entry coroutines (in contrast with user coroutines). 93d12de22 checked in files that are missing in the previous commit for lua_socket_log_errors. 1efea1b3d docs: documented the new lua_socket_log_errors directive and also updated the TODO list. f6bd4f7e6 feature: added new directive lua_socket_log_errors that can be used to disable automatic error logging for both the TCP and UDP cosockets. thanks Brian Akins for the patch. 45461af3a fixed a source line exceeding 80 columns. f9e7f3703 now we explicitly disable the user coroutine API in running contexts other than content_by_lua*, rewrite_by_lua*, and access_by_lua*. 2f5f9550c updated the systemtap-based test cases for user coroutines. 9c54ac2d2 improved the comments for the first few fields of ngx_http_lua_ctx_t. 626cb4a95 eliminated short enum names NONE, YIELD, and RESUME to prevent naming collisions. also use only 2 bits for the cc_op filed in the ctx struct. 75d2d7ab1 added new static dtrace probe http-lua-user-coroutine-resume. 4679f459a added (passing) tests for calling ngx.exit() and ngx.exec() in deeply nested user coroutines. also added new static probe http-lua-user-coroutine-create. 849492e5b added a (passing) test for deeply nested coroutines. also avoided using 3rd-party web sites in the test cases to prevent flushing them in the "check leak" testing mode. c314499de fixed a source line exceeding 80 cols. da5e42542 Merge branch 'master' into coroutine 44e38b134 fixed a place where we did not check the pointer returned from ngx_array_push. 646b0129d added a subtest for the error logs when resuming dead coroutines. bd78705a1 bugfix: ngx_http_lua_resume didn't recognize dead coroutine if the coroutine was resumed with args 6add2a593 avoided using hard-coded port number of the redis service in the test cases. d476dec56 added a test for using the coroutine-based pubsub API provided by Daniele Alessandri's lua-redis library. dc33fb339 optimize: now we use lightuserdata as the key to the coroutine parents table in the lua registry. we also use lua_rawset and lua_rawget wherever possible. 3572114b5 do not call the public C API in ngx_http_lua_coroutine.c for the sake of consistency. also checks if the request pointer is null in the Lua coroutine API implementations. 4f5e8e2f8 better error handling in inlined Lua loading and running. 9c4c72c5c bugfix: we should avoid complicated stack operations that might require memory allocaitons in the lua atpanic handler because it would produce another exception in the handler leading to infinite loops. a2543aa22 removed C macros that are no longer used. this was a merge mistake happened on the git "coroutine" branch. 9494c1220 bugfix: we should avoid complicated stack operations that might require memory allocaitons in the lua atpanic handler because it would produce another exception in the handler leading to infinite loops. fc2194ac7 more coding style fixes. e69527564 eliminated hard-coded nameserver IP address in the test cases in coroutine.t. 22a252dee bugfix: the main vm stack leaked memory when the entry coroutine completed successfully or tried to yield. abd231c01 even more coding style fixes. 9e90fbefe more coding style fixes. e7ca4988d more coding style fixes. df844cb8e fixed the test plan in coroutine.t and made it work with "check leak" testing mode; also added error message tests to all the test cases there. 676c3dbf8 various coding style fixes. 50357f146 Merge branch 'master' into coroutine 4cb88e205 display the stack top as debugging logs in ngx_http_lua_run_thread. 8d63530b7 fixed the serial number in t/089-coroutine.t. 6f402674b merged branch "master" into "coroutine". 3388d424f updated docs to reflect recent changes, especially the new "openresty-en" mailing list for English speakers. 0ee0c49cf bugfix: the UDP cosocket object could no longer be used after an read or write error happened. d577a3818 bugfix: ngx.exit(status) always resulted in 200 OK response status when status > 200 and status < 300. thanks Nginx User for reporting this issue. 63daa7571 minor coding style fixes. f0efac25b updated the error message in docs to reflect recent changes. dfe620204 bumped version to 0.5.11. 1dc7634b5 improved error message when calling ngx.req.socket() when the request body aleady exists. ef4a8acd7 documented that ngx.req.socket() is required to be called before ngx.req.init_body(). a071d3ee6 fixed two test cases for ngx.req.socket + ngx.req.append_body. also added a test for calling ngx.req.socket *after* ngx.req.init_body. 04ef7a499 bugfix: ngx.req.init_body/ngx.req.append_body/ngx.req.finish_body could not work with ngx.req.socket and resulted in infinite loops when the nginx request header reader has pre-read the beginning part of the request body. thanks Matthieu Tourne for reporting this issue. bugfix: the ngx.req.socket() object could not handle pipelined requests in some special cases. feature: added new dtrace static probe nginx_lua:::http-lua-req-socket-consume-preread. db0bebedb documented the ngx.req.init_body, ngx.req.append_body, and ngx.req.finish_body APIs; also bumped the version number to 0.5.10. 4697b1dc2 skipped the hup tests in "check leak" testing mode. d29e8b330 various fixes in the test suite for the "use hup" testing mode. 3ef8844b1 minor test updates d07f97163 fixed the test plan in 089-phase.t so that it works with different repeat_each settings. b994240df added stap based tests for client body temp file cleanups. 446e3477d fixed two places of variable set but never read reported by the clang static analyzer. 88ad0a001 fixed various corner cases for ngx.req.init_body/append_body/finish_body. also added some test cases for these new API. 20620cb32 fixed a clang warning regarding strncmp. d32294612 Merge branch 'master' into req-body 3fc42b417 fixed the ngx. table initial size. 15aef44c8 resolved conflicts while merging branch "master" into "req-body". 9b3bbf4f8 documented the ngx.get_phase() API. 28a022db2 updated .gitignore to reflect recent changes. 02a8b7ba9 minor fixes in the ngx.get_phase() call. c1cd17315 feature: added new Lua API, ngx.get_phase(), for fetching the name of the current running phase from within Lua. possible return values are "set", "rewrite", "access", "content", "log", "header_filter", "body_filter", and "init". thanks James Hurst for the patch. bd66f77fe bumped version number to 0.5.9 d1cfc94c8 bugfix: buffer error would happen when the "args" option table to ngx.location.capture (and ngx.exec) contained a multi-value argument whose key also required uri escaping. thanks Matthieu Tourne for reporting this. 0f62a62e3 bugfix: 3rd-party nginx C modules that use the public C API function, ngx_http_lua_add_package_preload, could result in segfault at nginx server startup due to uninitialized Lua VM pointer. thanks Ray Bejjani for reporting it. ebeb4ea8e fixed the provider name in stability attributes in ngx_lua_provider.d. d3a9ba25b feature: initial support for dtrace static probes. it requires nginx-dtrace though: https://github.com/agentzh/nginx-dtrace c25689b93 updated docs and bumped version to 0.5.8. a624ee948 updated .gitignore a bit. 3eab7b036 ensured that proper error message is always thrown when the iterator returned by ngx.re.gmatch is used in the context of another nginx request. e73e24443 bugfix: ngx.re.gmatch() might result in segfaults during nginx request cleanups if the iterator returned by ngx.re.gmatch() was collected (by Lua GC) before request cleanups. this bug had appeared in ngx_lua 0.5.0rc30 (and ngx_openresty 1.0.15.9). thanks Wayne for reporting this issue. 54c0a3549 bumped version to 0.5.7. d17a942ca Merge pull request #141 from dirkfeytons/no_pcre_compile_fix 8df3747ec Fix issue with unused variable when compiling without PCRE support. 6d67fc4b1 tweaked a test case to make it less possible to fail in slow testing mode. 1cae67d5e fixed a test case. 24fc460b4 documented the new options table argument and the "pool" option for the tcpsock:connect() method. 992e4f026 bugfix: tcpsock:connect(): numeric pool option values did not really work. also nil pool option was caused trouble too and we disallow that now. 31aa26383 rename coroutine testsuite name 8c03cc5a4 Merge branch 'coroutine' of https://github.com/chaoslawful/lua-nginx-module into coroutine 927ef1e86 Merge branch 'master' into coroutine 6a375a651 Merge pull request #138 from jinglong/coroutine 4f208bff2 delete useless comment in ngx_http_lua_thread_traceback 0976365ca update ngx_http_lua_thread_traceback to print the full traceback for the current coroutine and his ancestors 1d8d1578f feature: added an optional "optional table" to tcpsock:connect() which accepts a "pool" option to allow the user specify a custom pool name intead of the automatically generated one based on the host-port pair or the socket file path. thanks Brian Akins for the patches. 06abbea6b documented the UDP/datagram cosocket API. 0a2d1d246 bugfix: udpsock:send() might crash on null pointer access when the request object is absent or the u pointer is null. 4ae7d6a3c added (passing) tests for the size argument of the udpsock:receive(size) method. 49c29a081 feature: added the udpsock:close() method. 1a8bd0f14 merge with master 268493900 Merge remote-tracking branch 'origin/master' into udp-socket 405efbabd tweaked the test case a bit. 05c3a1e75 bugfix: the udp cosocket API could not talk over a unix domain socket. 24991b68a added a (passing) test for receive() timeout. 8b1040d25 bumped version number to 0.5.6. 053999e59 added a test case for successive udpsocket:setpeername() calls. 010d17d48 removed a useless comment from ngx_http_lua_socket_udp.c. 06d654b02 documented the ngx.req.get_method() and ngx.req.set_method(method_id) methods. 80e86f554 updated docs to reflect recent changes. 3b51a96c2 merged branch "master" into "udp-socket". 0cf6c86fa bugfix: the tcp/stream cosocket object might hang when another concurrent request is accessing it while its operation is still in progress; now we always check for potential access conflicts and return the "socket busy" error string if it is indeed the case. fd412f72e bugfix: the udp cosocket object might hang when another concurrent request is accessing it while its operation is still in progress; now we always check for potential access conflicts and return the "socket busy" error string if it is indeed the case. b6b23570a fixed the test suite to reflect recent changes. 0280aaa4f Merge remote-tracking branch 'origin/master' into udp-socket 3824e4466 udpsock:connect(): now we fetch ngx_socket_errno in case of error as soon as possible. 567da366d bugfix: the tcpsock:connect() method always returned the (vague) error strng "connect peer error" instead of the (detailed) system error string. 3232eb078 added more tests for udp cosockets. 8157284b8 bugfix: the udpsock:connect() method always returned the (vague) error strng "connect peer error" instead of the (detailed) system error string. 4a79d1b8d optimize: udp cosocket: now we use a global (static) receive buffer to avoid dynamic allocations on heap. f85139757 Merge remote-tracking branch 'origin/master' into udp-socket 42d9617e8 merged branch "master" to "udp-socket". 787a7b122 fixed a minor coding style issue. e9a74f68b feature: implemented the UDP cosocket API, ngx.socket.udp(). 30601c71f bugfix: the tcp cosocket object might automatically re-connect to the remote after it connected successfully in a single run (that is, no EAGAIN returned in the middle) and DNS domain names were used. 007d61a7c bugfix: tcpsock:receive() and tcpsock:send() always returned "error" as the error message. now it properly returns the system error string. 61858d95d bugfix: ngx.req.clear_header() did not remove all the instances for the builtin headers or custom headers. bugfix: ngx.req.clear_header() might accidentally remove request headers that are not specified at all and leave the specified headers with just empty header values when removing multiple built-in headers. thanks Matthieu Tourne for reporting the issues. e9d5d601a feature: added new Nginx API for Lua: ngx.req.set_method(method_id) and ngx.req.get_method. thanks Matthieu Tourne for suggesting these. 4960e01ec bugfix: we should always test if the request object pointer is null in the ngx.req.*_body API. c2f74d15e checked in a (skipped) test case for subrequest request headers handling. 05c0f5a8c bugfix: ngx.exec() did not accept the nil value for its second (optional) argument. 166de0c46 updated the TODO list in docs to reflect recent changes. 584ec028b bugfix: ngx.exit(404/403/500/...) would throw out Lua errors when the response headers with exactly the same status code had already been sent. thanks Matthieu Tourne for reporting this. 4275482f4 documented the init_by_lua* directives and also bumped version number to 0.5.5. 6e5e1738f Merge branch 'master' of github.com:chaoslawful/lua-nginx-module into coroutine 588ee4dcb removed a test in t/023-rewrite/exit.t. 5126e8153 fixed a test case in 085-if.t that hard-coded TEST_NGINX_CLIENT_PORT in nginx config. ce4314d46 bugfix: init_by_lua* might be skipped altogether when HUP config reload was used. 5445e0e8c bugfix: invalid memory reads might happen on HUP config reload when lua_shared_dict is used. 608c89bbf fix typo in config 8f1a44363 fix compiling errors 9c3c01aa4 remove unexpected merged codes 35bf172eb merge jinglong's commit bb7d35eaa merge master and jinglong's commit 2d3c907f4 Merge pull request #135 from jinglong/coroutine 27366974e improve coroutine apis c984bedd2 fix a harmless typo in ngx_http_lua_run_thread 943b3fe7a Merge branch 'init' ae9b7893c enlarged the timeout setting for TEST 16 in 082-body-filter.t to make it less possible to fail in slow testing modes. 8149324c2 feature: enabled print() and ngx.log() in the context of init_by_lua*. 15ec27758 bugfix: init_by_lua* might result in segmentation faults when multiple lua_shared_dict instances are defined. f4a15e29a feature: added new directives init_by_lua and init_by_lua_file. ab41caaf5 feature: now we print backtrace to error.log when Lua errors happen in body_filter_by_lua*. dae23ad7d fixed the test plan in t/041-header-filter.t. 240fc4ab3 feature: now we print backtrace to error.log when Lua errors happen in header_filter_by_lua*. b75195c40 fixed the test plan in 001-set.t. 97ba958d0 feature: now we print backtrace to error.log when Lua errors happen in set_by_lua*. e876411bd feature: now we print traceback to error.log when Lua errors happens in log_by_lua*. 7ce7fb2e2 coding style fixes in ngx_http_lua_socket_tcp.c. 924d093ea Merge branch 'master' into backtrace c03574631 Merge branch 'udp-socket' f8074dca4 renamed ngx_http_lua_debug_traceback to ngx_http_lua_thread_traceback, and other naming changes. dbc4ca764 renamed ngx_http_lua_debug_traceback to ngx_http_lua_thread_traceback, and other naming changes. 2902f9ff2 Merge branch 'master' into udp-socket 5a539500c bugfix: upstream data buffers were not marked as fully consumed when body_filter_by_lua* is used and ngx.arg[1] is overritten. this could result in connection hang for large response bodies. thanks Tzury Bar Yochay for reporting this issue. 418024960 updated .gitignore. a04e204d0 renamed ngx_http_lua_socket* to ngx_http_lua_socket_tcp* to prepare for the udp cosocket API addition. a96dd5515 bumped version to 0.5.4. d2dc90839 optimize: fixed the initial table size for ngx.req. 9ae5a3435 Merge branch 'master' into req-body 3074fddd1 fixed some english grammatical issues in the comments. e1e5b7f3b use ngx_memzero instead of memset in the previous patch from chaoslawful. 47eff35e9 bugfix: fix issue #132 dereferencing type-punned pointer will break strict-aliasing rules 538b97ae9 updated docs to reflect recent changes. 0178d4e7b bugfix: ngx.say and ngx.print might cause nginx to crash when table-typed arguments were given. thanks sztanpet for reporting this in github issue #54. 0428b88fc Merge branch 'master' of github.com:chaoslawful/lua-nginx-module c2d095a1f added some (passing) tests for "location if" compatibilities. f73785c64 updated docs to reflect recent changes. 09f063024 fixed an issue in the test case in 082-body-filter.t: we should not use "echo" and "content_by_lua" in the same location. 553432b59 bugfix: header_filter_by_lua* did not run at all when body_filter_by_lua* is defined at the same time. thanks Tzury Bar Yochay for reporting this issue. 5d59d498a reindexed the test in t/041-header-filter.t. 9f633c860 added a (passing) test for clearing the Content-Length response header in header_filter_by_lua. 0ff8afe0e fixed test cases that rely on the old (broken) HTTP 1.0 support in ngx_echo. 7d6547aeb docs: added more documentation for the Lua/LuaJIT raw bytecode support. thanks Wayne. 17fbfb771 optimize: merged two successive nginx pool allocations in ngx_http_lua_socket_resolve_handler to reduce overhead. 37a9fcd87 bumped version number to v0.5.1. a35ff3636 ngx.req.init_body: when the size argument is specified, honor that exactly; when the size argument is omitted, use the same logic as ngx_http_read_client_request_body to calculate the buffer size. 3a8d8dadc Merge branch 'master' into req-body 0bb38b0bd made tests less possible to fail in tcp-socket-timeout.t when the DNS nameserver happens to be slow. cd0139dc9 fixed some coding style issues. a8e1f16f0 docs: redocumented the "inclusive" option for the cosocket:receiveuntil method. c4d5e3a24 Merge branch 'master' into inclusive e0a6a36c7 added a (passing) test for default_type + charset + content_by_lua. 2b6c95cfe updated README and README.markdown by the tools. 565452051 bumped version number to v0.5.0rc32. 0eba3537b Merge branch 'master' into inclusive e0cabf043 added more (passing) tests for the "inclusive" option of cosocket:receiveuntil(). 2b8ea405f improved the error handling of the "inclusive" option for cosocket:receiveuntil and also added some test for this. removed the tests for the "inclusive" option to a separate test file, 084-inclusive-receiveuntil.t. 2174ed2e5 fixed a bad test case in 083-bad-sock-self.t. 9905167e3 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 51bc8fb49 bugfix: the lua VM might crash when calling the cosocket methods with a bad-typed self argument. 5545cfaad Merge branch 'master' into inclusive cdb6a6f94 fixed a coding style issue in the previous commit. 146fe0c61 bugfix: the zero-size buffer alert could occur in body_filter_by_lua* when the current buf is a special "eof" buf and the user has turned off the "eof" flag by assigning false to ngx.arg[2]. cea392987 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module c66daf057 Merge remote-tracking branch 'jinglong/bytecode' into bytecode bad3eee54 Use more descriptive names in ngx_http_lua_clfactory.c(like LUA_LITTLE_ENDIAN_4BYTES_CODE) 33e62fcf3 docs: documented the body_filter_by_lua* directives and the new bytecode file loading support. d92a14d7b Merge branch 'master' into body-filter 5fa0dbc1f merged jinglong's "bytecode" branch into "master". 1c6280f57 docs: documented the lua_transform_underscores_in_response_headers directive. f81ceeb40 feature: added new directive lua_transform_underscores_in_response_headers. thanks Kindy Lin. b09b8ee44 1,fix a bug in loading bytecode(faild to load no-stripped bytecode of luajit) 55153ceaf fixed the test plan in t/082-body-filter.t. f9e534f05 Merge remote-tracking branch 'origin/master' into body-filter 9cabf1c4a minor tweaks of the error messages and coding style issues in the byte-code support patch from jinglong in github pull #124. 3e9984a03 various coding style fixes. 71467020d added (passing) tests for the on-demand handler registration of body_filter_by_lua*. 2a63a168b docs: added a note for installation with lua 5.1 on ubuntu 11.10. thanks Dan Sosedoff. 81964d5a8 bufix: fixed the directive context for set_by_lua and set_by_lua_file. they really work in the contexts "server", "server if", "location", and "location if". thanks Liu Taihua. 119b85e16 feature: the lua statement "return ngx.ERROR" can now be used to abort the output stream in body_filter_by_lua*. 91b23e692 feature: ngx.arg[1] now also accepts a lua table of lua strings as its new value. 9f488b0ec feature: ngx.arg[1] and ngx.arg[2] now support overwriting in body_filter_by_lua*. 5591fb0cb Merge remote-tracking branch 'origin/master' into body-filter 19c803d76 merged "master" into "body-filter". 6183ad4f5 docs: fixed a typo: ngx.now returns time of the resolution of milliseonds, rather than microseconds. thanks Wang Xi. dffaf4896 fixed the test "unexpected globals sharing by using _G (header_filter_by_lua*)" by chaoslawful which did not really test what it was supposed to test. 6ef34e54f bugfix: lua main thread stack might leak when header_filter_by_lua* is used. 1ecb2f40c bugfix: too many values on the lua stack might be concatenated when generating backtraces for lua errors and the lua vm would crash when there happened to be values on the stack that could not be concatenated (like nil). stylefix: renamed the debug_traceback function to ngx_http_lua_debug_traceback. optimize: eliminated unnecessary string concatenations when generating backtraces for lua errors. 46019a271 reindexed the tests in t/075-logby.t. dff9bb898 fixed the test plan for 081-bytecode.t for the "check leak" testing mode. 172fe05aa Merge remote-tracking branch 'upstream/master' into inclusive 2e90054ca Merge remote-tracking branch 'upstream/master' into req-body 5c14bcd25 Adding code similar to nginx core, to prevent allocating buffers much larger than the request itself. 427d3d572 Update code, still using GLOBALS_SYMBOL_REQUEST. See Commit 89a997. 5078b1443 bugfix: the ngx.arg API was not usable within external lua module files in set_by_lua*. diagnosis: now we issue user-friendly error messages when the nginx lua APIs are used in the wrong directive contexts (e.g., using ngx.location.capture in set_by_lua*). 4e4e0b32c fixed more coding style issues in common.h. 64912a7b2 fixed coding style issues in common.h. 725c3a14e renamed ngx_http_lua_create_ng_table to ngx_http_lua_create_new_global_table; also fixed some coding style issues in 001-set.t. b42f6c8c5 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module acb1b47aa minor coding style fixes in ngx_http_lua_logby.c. 6ce7490d6 Merge branch 'master' into body-filter 3520a90a6 merge conflictions e5363496e bugfix: ngx.arg could not be used in user lua modules. 9bcb50325 feature: initial cut on the body_filter_by_lua and body_filter_by_lua_file directives. 6c650fafd bugfix: fixed unexpected globals sharing by using _G in log_by/header_filter_by/set_by fede5ccb5 minor coding style fixes in ngx_http_lua_logby.c. 02824efe0 Merge pull request #124 from jinglong/bytecode c5fde025d Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 40af5cdd8 cleaned up the "config" file, making lines shorter and easier to merge. thanks Matthieu Tourne for the patch. 656f6e272 eliminated including C headers that we do not actually use. 5347f9174 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 08b0433d0 bugfix: fixed unexpected globals sharing by using _G 8481276e1 optimize: now we register the "ndk" and "ngx" lua tables for log_by_lua* at config time rather than request time. this gives significant performance boost. also improved error handling in log_by_lua*. f3a3757c2 enforced lua garbage collection full cycles in those shdict test cases to prevent memory leak false alarms. 294ba6fe6 1, fix code style b79953e0e fix merge conflict 9ea8ba052 add simple test for coroutine support f4ed28d2d improved lua error handling in header_filter_by_lua*. 0f652c040 optimze: explicitly specified non-zero initial size for certain lua tables. 7ce0102d1 optimize: now we register the "ndk" and "ngx" lua tables for header_filter_by_lua* at config time rather than request time. this gives significant performance boost. b8e5b0219 fixed the "ngx" table initial size for set_by_lua*. f19686330 optimize: now we initialize the "ngx" and "ndk" tables at config time instead of at request time. bugfix: the lua vm crash protection based on longjmp for set_by_lua* was not really working. d6d7f872a renamed function init_ngx_lua_registry to ngx_http_lua_init_registry, and init_ngx_lua_globals to ngx_http_lua_init_globals. df104f916 optimize: now we store the metatables for ngx.req.socket() and ngx.socket.tcp() objects into the lua registry. 89a997aca optimize: changed the string keys to light user data for various tracking tables (coroutines table, regex cache table, cosocket connection pool table, ngx.ctx table, and etc). This gives minor performance improvement from eliminating key hashing and etc. thanks Dirk Feytons. 5cc8fd50f fixed a typo in program comments. thanks Dirk Feytons. f7f744efd Fix typos in error message. 1ce845313 docs: fixed the sample code for log_by_lua. 7292647a7 docs: marked the APIs that are available in the log_by_lua* context. ead78b766 bumped version to 0.5.0rc31. 1bf725345 updated the docs for log_by_lua and log_by_lua_file. 285b72716 bugfix: memory leak would happen when accessing a location using ngx.ctx in Lua contexts other than log_by_lua* but there is also another location that uses log_by_lua*. 445b916a7 bugfix: header_filter_by_lua would leak memory when it is the only directive of ngx_lua configured in a location *AND* ngx.ctx is used. 113c65818 reindexed the test numbers in t/025-codecache.t. c8063a8bb updated .gitignore again. cd825f51c updated .gitignore. 2a3d31d38 Merge branch 'logby' 3b1e9aaff updated docs to reflect recent changes. a58ebf89f 1, add more test cases for loading bytecode 76dcccdfd updated valgrind.suppress for linux i386. cfd3a0e43 now we use environments in the developer build script instead of hard-coded paths. e72096a47 1, check the version when loading bytecode fa64f3628 added downstream cosocket tests for the rewrite phase. 429b603c5 optimize: now we no longer call ngx_http_post_request to wake up the request associated with the current cosocket upstream from within the cosocket upstream event handlers, but rather call r->write_event_handler directly. this change can also make backtraces more meaningful because we perserve the original calling stack. 54d8736f6 added cosocket tests for lua code running at the rewrite phase. 26db2dda1 bugfix: cosocket:connect() might hang on socket creation errors or segfault later due to left-over state flags. 39b9138cf 1, add a test case for loading bytecode 1099cd3b6 minor fixes in cosocket. 2a418d8bb 1, add support for loading bytecode(both lua and luajit) 802e95b30 bugfix: the _G special table did not get cleared when lua_code_cache is turned off. thanks Moven. 95857be6f feature: ngx.log() now checks if the log level number is in the valid range (0 ~ 8). thanks Xiaoyu Chen (smallfish) for suggesting this. 154f5af33 fixed the newly added test case for log_by_lua + shared dict. 7ba84a74a Merge branch 'master' into logby 2afa6bfb3 added one (passing) test for log_by_lua + shared dict. 86f97f00b bugfix: ngx.sub() could leak memory when the "replace" template argument string is not well formed and the "o" regex option is specified. this issue was caught by Test::Nginx::Socket when setting environment TEST_NGINX_CHECK_LEAK=1. fd681f8d0 bugfix: fixed a compilation error in the previous commit. b30b56cf3 bugfix: ngx.re.gmatch leaked memory when the "o" option was not specified. this bug was caught by Test::Nginx::Socket when setting the environment TEST_NGINX_CHECK_LEAK=1. 9c96a3aaf Merge branch 'master' into leak f9e61f044 docs: massive wording improvements from the nginx wiki site. thanks Dayo. f74372491 Merge branch 'master' into leak d2d1904b6 fixed test plan for 056-flush.t for the "check leak" testing mode. 8c0221fc0 fixed test plan for 056-flush.t for the "check leak" testing mode. a058363c1 fixed another issue in the test case for the memory leak issue that was in receiveuntil(). d80359814 fixed an issue in the test case for the memory leak issue that was in receiveuntil(). 225fc72fc fixed invalid HTTP request headers in the req-body test cases. 1aab85928 bugfix: receiveuntil could leak memory, especially for long pattern string arguments. this bug was caught by Test::Nginx::Socket when setting the environment TEST_NGINX_CHECK_LEAK=1. 6440e4e61 updated valgrind.suppress further for linux i386. c7374aaa3 updated valgrind.suppress for the "hup reload" + valgrind/memcheck testing mode. a8dd2d70e added 080-hup-shdict.t to test if the data in shared dict is survived through nginx HUP reload. also updated valgrind.suppress accordingly. 9fbba9aeb added tests for the on-demand handler registration mechansim for log_by_lua*. dbac00503 resolved conflicts while merging "master" into "logby". we now adopt the new on-demand handler registration mechansim for our log_by_lua* directives. a287451c1 Refactored on-demand handler registration acb1cde11 minor coding style fixes in capturefilter.c. e1a91744d reindexed tests in 079-unused-directives.t ce0921789 added tests for handlers registered on-demand (i.e., determined whether their config directives are actually used in nginx.conf). 564d2bb8c minor coding style fixes and debug log message adjustments. 6d2e7a0f6 Merge branch 'master' into logby a830b61eb 078-hup-vars.t: no need to use the debug log level. a486c4cf0 added tests for the nginx core bug regarding nginx variables under HUP reload: http://mailman.nginx.org/pipermail/nginx-devel/2012-May/002223.html ab5069e5d merged branch "master" into "logby". 1075c325e fixed tests to work-around an issue with nginx listening on a unix domain socket (we have to remove the socket file before sending HUP). f1548c48d fixed tests to work-around an issue with nginx listening on a unix domain socket (we have to remove the socket file before sending HUP). c50378562 fixed ngx. table initial size for content/rewrite/access_by_lua*. 6ab79176d Reverting to da5e60c949dcd4d8ed68b838aaf681a933c3bae7 609255f1b Merge branch 'cleanup' d6ef8d61a Cleanup config, make line shorter and easier to merge Adding cleanup branch for potential other style refactoring 104b80949 Merge remote-tracking branch 'upstream/master' da5e60c94 fixed tests for floating point number inaccuracy issues on linux i836. e49edfa9d fixed typos in the tests. 54a0e568c minor optimizations in ngx.sleep handling. a89d8ce47 added more tests for calling ngx.location.capture before and after ngx.sleep. 2362917a6 updated docs to reflect changes (including documenting ngx.sleep.) c5be5ff2f optimize: fixed the ngx. table initial size. d6ba6b450 renamed t/074-sleep.t to t/077-sleep.t because we already have t/074-prefix-var.t (from the "prefix-var" branch). 4e7379f93 reindexed the test numbers via the "reindex" script. cc3de56b1 Merge branch 'master' into sleep 5a55dd6f4 bugfix: fixed various issues in jinglong's patch for adding ngx.sleep() in github pull request #120. 6446ee71b documented the rewrite_by_lua_no_postpone directive. 8f6fab621 Merge branch 'master' into no-postpone e7754953d updated docs to reflect recent changes. 8e750fa1b bugfix: the receiveuntil iterators would have memory issues with very small lua_socket_buffer_size settings in the inclusive mode. 1f8c3818f Adding test for inclusive mode 8f306812a Fix receiveuntil("pattern", { inclusive = false }) 05dee24fa Adding documentation for the receiveuntil option { inclusive = true } d509d07ec Adding logic for the receiveuntil option { inclusive = true } 92b47f9da fixed typos in the test case names in 075-logby.t 6e732efe6 1, fix a bug in sleep() (the number of argument must be 1) b2481bebe 1, update t/062-count.t(total count of ngx.* to 88) 2, update t/074-sleep.t 080990db7 1,add test cases for ngx.sleep() 4c207e540 1, add ngx.sleep() 0782f475c merged from master 2fd7a3a50 initial implementation works 3ac6f2614 various coding style fixes in Matthieu Tourne's patch for adding ngx.req.init_body(), ngx.req.append_body(), and ngx.req.finish_body(). also made the size argument optional in ngx.req.init_body() in which case the client_body_buffer_size configuration is honored. 205799736 Adding ngx.req.init_body() ngx.req.append_body() ngx.req.finish_body() 46aa87805 fixed coding style in Matthieu Tourne's patch for adding the rewrite_by_lua_no_postpone directive; also added some tests for it. 436cd30a9 Adding directive rewrite_no_postpone b241806f2 Merge branch 'master' into logby f229fccc5 various fixes in ngx.decode_args(). df2ec5acf added tests for the optional max_args argument to ngx.decode_args(); also documented this optional argument. 56d992b1a docs: documented how relative paths are processed when *_by_lua_file directives are used; also documented the $prefix and ${prefix} notations in lua_package_path and lua_package_cpath directive values. 5be3f2b36 Merge branch 'master' into prefix-var 3d6f752a0 docs: updated docs to reflect recent changes in set_by_lua. 89ba48983 Merge branch 'master' into setby 47ec23a33 updated docs to reflect recent changes in the logging API. e9cb51043 fixed a test case in 009-log.t for luajit 2.0. d823b8454 Merge branch 'master' into logging 2bd1f0f80 updated docs to reflect recent changes. 732fe370a added many more tests for log_by_lua* and also fixed issues with ngx.ctx in log_by_lua*. 447c7488b fixed some coding style issues in Matthieu Tourne's patch for log_by_lua* and also added a simple test for log_by_lua. 398710700 Adding log_by_lua and log_by_lua_file and documentation fd193aa4c fixed ngx. table initial size for ngx.decode_args(). 77ca488a5 Adding documentation for ngx.decode_args() 6a61f4384 added some tests for ngx.decode_args(). ecd83e9a1 minor coding style fixes in Matthieu Tourne's patch for adding ngx.decode_args(). 674b8709a Add ngx.decode_args() 4b4f48007 resolved conflicts while merging master into prefix-var. 2178f0bac updated README and README.markdown to reflect recent changes in both the .wiki doc and wiki2markdown.pl. 69a3d8970 Merge pull request #118 from zhuzhaoyuan/master c5016c17f Fixing incorrect merge from prefix-var branch 886792c5f Adding documentation for ngx.decode_args() 50f47a99b Merge branch 'devel' d0f5ed363 Merge remote-tracking branch 'upstream/prefix-var' 849ca03dc Merge remote-tracking branch 'upstream/logging' cb5c37ec7 generated README.markdown by using wiki2markdown.pl b1ca2dd5b updated the wiki file (http://wiki.nginx.org/HttpLuaModule had been updated) a3524ab96 synchronized the wiki from http://wiki.nginx.org/HttpLuaModule 54d4b8fe1 Merge branch 'master' of https://github.com/chaoslawful/lua-nginx-module 087694f4a feature: special nginx variable $prefix is now available in the lua_package_path and lua_package_cpath, which evaluates to the server prefix string (as specified by the -p PREFIX command-line option of the "nginx" executable). thanks Matthieu Tourne for the patch. efb33ad7c added a leading comment to README.markdown to indicate that is is generated automatically. 1e6de3d93 optimize: eliminated unnecessary lua-side operations in ngx.log() and print(). 33b3d45ea modified the message prefix of print() from "[lua] print: " to just "[lua] "; also updated tests to reflect recent changes. 932a748a4 Merge remote-tracking branch 'upstream/logging' 227b9c3ef Merge remote-tracking branch 'upstream/master' 0a258abde fixed some typos 0538286ea Merge pull request #117 from zhuzhaoyuan/master 77c715d45 fixed some minor grammatical errors 5f1c7c32c lua -> Lua fd0fa3e54 Merge branch 'master' of https://github.com/chaoslawful/lua-nginx-module 2ca579687 Merge pull request #116 from dirkfeytons/master 34d6f7da0 bugfix: the set_by_lua directive did support nginx variable interpolation and there was no easy way to use the dollar sign characters in the literal Lua source. the set_by_lua_file directive still supports nginx variable interpoloation in its lua file path argument. thanks Vittly for reporting this in github issue #111 and jinglong for the test in github pull #115. edd3e3f62 Only include lua_regex_cache_max_entries if NGX_PCRE is defined. 2cd7586ce feature: added the "[lua]" prefix to the log messages produced by ngx.log() and print(). thanks Matthieu Tourne for the patch. 28da7e3f9 changed the chunk name of set_by_lua from "set_by_lua_inline" to "set_by_lua". f75f20d18 feature: ngx.log() and print() now output more debugging info, i.e., the current lua source file name (if any), the current source line number, and the current calling lua function name (if any), into the nginx error.log file. thanks Matthieu Tourne for the patch. f8e612af3 changed the chunk name of set_by_lua from "set_by_lua_inline" to "set_by_lua". 57a189a55 Merge pull request #114 from monadbobo/master 8e2e4a9e7 remove some dead assignment via scan-build. e841106d1 added a (passing) test for setting ngx.header.content_encoding that should bypass the ngx_gzip output filter. c465d2bdc Add ngx.decode_args() 57e8d9991 added a (passing) test case for cosocket:send(""), that is, sending an empty string. a3961fe7b bugfix: cosocket:receive(0) was not allowed and would throw an error saying "0" is a bad pattern. thanks huang kun for reporting this issue. ca3239a25 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module cd04674b8 deleted a reduntant blank line c4f371671 fixed minor coding styles 54f5a70d7 deleted a reduntant blank line 4174f0c6b fixed minor coding styles 61960c5ad Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 0d1db00cf remove duplicate string conversion 7a7ac79f3 removed dead code found by Simon Liu. d457e01b2 enlarged the timeout threshold of TEST 10 in 027-multi-capture.t. a7bd2ef07 enlarged the resolver timeout for TEST 4 in 058-tcp-socket.t. a11ba9b04 enlarged the timeout threshold of TEST 5 in 067-req-socket.t. 3584b61d2 Merge remote-tracking branch 'zhuzhaoyuan/master' fbbc89d93 cosocket: simplified the code for downstream cosockets a bit. 8e24cd1ef Merge remote-tracking branch 'upstream/master' 581e0495b lua -> Lua, luajit -> LuaJIT, and fixed some minor typos a34f9b6ea bugfix: gcc 4.6 complaint about comparing size_t values with off_t values. 754d547ca bugfix: ngx.req.socket() did not honor the "Expect: 100-continue" request header and could hang. thanks Matthieu Tourne for the patch in pull request #107. 21450b7c5 bugfix: the ngx.req.socket() object (i.e., the downstream cosocket object) did not work with HTTP 1.1 pipelined requests at all. e7f56d021 bugfix: downstream cosockets might lose the last part of the request body when receiving data. this regression had appeared in v0.5.0rc25. thanks Matthieu Tourne for reporting it. 9144d2487 Fix receiveuntil("pattern", { inclusive = false }) 8cd749f33 Adding failing test 8e6877379 minor coding style fixes in the patch for adding Lua backtraces. also added 073-backtrace.t to test it. see github pull request #107. f079f8b3a Adding trace to errors dbe0dc4e4 now we call ngx_http_lua_socket_finalize in cosocket:setkeepalive() to help buffer reuse. d00976d80 bugfix: nginx could crash on request fialization when running the cosocket cleanup handler due to the lack of check of the ctx pointer. thanks shaneeb for reporting this in github issue #110. b440e5b2d updated t/024-access/exit.t a bit. d4b111b61 Merge remote-tracking branch 'upstream/master' 8f1b3d9aa added a test for If-Unmodified-Since and 412 error page. eeb1816c6 optimize: now ngx.log is much faster when the log level argument is lower than the actual error_log level specified in nginx.conf. thanks Matthieu Tourne for providing the patch. 02b1db9e5 minor optimizations. 0ceb1045f added (passing) tests for conditional GET requests. decdf0129 added error log tests to t/044-req-body.t. e9a5eb1a0 bugfix: ngx.req.get_body_data() could not handle multi-buffer request bodies and discarded the body data after the first buffer. df32739d0 fixed test index in 024-access/subrequest.t. 8e2faf71b added tests to expose the bug in the nginx core reported by drdrxp in agentzh/nginx-eval-module#1. becf72a1a added a (passing) test for github issue #110. 34a36afa1 Adding documentation for the receiveuntil option { inclusive = true } 20b339571 Adding logic for the receiveuntil option { inclusive = true } ef8e2bf8c Adding test for inclusive mode add1a0ad8 updated .gitignore. 9e935ee31 add skeleton of coroutine api 2db0ae306 Merge remote-tracking branch 'upstream/master' 77eb00333 Adding README.markdown 1901199ad Adding log_by_lua and log_by_lua_file and documentation 8d287851e bugfix: the previous patch for using ngx.ctx in set_by_lua* could result in memory leaks; now we ensure that the request cleanup handler is always registered when set_by_lua* is used. ef9112084 added error log tests to 033-ctx.t. bee1cabcb bugfix: ngx.ctx was not accessible at all in set_by_lua*. thanks Pierre. 4e56036c2 minor code refactoring. 004b7c8ba bugfix: fixed typo "on-array", which should be "non-array", in an error message. 6de0c1c6c bugfix: cosocket connections from the connection pool might lead to segfaults if it is not used immediately. thanks xukaifu for reporting this as github issue #108. 370955d21 removed too restrict timeout settings in the test suite. c7ec9c97d bugfix: debug logging in the cosocket receive line method could lead to invalid memory reads under extreme network conditions. this issue was caught by mockeagain in reading mode. f3f561f1e updated valgrind.suppress for linux i386 further. 76bf73c7e updated valgrind.suppress. 200bac2c2 test: enlarged resolver timeout for the cosocket tests even more. 7667027d4 enlarged resolver timeout for the cosocket tests. d611eeee7 added more error_log tests for the cosocket tests. 776f4999d Merge remote-tracking branch 'upstream/master' e0eea5355 Fix issues with POST using http 1.1 (test for expect) b80b502be Adding ngx.req.init_body() ngx.req.append_body() ngx.req.finish_body() a12d72f25 Adding "variable" $ngx_prefix to lua_package_path 2ee6f4694 Adding trace to errors fa3eeb01a Adding directive rewrite_no_postpone 2bb9d6fd8 still use 2 sec as the resolver timeout setting in 058-tcp-socket.t TEST 8. e442e7661 fixed tests for mockeagain in reading mode. 00d05f26d bugfix: downstream cosockets might hang on the receive(size) method call for slow connections. mockeagain in reading mode caught this issue. 1c0e24a3c various fixes in the test suite. 4591dc704 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 6667bf628 feature: made ngx_http_lua_api.h visible to other nginx modules by adding src/api to the CORE_INCS variable value in the config file. thanks Brian Akins for suggesting this in github issue #105. 8a6fc75fa change lua_pop macro to lua_settop function in gdbinit script a84e94623 added support for PCRE_INC and PCRE_LIB to the developer build script. 1cb522d49 fixed the developer build script. f5aaee3d6 updated .gitignore. 43cac16e5 renamed ngx_http_lua_add_preload to ngx_http_lua_add_package_preload; also added new public C API ngx_http_lua_get_global_state, as suggested by Brian Akins in github issue #100. 6e9277404 minor code refactoring: we no longer include ddebug.h in common.h; and we put publich API functions into ngx_http_lua_api.h and ngx_http_lua_api.c. 5692c8f39 Merge pull request #101 from bakins/ngx_http_lua_add_preload caecbe2e5 add gdbinit script to ease lua debugging 95aa6577c Merge branch 'master' of https://github.com/chaoslawful/lua-nginx-module 6ff5df616 updated docs to reflect recent changes (documented the ngx.HTTP_OPTIONS constant). 68638bd3a feature: added new constant ngx.HTTP_OPTIONS for the HTTP OPTIONS method; also added support for OPTIONS method in the subrequest capture APIs. thanks Jónas Tryggvi Jóhannsson for requesting this in github issue #102. 2b3f5f90e bugfix: we no longer forcibly quit the lua threads by clearing out its environment and running it blindly to the end because Lua GC will collect all those unfinished coroutines anyway. 4cfc2488f bugfix: improved the longjmp handling. 31378f14f add ngx_http_lua_get_request f7003733b add ngx_http_lua_add_preload e96822a5a bugfix: certain compilers might complain about missing declarations for types like int8_t. now we explicitly included stdint.h. thanks runner-mei for reporting it in github issue #98. 19bd32224 cosocket: various optimizations in timeout handling. this gives about 2.5+% performance boost in some benchmarks using lua-resty-redis and lua-resty-mysql. c74667407 updated docs to reflect recent changes. bbac7d623 bugfix: made the sha1 library an optional dependency, as suggested by runner-mei in github issue #94. 1a1cde4ca fixed a coding style issue: we did not declare C variables at the beginning of the current code block in ngx_http_lua_del_thread, reported by runner-mei in github issue #93. e84711d08 bugfix: incorrectly used ngx_conf_log_error by using NGX_ERROR as the first argument, as reported by runner-mei in github issue #92. 37f749eb2 fixed typos in lua exception messages. 2ac3aa2a0 updated docs to reflect recent changes. c9c5f9486 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module b4c2a37d3 fixed 061-lua-redis.t a bit. 1dc6c21e4 minor coding style fixes. 6de0dae34 feature: added new directive lua_http10_buffering which is on by default. 58cd006b0 fixed a test case in 024-access/satisfy.t. ee0bf0b89 feature: added new constant ngx.DECLINED. bugfix: access_by_lua could not work with the "satisfy" config directive. b6a6d5b1b Merge branch 'master' of https://github.com/chaoslawful/lua-nginx-module 04332d929 optimize: now we recycle the special flush buf and chain link for ngx.flush() to prevent request-scoped memory leaks when emitting long data streams to the downstream. 58cd7f0f2 added a (passing) test case for multi-value args to ngx.req.set_uri_args. 3dfd00aff bugfix: timestamp could overflow on 32-bit systems in the shared dict API; now we use 64-bit integers. fcfdd73d2 documented the shdict:flush_all() method. ae7b5e972 shdict: now we aggressively remove three items from the store in the flush_all method. 17bb70935 improved Weiqiang Li's patch by fixing the coding style and avoiding unnecessary operations. also added a test case for the new flush_all method. f5d9b6c90 add flush_all api to shared dict 2b37a7c7a docs: documented the max concurrent subrequest count limitation and max error log line size limit. 9da8286df added a test case for emitting large messages via ngx.log(). 215a9f7af updated docs to reflect recent changes. 3ff937f3a bugfix: the shared dict storage might leak memory in the store: ngx_http_lua_shdict_lookup incorrectly assumed that nodes with identical keys are linked together, which might not be true after tree rebalance. thanks the patch from Lanshun Zhou. 261020646 optimize: removed a redundant piece of code for subrequest headers_in fixes in ngx_http_lua_adjust_subrequest. f21bd80b0 bumped the version number in docs. 99b02286f now we use the buf tag literal everywhere and removed the "tag" field from the location conf struct. ec4becfea bugfix: the exptime argument to shdict:set/add/etc methods was incorrectly ignored when the flags argument is also specified. thanks the patch from Brian Akins. 81f1d7ca4 fixed typos in docs. thanks 王斌. 6c713ea68 removed an unnecessary line of code. 34f8f272c updated docs to reflect recent changes. cdcbef310 Merge branch 'master' into cosocket ef311cd1c updated developer build script. 003650d1b bugfix: fixed a debug log message. e8aa2495f bugfix: for big input data, the cosocket reading methods could result in crashes due to incorrect use of luaL_Buffer. now we eliminate luaL_Buffer altogether by managing the recv buffers ourselves. the recv buffers can also be recycled. 87ebe182f updated the developer build script. 32e8ad4e1 bugfix: fixed various typos in source comments also avoided using luaL_checkstring which could do another longjump on its own. thanks 王斌. 67c79c0d2 added tests for cycled subrequests; also increased the "repeat_each" count in 027-multi-capture.t to make an issue with too small MAX_SUBREQUESTS easier to reproduce. aaab8c750 fixed shdict tests on i386; also ensure to configure "postpone_output 1" for the sync flush test case that requires buf reuse. e7f8eb729 bugfix: tcpsocket:setkeepalive() will return errors when the current connection has readable data or there is still unread data in the ngx_lua upstream buffer. bugfix: cosocket methods no longer explicitly return nil error strings upon success. ae6b59a0a refactored the test suite a bit. aa4bd3878 bugfix: when the parent request takes a request body, the subrequest does not take any bodies, and the subrequest's method is neither "PUT" nor "POST", then the subrequest will no longer inherit the parent request's request body. thanks 欧远宁 for reporting this issue. 9026d59fd bugfix: data might be accidentally read into the lua space on idle sockets when the last operation is a read operation *and* a read event suddenly arrives for edge-triggered event models. the same might also apply to write operations too. bugfix: invalid reads might happen in the reading iterators returned by the receiveuntil() method which could lead to segfaults. 1bce88568 added tests for the various "lua socket blah blah timed out" error messages; also tweaked other cosocket test cases for different test modes. f95c55f7a bugfix: "closed" error would occur for long-running requests that hold the idle cosocket object for a period of time that is longer than the read timeout setting: we should delete the read event timer in time when the receive call has already got a read event. thanks 欧远宁 for reporting this issue. 1b702e540 added error logs for socket timeout errors. 78ed3f573 added error logs for closed errors. 7cb4e0957 introduced a minor optimization that we can save one recv call when the read event is active *and* the read event is not ready. e633e75d9 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module fc7893d05 now we recycle the downstream output buffers to save memory and dynamic allocation times for long-running requests. 60e70ef7e bugfix: now we require the SHA1 library in the "config" file. 060e9bf49 Merge branch 'devel' d4167c1a1 bugfix: macro directives were used inside a macro argument which made gcc 3.2.3 unhappy. thanks Feng Bin. 11a13f069 bugfix: cosocket API could not be used before ngx.location.capture and its friends for fast network access: tcpsock:send() method did not reset u->waiting properly. thanks 欧远宁. 89af745e1 updated docs to reflect recent changes. cbc1fd22a add gdb script to ease Lua debugging 96e9b3038 feature: allow use of ngx.null in ngx.log() and print() arguments. 2f1c2a5e0 opt: fixed the "ngx." table initializing sizes. d29c611c8 bugfix: could not compile with nginx 0.8.x. thanks 欧远宁. 25abe98ca feature: added the ngx.sha1_bin method which returns the binary form of the SHA-1 digest. 60335f37b minor fixes in the tests. 2614f3ffd bugfix: we incorrectly allowed ngx.null in the string table argument to cosocket:send() method. c73f87480 updated docs to reflect recent changes. 14e079cca fixed ngx. table entry count during table initialization. 2c5a75838 feature: added constant ngx.null which is a NULL light userdata to represent "nil" values in lua tables and etc. this is compatible with at least lua-cjson library's cjson.null constant. 51a6bdfad minor coding style fixes. e3123d322 Merge branch 'last_modified' cef799110 add last-modified test 90ae31516 last modified jumbo d1085f9e9 fixed typos in docs. thanks @cyberty. a8cad73ed updated docs to reflect recent changes. 1d7626f42 cosocket: feature: now cosocket:send() method supports lua tables of string fragments which can save unnecessary string concatenation operations on the lua land that are usually quite expensive. 907f825a4 cosocket: fixed bugs in debugging logs. 5a3e31777 updated docs to reflect recent changes. 1e8f8e5f5 Merge branch 'dict_flags' 8d576f2ce use uint32_t as the type of shdict user flags. c8967e5a6 match new error message 9ef0b86d6 do not return flags if not set for backwards compatibility 24177e8ed expect nil de5e7bf19 user flag test edc9633d9 Add user flags 170c5484e updated docs to reflect recent changes. ef46b7f33 cosocket: documented the in-pool connection monitoring feature requested by @ldmiao. 653d1ec1f bumped the version number in docs. 750b92809 cosocket: reverted casual changes to the developer build script in the last commit. 1cec50410 cosocket: bugfix: fixed -Werror=unused-but-set-variable warnings from gcc 4.6. 07329405e cosocket: bugfix: when the object returned from ngx.req.socket() is used across the request boundary, segfault would occur; so now we protect the downstream cosocket object from being used outside the current request lifetime. 72f7fb5b0 cosocket: documented the ngx.req.socket() function. 0b99b3505 cosocket: documented the sock:receiveuntil method. 44459f5dd cosocket: documented most of the cosocket API. c6f165e39 cosocket: added a (passing) test for keepalive unix domain sockets. bc4baee25 Merge branch 'cosocket' 204ce2b3d updated docs for the v0.4.1 release. 9e30acfec cosocket: fixed compilation failures without --with-debug: misuse of the ngx_log_debugN macros. 7848542c8 cosocket: added a test case for extremely small buffers when calling sock:receiveuntil. a6183a1a0 minor tweaks in tests. 8d7cc5fba cosocket: optimized the chainlink and buf recycle logic for the subrequest API and cosocket API. ba7a62fbb cosocket: bugfix: the request cleanup handler could access the (invalid) upstream userdata after Lua GC frees it. also fixed the lua table initialization for ngx._tcp_meta. 3bb79438c cosocket: feature: implemented "timeout" and "size" arguments to the setkeepalive() method to override the config settings via the directives lua_socket_keepalive_timeout and lua_socket_pool_size. 2bb7ba793 cosocket: check zero connection pool size. d65eeee42 cosocket: feature: "lua_socket_keepalive_timeout 0" now means unlimited connection idle time. ce5b54349 cosocket: added tests for the default lua_socket_pool_size value (30). fa07de06c cosocket: feature: added config directive lua_socket_pool_size to control the connection pool size (in terms of number of connections) per host-port pair. bc8a9097d cosocket: added debugging output for keepalive timeout values. 154fce40d Merge remote-tracking branch 'origin/master' into cosocket fb3d82db9 Merge branch 'master' into cosocket f1269407d cosocket: bugfix: we did not reset c->read->handler and c->write->handler for connections got from the connection pool which could lead to segfaults; feature: new config directive lua_socket_keepalive_timeout to specify the max idle time for connections in the pool. a95e02faa bugfix: ngx_http_lua_header_filter_init was called with an argument which actually accepts none. this could cause compilation errors at least with gcc 4.3.4 as reported in github issue #80. thanks bigplum (Simon). 9d5e827c7 cosocket: call ngx_close_connection() directly instead of introducing ngx_http_lua_socket_keepalive_close(); also added a (passing) test case for premature close of upstream sockets for idle connections in the pool. dcd633f97 cosocket: fixed connection pool cleanup logic and added support for max idle timeout. 5b2a977b3 cosocket: initial prototype for the builtin connection pool support via the new cosocket method "sock:setkeepalive()". also always reset u->length and u->rest for the "sock:receive()" method. e60a94814 cosocket: did a minor optimization for receiveuntil patterns no longer than 2 bytes. 7a4cbfb4a cosocket: bugfix: fixed a minor inconsistency in the reading iterator returned from sock:receiveuntil when the "size" argument is specified. also added some (passing) tests for a true multipart parser. 54a6f750d cosocket: use 8.8.8.8 as the default TEST_NGINX_RESOLVER env value in the test suite. 4cecc53e3 cosocket fixed a typo in ngx_http_lua_socket_read: we should use r->headers_in.content_length_in instead of r->content_length_n. 9a7a12a46 cosocket: fixed lua table entry count in table initialization. bc93b61f7 cosocket: minor coding style fixes. 83d972e38 cosocket: bugfix: request sockets reading should honour the Content-Length request header (if any). 7bd0fdbeb cosocket: feature: ngx.req.socket() works. 9c461bf15 fixed lua table initial entry count; also added initial skeleton for ngx.req.socket() but not working yet. 9e4abfdcd minor test fixes. 2f20b7acd cosocket: added support for the "size" argument to the reading iterator returned by the sock:receiveuntil(). 51b793007 cosocket: introduced a minor optimization that we could save the first two elements in the cp->recovering array. 38c4fa074 cosocket: added a lot more tests for sock:receiveuntil. b045cfae4 cosocket: bugfix: use the luaL_addchar macro to simplify the state machine logic. d8548e4a4 cosocket: decreased memory usage for unambiguous boundary patterns in sock:receiveuntil(). 9a673b787 added support for ambiguous boundary patterns. 19b071c3e feature: first cut on the socket:receiveuntil(pattern) method. ambiguous boundary patterns and the "size" parameter to the reading iterator are not implemented yet. 92e0e6ef0 added (passing) test cases for cosocket send timeout settings. 75a52b465 RecvUntil.pm: fixed Makefile. 30a17916c checked in a perl prototype for the receiveuntil method implementation. 17ee6b60c updated .gitignore. 884ae49bf feature: implemented method settimeout() for ngx.socket.tcp() objects. 7962a9fb1 Various fixes in cosocket b1b92000b fixed test index. a2859d4fe fixed test index. 735355c98 Merge branch 'master' into cosocket 6e8c4aba5 renamed .t files. 30cf86dd6 merged master to cosocket. dc37474df bugfix: fixed all the warnings from the clang static analyzer. fb84d6fe0 adjusted the tests a bit. 733d26d16 bugfix: ngx.exit, ngx.redirect, ngx.exec, and ngx.set_uri(uri, true) could return (they should never return as per the documentation). this bug had appeared in v0.3.1rc4. thanks @cyberty for reporting it. b166210bc added change log for v0.4.0 and also documented the way to confirm that pcre jit is actually enabled. bc9142cb3 allow use of the DDEBUG macro from the outside (via the "-D DDEBUG=1" cc opton). 7bdd8505b updated README. 37c4880eb docs: massive wording improvement from Nginx User. e43eab96a now we state that ngx.re API requires pcre 8.21+ for its regex JIT support in the docs. 805f6a24a updated docs to reflect recent changes. 11ddbdf9f added debug logging when ngx.req.get_headers() hits header count limit. d40fcc669 added debug log when ngx.req.get_uri_args and ngx.req.get_post_args hit max args limit. 8e8517c64 updated valgrind.suppress a bit. 85f876ec1 bugfix: hash table collision attacks were possible in ngx.req.get_headers() and now it only parses at most 100 headers (can be controlled by the C macro NGX_HTT_LUA_MAX_HEADERS. ngx.req.get_headers() now also takes an optional argument that can be used to specify a custom header count limit (defaul to 100). one can disable the header count limit altogether by feeding ngx.req.get_headers() with a zero value argument. 0ece0793e added more tests for max_args argument. 3a2b80b05 tweaked the timeout settings for two test cases. 75876b67c bugfix: ngx.req.get_uri_args and ngx.req.get_post_args now only parse up to 100 arguments by default. but one can specify the optional argument to these two methods to specify a custom maximum number of args. thanks Tzury Bar Yochay for reporting this. 2b18629c2 bugfix: removing builtin headers in huge request headers with 20+ entries could result in data loss. thanks Chris Dumoulin for the patch. f9efd3288 bugfix: ngx_lua could not compile with nginx 1.1.12+. thanks deltay for reporting it in github issue #76. b0f158232 fixed the test cases regarding invalid escape sequences for LuaJIT 2.0.0 beta9. 81b9bbb51 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 6f9a1f9b7 now we use pcre 8.21 jit build in the developer build script. 33844f1b8 fixed a test case in t/057-flush-timeout.t on FreeBSD. f6ea32e0e removed --with-cc=gcc46 from util/build2.sh. 4f0d035cd updated docs to reflect recent changes. thanks Nginx User. 78014b647 bugfix: request header value strings must be null terminated and was possible to introduce memory invalid reads in the past. thanks Maxim Dounin. 66d35ae23 cosocket: fixed the lua-redis test case a little. a5e501045 cosocket: fixed ngx_log_debugN for non-debugging builds. also added a passing test case for running Daniele Alessandri's lua-redis library by emulating LuaSocket via ngx.socket :) 166a71112 cosocket: we now allow string-typed size argument for sock:receive(). also added a (passing) test case for running Neil Richardson's lua-memcached library by mocking LuaSocket with ngx.socket :) 74738a721 cosocket: minor coding style fixes. 976d3e1fd cosocket: implemented the ngx.socket.connect() shortcut. 7ec21aeea cosocket: fix buffer recycling logic for the "receive" method; also added "buffer too small" error handling. 66f4d22e1 cosocket: fixed receive(n) to only return exactly n bytes of data as per LuaSocket's behavior. also made receive() return the 3rd value for the partial result when error occurs, just like LuaSocket. aeaddfe41 cosocket: implemented the number-typed pattern parameter for the "receive" method as per the LuaSocket TCP API. 592a53446 cosocket: fixed resolver error handling for cached negative results. 3ca2a900e cosocket: implemented the "*l" and "*a" pattern argument for the receive() method as per the LuaSocket TCP API. 072456997 cosocket: fixed resolver error handling a bit. ecb161cf0 Merge remote-tracking branch 'origin/master' into cosocket f63c91437 Merge branch 'master' into cosocket 83a1e64a4 cosocket: added a (passing) test case for resolver timeout handling. f79766317 cosocket: fixed bugs in resolver failure handling. 9b21eb38d cosocket: various coding style fixes. 5353b5bd3 cosocket: various fixes in the unix domain socket support. 33fcd577b bugfix: ngx.var.VARIABLE might evaluate to nil even if there is a valid value because the nginx variable value's valid flag might not be initialized properly. this bad had appeared in v0.3.1rc40. 4e4fe381c cosocket: fixed timeout handing in the connect() method. 6da957c93 now we return the errstr "closed" when manipulating a closed socket object, just like LuaSocket. 202336c40 better socket errstr handling. c0e379575 added a (passing) case to test the "connection refused" error. 1810fb0bc eagerly free u->buffer in ngx_http_lua_socket_finalize. 32b1a5899 cosocket: now we support unix domain socket address for the "connect" method; also improved the error messages. 4b65f824c first cut on the nginx builtin nonblocking resolver support for ngx.socket.tcp(). eea55f590 implemented the socket:close() method. 978c9779b bugfix: socket:receive() will ignore all the CR char in the inputs, just like LuaSocket. 1afdd5265 turned off ddebug and also fixed source lines exceeding 80 cols. 6c0edbd84 fixed a serious bug in socket:receive(). the test case is passing for multiple receive calls. fa1d4b5f1 completed the first cut on the socket:receive() method. the first test case is now passing, but sock:receive() is still buggy. 37d7fd457 now we use dummy handler as the read/write event handler wherever possible (a complete fix would require deleting and adding read/write events for level triggered event models). 563e14b1a ngx.socket.tcp()'s send method is mostly working now :D c6113b309 added new directives lua_socket_connect_timeout, lua_socket_send_timeout, and lua_socket_read_timeout. only really implemented the first one ;) 04e3122de minor fixes in socket:connect(). 220af136e socket:connect() kinda works. 37cc4a24a updated valgrind.suppress further for Valgrind SGCheck. 709d62db3 updated valgrind.suppress further for Valgrind SGCheck. f0faa955e Merge branch 'master' into cosocket 4fc7a965c updated valgrind.suppress for Valgrind SGCheck. 9161a993b bugfix: more_set_input_headers did not handle the Accept-Encoding request headers properly. thanks 天街夜色. 29e8b41e9 bugfix: there were various places where we did not check the pointer returned by the memory allocator. b35bcb2d6 updated README and README.markdown. e9de829c9 docs: updated docs to reflect recent changes. thanks Nginx User. b1d8d6227 bugfix: ngx.flush(true) could not be used before I/O calls like ngx.location.capture. this bug had appeared in v0.3.1rc34. 9e811fbbb more work done on the cosocket scaffold. 0e1770ac4 initial scaffold for ngx.socket.tcp(). also did minor optimization for the "ngx" table and the metatable for "ngx.shard.DICT" objects. 2c6a22a29 fixed some small bugs in the ngx.socket.tcp test case. a44b8ce96 added a test case for the ngx.socket.tcp API. not passing yet. 8153df5c6 bugfix: ngx.var.VARIABLE evalues to nil when the nginx variable is purely invalid. ea24c93c8 documented ngx.HTTP_GATEWAY_TIMEOUT and also included edits from Nginx User. f88d229ce added a test for ngx.HTTP_GATEWAY_TIMEOUT. a3bc3fcee added constant ngx.HTTP_GATEWAY_TIMEOUT (504) per Fry-kun in github issue #73. 9cbf7c376 docs: massive documentation improvements. thanks Nginx User. 7a4617ff8 fixed two spots of gcc 4.6 warnings. c9f5e028b enable the default -O in the developer build script. a635ab8be bugfix: use of the ngx.re API might lead to errors like "pcre_compile() failed: failed to get memory" due to incorrect pcre_malloc and pcre_free handling. thanks Vittly for reporting this in github issue #72. 745b47fd2 more fixes in 057-flush-timeout.t 34ee97908 fixed the flush-timeout test script. bd1da870a bugfix: fixed ngx_log_debugN which fails to compile without --with-debug. thanks @ldmiao for reporting it. 47d977391 checked in the tests for the bug regarding connection timeout error checking fixed in the previous commit. 06fd57947 bugfix: now we check timed out downstream connections in our wev handler. 28ae78f0e updated docs to reflect recent changes. 09ccd15b5 feature: added "wait" boolean argument to ngx.flush() to support synchronous flushing; ngx.flush(true) will not return until all the data has been flushed into the system send buffer or the send timeout has expired. db85756a0 fixed gcc 4.6 compilation warnings by removing some dead code. 6b8c2d8a2 more docs love. 462633481 updated the docs to reflect recent changes. thanks Nginx User for polishing the documentation a lot. c598e718c feature: added new API ngx.update_time which calls ngx_time_update in the Nginx core. 79a19650a reformatted the tests. 2a134b179 omitted unnecessary checks in our lua hooks. 11617ee1e Merge remote-tracking branch 'origin/master' into ngx-now 1e7bd81f5 fixed the test case for ngx.now 08318e606 add missing test file for ngx.now d6ae4883b feature: added "ngx.now" for get time with msec(float) 5fcb1a7b8 updated docs to reflect recent changes. 806a99a3f feature: added opions "copy_all_vars" and "vars" to ngx.location.capture and ngx.location.capture_multi. thanks Marcus Clyne for the patch; also fixed a bad regression in ngx.location.capture_multi when the request option table is specified. c43d510fb updated docs to reflect recent changes. thanks Nginx User. 881a0ae60 fixed a gcc 4.6 warning. 3e0c15ace reverted build2.sh. 4db4603b1 fixed a gcc compilation warning for pcre < 8.20. 99f45c46c now we check if pcre jit indeed works by scanning error.log in the related tests. 951103f3b tested the "d" and "j" regex options for DFA and JIT modes for ngx.re.gsub. 5c2a86cb3 now "j" and "d" regex options are confirmed to work with ngx.re.sub(). c444de8e4 ngx.re: now we disable jit automatically when in dfa mode. 85fb303ff bugfix: ngx.re.gmatch may free the pcre study data too early when the "j" option is specified to enable pcre jit, which might cause crashes. 5a729fca9 coding style fixes. 85a74e068 fixed pcre pool management in the cleanup handler. df000b92d feature: ensured that the "j" (JIT) option for ngx.re.gmatch works properly. 8f28c7f0a turned off ddebug. f360e6903 feature: implemented "d" and "j" regex options for ngx.re.match to enable PCRE DFA mode and JIT mode, respectively. thanks @姜大炮. the support of these two new options in ngx.re.gmatch, ngx.re.sub, and ngx.re.gsub is currently broken and needs fixes in future commits. 457280136 massive documentation improvements. thanks Nginx User. 09fc7c73e tweaked drdrxp's hmac-sha1 patch a bit and also added a test case for it. fd47016fa Merge remote-tracking branch 'drmingdrmer/hmac' into hmac 6dd6f02e0 updated valgrind.suppress a bit. 5beba3733 add ngx.hmac_sha1 a5dc446cd tweaked the developer script a bit. efd374014 bugfix: Cache-Control header modification might introduce empty value headers when using with the standard ngx_headers module. ae29491dd added one more passing test. fa5cafdcf updated docs to reflect recent changes. 64a2b730a renamed ngx.req.encode_args to ngx.encode_args. 1259fbc81 fixed various issues in shrimp's commits for ngx.encode_query_args. also renamed ngx.encode_query_args to ngx.encode_args. 131f13d6b Merge branch 'master' into args 82c566aae confirmed that we work with nginx 1.0.9. 860199f99 updated docs to reflect recent changes. 30a2e898e minor tweaks. b92cbf456 ngx.req.encode_query_args is now supporting args value to be lua table f0942d7a3 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module into args c3a6737b7 add encode_query_args function into ngx.req e5c62d084 added one line of comment. dc49eb206 feature: added "ctx" option to ngx.location.capture: you can now specify a custom Lua table to pass to the subrequest as its "ngx.ctx". thanks @hugozhu. 9942742eb made tests more stable. 4d92cb158 fixed compatibility with nginx 0.8.54. thanks 郭颖. 74755eb0e bugfix: ndk.set_var.DIRECTIVE had a memory issue and may pass empty argument values to the directive being called. thanks dannynoonan. 1eb73d67c updated docs to reflect recent changes. edde16355 now incr returns the new numerical value as its first return value. d01adf7d7 now we still enable --with-debug in our developer build script. 259524953 fixed compilation warnings without --with-debug for gcc 4.6.0. a9842859b fixed another spot of -Werror=unused-but-set-variable warning issued by gcc 4.6.0. 9656a97f0 fixed one spot of -Werror=unused-but-set-variable warning issued by gcc 4.6.0. 24da18171 feature: implemented new methods "add", "replace", and "delete" for ngx.shared.DICT. also made the "set" method return 3 values: "success", "err", and "forcible". a935e6fdb enable the ngx.shared API in set_by_lua* and header_filter_by_lua* too ;) 9c26604bf documented the shared dictionary API. d4224b979 no longer set too many worker connections in t/030-uri-args.t. d7c8be39c fixed test cases for 32-bit systems. e6f600275 reindexed the tests. 8d31d75cc shared_dict set: now we try harder when failing to allocate new entry by forcily removing up to 30 least recently used entries. aad4815f7 shared_dict: now we use uint8_t for value type and uint32_t for value_len. 4518fcf71 implemented shared_dict set nil, which effectively removes the key from the dict. b9d28596d now we support 0 expiration time to denote infinite expiration time in shared_dict set. and it is default to 0 when the set method does not take an "expire" argument. f32e5ed8f added more tests for various error cases and LRU. 192ec1e9d bugfix: shared dict get: we should not unlock the mutex too soon. thanks drdrxp. 2549ab48e added more (passing) tests for the shared dict API. f5a4f7243 the shared_dict get and set are now complete and usable :D b71a0b52a resolved conflicts while merging the "master" branch to "shm". 5973268d3 updated docs and turned off ddebug. d3e601fc9 added tests for setting ngx.var.VAR to nil values. 3638fd09c bugfix: no longer free request body buffers that are not allocated by ourselves. 61b9d83fe now we allow setting ngx.var.VARIABLE to nil. a79cc7500 added a small test case. b25d06b32 improved the README file's formatting. 58d6bc91e fixed reading size_t as an off_t in ngx.req.set_body_data() which may lead to memory issues on 32-bit systems. 0a8a11b99 put the debug log outputs to the right place. 739825a7c no longer set the NGINX_ALLOW_REQUEST_BODY_UPDATING macro in developer build script. f03ac7ca3 fixed -Wset-but-not-used warning issues caught by gcc 4.6.0. 0cb010bb3 bugfix: lua_need_request_body should not skip requests with methods other than POST and PUT. thanks Nginx User. 8eef13e10 updated docs to reflect recent changes regarding the request body API. 5cef7124f no longer use the NGINX_ALLOW_REQUEST_BODY_UPDATING macro and r->content_length_n. now calling ngx.req.read_body() after ngx.req.discard_body() is a no-op. ad0300696 fixed compatibility with standard nginx. 5c36f6e8c now we complete the work for ngx.req.set_body_file(), ngx.req.set_body_data(), and ngx.req.discard_body(). 893f7e72a now we also override Content-Length for ngx.req.set_body_data(). 2fbea05b9 initial cut on the ngx.req.set_body_file() API. ea81bb2f0 implemented new function ngx.req.set_body_data() to override the current request body with in-memory data. 1122cbd49 fixed a test cause because Test::Nginx fixed a bug in its Content-Length handling. a0a9fb49a documented the new APIs: ngx.req.read_body(), ngx.req.discard_body(), ngx.req.get_body_data(), and ngx.req.get_body_file(); also improved the coding style and the test suite a bit. 569e3511c added (passing) tests for ngx.location.capture + ngx.redirect under http pipelining. 982cb581a refactored the code for access_by_lua and access_by_lua_file to reduce code duplication. 2c9a564a4 refactored the code for rewrite_by_lua and rewrite_by_lua_file to reduce code duplication. b6c7dd053 bugfix: fixed hanging issues when using ngx.exec() within rewrite_by_lua and access_by_lua. thanks Nginx User for reporting it. b0474ca75 implemented new function ngx.req.get_body_file(). aefb1c490 implemented new method ngx.req.get_body_data. 38c832593 implemented ngx.req.discard_body() function to let user lua code to discard request body. 18f30a16a now we use ngx_http_block_reading instead of ngx_http_empty_request handler or read event handler. 0f18d9936 implemented ngx.req.read_body() which does synchronous non-blocking request body reading in full buffered mode. b45910b44 minor code refactoring. b298984e0 fixed compilation failures when --with-debug is turned off. 6c1c1666b now we prohibit use of true jump argument in ngx.req.set_uri() in contexts other than rewrite_by_lua and rewrite_by_lua_file. a lua exception will be thrown if the context is incorrect. 6ff491bd1 now we change the ngx.req.set_uri() API a bit by changing the optional argument "break_cycle" to "jump". so now it will not trigger location jump by default (because "jump" argument is false by default) and in case "jump" is given true, the function will re-search locations and jump to the new location and never return. 6be7dad62 added more complex samples to the docs for ngx.req.set_uri(). 89dcc5b8d documented the new APIs ngx.req.set_uri() and ngx.req.set_uri_args(). thanks Vladimir Protasov (utros) and Nginx User for suggesting this feature in github issue #62 and the nginx mailing list, respectively. f72eb473c documented that rewrite phase Lua code will be skipped if location re-lookup is triggered by the standard ngx_rewrite module's rewrite directive. thanks Nginx User. 95faaaa2d now we skip rewrite phase lua handlers altogether if ngx_rewrite's rewrite directive issue a location re-lookup by changing uris (but not including rewrite ... break). a2d115e65 added more (passing) tests for ngx.req.set_uri and ngx.req.set_uri_args. 2df39a9e1 now we implemented ngx.req.set_uri() and ngx.req.set_uri_args() to emulate ngx_rewrite's rewrite directive (without redirect or permanent modifiers). 0bb889956 updated docs to reflect recent changes. 75f960b06 added constant ngx.HTTP_METHOD_NOT_IMPLEMENTED. thanks Nginx User. 3c4b1ff31 added one more (passing) test case. c5fbee750 now we explicitly clear all the modules' contexts before calling ngx_http_named_location. 0457ff206 more treatment of the previous fix. 8f8496419 fixed the download page links in docs. e5b8c8f46 bugfix: calling ngx.exec() to jump to a named location did not clear the context object of ngx_lua properly and might cause evil problems. thanks Nginx User. 4c7176876 turned off the master mode. d5e164208 the first test case is passing! b77bf67fc first cut on the shared dict feature. 65e475965 updated docs to state that we work with nginx 1.0.8 and 1.1.5. 05fbec643 updated developer build script a bit. 0ebffdfb4 no longer set header hash to 1. use ngx_hash instead :) c3acd88c2 minor style fixes. 8b586da4f fixed regression in the last commit: we should hash the header key, not value. 32efa828b we should not set header->hash to 1, we should use ngx_hash_key_lc to generate it. 4ad6d40e0 updated .gitignore. bb2539bb5 now we properly support setting the Cache-Control response header via the ngx.header.HEADER interface. eac237f88 fixed a test case for HTTP 1.0 streaming output. 3cbf39f3a now for HTTP 1.0 requests, we disable the automatic full buffering mode if the user sets the Content-Length response header before sending out the headers. this allows streamming output for HTTP 1.0 requests if the content length can be calculated beforehand. thanks 李子义. 752be5db1 use lua_Number instead of lua_Integer for crc32 functions' return values because 32-bit signed integers are too short for the crc32 digest. 0727d20dd documented the ngx.crc32_short and ngx.crc32_long methods. 9e043c690 exposes the CRC32 API of the Nginx core to the Lua land, in the form of the ngx.crc32_short and ngx.crc32_long methods. thanks @Lance. 6800229f0 documented the new feature that ngx.exec accepts a Lua table as its "args" argument value. fffdb9317 turned off ddebug. 2b625542d now ngx.exec() supports lua table as the second "args" argument value. thanks sexybabes. 60a8b4a61 documented the new ngx.headers_sent API. 47bee750d implemented the ngx.headers_sent API to check if response headers are sent (by ngx_lua). thanks @hugozhu. ab61a0331 renamed ngx_http_lua_patch.[ch] to ngx_http_lua_pcrefix.[ch]. 319800188 even more refactoring of the lua hooks. 8a1367756 more refactoring of the lua hooks. 2684f5b07 massive refactoring of the lua hooks. 87f360c9f fixed doc formatting issues. f5c7c9d1d updated docs from wiki. 88b551d3d now we also return Last-Modified for the subrequest response object. thanks @cyberty and sexybabes. 259d378dd refactored ngx_http_lua_wev_handler a bit to make it smaller. cd53678b3 minor refactoring of the various lua hooks. 7a5016e6b fixed an issue in ngx.redirect, ngx.exit, and ngx.exec: these function calls would be intercepted by Lua pcall/xpcall because they used lua exceptions. now they use lua yield just as ngx.location.capture. thanks @hugozhu for reporting this. f147ba4e9 rewording the doc for ngx.exit a bit. ac24af7f0 documented the way to output error pages with custom dynamic bodies in Lua. thanks rik1083. 6c7e74fb6 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 0e2b7993b enlarged a timeout setting for one of our test cases. 71993f12a documented the reading ngx.header.HEADER feature. bdf56a9da * fixed a bug when setting a multi-value response header to a single value (via writing to ngx.header.HEADER): the single value will be repeated on each old value. * added support for multi-values of reading ngx.header.HEADER. * added more tests for reading non-existent response headers. b0c96e306 simplified the ngx.header.HEADER reading logic. but multi-value headers are still not supported yet. 577de863d implemented reading response headers: VALUE = ngx.header.KEY. 1a3b82be8 do not use ngx_flag_t in internal implementation. we use unsigned for boolean values consistently. 71fba5afb updated the documentation from wiki.nginx.org. 8dc5c9bb1 fixed a bug when the both the main request and the subrequst are POST requests with a body: we should not forward the main request's Content-Length headers to the user subrequests. thanks 朱峰. dd0d4d096 releng work for v0.3.0. 7e997bbbd added header_filter_by_lua test for config merge 9255687ef added test for overriding header_filter_by_lua config 8924e72f1 fixed bug, header_filter_by_lua didn't worked in server or http config 69da13b5d added more debugging outputs to the capture filters. 5a14de4a4 updated valgrind.suppress for archlinux. 864bf0274 removed those ugly lua_package_cpath from the exit.t test files. 8ef144d5c now we use lua-cjson in our test suite instead of lua-yajl. 951420328 renamed 050-header-filter.t to 041-header-filter.t. 4bdd15489 fixed -Wunused-but-set-variable warnings issed by gcc 4.6.0. 97d6c28a2 fixed test plan in ndk.t. eb666c15b marked nginx APIs available in the context of header_filter_by_lua* in the docs. 644b1da68 added more tests for header_filter_by_lua (confirmed that various APIs are properly injected). 138064090 added a (passing) test for header_filter_by_lua_file. 2b53d74b5 renamed the old filter.c to capturefilter.c. e4d00091a only register our capture header/body filters when relavant directives are actually used in nginx.conf. 010297e8f Merge branch 'header_filter' of github.com:chaoslawful/lua-nginx-module into header_filter 13d8ffe6e now we initialize the ngx_http_lua_requires_header_filter in pre config handler. 7d01579b7 Merge branch 'header_filter' of github.com:chaoslawful/lua-nginx-module into header_filter 210b38348 added more test for header_filter_by_lua e3ca6ee3a Merge branch 'header_filter' of github.com:chaoslawful/lua-nginx-module into header_filter 2a4a22d6f we will not register an access handler if nginx.conf does not use rewrite_by_lua* after HUP reload. 534dc1d9a we will not register a rewrite handler if nginx.conf does not use rewrite_by_lua* after HUP reload. f6cd4f54b added test for capture and header_filter_by 16606038d fixed some coding style issues. a7f05f3a5 cleaned up the API registration code. da21df069 merged master into the header_filter branch. d8b5cff81 Merge branch 'master' into header_filter 02d5ac66a refactored the Lua API injection code into groups. 0959786f1 added test for wrong lua code 4fa354eb2 Merge branch 'master' into header_filter a5b756c4f rename file name for ngx_links script 66fdc880f we should set the ctx->headers_sent flag after we have actually called ngx_http_send_header. this should pave a way to the new header_filter_by_lua* directives. c2cbbeac2 fixed issues for HEAD requests. a1aae4b11 checked in util/build2.sh. 06edf2a0d checked in util/build2.sh f6fa44f60 return NGX_ERROR after run lua failed in header_filter_by_lua f415f8186 go on next header filter when error found in header_by_filter 89af70819 fixed filter chain bug 2b1788528 added header_filter_by_lua command d41f205df updated docs in markdown and plain text accordingly. 0b733c4af explicitly documented the "ngx" and "ndk" standard packages introduced by this module, which are also the Nginx API exposed to the Lua land by ngx_lua. also documented the (new) ability to explicitly require them in the user Lua code. 4355225aa fixed a small formatting nit in the docs. 8e91a6a05 documented the new "o" regex option for the ngx.re.* API, as well as the new lua_regex_cache_max_entries directive. cc12d56e7 now we add "ngx" and "ndk" table into package.loaded such that the user can write "local ngx = require 'ngx'" and "local ndk = require 'ndk'". thanks @Lance. f291379d7 checked in t/040-gsub-o.t. 09afd869f fixed compilation errors while bulding nginx without --with-debug; splitted source lines exceeding 80 cols. 59eba8b24 implemented the "o" regex option for ngx.re.sub(). 1f1b0f0f8 implemented the "o" option for ngx.re.gmatch, so as to cache compiled regexes. 108cca013 implemented lua_regex_cache_max_entries directive to control the upper limit of the global regex cache size. when the user lua code is exceeding the regex cache, it will revert to non-compile-once mode and print out a warning to error.log 5d887904c added debugging outputs by ngx_log_debugN for ngx.re.match. e90a5a550 implemented the "o" regex option (i.e., the compiled-regex cache) for ngx.re.match(). 2097cef56 Revert "bumped the version number." de284ea91 bumped the version number. 6381eba76 splitted source lines exceeding 80 cols and also updated the docs from the wiki page. 75a9a0dbf Merge branch 'regex' 91f12efcf fixed a bug in the ngx.re regex API that look-behind assertions in PCRE regexes did not work properly. 3ef84e0f8 updated docs to reflect recent changes. e92921609 now we enable ngx.re.* regex API in set_by_lua* too :) 9eda6ccc7 minor tweaks of the tests. 16aa083ca fixed < and > symbols in the markdown docs. 3ce0b7a24 updated links in the doc. e0b45fe69 use HttpBlahModule instead of NginxHttpBlahModule in the doc. 7f09f235a renamed the wiki file. 39556de94 fixed issues found by gcc 4.6 -Wunused-but-set-variable warnings. f3653cede fixed github issue #52: compile error with nginx 1.0.5 on Ubuntu natty. 188cd4103 documented the new ngx.re.gsub function. 9c6595514 splitted source lines exceeding 80 cols. bd8e4a1fe implemented the ngx.re.gsub method. 2be93496f documented the optional "ctx" table argument to ngx.re.match. 53574fba9 added support for the ctx argument to ngx.re.match. b73bb88a9 refactored the code a bit and introduced auxiliary function ngx_http_lua_ngx_re_parse_opts. a713340e9 documented the new ngx.re.sub method. 6be0d9cea now we support function to be passed as the "replace" argument to ngx.re.sub(). 4a497814c added support for anchored match modifer "a" to ngx.re.match, ngx.re.gmatch, and ngx.re.sub. 10609bced implemented ngx.re.sub(subj, regex, repl, opts?) method for PCRE regex subsitution. now a template scripting language is supported in the "repl" argument, for example, "$0: $1". "repl" does not support lua function yet. 14c0f0e0c refactored logging related APIs to a separate C compilation unit. 9d842d0f5 minor code refactoring. d32ab9731 refactored subrequest related APIs to a separate C compilation unit. da18e0b4c refactored code for NDK related APIs to a separate C compilation unit. 2c862bb01 checked in missing files. a35f8213b refactored code for redirect related APIs to a separate C compilation unit. 799bd9dff refactored code for time related APIs to a separate C compilation unit. a6c779c8a refactored code for echo related APIs to a separate C compilation unit. ef08db33c refactored code for headers related APIs to a separate C compilation unit. 791ef6cd2 refactored the ngx.req.get_*_args API to a seperate C compilation unit. e2560a43a refactored the ngx.ctx API to a seperate C compilation unit. bd41801bc refactored the ngx.re API to a seperate C compilation unit. cafd7842f documented the ngx.re.gmatch interface. aa747edf6 fixed a memory bug in ngx.re.gmatch(); also added more tests. 8be276db7 first cut on the ngx.re.gmatch() implementation. the first test case is passing now :) bf52ee08b documented the new ngx.re.match() API; fixed unmatched subpattern capturing (we should return nil instead of "" here); only enable ngx.re.match when PCRE is enabled in the nginx core. 8f021621f checked in the first version of the ngx.re.match() regex API implementation. f4f4b6296 sync'd docs from the nginx wiki page. dca8a24b7 made setting ngx.header.HEADER after sending out response headers throw out a Lua exception to help debugging issues like github issue #49. thanks Bill Donahue (ikhoyo). 24772d3f7 sync'd docs from the nginx wiki. c2f3d0edc fixed special char escaping in internal cross links in README.markdown. d3800ccf2 added internal cross-links to README.markdown. 982c664f5 fixed links in README.markdown. fba615a89 added more hyper-links to docs. ccec92f6c added hyper-links to NginxHttpBlahModule tags. e6f3425f8 massive doc improvements. 94c51becf added two samples tiddlers on openresty.org to the See Also section in the doc. 9ca18712e fixed formatting issues in README.markdown. 89cdf6e7f updated README.markdown. 82cab4e24 updated docs from wiki. 507c10831 now we generate README.markdown from doc/manual.wiki. 3659ede68 more formatting improvements. 1d13a1ca2 try markdown links. d49e3fe40 fixed more formatting issues. fd0ef5bb1 more README formatting fixes. dea32100c even more formatting fixes. 3048d74cd more formatting fixes. 356520354 more formatting fixes in the wiki doc. d88e97af4 udpated docs. 05956d68e updated doc/manual.wiki accordingly. 2871af384 more README tweaks. dce23b6c1 updated manual.wiki. 205506be9 more README love. 7a2ee2e9e massive README updates. 437229005 some cross-link love. 62b0e84d6 checked in doc/manual.wiki. f3a628ab2 updated README.markdown to ease converting to wiki. also checked in doc/manual.wiki. 5d318deaf updated docs to reflect recent changes. c43294e8b now ngx.ctx = {...} assignment is also supported. fc44ddb7b fixed a typo in README found by 万珣新. 4b9345088 documented the ngx.ctx "magic table"; also checked in the tests for ngx.ctx. f26d17a89 fixed a memory leak when setting ngx.ctx and later doing an ngx.exec() internal redirect. cfa5eb772 added lots of ngx_log_debugN invocations; completed the first run of the ngx.ctx implementation (still buggy). 445c7309b minor edits in the tests. 302edda86 added tests for outputing lua tables. 988040915 now ngx.print/ngx.say allow (nested) array-like table arguments. the array elements in them will be sent piece by piece. this will avoid string concatenation for templating engines like ltp. d9f68ec6a updated tests to reflect recent changes; also updated README to require identical values in client_max_body_size and client_body_buffer_size when turning lua_need_request_body on. cf52bc17a renamed ngx.req.get_query_args to ngx.req.get_uri_args; the old ngx.req.get_query_args is now deprecated. 5b2eb9633 documented that lua_need_request_body is required to be turned on for ngx.req.get_post_args(). bd6e57214 documented the ngx.req.get_post_args() method in README. 8de549eab added tests for ngx.req.get_post_args(). f2ad70e1b implemented the ngx.req.get_post_args() method for Lua. c8c75c35e fixed a bug in ngx.req.get_query_args(): args requiring unescaping could corrupt r->args buffer. 0e03a4414 updated docs to reflect recent changes in print() and ngx.log(). 10aea81c8 now we also allow Lua booleans and nils in arguments to ngx.log() and print(). 44182153f documented the ngx.req.get_query_args method. this new interface resolves github issue #15. thanks Bertrand Mansion (golgote). 5f0744c15 now we support multi-value keys in ngx.req.get_query_args(). 2502bdcd0 now we allow boolean and nil values as args to ngx.print/ngx.say; also done the first cut on the ngx.req.get_query_args() API. db34dab6b updated valgrind.suppress according to nginx 1.0.5. 52d265b02 reverted bad commits. e31406fa1 worked-around the "stack overflow" issue while using luarocks.loader and disabling lua_code_cache, as described as github issue #27. thanks Patrick Crosby. f2fbc1f24 worked-around the "stack overflow" issue while using luarocks.loader and disabling lua_code_cache, as described as github issue #27. thanks d40eb065e worked-around the "stack overflow" issue while using luarocks.loader and disabling lua_code_cache, as described as github issue #27. thanks 281f7487f we should have returned NGX_DONE instead of NGX_DECLINED when waiting for more request body at rewrite and access phases. this should fix the "zero size buf" alert while combining lua_need_requesty_body on + access_by_lua/rewrite_by_lua + proxy_pass/fastcgi_pass. thanks 万珣新. 1cf8f4fa6 minor coding style fixes. e06c869a0 fixed the support for macros LUA_DEFAULT_PATH and LUA_DEFAULT_CPATH: we get these custom paths work even when the config directives lua_package_path or lua_package_cpath are not used at all. 65f178f59 documented the ngx.parse_http_time() method. thanks James Hurst. 359281876 polished the implementation of ngx.cookie_time, ngx.http_time, and ngx.parse_http_time a bit: removed request object fetching code because we never use it and also added code to test NGX_ERROR returned by ngx_http_parse_time (we return nil in that case). 2fbc16dba Merge remote-tracking branch 'pintsized/master' into devel 243eb9e5b added support for user C macros LUA_DEFAULT_PATH and LUA_DEFAULT_CPATH. for now we can only define them in ngx_lua's config file because nginx configure's --with-cc-opt option hates values with double quotes in them. sigh. 2d285e983 Added ngx.parse_http_time() dc3fa1cd1 Added ngx.parse_http_time() a2eb4c6b9 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 0457c06c0 fixed an issue regarding defining global variables in C header files: we should have defined the global ngx_http_lua_exception in a single compilation unit. thanks @姜大炮. 9b65b6714 fixed the date in the Changes file. 96f72bd3d fixed a source line exceeding 80 cols. 8e7d37eb9 checked in the Changes file. 4dffb3cea removed the limitation that we cannot capture subrequests with internal redirects from the doc. 5cd3b677b documented setting nginx special variables $limit_rate/$args, and reading special variables $1, $2, $3, and etc. 31bcaa821 ensure that we can compile when pcre is disabled in the nginx build. 95528f511 Merge branch 'devel' c808ce7c3 Merge branch 'devel2' into devel 7c835bde1 now we support ngx.var[1], ngx.var[2], and etc to refer to the nginx regex capturing variables \$1, \$2, and etc in Lua. this resolved github issue #43. thanks Tobia Conforto for reporting it. a28d67ad0 minor test suite refactoring. 40e8a644f now we use the same value overriding mechanism as ngx_rewrite's set command for ngx.var.VAR = new_value. Assigning values to special variables like $limit_rate and $args should now work; also writing to built-in variables that are not changeable (like $arg_PARAMETER) will result in a 500 error page, as expected, now. thanks Richard Kearsley for reporting it. 3d1ec74e8 fixed the lua_code_cache off warning when the lua_code_cache is explicitly on. thanks Feng Xingguo. 9d4744574 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 9ff893ff8 applied the patch from cyberty to add ngx.http_time() function to expose the nginx core function ngx_http_time to the Lua land. 8e76765ae applied the patch from Feng Xinguo (@cyberty) to add ngx.http_time() function to expose the nginx core function ngx_http_time to the Lua land. dcdcf87ca confirmed that we work with nginx 1.0.4. ef3605b13 updated the ngx_openresty bundle link to openresty.org. ae7b7b8d1 we should have used off_t consistently. mixing it with size_t can cause Bad Things. this should have fixed github issue #42. f39821aaa fixed a formatter mismatch issue in ngx_http_echo_adjust_subrequest. thanks 王斌. 1fa2e121e added two passing tests for setting content-type response header with a charset. bcb1f2c1c suppressed one more valgrind false-alarm for nginx 1.0.x. c52525b3a now in the subrequest capturing processor, we worked around an issue in ngx_http_static_module that when it issues 301 redirect for directory access w/o a trailing slash, it does not inject r->headers_out.location into the r->headers_out.headers list. thanks moodydeath for reporting it in the discussion of github issue #41. b9a84fc3a fixed a tiny bug in the subrequest + internal redirect fix: we should not override the current ctx completely, as mentioned in github issue #41. 6709d16c0 reindexed the tests. a7c013667 added a test for internal redirects by the "index" directive. c3b03fed2 fixed a bug in ngx.location.capture() and ngx.location.capture_multi() that we could not capture locations with internal redirections in them. thanks moodydeath for reporting it in github issue \#41. 1a58a2931 fixed redundant last chunk issue for ngx.exec() invocation at rewrite and access phases: we should quit the current core_run_phases cycle; this also fixed github issue #40: 2 Subrequest calls when using access_by_lua, ngx.exec and echo_location. 9c8b21969 Merge branch 'exit-fixes' 6c147f4e2 used longer timeout for access/exit.t 0f2c228ff updated the documentation for ngx.exit() in README. 7492a1ea6 fixed ngx.exit(status) where status >= 200 and status < 300 for access_by_lua*: it should quit the whole request altegother and skip all those subsequent phase handlers (if any). 15229c2d6 now exit(status) where status >= 200 and status < 300 will successfully quit the current request altogether if being used in rewrite_by_lua or rewrite_by_lua_file. thanks moodydeath for reporting this issue. 1ab26d015 repeat each test case twice in t/016-resp-header.t. e4e299409 fixed github issue #39: setting differnt headers with common prefix might interfere with each other. thanks moodydeath. 43345dcbe documented that ngx.req.get_headers() and its friends only operate on the current request. it has no effect on the current request's subrequests. thanks moodydeath. e8c9ea9e0 fixed GitHub issue #38: request headers did not forward to subrequests when the "method" or "body" option is explicitly specified by a non-nil value for ngx.location.capture(). thanks Richard Kearsley. 2081f73a5 fixed the link to ngx_openresty. d0026ac6d added pointer to the ngx_openresty bundle in the Installation section. ce83076c7 minor formatting. 0dca6659b minor formatting. 2e5d42024 fixed a bug in output header set; we should always set the header->hash to 1. thanks moodydeath for reporting it. 33f2decc4 confirmed that we work with nginx 1.0.2 as well. 75e67b6bb confirmed that we work with 1.0.1. f337896d4 fixed a spot that triggers the "variable set but not used" warning issued by gcc 4.6.0. 670d12b5e splitted source code lines exceeding 80 cols. 6071175d7 suppressed the false alarms on nginx 1.0.1. 6cfe38e07 minor coding style fixes. 4ffeefec2 fixed test failures due to randomness involved in Lua table's pair order; the test suite is passing completely with LuaJIT2.0 now. 9739fccaa added support for multi-value request headers in ngx.req.get_headers(). 23cad91f0 now we turn the ngx.req.header table into an ngx.req.get_headers() function; we also added ngx.req.set_header(name, value) and ngx.req.clear_header(name). thanks moodydeath. 7bba8bfec renamed the 016-headers.t to 016-header-out.t. 098838e5c minor code refactoring for the headers out stuffs. cfa8109d9 minor coding style fixes. 35b4c8d86 implemented the ngx.req.header table interface for retrieving all the request headers for Lua. thanks moodydeath. c230c16f5 no longer use request_eval and respones_eval sections in the tests because they are deprecated now in Test::Nginx. 08ac36810 marked features that require the ngx_devel_kit (NDK) module. 25ff9e40d Merge branch 'optional-ndk' of github.com:chaoslawful/lua-nginx-module into optional-ndk 28b3882d7 now we make ngx_devel_kit (NDK) optional. thanks Kirill A. Korinskiy. 1f8751d1c now we make ngx_devel_kit (NDK) optional. thanks XXX. babcd9e22 documented that we work with nginx 1.0.0. ff7f76976 updated build10. a367a9e57 removed a duplicate definition of the ngx_str_set macro caught by ctags; also fixed a warning thrown by gcc -O3 on Mac OS X 10.6. 0e0b0fc26 also apply PCRE patch to set_by_lua* directives a49c175e6 add patch to use PCRE related LUA extensions in ngx_lua 580279dd3 add warns about data sharing trick in readme 30170eff2 added a quick note regarding ngx.OK/ngx.DONE/ngx.AGAIN/ngx.ERROR. thanks wendal. ce944e1f6 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 86d6b00f9 documented one known issue that ngx_lua cannot capture locations with internal redirections (either via error_page or ngx_echo's echo_exec directives or ngx_lua's ngx.exec()). 4ffe58d82 added more complex tests (using memcached) for the ngx.exec() after ngx.location.capture() bug; it is already passing. 271a7e184 now we change the way we process HTTP 1.0 requests by automatically buffering all the user outputs generated by ngx.print()/ngx.say() calls, which is much more natural than the old broken way. bd6509047 fixed a regression in the previous ngx.exec() fix when using nginx 0.7.x and 0.8.x < 0.8.11. 241ba237b fixed the "ngx.exec() after ngx.location.capture() hanging" bug for rewrite_by_lua* and access_by_lua* as well. also added tests for these cases. 2431340d8 fixed the bug regarding use of ngx.exec() after ngx.location.capture(), which led to hang. 8a37e835b replace readlink cmd in order to make build.sh working under OSX d6f7dd560 more README tweaks. 52f027bb0 fixed another typo in README. f49621318 fixed a typo in README. f7b3925bb emphasized that the data sharing is per-worker not per-server. ae8c97c8c added a separate section "Data Sharing within an nginx worker. 7a0570480 fixed a typo. d63963efb documented in details about data sharing and race conditions by means of required Lua user modules. 74ba36fea updated README to reflect the changes that we always add those extra linking options on darwin systems because it is too hard to tell if it is a x86_64 system or not. c7907e031 added a test for the hanging bug regarding ngx.exec() used after ngx.location.capture(). a51a2a7ef Merge branch 'master' of github.com:chaoslawful/lua-nginx-module daad6fcef fixed a typo in the error messages. 6bb9a260c fix luajit linking opt on OSX 5a57432cb add missing module info for unit-test; remove unused code; update ndk dependency 98924adae documented the ngx.is_subrequest attribute and enabled ngx.status and ngx.is_subrequest in set_by_lua* as well. 03b3d311d applied a patch from moodydeath to introduce the "ngx.is_subrequest" attribute. a32193bdc now we encourage use of the client_body_in_single_buffer directive instead of big client_body_buffer_size. ccaf13216 updated the contexts each config directive can be used within. 4d4ba140f now we allow rewrite_by_lua(_file) and access_by_lua(_file) at server and http config levels. 0b08a6e65 updated valgrind.suppress. e42cdc0f4 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 4781ccc5c set vv->no_cacheable too for ngx.var.foo = xxx. 28aa858eb Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 49788e19e fixed typo in config; added extra linking options needed by LuaJIT in 64bit OSX 1db066e64 emphasized in README that Mac 64-bit users have to edit the "config" file themselves when building with LuaJIT 2.0 (for now). fde4b44e6 updated the Status section of README. 06c71b8cc minor tweaks of README. 48063d36a skip more false-alarms for valgrind when building nginx using -O3. 8bc6ec53b fixed the zero size alert caused by ngx.print("") in Lua. 4a7afc242 now we always allocate r->request_body for subrequests when the method option is specified for ngx.location.capture*. this prevents accidental inheritance of parent request's request body when client_body_buffer_size < client_max_body_size. 44fb57098 fixed indentation. 4de07de5d fixed a typo in README. 699c4abd8 added notes about variable number of subrequests for ngx.location.capture_multi to README. thanks Marcus Clyne. 0b39e1e25 optimized the buffer management process a bit for ngx.location.capture*: one the response body is a single buf chain, do not bother concatening it into a new buffer. 149fea4b4 states that we no longer require openssl in README. 0a6ecfe67 now we no longer explicitly require OpenSSL crypto, we now use ngx_md5.h exclusively, and no NDK_HASH pain any more. 6d4ab5ee1 fixed various minor coding style issues. 92520b0ce mentioned the "cosocket" mechanism in the Future Plan section. 19ad8e7a5 minor test adjust. f408e32f7 now we report an error at config time when rewrite_by_lua* are used with nginx 0.8.42 ~ 0.8.53. a6e80250b minor README tweaks. f0b0540b8 updated the TODO, Known Issues, and Future Plan sections in README. af1ebf104 fixed regressions while building with nginx 0.7.x and also confirmed that rewrite_by_lua* work with nginx 0.7.x. 63901b1fb added notes regarding cases when ngx.location.capture and ngx.location.capture_multi fail to capture subrequests' outputs. 972933203 now we recycle the chain links and associated bufs among subrequests issued by one or more ngx.location.capture_multi() calls within a single (parent) request. 4b9c29c6b we now free unused memory chunks more aggressively to reduce memory usage. 60a88383a added some tests for using ngx.location.capture_multi() at rewrite, access, and content phases at the same time and these tests are all passing :) c8aeedc87 we now cancel the ctx->body field and use the parent request's ctx->bodies instead, thus saving some bytes per request. ca4a24322 now we make ctx->waiting a counter and cancel the ctx->waitings array. 5aee1af16 we now post the parent request ourselves in the post_subrequest callback in some extreme condition that the current (sub)request is not active AND it has some weird postponed requests associated with it. this work-around makes those crazily complicated test cases for ngx.location.capture_multi() pass now. a5819c8a7 no longer set the NGX_HTTP_SUBREQUEST_WAITED flag for subrequests. 71fa89025 minor optimizations: we only pass NULL chains down the output filter chain when we really need (that is, the current request is active *AND* there is postponed outputs in r->postponed). 4265dbdc2 minor optimizations in ngx.location.capture_multi() and also fixed a bug in its request options handling (we did not initialize the options properly for *every* request). 3ad08c9e3 updated the TODO list in README to reflect recent changes :) ce540ead3 documented ngx.location.capture_multi() in README. 0048b1fbc the post subrequest callback may be called multiple times (due to finalizing in-active requests) and those useless left-over calls may cause segfaults while accessing parent requests' ctx struct. now we add checks to post_subrequest to prevent its main logic from running twice or more. b6e2e5517 added more tests for ngx.location.capture_multi: 4 parallel subrequests are confirmed to work ;) ef2dbff1f ngx.location.capture_multi(): now we actively switch the active request to the next (postponed) subrequest if the current request is still waiting for its subrequests. 079cb2aab added tests for ngx.location.capture_multi(). 8b19dd8b1 implemented ngx.location.capture_multi(). 4f8f26dae mentioned bad race conditions while reloading lua modules when the lua code cache is off. 2ed82042e minor config cleanup. 65b587c6e added notes for installation on Ubuntu/Debian/Fedora/RHEL/CentOS. 9303bdaf7 added a failing test that ngx.location.capture() cannot capture subrequests with internal redirects because ngx_http_internal_redirect() clears module ctx structs. 4f3607b93 now we skip those lua5.1 and luajit2.0's builtin packages while clearing package.loaded when lua_code_cache is off. 64c6b3497 when subrequest status is 0, assuming 200. adf6c0099 added a test case to demonstrate how to kill timed out mysql queries and also confirmed that we also work with nginx 0.9.4. 6bf089878 added more test cases for phase postponing. 43513dddf added more docs for the Lua code cache. 7d9e04187 updated README to reflect recent changes regarding the lua code cache control. e1522b1d9 added more test cases. c201c8892 now we also pre-calculate cache keys for lua file paths that do not contain nginx variables. d0de36b0a inlined lua code now calculates the digest key only once at config time, this will save some CPU cycles per request. 68b171b73 now we make use of the new ngx_http_complex_value_t struct and related utility functions provided by the nginx core for nginx variable handling in lua file paths. 8b30373df added more code-cache tests for set_by_lua_file. 7ea8bd5a4 fixed a typo in README. 4dceab188 documented the new "lua_code_cache" directive. 47ef132c0 now we forcibly flush "package.loaded" for each http request when lua_code_cache is off. baaaabcc9 first cut on the "lua_code_cache off" directive. mostly working but reloading lua modules still needs some work. 7b30e2984 now ngx.log and those log level constants are available in the context of set_by_lua and set_by_lua_file. 92d7a4f71 minor test code cleanup. 7db7ae134 fixed a typo in README. b626757ed fixed README's wording a bit. c8f59c7fb Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 284c7f1b5 documented that subrequest issued by ngx.location.capture always inherit all the request headers of the parent request. 18293939a Merge branch 'master' of github.com:chaoslawful/lua-nginx-module ac1b3de7e updated todos d2006cbfd fixed a typo: $LIB_LIB should be $LUA_LIB. thanks Vladislav Manchev. de270bf8e fixed -lcrypto library search under /lib for Solaris. ngx_lua should build out of the box there. 5f6813866 No ONLY in exit.t 0fbf2c848 updated config to check openssl and -W,-E support on the fly. f2541c2d5 minor edits. ee1cb7dd6 added a more complicated sample for access_by_phase. 68069101e checked in auth.t. 96b9bbe63 removed unused debug options 84131c0fd resolved conflictions 45de0f0c0 add tests in subdirs into run_test script a910ced9d fixed test cases for earlier versions of nginx. 1660f5731 updated test requirements 0745d1e93 modified doc to reflect *_file directives' change c689ef514 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 4ba628259 allow using nginx vars in *_by_lua_file directives 44798330a added missing vim modeline 4d153cbae updated the Installation section. ae257b0c2 added one more (passing) test case from Sirsiwal, Umesh e9502dd23 now we no longer emit anything (even special bufs) after eof. 80bb55a3e updated the year list in the copyright notice. 92381c521 edited my names in README. c62a7a523 removed a --- ONLY flag from the test suite. 57d1f80cf rewritten the HTTP 1.0 handling section in README. we can actually automatically generate a Content-Length header for HTTP 1.0 requests. f2374de19 fixed a typo in README. 69527323a added a section in HTTP 1.0 outputs to README. 17bffb5c2 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module ed48b9303 fixed an issue regarding HTTP 1.0 outputs. face45b54 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module e1da31636 fixed comment mark 44bbe7068 applied a modified version of neilljordan 's patch to add support for multi-value response headers returned from subrquests. 9a7c06c4a fixed a bug in rewrite_by_lua* and access_by_lua* regarding automatic response headers sending. thanks Roman Vasilyev. c2ec0b3ab added a test for auth_request + ngx_access. 077ee1a4d documented that access_by_lua* also supports lua_need_request_body. 417e3a760 added a sample for mixing rewrite_by_lua_file, access_by_lua_file, and content_by_lua_file. d2e6375c8 added more tests for access_by_lua. 3da14bc61 added t/024-access/*.t. 02f32dd21 added more sample configs to Synopsis section. 20e919d61 access_by_lua and access_by_lua_file are passing tests now. 2606b2f2f updated .gitignore. 51971a48f added compatibility notes regarding 0.9.x. 554524258 resolved conflicts b0da782fb added typecasts to suppress clang warnings 0590c96d5 now we return NGX_DONE when ngx_http_read_client_request_body returns NGX_AGAIN in content_by_lua. f5187bff3 specified which context a specific lua nginx API is available, like being available in rewrite_by_lua and content_by_lua. 77a036c5a documented that rewrite_by_lua will NOT work with nginx 0.8.41 ~ 0.8.53. 0d2001b02 massive code layout refactoring. 17d56682c moved the handler functions out of directive.[ch]. 657bea5b2 moved t/024-mixed.t to t/023-rewrite/. 530be0965 checked in more tests for rewrite_by_lua. 2f2b1b666 fixed a bug regarding content handler reading request body. 3a25d1866 documented the current behavior of the "lua_need_request_body" directive. 2b53d0d52 re-implemented the "lua_need_request_body" directive. now it is both working for rewrite_by_lua and content_by_lua. 18df04491 now we postpone rewrite_by_lua to the end of the rewrite phase; also reset ctx in content_by_lua to avoid left-over ctx flags set by rewrite_by_lua to taint our content_by_lua handlers. 65ef4ca5e fixed compatibility issues with nginx 0.7.x but still rewrite_by_lua does not work with 0.7.x. 11050d43b rewite_by_lua tests. f8f272aee sanity.t and subrequest.t for rewrite_by_lua* now passing. 9372747c5 rewrite_by_lua starts passing tests. ac647f3e8 coding style fixes. 13dbf2ab3 first cut on rewrite_by_lua support, not there yet. d66c01d39 updated ndk upstream location fb58b876e updated ndk dep 3c1b63a4f Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 2d37ba51d now we use the 2-clause bsd license. 52a7f21c3 Add auto-discovery for FreeBSD. bc1c2d63a added notes about using luajit under 64-bit darwin os; updated ndk depedency 113ba8b72 $ngx_found value cannot be accessed before auto/feature, because it carries-over result from the previous feature check. 9ed533cc0 Add autodiscovery support for Debian Lenny. add96fcf0 added more tests for 500 in subrequests. 967557e8d more README tweaks. 18588a560 documented that you can only write to an nginx variable in Lua when you have predefined it outside at config time. also documented an interesting work-around for set_by_lua to return multiple values to multiple nginx variables at the same time. d4e72a9c2 marked those lua interfaces only available in content_by_lua. ae3ae2e7f renamed ngx.utc_time() to ngx.time(), and canceled the old ngx.time() functionality. also renamed ngx.strtime() to ngx.localtime(), and ngx.utc_strtime() to ngx.utctime(). a348f369b removed trailing spaces in README. ec5a8bc61 more README tweaks. 561a72298 fixed an english wording error. 0e0f1e530 fixed ThinkPad spec in the Performance section. 93186ff6e minor README fixes. 055818238 fixed english wording in Known Issues. d7693625b more README tweaks. 70bba9064 more README tweaks. a7b79f070 states that subrequests are completely different from HTTP 301/302 redirection and internal redirection. d88aa2b07 more README tweaks. 7415b527e more wording tweaks in README. 1fce2771f minor wording tweaks in README. 46642db58 explains how nginx subrequests work and what it can do. e870cad23 documented the "args" option for ngx.location.capture(). bf7f4f76c implemented the "args" option for ngx.location.capture. 74f541f5b tweaked the docs for ngx.redirect(). 32c3686a1 implemented, tested, and documented the new ngx.redirect(uri, status) method for Lua. d98a14778 documented the share_all_vars option for ngx.location.capture in README. d53fe2831 added a share_all_vars option to ngx.location.capture to resume the old behavior of sharing all variables among parent and sub requests. 06563fa52 now we do not share variables by default. 8eb0d8010 removed ngx.throw_error from the documentation. 82ff13ad1 more README love. 1c1b04550 implemented ngx.utc_strtime() and ngx.time(). cbc0ca96c further renamed ngx.utc_now to ngx.utc_time, and ngx.now to ngx.strnow per Piotr's suggestion. fa9f606ce renamed ngx.time further to ngx.utc_now. 8a06613c7 documented that ngx.now() returns local time while ngx.time() returns GMT time. ad2b41ff6 renamed ngx.get_today() to ngx.today(), ngx.get_now() to ngx.now(), and ngx.get_now_ts() to ngx.time(). 9ecb1f073 minor formatting fixes in README. f901a4064 documented ngx.get_today(), ngx.get_now(), ngx.get_now_ts(), and ngx.cookie_time(t) in README. 77d344d3d implemented ngx.cookie_time(timestamp) as per Igor A. Valcov. a4b8f98d3 added a link to chaoslawful's wiki page for ngx_lua. 76507f452 minor README tweaks. b41e7dd96 removed non-GET method support in ngx.location.capture from the TODO list in README. 1b87f64b0 documented the option arg for ngx.location.capture as well as the "method" and "body" options. 0e312b7b1 checked in the tests for POST/PUT/DELETE/HEAD subreqeusts issued by ngx.location.capture. 8e9a88981 implemented the method and body options for ngx.location.capture. 539cad599 fixed a typo in README. 6bf961e22 updated TODO section. e4a02b350 now we escape all those chars escaped by FF3.5's encodeURIComponent in ngx.escape_uri. 9ea82353a style fixes. 102608046 fixed line number. 2cf4b0aa1 documented that nil args are allowed in print and ngx.log but not ngx.print nor ngx.say. 583f00758 no longer allow nil arguments in ngx.print nor ngx.say. 69dabae30 added ngx.location.capture_multi to the TODO list. ee83dbf78 now we allow use of nil in print(), ngx.log(), ngx.print(), and ngx.say(). cb4e03208 more README tweaks. fd45a1619 more README tweaks. cca047e55 more README tweaks. 1223e88e7 minor README tweaks. a88715d9f renamed "NginX" to "Nginx" in README because the former looks weird to me ;) 1de920040 improved wording a bit in README. 4383444b2 more comments on ngx.send_headers() in README. e5bd77e86 documented ngx.encode_base64 and ngx.decode_base64. b54c7568a renamed ngx.base64_encode and ngx.base64_decode to ngx.encode_base64 and ngx.decode_base64 for consistency. 47d397dd0 documented res.header where res is the retval of ngx.location.capture. 45220955a implemented the response headers support in ngx.location.capture. 435a0a3a5 documented that keys in ngx.header.HEADER will be matched case-insentively. 7af330114 added a failing test for $arg_v not defiled side-effect bug. 783dc72dd minor optimizations by specifying pre-allocated item count in lua_createtable. e126d5664 improved the error message: "content_by_lua prematurely ended" => "content_by_lua aborted". 04876fcf0 now we make print in Lua use the ngx.NOTICE log level. 3c998b20d renamed ngx.throw_error to ngx.exit. the former is now deprecated. 78667e424 updated .gitignore. ed3cda136 now we make "print" use the debug log level and the "lua print: " prefix. 1a2962311 confirmed that we work with 0.8.53. 96f6d4c60 now we cached the ndk.set_var.DIRECTIVE lua closure to eliminate config directive lookup at every call. c76f755bb eliminate allocating "hv" on the heap to reduce runtime cost. 19c9415ad now we also escape "=" in ngx.escape_uri. 9fd1a9704 now we allow ngx.throw_error(0). 0927d6439 fixed typos in error messages. 855d522e1 avoid using newlines in closure factory wrapper code to ensure the line numbers in error messages are correct. 7c8c131af documented ndk.set_var.DIRECTIVE interface. 16d947f3a checked in 018-ndk.t for ndk.set_var.xxx testing. cdc883239 added static for clarity. abd0f29d2 minor style fixes in 006-escape.t. 25284b10c now we also escape / in ngx.escape_uri. d92839afb implemented ndk.set_var.DIRECTIVE such that we can invoke directives of other nginx C modules directly from within Lua :D d954160e3 implemented and documented and tested ngx.exec to named locations. 6fc54f5ef fixed a typo in README. f33ac9d2e now we allow overriding multi-value headers. 10deafbf7 documented the multi-value header setting feature. a1a32738b implemented multi-value header setting. ce82ec28c states that ngx.exec never returns. 3811a28b8 documented how to clear a response header. 226a207df documented ngx.header.xxx, ngx.exec, and ngx.status in README. acdc74c14 implemented ngx.exec for Lua. 53abbc08d removed C++ style line comments. 0fa54cef4 more style fixes. 0eebb17ba coding style fixes. e6712e797 repeat_each(2) in 016-headers.t. da9fa90a7 checked in the test file 016-headers.t f5bac10fc implemented the ngx.header.foo API for Lua to set/add/clear response headers. cea93b2f5 implemented 'ngx.status = xxx' and 'my_var = ngx.status' on the Lua land, which is just mapped to nginx core's r->headers_out.status 7dccc5a33 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module b04fff9f8 nginx core's ngx.escape_uri does not escape the plus sign (+), we now use our patched version of this function. ff30f4436 merged marcus' modification; updated ndk depedency c6837de02 Update ndk_md5_hash() to work with updated NDK 7aff45f2a force enabling NGX_OPENSSL_MD5 to solve weird complation issues. f75abbaf8 turned off ddebug. 238c17c22 renamed 011-bugs.t to 014-bugs.t 5d0f7a8e8 tweaked kindy's patch for base64/md5_bin/get_today etc a bit. and pfree aggressively to prevent leaking 3348b1534 added: ngx.now() ngx.now_ts() ~ timestamp ngx.md5_bin(s) ngx.base64_encode(s) ngx.base64_decode(s) 0a6728d78 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module fadcc9f8b checked in t/011-bugs.t. ed8abcc51 updated config; updated dependency 4eb5d5e43 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 18297b16c fixed ngx.quote_sql_str which should put the surrounding quotes. 5a77f7ce9 removed unused readme file e3f677a14 removed skip tag for ngx_http_auth_request tests 387f4d5b2 modified build script; modified installation section of readme 712f1d15b complement the directive documents dc9797ecc removed finished job: read request body 2b134cda5 added lua_need_request_body directive to force reading request body; modified tests prefix 253a647db fixed log level signess mismatch 71c41e926 fix readme typo 20c22c2f8 fix readme fmt 1baf7b647 fix readme fmt 6073e0ea2 removed todo file, move all contents into readme 6621e4806 modified todo fmt; add issues in readme 7e808f71b fix readme fmt 5cc5897fd fix readme fmt 96e6f4020 fix readme fmt 488d871c5 fix readme fmt 288ef90b0 fix readme fmt 8e93880bc modified readme fmt d6d01dd89 format readme c78ba3d7f added markdown format readme cea679320 added new feature intro to README 403167a27 added notes to todo list 75b3362d5 * allow default path expanding in path/cpath and added tests * added revim script to automatically insert vim modeline to sources * added retab script to reexpand tabs for given files * format sources and tests 9f206095f remove ngx.log() from todo list bd5c0f471 * added ngx.log() api and prime unit-tests * restored missing vim filetype in unit-tests 1b18a2188 updated todo list eeea4fca2 Revert "xx" cee9eb63a xx eb1c7ea8d reindexed tests fd819a18b updated dependency e09ee9fd2 added ngx.get_today support 15327bb00 resolved conflict between the branches ngx_md5 and share_var. 208a5468e added tests of using ngx.md5 in set_by_lua b2ad6af08 Merge branch 'share_var' 900e35104 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 5a563ab77 Flush data from memcached during tests initialization. 604e01e32 flush testing memcached before tests begins d8bbb0d7f added testing dependency modules order notes in README 198184925 added a test of share variables in main request bfdd68b57 see nil in ngx.md5 as a null string eadf67ed5 removed explicitly testing dependencies, note them in README instead 1311727d7 added impl of ngx.log to todo list; updated dependencies 9c1b5d5b1 Remove missed skip_nginx block. eb2381c90 Don't hide the fact that this test doesn't work with nginx-0.8.42+. e1eabdcfe added a test of sharing variables 0568303bd added a test of sharing variables 361bc3acd Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 93ce856ea Disable DDEBUG and lower the number of repeats for content tests. 4c34ec535 turned off ddebug :P f796a1aea Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 112f755d9 Fix missed lua_cpath. d3525580d fixed a bug about null string in ngx.quote_sql_str 3ad40f2cf updated dependecies 2eda39777 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 52746dbfc added lua cmod path in CentOS to tests b559b6c84 added ngx.md5 support 321d63ab2 share variables in subrequest 670f1057b added more tests. 2ae707c62 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module d6497f1d2 Make it work with the build farm. c156cbd31 tags to spaces. 6075d86b1 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 1f9868185 Revert "some tabs to spaces." c149e8668 Revert "share variables in subrequest" a0ca0193f Revert "added ngx.md5 support" 5042c6e62 Revert "fixed unitialized pad and ngx_md5 return value type issues." 65e364339 fixed unitialized pad and ngx_md5 return value type issues. 88f35b179 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module f28dbe39e some tabs to spaces. 3d071fa82 added ngx.md5 ... de24252a2 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 611c8568d added ngx.md5 support dbb071344 added reported issues 5e8cf3d5d share variables in subrequest afa444855 added test of using symbol $ in inline lua 82a2d6f7c updated dependencies 30df65d82 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 048c3682d committed my merge. ad506f9df checked in more tests. a18285ba8 added ngx.quote_sql_str 324cff234 added todo lists c00573fbf fixed several problems in tests 189e56da5 * updated depdencies * added vm panic protection for content_by_lua directives * skipped not-accurate-enough test 9fea98919 enable that bug for ngx_lua. 202d948d7 updated dependencies 9566fd751 make the lua wev handler check r->done and ctx->cleanup. 547786f1c Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 00b94607f mentioned that our test suite requires th engx_auth_request module. 7832a117b resynced external dependencies b9459f1cc documented how to build this module with LuaJIT 2.0 w/o patching config. d934c912f added support for LUAJIT_LIB and LUAJIT_INC env in config. also croak when it fail to find lua/luajit when LUA_LIB or LUAJIT_LIB is set. 4d057e486 fixed more bad links due to github escaping. ffb1f4326 fixed a link due to github escaping. d353933d0 tweaked README more. df79322ab tweaked README a bit more. 26d9dc4cd claims that we are already production ready :) 9f45d4da2 splitted lines that are too long :) 5e4dc3157 added a performance section to README. c26249505 splitted long lines. a2f5cbe21 documented the Nginx Lua API that we have already supported. eb9d381a6 documented the lua_package_path and lua_package_cpath directives. 891dffa8f more ddebug info... 52d2f6cd9 fixed compatibility with nginx 0.8.36 and 0.7.66+. a146d3082 added support for lua_package_path and lua_package_cpath directives as per Piotr Sikora's suggestion. 2540acd81 fixed a compilation error in luaL_error invocations. 5b94570cc use "return luaL_error(...)" instead of "return NGX_ERROR" in lua c functions. 16627e894 implemented ngx.escape_uri and ngx.unescape_uri in both set_by_lua* and content_by_lua*. 62e9a5460 even more ngx.HTTP_XXX constants. 514befedb more ngx.HTTP_XXX constants. c09313d9e minor coding style fixes. fac21194a splitted a long long line of code. 64dd62de2 fixed an memory issue in ngx.var.foo assignment: we should copy out the pointer returned by lua_tolstring. b69e7b5e9 croak when setting non-existent nginx variables in Lua. 5ad33b74b added tests for setting nginx variables from within content_by_lua Lua code. bba0946a7 direct assignment to nginx variables from within Lua code as in "ngx.var.some_var = 32" now works :D 9abf8f208 added support for reading nginx variables directly from within set_by_lua by means of ngx.var.foo. 70467b68a turned off ddebug. a97c330a1 confirmed that we work with nginx 0.8.45. 41261ce76 emphasized that default_type is used to control the MIME-type of the response. 497f2b757 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module ea4c8b6ac tab to spaces in cache.c 2bdd9051a updated echo-nginx-module dependency 494856411 update test-nginx and ngx_devel_kit dependency 967f7dab9 repeat more times in the test suite. 6d4830396 refactored the ngx.var.xxx implementation and added a (passing) test case for content_by_lua + ngx_auth_request ef259e7ce implemented ngx.throw_error interface. 4af58bae1 more tests for require. 5cf560bc6 restored valgrind.suppress file. 993590daf better error diagnostics. 8f764bf53 more tweaks. 1d33e8946 more tweaks. 5a50cfd9a indentation fixes. fc2bba529 tab to spaces for directive.c c6701d161 backported the fix for internal redirect from ngx_echo. fef2069b7 fixed the digest calculation regression for lua loadbuffer. 98fd900d4 refactored the ngx.location.capture implementation a bit. ac2520ba4 now we rename ngx.echo to ngx.print and also introduced ngx.say that append a newline automatically like Perl 6's say 9ecff4791 refactored the ngx.echo function implementation. bbc5e44c9 massive code refactoring and cleanup. bb3e73b1b include ngx_md5.h instead of explicit openssl/md5.h. eed7de1e8 added more comments to the samples in README. 9198f867c added more samples to README. bd4d6d51a added myself to the author list :) 87209af71 fixed typo nginx version macro... ebcfcf4e1 fixed nginx version typo 221221dff * lift lua-nginx-module to the top of config modules * added conditional compilation for building under 0.7.x branch 624f83d78 updated README to claim that we require at least Lua 5.1. b363ddf08 avoid using ndk whenever possible because prototype is missing on *BSD. 84bdafdc7 fixed a memory issue in ngx.echo: we should copy the lua string bytes. 0093e9e58 updated .gitignore. e953ab595 checked in util/ngx-links to trim ngx_http_blah_blah_ prefix via symlinks. b17746e54 renamed _by.[ch] to by.[ch]. 8e09749fc added more tests 5a3078070 BIG DAY! ngx.location.capture passed the 1st test! ec489c72e tab to spaces and also checks the case when ctx is failed to allocate. 02e15406c make request handling coroutines fully separated c92a1a3ec added closure factory loading methods a58172a27 added nginx var modification hook skeleton 777c2d881 updated test-nginx dependency b0820ec2f added one more test case to 2-content.t. 41a3c3e7c fixed the merge conflicts. d39f331ff added more test cases. 741b3cca0 added -E linker options to export lua symbols correctly, for external module usage 6e2513a8a removed unused variables 595e4e142 move all dependency modules into deps/ directory ed0ab1881 added new test-nginx position 9c554bf5d changed test-nginx position dfac35bc8 modified todos 452335df0 * fixed keep-alive hanging bug when using HTTP/1.0 protocol * added more documents about content_by_lua dd9cf532e Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 61a1cbdfd add some comments e5d22ad73 fixed errors in unit-tests 12181757a make ngx.flush() working 7d5753bf5 implemented basic content handler functions: * override print() to output error log * ngx.var[] table to fetch nginx variables * ngx.echo() to output in-memory contents 68cea2ca1 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 4102502ee reconstructed nginx request passing method for set_by_lua directives f422e7525 tab to spaces in t/1-set.t. 2fbde3c9a Merge branch 'master' of github.com:chaoslawful/lua-nginx-module a6a1f9e83 declared that we are compatible with the latest nginx 0.8.40 and 0.7.66. 844bf3326 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 8fde5c1b6 removed old unit-tests db5e0e123 recovered run_test util and added missing source files 2de7148a0 updated submodule test-nginx repository revision f86b58725 various fixes. 0ef14aaf3 now we print the detailed error messages to error.log when lua_load fails. 9b3bdee1c added more files to ignore. 4f9535212 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 99e2b1418 improved util/build.sh using wget. cc7659699 * modified code format, added vim modeline * extract lua env init code into individual functions * added some unit-tests for content_by_lua directives b9d2655d2 Merge branch 'master' of github.com:chaoslawful/lua-nginx-module 94d56e379 added more tests d4b754a8b added basic tests and reindex script 97dd3cdea restored nginx tarball fetching command 3a5c8c08d added .gitignore file 766ade8a1 changed submodule name 9dbc8e8a8 changed test directory name deac6c109 changed test-nginx to submodule points to external repo c6f98fb08 changed lua state storage position; added skeleton content_by_lua* entries 38b202cc7 added unistd.h before including md5.h c990a63b7 fixes the feature test code. 9aba7a3c4 added -lm to ngx_feature_libs. 023579763 fixes the feature test code. 292ab8ab2 added support for env LUA_LIB and LUA_INC in config. 3154636c9 now we use openssl/md5.h 5e7c84bb8 removed done ones; added new ones a5b477357 added .gitignore file 315f20b6b implemented code cache and primitive vm persistence fc236d105 added todo 82619f35b added inline variable check to Lua script/file path; turn to standard Lua+Coco patch; modified log formatter char 539d5fe6a modified comment f07f1fb83 added NGX_HTTP_LUA_ELLIPSIS macro to control if args are passing to script as default arguments (accessed through ellipsis operator ...) 66d737464 modifed readme 601633b09 modified readme contents 23d495b8a * split logic into multiple files and changed config file accordingly * added readme 81f809028 prim working version d6a0d6c6a removed unused ddebug.h 924004558 init commit REVERT:11ab5315bMerge commit 'f583d996a108a58166fc986bf4227a3cea432a07' into dev REVERT:f583d996aSquashed 'src/deps/src/luajit/' changes from 492cfdd0d8..aa038d2599 REVERT:f8429d6e4Update LuaJIT to v2.1-20231021 REVERT:576cb8197Merge commit 'c473aa40807f32438ffe34bdfe07f8f0485a6aa4' into dev REVERT:c473aa408Squashed 'src/deps/src/lua-resty-openssl/' changes from b23c072a4..89195843c REVERT:456e6a33dUpdate lua-resty-openssl to v1.0.1 REVERT:11c4fde61Merge commit '805e5c9cee2a72af6b6297b2993109511b42d485' into dev REVERT:805e5c9ceSquashed 'src/deps/src/libmaxminddb/' changes from ac4d0d248..93a7e0e56 REVERT:afcf420eeUpdate libmaxminddb to v1.8.0 REVERT:7aa6affe1Merge commit 'e3f305a953ef5dbf6802090c7013f4c38d762449' into dev REVERT:e3f305a95Squashed 'src/deps/src/ngx_devel_kit/' changes from b4642d6ca..91e30eb05 REVERT:cba20187cUpdate Nginx devel kit to v0.3.3 REVERT:10a58377bFix multiple CVEs related to libpq * CVE-2023-5869 * CVE-2023-5868 * CVE-2023-5870 REVERT:7c564e4cbUpdate pre-commit hooks to latest versions REVERT:bff775f00Fix issues with the Linux integration and external databases REVERT:71db00281Merge pull request #759 from bunkerity/dependabot/github_actions/dev/ruby/setup-ruby-1.161.0 REVERT:940eecd06deps/gha: bump ruby/setup-ruby from 1.160.0 to 1.161.0 REVERT:42f7ef486Update user interface demo image in README.md REVERT:b2a56a82aUpdate BunkerWeb UI demo to use thumbnail image REVERT:0d0bad79bUpdate Python version in Dockerfiles REVERT:b539a97adFix CVE CVE-2023-5678 in Dockerfiles REVERT:05da26f01Update dependencies to latest versions REVERT:e153c33aaUpdate maxminddb and other dependencies versions REVERT:8d024a099Merge pull request #751 from bunkerity/dependabot/github_actions/dev/rickstaa/action-create-tag-1.7.1 REVERT:ca6271c60Merge pull request #750 from bunkerity/dependabot/github_actions/dev/ruby/setup-ruby-1.160.0 REVERT:fbbec2f7fdeps/gha: bump rickstaa/action-create-tag from 1.6.6 to 1.7.1 REVERT:9c6f5289ddeps/gha: bump ruby/setup-ruby from 1.159.0 to 1.160.0 REVERT:bcded8f7cAdd refurb as a pre-commit-config hook and apply pre-commit-config REVERT:966a78da9Update Git attributes to ignore text and end-of-line settings for vendored files REVERT:f111124b3Update dependencies versions REVERT:d2b82b29dFix CVEs CVE-2023-43787, CVE-2023-43785 and CVE-2023-43786 REVERT:dc5a7b8b2Update mmdb files REVERT:c32522ae2Update Certbot module to version 2.7.4 + Update python deps hashes REVERT:54ead4e49Merge pull request #744 from bunkerity/dependabot/github_actions/dev/rickstaa/action-create-tag-1.6.6 REVERT:d83536969deps/gha: bump rickstaa/action-create-tag from 1.6.4 to 1.6.6 REVERT:b79b6548bMerge pull request #741 from bunkerity/dependabot/github_actions/dev/hashicorp/setup-terraform-3.0.0 REVERT:b05b98185docs - update plugins to 1.2 REVERT:e8803e346cache linux test images, fix linux example of proxy protocol and add more logs to k8s tests REVERT:7565b2df5Merge branch 'dev' into staging REVERT:c817f45abadd ready checks to limit and redis core tests and fix wrong http port for behind reverse proxy linux test REVERT:f9f616a66Merge branch 'dev' into staging REVERT:4871185dcUpdate python deps and pin Flask-Login version REVERT:cd773b6e8add ready checks to reversecan and sessions tests REVERT:898ef2effdeps/gha: bump hashicorp/setup-terraform from 2.0.3 to 3.0.0 REVERT:fa628cb7dlinux - add default API_LISTEN_IP REVERT:18d682b5alinux - add missing API_LISTEN_IP initial setting and perform only hot reload REVERT:4fbd974d2tests - set trace verbosity for geckodriver logs REVERT:a7c343369Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:7d69b9105tests - fix missing geckodriver log file in ui tests REVERT:29d7d94b2[#739] Fix potential issue when fetching docker instances in the web UI REVERT:84eb94720tests - add geckodriver log file for ui tests REVERT:40e118a71tests - add more logs to ui linux tests REVERT:0e3d8e59ctests - retry UI access in case of network exception REVERT:86875f486tests - fix misc ready check when using https and add ready checks for linux ui REVERT:d4a2ba5fctests - add ready checks to customcert and misc REVERT:3020c5c8etests - add ready check for customcert core test REVERT:c1562bc89Merge pull request #737 from bunkerity/dependabot/github_actions/dev/github/codeql-action-2.22.5 REVERT:322cfd217deps/gha: bump github/codeql-action from 2.22.4 to 2.22.5 REVERT:caf732be1Merge pull request #736 from bunkerity/dependabot/github_actions/dev/ruby/setup-ruby-1.159.0 REVERT:667620b52deps/gha: bump ruby/setup-ruby from 1.158.0 to 1.159.0 REVERT:fb21786b8linux - fixing nginx service not disabled and fix another missing error log path in UI REVERT:5887b894fui - fix wrong error path when starting nginx REVERT:4e820f6delinux - remove sudo command when reloading nginx REVERT:35d16233cci/cd - ignore ready conf for db tests and fix linux path for ready conf REVERT:9775cd5bbci/cd - fix missing string in /ready endpoint and add /ready endpoint to linux tests REVERT:274a8cdfbci/cd - trying to fix race condition for core tests REVERT:d73a5d0f4Merge pull request #735 from bunkerity/dev REVERT:ed0e156bcUpdate Werkzeug to version 3.0.1 in web UI REVERT:8ec9a7df4Fix compatibility issue with Docker Compose v2 2.23.0 in examples and docs REVERT:72d856abeUpdate certbot to version 2.7.3 + regenerate hashes for db and scheduler REVERT:ab76c458eMerge pull request #732 from bunkerity/dependabot/github_actions/dev/ruby/setup-ruby-1.158.0 REVERT:6edf97a0ddeps/gha: bump ruby/setup-ruby from 1.157.0 to 1.158.0 REVERT:58d6b8142use cap in Linux and add openssf badge REVERT:a83a74cfaMerge pull request #729 from bunkerity/dev REVERT:0975de123[#717] Add a pool_recycle database engine arg to avoid losing connection with database REVERT:762092e5eRemove no longer necessary retrying module REVERT:8963cb4d1Update python deps REVERT:c2252503dMerge pull request #721 from bunkerity/dependabot/github_actions/dev/ossf/scorecard-action-2.3.1 REVERT:626f10b4cMerge pull request #722 from bunkerity/dependabot/github_actions/dev/actions/setup-node-4.0.0 REVERT:f2b9fc0f8Merge pull request #724 from bunkerity/dependabot/docker/src/autoconf/dev/python-a5d1738 REVERT:c8eae49e5deps/autoconf: bump python from `dc2e889` to `a5d1738` in /src/autoconf REVERT:ab320794aMerge pull request #723 from bunkerity/dependabot/docker/src/ui/dev/python-a5d1738 REVERT:572436f20Merge pull request #720 from bunkerity/dependabot/docker/src/scheduler/dev/python-a5d1738 REVERT:6f366450bdeps/ui: bump python from `dc2e889` to `a5d1738` in /src/ui REVERT:f6d2e205cdeps/scheduler: bump python in /src/scheduler REVERT:50a60382aFix CVE CVE-2023-5363 REVERT:989c14ae7Fix CVE CVE-2023-5363 REVERT:a847f7778deps/gha: bump actions/setup-node from 3.8.1 to 4.0.0 REVERT:8708ad70cdeps/gha: bump ossf/scorecard-action from 2.3.0 to 2.3.1 REVERT:eeda7a18cUpdate python deps + add retrying module to db REVERT:5193d6cd1Update docker images REVERT:09ee05083Merge pull request #719 from bunkerity/dependabot/github_actions/dev/ruby/setup-ruby-1.157.0 REVERT:0afed0621Merge pull request #718 from bunkerity/dependabot/github_actions/dev/github/codeql-action-2.22.4 REVERT:8919592f5deps/gha: bump ruby/setup-ruby from 1.156.0 to 1.157.0 REVERT:d253b4438deps/gha: bump github/codeql-action from 2.22.3 to 2.22.4 REVERT:f798a9ef9Merge pull request #715 from bunkerity/dev REVERT:cd902eba3prepare for 1.5.3 🚀 REVERT:029217ff4Fix update-version.sh script REVERT:10db67b87Merge pull request #714 from bunkerity/dev REVERT:c7543df86Add an handler when the ui test is reaching an error page due to a connectionFailure REVERT:1f5a1beac[#645] Fix web UI not keeping the data when changing the sub server names + Fix custom cert when the server name have multiple domains REVERT:ff1fc9280[#712] Fix custom configuration changes not taking effect immediately REVERT:838dcb17cMerge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:b18dbddcdMerge pull request #713 from bunkerity/dependabot/pip/src/scheduler/dev/certbot-2.7.2 REVERT:ca6938dfeUpdate ConfigFiles to use the correct name regex in web UI REVERT:643ea7c21deps/scheduler: bump certbot from 2.7.1 to 2.7.2 in /src/scheduler REVERT:e41ce10e3Merge pull request #711 from bunkerity/dev REVERT:b265cbad5ci/cd - trying to fix azure/kubectl action REVERT:7e3aad9f0[#645] Fix impossible to edit the server_name of an already existing service if the primary one was unchanged in web UI REVERT:60d43d0ceHandle service creation and editing more elegantly in web UI REVERT:2df85b2c9Updated python:3.12.0-alpine image's sha256 REVERT:3a3255e7bMerge pull request #709 from bunkerity/staging REVERT:4c273fe84Merge pull request #708 from bunkerity/dev REVERT:9964f42e6Fix magento k8s tests REVERT:b2cf8986fTweak magento tests to use latest version back REVERT:7f219bea0Fix CHANGELOG release date for v1.5.2 REVERT:b9f05ad16Downgrade magento versions to working ones REVERT:bd6065af8Update python deps and pin urllib3 version to 1.26.18 + Update pre-commit-config to format requirements.in files as well + Apply pre-commit REVERT:619e5644fRemove pip caching when setting up python in workflows to avoid errors REVERT:3c3643021Merge pull request #707 from bunkerity/dev REVERT:7598dbc54Update python deps REVERT:f3982367aUpdate dependabot script to add reviewers and tweak the schedule REVERT:d4f65903eUpdate dependabot config file to include terraform and other python deps paths REVERT:38429efacMerge pull request #705 from bunkerity/dependabot/github_actions/dev/actions/checkout-4.1.1 REVERT:d92e9a07aFix k8s terraform script REVERT:6738b9552deps/gha: bump actions/checkout from 4.1.0 to 4.1.1 REVERT:0da22f44bUpdate k8s terraform file and update scaleway terraform version REVERT:d77f6a72cFix README.md links and versions REVERT:7bf8be324Try to fix magento k8s tests with static versioning REVERT:b9c5d3277Fix timeout in ui tests and access_page function REVERT:b1b1ab868Fix wrong values in helm chart values file for elasticsearch in k8s magento example REVERT:530b8a945Fix allow empty values when saving a config in web UI REVERT:22552c5b8[#694] Optimize certbot renew script to renew all domains in one command REVERT:db0dd5dae[#694] Fix rare bug where database is locked REVERT:f89456cd4Merge pull request #699 from Crazy3lf/master REVERT:34d68e8b7Update regex for email REVERT:476d86706Fix magento k8s tests by removing elasticsearch REVERT:4a10ec8c3Merge pull request #701 from bunkerity/dev REVERT:c4b873e3fFix /etc/bunkerweb dir missing in linux core tests REVERT:bcaa8faa7Replace deprecated `set-output` command with the new format REVERT:08944b901Tweak test-core-linux to fix potential bugs REVERT:13be6a43cAdd more logs when an url file is in cache and gets deleted REVERT:2737fe7ceUpdate python deps REVERT:2823fa2abUpdate plugin.json REVERT:001246b38Merge pull request #697 from bunkerity/ui REVERT:1a43380d2Merge pull request #696 from bunkerity/dependabot/github_actions/dev/github/codeql-action-2.22.3 REVERT:0b319d1aaMerge pull request #695 from bunkerity/dependabot/github_actions/dev/rickstaa/action-create-tag-1.6.4 REVERT:7a15f8a65deps/gha: bump github/codeql-action from 2.22.1 to 2.22.3 REVERT:a4a413eecdeps/gha: bump rickstaa/action-create-tag from 1.6.3 to 1.6.4 REVERT:7e3dabc5fUpdate patch commands in deps.json to skip Reversed warning REVERT:29737209bSquashed 'src/deps/src/luajit/' changes from e598aeb74..492cfdd0d REVERT:8093c6161Merge commit '29737209b138a1485d55c53acf1a6783b6e60167' into dev REVERT:85913d6b2Update luajit to v2.1-20231006 REVERT:15d3180b6move disabled inp msg REVERT:522527f0aMerge pull request #690 from bunkerity/dependabot/github_actions/dev/ruby/setup-ruby-1.156.0 REVERT:85ef4e4deMerge pull request #691 from bunkerity/dev REVERT:46d8acf7bUpdate dummy-plugin to new standards REVERT:77bfe2697Add StyLua and luacheck to precommit config file and apply it REVERT:da2a1eaa5deps/gha: bump ruby/setup-ruby from 1.155.0 to 1.156.0 REVERT:cd1f87b9aUpdate pre-commit config hooks version REVERT:e25fab28bfix disabled msg behavior REVERT:c125a9bddMerge pull request #689 from bunkerity/dev REVERT:10fd431fbTweak update python deps script to make it more elegant REVERT:309689185Update pythons deps REVERT:799756176Merge pull request #684 from bunkerity/dependabot/github_actions/dev/github/codeql-action-2.22.1 REVERT:a12e5ca89Merge pull request #683 from bunkerity/dependabot/github_actions/dev/stefanzweifel/git-auto-commit-action-5.0.0 REVERT:15ad3a625Merge pull request #681 from bunkerity/dependabot/github_actions/dev/ossf/scorecard-action-2.3.0 REVERT:c57d725f4Merge pull request #680 from bunkerity/dependabot/github_actions/dev/ruby/setup-ruby-1.155.0 REVERT:95389260aMerge pull request #688 from bunkerity/dev REVERT:6e5dd5557Fix CVE CVE-2023-44487 REVERT:565f4e3f7Merge pull request #687 from bunkerity/dev REVERT:f39adcab5Update CHANGELOG.md REVERT:a3ec85b57Fix often occurring error with ace script in web ui REVERT:b063ac8a3[#652] Fix error when deleting a service that have custom configs on web UI REVERT:ff85f1c2bUpdate CHANGELOG.md REVERT:4a9fdba42[#645] Fix errors when using a server name with multiple values in web UI REVERT:47a7e1680Fix secure_scheme_headers shenanigans with web ui REVERT:453108da9Update mmdb files REVERT:2cbb10b3aRevert "Test Aqua security vulnerabilities with BW" REVERT:d4d9f8745Test Aqua security vulnerabilities with BW REVERT:899484c38deps/gha: bump github/codeql-action from 2.21.9 to 2.22.1 REVERT:d461f3745deps/gha: bump stefanzweifel/git-auto-commit-action from 4.16.0 to 5.0.0 REVERT:cd0ceb48bdeps/gha: bump ossf/scorecard-action from 2.2.0 to 2.3.0 REVERT:dc92ae825deps/gha: bump ruby/setup-ruby from 1.154.0 to 1.155.0 REVERT:f5fe685d4Fix children classes of Test REVERT:f4ce2c68fFix bw api not returning the reason of bans REVERT:d1a0f66c9Merge pull request #677 from bunkerity/dev REVERT:6935d1cb8Merge pull request #676 from bunkerity/dev REVERT:7ac66a6c6Update python deps REVERT:2aa9f46efFix default values in whitelist job REVERT:8f456722eAugment delay in WebDriverWait in ui tests REVERT:8ae7b8f43Fix redirect tests docker-compose file REVERT:9b4a9277dAdd libpq as a dependency for the Database to be able to connect with postgres REVERT:172874d1cFix redirect tests on docker REVERT:a518f47b9Update CHANGELOG.md REVERT:0cee41867[#656] Fix ACME renewal fails on redirection enabled Service REVERT:e956e03baMerge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:c08fd07a6Update linguist-vendored to add modsecurity files and non patch deps files REVERT:466c8e584Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:27d3ca1cdautoconf - fix wrong types for dynamic settings REVERT:410557009Add .gitattributes to override linguist-vendored paths REVERT:e7498279cRevert Docker image update for tests REVERT:fe87486f9Merge pull request #673 from bunkerity/dev REVERT:c2db157bbUpdate python docker image to 3.12.0 REVERT:eb8088164Tweak Dockerfiles to make the build nicer REVERT:202698f41Fix python deps conflicts and update them REVERT:0eb18cb31Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:f12a01410autoconf - update settings from db REVERT:628068e9aLint files with prettier REVERT:f3694f0ccAdd prettier as a precommit hook REVERT:b56cce63fFix codespell typos in README.md REVERT:87ca17663Fix typos raised by codespell REVERT:eea5dd9b7Add codespell precommit hook REVERT:8fbe69261Fix mkdocs.yml file duplicate copyright key REVERT:cf82e73e9Fix swarm postgres ui integration example REVERT:6b2df3585Tweak py file to respect flake8 rules REVERT:508c728b6Tweak pre-commit config and pyproject.toml file + Add flake8 as linter in precommit config REVERT:75e8c8339Update CHANGELOG.md REVERT:07676a3d0Use hashes instead of versions in github workflows REVERT:f0761eed2Revert "Add fuzzing tests in CI/CD" REVERT:4babce974Add fuzzing tests in CI/CD REVERT:a263f1f4fUpdate cron for dev-update-mmdb REVERT:31a839968Merge pull request #666 from bunkerity/dev REVERT:d8b256167Merge pull request #665 from bunkerity/dev REVERT:87d2f04ebRemove no longer necessary temp fix for Flask-login REVERT:c006e5088Update python deps + Update Flask-Login to include the compatibility with Flask 3.0.0 REVERT:df9bf1f56Merge pull request #664 from bunkerity/dev REVERT:6b0e623e5Update Dockerfiles to install pip and its deps before the project ones REVERT:85068bfeeAdd temp fix to support Werkzeug>=3.0.0 with Flask-login REVERT:5a7f9147fUpdate python deps and update script REVERT:358905770Fix bunkerweb-ui.sh script with variables not being exported correctly REVERT:5ed595be6Fix shellcheck tests failing REVERT:e21e0c812Add shellcheck and gitleaks to pre-commit-config + tweak excluded paths REVERT:1b7e1840cFix blacklist core tests' requirements.txt file REVERT:1f90d3668Add a pre-commit-config file and passed all checks REVERT:f3fc69110Fix typos in Dockerfile when installing python dependencies REVERT:073e8575eUpdated Dockerfile, python deps and npm package to use pinned dependencies REVERT:cd4d529d7Merge pull request #660 from bunkerity/dev REVERT:b4a320afaMade ui tests better REVERT:8ed656068Small fixes on linux paths creating unnecessary folders REVERT:8fa7adb61Small refactor on how the autoconf updates the config REVERT:4ec754143Handle changes more elegantly with the scheduler REVERT:0f7df13dfOptimize save_config script REVERT:48096d711Optimize the way the UI handles services creation and edition REVERT:c0816bb11Fix potential cross-site scripting vulnerability in plugins.js in the UI REVERT:18e5f7bffMerge pull request #659 from bunkerity/dev REVERT:ece5ce1cdAdd HTML sanitization when injecting code in pages in the UI REVERT:4d5002674Extract codeQL workflow to have a separate one + Add scorecards analysis workflow file + Add UI tests for the UI branch REVERT:1c71572f4Update tsparticles in the UI + remove unused static files REVERT:685cb9809Update README to fix a few links and add the security scorecard badge REVERT:65d0aa3a8Merge pull request #658 from bunkerity/dev REVERT:6e2db5991Add a sleep before changing from cache page to log page to avoid errors in ui tests REVERT:1db769c32Remove bugged UI tests check in linux REVERT:db99d1687Update the condition that checks the integration in core tests REVERT:579c80357Update UI starting script and ui tests script on linux REVERT:b901d2971Update python deps REVERT:e23f931bdReplace gevent with gthread in UI for security reasons REVERT:15eef6ef5Try to fix python deps issues with linux and try to have more logs in linux ui tests REVERT:cc0167f42Fix ui linux tests when waiting for the ui to be ready REVERT:fd4c147b8Update how the scripts wait for the UI to get ready before starting the tests REVERT:95afba879Change how the ui tests waits for the ui to be ready REVERT:ea5cb0db2Try to fix ui linux test by adding more sleeps REVERT:cb3250e4eFix UI linux test (again) REVERT:153e9fecfFix bunkerweb linux scripts REVERT:81b5e80daTry to fix deps permissions with linux ui tests (again) REVERT:6a162d725Fix linux permissions with ui tests REVERT:be5fe2830Try to fix ui python deps in ui linux tests REVERT:380e609abChange ui linux tests command into development mode REVERT:93006cf5cFix Firefox installation in core and ui linux tests REVERT:39f17bce6Try to fix permission issues with Linux and ui python deps REVERT:94c7c832eFix permissions with python deps in ui linux tests REVERT:42be334e4Fix permissions with ui tests on linux REVERT:cad3012e6Try to fix python dependencies error with test ui linux REVERT:a04282d3fFix test core redis with linux REVERT:c757f5d49Re generate requirements.txt file for the UI with python3.9 REVERT:052e06022Fix core and ui workflow file for staging tests REVERT:e71b71146Merge pull request #655 from bunkerity/dev REVERT:b90da0f90Add better health check in linux ui tests REVERT:5c1fafe51Updated CHANGELOG.md REVERT:c964d68f9Add more tries when the dnsbl server isn't found REVERT:78a29e65eTweak reversescan core test to avoid false negative REVERT:0e9f29cc5Revert "Fix UI shenanigans with python deps" REVERT:70ab9740dFix UI shenanigans with python deps REVERT:0303a8f7bUpdate staging workflow file to include core and ui linux tests REVERT:16d4c1133Optimize the way errors are being checked in linux core tests REVERT:2ddc8cec7Update dnsbl list regex to accept an empty one REVERT:6534a429aFix looking for error in the wrong place in test code linux REVERT:25eb8de01Try to fix a few shenanigans with linux core tests REVERT:2065d688fFix ui tests with docker checking the wrong containers if healthy REVERT:87f84d438Add a retry on nginx error in linux core tests REVERT:99b30af8eFix reverse scan python script REVERT:1ff2aed68Fix UI docker tests docker compose file REVERT:48bcb1198Rearrange imports for blacklist init core test REVERT:ae9450d0dAdd whitelist and greylist linux core tests REVERT:9a17e92d6Fix typos in dnsbl core test REVERT:2244f734fAdd dnsbl linux test REVERT:a29ac80e4Add country linux tests REVERT:cff5c7767Fix sessions core test for linux REVERT:6ae6764f2Fix blacklist core tests docker compose REVERT:27959e1aaFix sessions permissions issues with python requirements REVERT:47e8f20f8Fix CVE CVE-2023-38039 REVERT:6283ce2ddAdd linux tests for blacklist and bunkernet REVERT:f3d6f860eRemove old cached files if urls are empty REVERT:61c8ef73bFix permission issues with sessions core test with linux REVERT:be25ae8e0Fix failing linux core tests + add more logs when an error occur in ui tests REVERT:33e200f65Fix UI using the wrong database when generating the new config REVERT:57374ecc2Fix tests ui with linux REVERT:601f0fde6Fix tests ui linux not starting the ui service REVERT:fdb9a7c29Fix errors linux tests permission issues REVERT:df1205882Fix tests ui linux executing the wrong file REVERT:db404a62cFix ui tests misconfiguration REVERT:a0aced3e5Fix tests ui linux workflow file REVERT:e378be9a9Fix typo in tests ui linux file name + add more logs in ui docker tests REVERT:432d1587cAdd linux ui tests REVERT:2ad886178Fix selfsigned job with cryptography not being found REVERT:da4390b48Fix python modules version conflict with web ui REVERT:7bd48203aFix and update python deps REVERT:ce2fa3d36Fix a few core tests for linux REVERT:bca36e296Update self-signed job to regenerate the cert if the subject or the date has changed REVERT:06da40bf1Added more linux core tests REVERT:84a27a3fcFix DB core test with docker REVERT:9e3425182Fix path issues with db core test init REVERT:c90cd7399Fix permission issues in tests core linux REVERT:91e5528a3Fix already existing tests core linux REVERT:aeee38ad3Fix misc problems related to linux REVERT:d97326656Fix Database not clearing old services when not using multisite REVERT:8a6e14d8cAdded linux tests to a few core plugins REVERT:0ece8fda0Fix permission issues when starting BunkerWeb in antibot linux tests REVERT:e93513224ci/cd Try to fix permission problems with Firefox in test core linux REVERT:761c01af6ci/cd Fix test core linux shenanigans with Firefox REVERT:0d9349611ci/cd Try to fix errors with firefox in test core linux REVERT:094d5d5dfci/cd Fix a few things with test core linux + finish antibot linux core tests REVERT:fdae4549cci/cd Fix permission issues (again) with test core linux REVERT:d59cf1835ci/cd fix permissions issue in test core linux + fix shenanigans with antibot linux core tests REVERT:43b1a038fci/cd clear out firefox before reinstalling it in test core linux REVERT:d192fbb82ci/cd Install Firefox manually in test core linux REVERT:0239ca64bci/cd test core linux remove dns resolvers override REVERT:1dd1caeeaci/cd Fix Firefox installation for test core linux REVERT:a0516f773ci/cd Install firefox from apt instead of snap + fix antibot core tests for linux REVERT:480c680f1ci/cd Fix timeout in geckodriver download for test core linux REVERT:a94dab208ci/cd fix retry job when downloading the geckodriver in test core linux REVERT:d0a1aab15ci/cd Fix perms issues (again) and optimize some things in test core linux REVERT:dd0c4c93aci/cd Install requirements and deps in test core linux REVERT:294402dbfci/cd fix perms issues with test core linux REVERT:cd35d35c2ci/cd Fix perms in variables.env for test core linux REVERT:4cce8385cci/cd fix write in /etc/hosts file in test core linux REVERT:990b6336eci/cd Fix test core linux with dpkg versioning REVERT:ccc5eb304ci/cd Fix version error with ubuntu and test core linux REVERT:6a3839040ci/cd Fix tee command not being ran as sudo in tests core linux REVERT:453cfc2dcci/cd Fix BunkerWeb installation job with linux core tests REVERT:0b14f8a5dci/cd Fix install command in linux core tests REVERT:624f4b5bbci/cd Fix path of the .deb file REVERT:61bc8a3b1ci/cd fix .deb fetching in Linux core tests REVERT:fa91bf6c6ci/cd change needs and logic in test core linux REVERT:b54c7eb61ci/cd test secret inherit for ubuntu private test image REVERT:30cba0a77ci/cd fix dev.yml REVERT:80d56fccaci/cd start working on linux core tests REVERT:69307fba6Fix issues with GitHub rejecting the requests REVERT:7c5177bf4[#643] Fix UI clearing configs folder at startup REVERT:b5bd17d4dMerge pull request #641 from bunkerity/dev REVERT:ad65e01a8Update CHANGELOG.md REVERT:1259fb67dMerge pull request #634 from bunkerity/dependabot/github_actions/dev/docker/setup-buildx-action-3 REVERT:b9e752f12Merge pull request #636 from bunkerity/dependabot/github_actions/dev/docker/login-action-3 REVERT:278eb0c8aMerge pull request #635 from bunkerity/dependabot/github_actions/dev/docker/build-push-action-5 REVERT:dec97c8c3Merge pull request #637 from bunkerity/dependabot/github_actions/dev/docker/metadata-action-5 REVERT:9222420b7[#640] Fix shenanigans when executing docker compose restart REVERT:07fb7cf16[#638] When renaming a service in the UI, migrate the custom configurations as well REVERT:f83b2278dFix versions conflict between greenlet and gevent with UI REVERT:e51e17835Update python deps REVERT:3c95971e3Fix CVE CVE-2023-4863 REVERT:bb7ef35aeMerge commit '35d13d7a097dd094cdbe993f18f29de0b08f1f2b' into dev REVERT:35d13d7a0Squashed 'src/deps/src/zlib/' changes from 04f42ceca..09155eaa2 REVERT:d96253878Merge commit '4430cf47ddc1f3647b3bc129f46fed2d7a145f8c' into dev REVERT:4430cf47dSquashed 'src/deps/src/luasec/' changes from fddde111f..4c0628705 REVERT:37a2343e2Merge commit 'd8ee65aa70e9737330c8a83301fd66c7dc8a8d7a' into dev REVERT:d8ee65aa7Squashed 'src/deps/src/lua-resty-session/' changes from 8b5f8752f..5f2aed616 REVERT:6752b3647Merge commit 'd7bde18da2a8a81f2d5f256bc975b1fb5b546107' into dev REVERT:d7bde18daSquashed 'src/deps/src/lua-ffi-zlib/' changes from 1fb69ca50..61e95cb43 REVERT:af902fc4eMerge commit 'e0a89a2fcd1d0dd4cc103fc054242e8e8b10b7bf' into dev REVERT:e0a89a2fcSquashed 'src/deps/src/modsecurity/' changes from 205dac0e8..ccc2d9b53 REVERT:5ec7eb53aSquashed 'src/deps/src/luajit/' changes from 04f33ff0..e598aeb7 REVERT:26d3d6c6cMerge commit '5ec7eb53a1fa30beb59d3358f16716483787b02e' into dev REVERT:0aaede4d6Update core deps REVERT:955c7e063deps/gha: bump docker/metadata-action from 4 to 5 REVERT:8ea823e06deps/gha: bump docker/login-action from 2 to 3 REVERT:a6efa5205deps/gha: bump docker/build-push-action from 4 to 5 REVERT:a6b30f6a6deps/gha: bump docker/setup-buildx-action from 2 to 3 REVERT:1144a7381make logs optional in issues, change assignee for dependabot and edit sitemap URL of the doc REVERT:c364e4666ci/cd - disable redirect when pushing doc REVERT:d4f38cc79ci/cd - fix error when parsing ARM types REVERT:b6d49865bci/cd - get ARM type availability REVERT:d0a8cc381ci/cd - use volume id instead of index for arm instance REVERT:30c952e9eci/cd - set boot volume for arm instance REVERT:2382fdd37ci/cd - start arm server after creation REVERT:05ecf558cci/cd - use latest scw cli version REVERT:2b7ce389bci/cd - reflect changes on release tf from refactoring REVERT:d5d7364b1Merge pull request #632 from bunkerity/dev REVERT:3adbd8757[#628] Fix scheduler generating the wrong configuration with Linux REVERT:fd7950863Merge pull request #631 from bunkerity/dev REVERT:3ae9636d5Fix error with the CSP header override of the antibot REVERT:f99349900Merge pull request #630 from bunkerity/dev REVERT:ea6ae5253Update ANTIBOT_HCAPTCHA_SECRET setting's regex to support new format REVERT:5811dc549Merge pull request #629 from bunkerity/dev REVERT:6404b701cUpdate changelog REVERT:2b5654ba3Update coreruleset to version 3.3.5 REVERT:c948e449a[#622] Handle configs dir more nicely in Linux REVERT:fb5a8dc4f[#622] Fix permissions with folders in linux integrations REVERT:5f19b3fdaMerge pull request #627 from bunkerity/dev REVERT:2fce08b72Upgrade issue templates REVERT:2ed6584ddUpdate python deps hashes REVERT:d6a14b671Merge pull request #626 from bunkerity/dev REVERT:b3c398cb5Remove jinja2 from requirements.txt as it creates conflicts REVERT:6334a3d63Merge pull request #623 from bunkerity/dev REVERT:8ab4ea2e2Update id of ui.conf rules to avoid conflicts REVERT:11664cc1dFix wrong variable name in limit core tests REVERT:9535c0414Fix shinanigans with both multiple and global settings not being stored correctly in datastore REVERT:8cafded89Fix variables that are both multiple and multisite not being stored properly in datastore REVERT:c6b2199ddprepare for 1.5.2 🚀 REVERT:c418acdcfUpdate CHANGELOG.md REVERT:9d0d72ba0[#576] Add support for ModSecurity JSON LogFormat REVERT:cbc625938Update mmdb files REVERT:f57fc5d3fFix menu.html dark_mode attribute in UI REVERT:c7e834a0dUpdate python deps REVERT:673ee921fLint files REVERT:9fb8dfca4Fix Scheduler running two times for no reason REVERT:4787400d7[#615] Fix BunkerWeb not being able to start after a restart because of the /var/run/bunkerweb directory missing in Linux REVERT:f59476c26Merge pull request #621 from bunkerity/dev REVERT:4be53d0cbMerge pull request #620 from bunkerity/ui REVERT:55ba29cd5Fix UI error when values are empty REVERT:947690af8Fix UI workflow REVERT:5cdf0ecf4Merge pull request #619 from bunkerity/ui REVERT:d1dd1fbaeFix shinanigans with the /data volume in the doc REVERT:1b84c6202[#613] Fix logs with web-ui and Linux REVERT:a2e0f1fe6Merge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:639eed8d0Deactivate BunkerNet on first start with linux REVERT:500c3564aci/cd - perform staging tests again REVERT:448efc0efMerge branch 'staging' into dev REVERT:1b660691dci/cd - fix typos for docker/packages pushes REVERT:e62b7c9d1Remove unused js files in web-ui REVERT:b87316d7cMerge pull request #617 from bunkerity/ui REVERT:4cff39f49Merge pull request #616 from bunkerity/dev REVERT:bceb28602Lint files REVERT:d9d6ed9bbFix settings regex with web-ui REVERT:01be5baeaMerge pull request #611 from bunkerity/dev REVERT:059afec43Update rhel docker image REVERT:e564d8407Merge pull request #610 from bunkerity/dev REVERT:2c15b3746Fix rhel typos "el" instead of "rhel" REVERT:6f26c42c8Merge pull request #609 from bunkerity/dev REVERT:c5059ab22Update doc to include TLS as well as HTTPS in some sections REVERT:a7a317b5bMerge pull request #487 from bunkerity/dependabot/github_actions/dev/scaleway/action-scw-c718eca1fcb9fec1fb1433752d61599c6a0ad2e9 REVERT:0681cf2c9Update actions/checkout to v4 REVERT:3a02c0ca5Add more delays in badbehavior core test REVERT:040d44714Change SQLite config to avoid locking REVERT:07725356bMerge branch 'staging' into dev REVERT:6a995723cautoconf - fix changes check bug with same variable name REVERT:47bf7299aLint py files REVERT:656c5008dscheduler - ignore changes on first loop REVERT:c206daf9dadd basic config lock between autoconf and scheduler + remove reverse-proxy tests for linux REVERT:cf55ade15ci/cd - various fixes for k8s tests REVERT:d28432e5fFix API_SERVER_NAME regex REVERT:b5638aae1ci/cd - move k8s login in staging-tests job REVERT:4450762b8ci/cd - fix image name in k8s tests REVERT:6e1660cd0autoconf - fix wrong config update REVERT:cb4c99f45ci/cd - fix docker tag command for linux tests REVERT:64d2ed91eci/cd - fix secret key REVERT:0e2420cffci/cd - add timeout for cleanup jobs REVERT:fa165522eci/cd - use same md for openssl commands REVERT:b03680388ci/cd - remove double untar for k8s tests REVERT:bae27806bci/cd - fix tf state upload/download again REVERT:11794da8cci/cd - fix tf artefact command REVERT:c52e54b81ci/cd - fix tf files again REVERT:e5c37a00aci/cd - fix k8s tf REVERT:9a3c26bf6Merge branch 'dev' into staging REVERT:56422bca4Update python deps regex for UI REVERT:ee47407dfMerge pull request #606 from bunkerity/dev REVERT:936b1e88fRemove old CVE fixes for nginx image REVERT:f9f5b6570Remove old CVE fixes for python images REVERT:8e8e042c2Testing CVE on bw REVERT:1676ebeb7Test CVE on autoconf REVERT:637573e59Update docker images and python deps REVERT:c3a4847deUpdate startup and temp env in bash files REVERT:3db7904d4ci/cd - fix wrong image tag for Linux test images REVERT:037e1ba56docs - add ghcr.io REVERT:d6aa6a9b0ci/cd - staging improvements REVERT:9aba00673Fix oddities with the scheduler and the Database REVERT:f7d9af9d6Fix potential infinite loop when waiting for a configuration from the autoconf REVERT:95c796c1eci/cd - delete temp compose downgrade REVERT:423e3b4a3ci/cd - log to ghcr before getting tests containers REVERT:511597b7eci/cd - fix tests image names REVERT:bb77dcedfci/cd - edit username for ghcr auth REVERT:3d0f17808ci/cd - add dummy username for ghcr auth REVERT:5a9836fecci/cd - fix nested permissions REVERT:e1edfe4a7ci/cd - fix missing permissions in wf REVERT:e81ab4ff9Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:87b405340ci/cd - use gh cache for docker cache and pushes to ghcr.io REVERT:45a81203eUpdate python deps REVERT:9feb66710autoconf - force updating first configuration REVERT:3d13cf345autoconf - only update data when needed and atomic changed metadata update REVERT:00cb6c1a8tests - fix regex for geckodriver version REVERT:898ee7ec8tests - tweak dpkg before installing BW REVERT:643b30f99tests - ignore wrong testing version in deb packages REVERT:69e944d56Revert "Fix LinuxTest package installation commands" REVERT:2b7f627d8Merge pull request #602 from bunkerity/dev REVERT:82fb7b277Fix LinuxTest package installation commands REVERT:1042e546bMerge pull request #601 from bunkerity/dev REVERT:6d1d464e1Remove tries limit in wget commands (defaulting to 20 tries) REVERT:b5de52eadAdd more retries when testing the newly created service in ui tests REVERT:267522749Merge pull request #599 from bunkerity/dev REVERT:4f82856b4Update staging-create-infra to use a static version for monolithprojects.github_actions_runner == 1.18.1 REVERT:d670b409bMerge pull request #486 from bunkerity/dependabot/github_actions/dev/docker/build-push-action-4 REVERT:0b93916a3Merge branch 'dev' into dependabot/github_actions/dev/docker/build-push-action-4 REVERT:76408cf04Merge pull request #598 from bunkerity/dev REVERT:f7cd7d9daAdd dependency on tests-ui to not fail to push the testing image REVERT:8632dd324Fix exit code for ui tests REVERT:fbf0232d5Update python deps REVERT:5b6f00dfcRevert "Remove unused imports in ui tests" REVERT:681def5f0Remove unused imports in ui tests REVERT:a844b235bRemove geckodriver.log REVERT:73e31ca62Add wget to fix error with tests REVERT:d82136f04Fix UI tests not exiting if container fails to start REVERT:55fd17790Fix wget command when downloading the geckodriver sometimes fails REVERT:d8c95869eFix database with multisite variables REVERT:f24802b21ci/cd - perform staging tests again REVERT:758fc13c3ci/cd - replace version string for testing release REVERT:cd825cd34ci/cd - fix wrong VERSION path for testing release REVERT:c03b1bb20ci/cd - update VERSION file for testing release REVERT:a5e50d0f7ci/cd - fix linux package name for staging REVERT:1a57e0a20ci/cd - remove linux arm64 packages pushes REVERT:de568f335ci/cd - temp disable staging tests REVERT:244b91247ci/cd - fix syntax error in push-github wf REVERT:08ce31bb0ci/cd - prepare for testing releases REVERT:7f47ac18cFix plugins errors when reloading with a select and upgrade check REVERT:b6b87fcb0Update python deps REVERT:8bada2a02Update update-version script and bw version in after-remove scripts REVERT:b8778de08use nightly tag for docker-socket-proxy REVERT:b42b732d7Merge branch 'staging' into dev REVERT:fc1c81ce2linux - add python3 dev dependency when building packages REVERT:76d36f3b9v1.5.1 release REVERT:63355bb88tests - increase radarr delay (again) REVERT:0ecf47876Merge pull request #592 from bunkerity/staging REVERT:59dfb728fFix DNS_RESOLVERS regex to be more open REVERT:47c560dd3Merge pull request #591 from bunkerity/dev REVERT:ff1e6cc28k8s - use same namespace as ingress for services REVERT:81c2c3187Fix config synchronization in scheduler + Remove MULTISITE variables being fetched when MULTISITE is set to no REVERT:7f3f3ac7eAdd delay to radarr automatic tests REVERT:58d69ec20Merge pull request #590 from bunkerity/dev REVERT:012bc3b43Merge pull request #589 from bunkerity/staging REVERT:600ea7e16Update python deps REVERT:18ee15971lint python files REVERT:eee26b5d7tests - add delay for reverse-proxy-singlesite REVERT:c00157ef3fix wrong instances when using docker mode and add delay to docker-configs tests REVERT:6047a4335set default value for ports in bw entrypoint, fix core db tests and fix missing PYTHONPATH for certbot job REVERT:ee2aeda13tests - add static delay for linux tests and fix core db tests REVERT:bb6fd3073linux - force kill nginx if graceful one doesn't work REVERT:6e6c08a71ui - various edits REVERT:5df2a74caimproved LE certificates checks and fix missing full SERVER_NAME when MULTISITE=no REVERT:843c02370tests - fix wrong command in linux tests REVERT:8f7833413linux - fix letsencryt not working and fix permissions on /etc/bunkerweb/configs for tests REVERT:0ccd75781linux - add missing pip to rhel REVERT:adbed77f7linux - install pip the official way REVERT:ef7a6ac42linux - fix fedora dockerfile REVERT:31ca183b1Merge branch 'dev' into staging REVERT:a763879c1doc - update settings REVERT:03ba91e96autoconf - fix deadlock with k8s REVERT:38ab5ea21redirect - custom status code REVERT:ee5397df5bw - add HTTP and HTTPS port to temp config REVERT:9efd7a5a5sessions - fix infinite loop when session checks fail REVERT:784ce643fdb - disable connection pooling for one shot tasks REVERT:f3081e3c3scheduler - fix parent setter call REVERT:26a1ef689Update mmdb files REVERT:e2fe947cbci/cd - fix tests UI not showing logs REVERT:bf9cd367dfix missing Strict-Transport-Policy header, fix X-Forwarded-Prefix with regex URLs and print logs when UI tests failed REVERT:26f2852e5scheduler - fix typo in fstring REVERT:e93b2f65fcache dev container images, fix CVE-2023-35945 and force scheduler to reload when instances change REVERT:f3ba16be9add instances changes check to scheduler and auto push dev container images REVERT:d9394567eadd missing ctx arg in core plugins, always add X-Forwarded-Prefix header and add doc about timezone in containers REVERT:d59b305f1fix concepts image in doc, revert clientcache update and refactor headers REVERT:ad45bbb4dUpdate python deps and fix error with PyYAML compilation REVERT:db03aa9c7Merge pull request #565 from bunkerity/dev REVERT:bb14be820Update python deps updater REVERT:bedcf0c17Fix bug with newer version of PyYAML by downgrading REVERT:68e9b057dMerge pull request #564 from bunkerity/dev REVERT:810340a49[#559] Fix typos for custom-cert's settings in docs and examples REVERT:a4db7c294Fix CVE CVE-2023-2975 REVERT:758901dfcFix CVE CVE-2023-2975 REVERT:9216becb5Update python deps REVERT:db413cc03Merge pull request #555 from bunkerity/dev REVERT:a4f4dfe4eremove unused imports in save_config.py REVERT:0d554a5f5Update SERVER_NAME regex to be more open REVERT:c11b44285Merge pull request #554 from bunkerity/dev REVERT:25af02e4aFIx prevent the `DATABASE_URI` setting from being saved inside the database REVERT:9eec9e26c[#552] Fix scheduler not changing databases on linux REVERT:845364b2bUpdate log paths for linux based integrations REVERT:3dac0aef0tests - temp fix for compose network errors REVERT:08f9e5f20Fix bad behavior core tests by adding a custom subnet to the bw-docker network REVERT:fccb25beeAdd automatic bw-docker network removal between each try REVERT:d6407b818Fix db core tests by making the network bw-docker entirely external REVERT:1cf281ef8Update core tests to be even more verbose REVERT:3a714b9a3Update core tests to be more verbose REVERT:864619542Fix core db tests (again) REVERT:be46f7a8dOptimize db core tests REVERT:559039dfdLint .conf files that contains lua code + remove useless comments REVERT:aa0769ddeMerge pull request #549 from bunkerity/dev REVERT:ae6ccfcffApply patch to luajit-geoip REVERT:ed234fd63Apply post_install script to lua-resty-openssl REVERT:09ae6da55Apply patch to lua-resty-ipmatcher REVERT:b516ca2eaApply patch to lua-ffi-zlib REVERT:1e7f92af8Apply patches to Modsecurity-nginx REVERT:008dc09a6Stop checking return code of post_install scripts in init_deps.sh REVERT:fcd230192Fix init_deps.sh REVERT:f3809bc69Add -R to pull commands in init_deps.sh REVERT:96586d4a6Apply post_install script to Modsecurity REVERT:a75b90f52Squashed 'src/deps/src/modsecurity/' changes from bbccedbdd..205dac0e8 REVERT:948182ffdMerge commit 'a75b90f525b90bd74c090702034e02fdd6250e0e' into dev REVERT:544b4040eAdd post_install scripts to init_deps.sh and update install.sh REVERT:6e146e2a5Squashed 'src/deps/src/modsecurity/' changes from 205dac0e8..bbccedbdd REVERT:847ff5a3dMerge commit '6e146e2a54cb29eb0ac1bc9d65766fe90d30fa4f' into dev REVERT:bbccedbddChange tags into hashes in deps.json REVERT:14d69fa59Update mmdb files REVERT:d5e358b72Merge pull request #548 from bunkerity/dev REVERT:e0055328aFix add missing deps for core db tests REVERT:c93d5a2fcFix CVE CVE-2023-3316 REVERT:5631e2737Merge pull request #547 from bunkerity/subtrees REVERT:3505c0d18Remove clone.sh file REVERT:7b566b885Squashed 'src/deps/src/zlib/' content from commit 04f42ceca REVERT:ffd310031Merge commit '7b566b885e99301b243c5f61360e65238035e048' as 'src/deps/src/zlib' REVERT:45dca7b44Merge commit '2ab324a69f219b4051b2e77d211ee1a7fb1462b5' as 'src/deps/src/stream-lua-nginx-module' REVERT:2ab324a69Squashed 'src/deps/src/stream-lua-nginx-module/' content from commit 309198abf REVERT:f85f86e46Merge commit 'c1073460677ba8aa2e325a1c57c3db1458f9fde5' as 'src/deps/src/luasocket' REVERT:c10734606Squashed 'src/deps/src/luasocket/' content from commit 95b7efa9d REVERT:a7d4cc5bbSquashed 'src/deps/src/luasec/' content from commit fddde111f REVERT:bd600e0d0Merge commit 'a7d4cc5bbaabf8683b3b5cc1f42f9bd145cf1aa8' as 'src/deps/src/luasec' REVERT:d15662693Merge commit '2d86912af87048b94c2921a60b3a8a5a0953e132' as 'src/deps/src/lualogging' REVERT:2d86912afSquashed 'src/deps/src/lualogging/' content from commit 465c99478 REVERT:1fb404757Merge commit 'f3ceeb73a958e774b1e2fa55d2607cdd3eb419ca' as 'src/deps/src/luajit-geoip' REVERT:f3ceeb73aSquashed 'src/deps/src/luajit-geoip/' content from commit fde33e045 REVERT:f81788c00Merge commit '2678b91586e9183b47327fbb0f11ad23020f195f' as 'src/deps/src/lua-resty-upload' REVERT:2678b9158Squashed 'src/deps/src/lua-resty-upload/' content from commit 03704aee4 REVERT:2d06f2d7aMerge commit 'bc06cd71b8896c6e7a1aac4610c9c3f878956238' as 'src/deps/src/lua-resty-template' REVERT:bc06cd71bSquashed 'src/deps/src/lua-resty-template/' content from commit c08c6bc9e REVERT:a6379356eMerge commit '3038a0b027f09090e1cd8f101d2ee8c52c383070' as 'src/deps/src/lua-resty-string' REVERT:3038a0b02Squashed 'src/deps/src/lua-resty-string/' content from commit b192878f6 REVERT:fdf0050a9Merge commit 'ee5198ba2810e33e08ff987ede5abe10fc74f6e3' as 'src/deps/src/lua-resty-signal' REVERT:ee5198ba2Squashed 'src/deps/src/lua-resty-signal/' content from commit d07163e8c REVERT:a3cd342f3Squashed 'src/deps/src/lua-resty-session/' content from commit 8b5f8752f REVERT:6f8ff3f12Merge commit 'a3cd342f3e1fffd7b16b83a24e03bb9ed501b319' as 'src/deps/src/lua-resty-session' REVERT:2f1cde097Merge commit 'eca8662cfe981f66ab92b53bbf83af65da02b2b7' as 'src/deps/src/lua-resty-redis' REVERT:eca8662cfSquashed 'src/deps/src/lua-resty-redis/' content from commit d7c25f1b3 REVERT:0b94df087Merge commit 'e59161ec204c7a95e4751b1c0e9a6bead7fcab39' as 'src/deps/src/lua-resty-random' REVERT:e59161ec2Squashed 'src/deps/src/lua-resty-random/' content from commit 17b604f7f REVERT:a28005988Squashed 'src/deps/src/lua-resty-openssl/' content from commit b23c072a4 REVERT:38fdd39d0Merge commit 'a2800598825bb5a03b577cca2874ff1cfae863f4' as 'src/deps/src/lua-resty-openssl' REVERT:c2fa53ca1Merge commit '31bf774f63b8b46a3c7b53028853036fff6fa0b8' as 'src/deps/src/lua-resty-mlcache' REVERT:31bf774f6Squashed 'src/deps/src/lua-resty-mlcache/' content from commit f140f5666 REVERT:7b2273aebMerge commit 'c82b0bdd27762d2d4a9901a187506d2e5abd74f5' as 'src/deps/src/lua-resty-lrucache' REVERT:c82b0bdd2Squashed 'src/deps/src/lua-resty-lrucache/' content from commit a79615ec9 REVERT:3dc8cc87cMerge commit '746a6e16d027ab3bddfc610c987e5d61ab9b69d0' as 'src/deps/src/lua-resty-lock' REVERT:746a6e16dSquashed 'src/deps/src/lua-resty-lock/' content from commit 9dc550e56 REVERT:62e740a0bMerge commit '19515d9b26f2f4886ca117b91384509087f0ff3a' as 'src/deps/src/lua-resty-ipmatcher' REVERT:19515d9b2Squashed 'src/deps/src/lua-resty-ipmatcher/' content from commit 7fbb618f7 REVERT:e566b98afMerge commit '7160fd94e3dc22299ee3c9f8b0e71a5e2c1bb501' as 'src/deps/src/lua-resty-http' REVERT:7160fd94eSquashed 'src/deps/src/lua-resty-http/' content from commit 4ab4269cf REVERT:cdd42bf25Merge commit '1a7d4e58be28238599df3f5c15c56380c3e99732' as 'src/deps/src/lua-resty-env' REVERT:1a7d4e58bSquashed 'src/deps/src/lua-resty-env/' content from commit adb294def REVERT:49db9c24dMerge commit '0f4a0cb0ef514bee6b810f6d6cf982c5ef0abfca' as 'src/deps/src/lua-resty-dns' REVERT:0f4a0cb0eSquashed 'src/deps/src/lua-resty-dns/' content from commit 869d2fbb0 REVERT:fe76b6830Merge commit 'fd02afef8ec1ceb8a816dc202d05c6ece9887d31' as 'src/deps/src/lua-resty-core' REVERT:fd02afef8Squashed 'src/deps/src/lua-resty-core/' content from commit 31fae862a REVERT:29d135bdbMerge commit '36023392a6e3c8fb6aebb46140db759e61da220e' as 'src/deps/src/lua-nginx-module' REVERT:36023392aSquashed 'src/deps/src/lua-nginx-module/' content from commit c47084b5d REVERT:b01aa0b15Merge commit '32485e2860c2ea31fcef5b575f446c7a3036a550' as 'src/deps/src/lua-gd' REVERT:32485e286Squashed 'src/deps/src/lua-gd/' content from commit 2ce8e478a REVERT:c46cd666aSquashed 'src/deps/src/lua-ffi-zlib/' content from commit 1fb69ca50 REVERT:909841ea6Merge commit 'c46cd666ab76bad7bd05c6261d692cda5b380f32' as 'src/deps/src/lua-ffi-zlib' REVERT:47ee3884fMerge commit '4f9b885a2e8b7a10653653fee3bb91cf5102b0ef' as 'src/deps/src/lua-cjson' REVERT:4f9b885a2Squashed 'src/deps/src/lua-cjson/' content from commit 881accc8f REVERT:bb450ac96Squashed 'src/deps/src/libmaxminddb/' content from commit ac4d0d248 REVERT:e13868c63Merge commit 'bb450ac96595432625ac34de8f7f42b3d06a5b30' as 'src/deps/src/libmaxminddb' REVERT:772e05d37Merge commit '4a7228d2dcb7fe62526016b90a7c497fb6531e76' as 'src/deps/src/libinjection' REVERT:4a7228d2dSquashed 'src/deps/src/libinjection/' content from commit 49904c42a REVERT:209d4a461Merge commit 'ae8d8b233d52cbfdee68bd3ba21713149f5659c8' as 'src/deps/src/lbase64' REVERT:ae8d8b233Squashed 'src/deps/src/lbase64/' content from commit c261320ed REVERT:992710650Merge commit '1d1739b4eaa274c25c52b8ceb79ebdc717633ec0' as 'src/deps/src/headers-more-nginx-module' REVERT:1d1739b4eSquashed 'src/deps/src/headers-more-nginx-module/' content from commit bea1be3bb REVERT:e43880b08Squashed 'src/deps/src/ngx_devel_kit/' content from commit b4642d6ca REVERT:a09d5eb2cMerge commit 'e43880b08395df25663560da3d8154226a167a77' as 'src/deps/src/ngx_devel_kit' REVERT:8973eb029Merge commit '26773844e7bd57df1216bd74360a62ec2dc976e3' as 'src/deps/src/nginx_cookie_flag_module' REVERT:26773844eSquashed 'src/deps/src/nginx_cookie_flag_module/' content from commit 4e48acf13 REVERT:79d1b4459Merge commit '22e69251d9b5cd2611abf77ef7352abfa4d409d7' as 'src/deps/src/ngx_brotli' REVERT:22e69251dSquashed 'src/deps/src/ngx_brotli/' content from commit 6e975bcb0 REVERT:4cd57ab8fMerge commit 'b99663928782619ef854b4bf10a2bf7450d75266' as 'src/deps/src/nginx' REVERT:b99663928Squashed 'src/deps/src/nginx/' content from commit 84cd72177 REVERT:d7f25398aMerge commit 'a676d333fda890838d8fc4766720cc3f1d4c5389' as 'src/deps/src/modsecurity-nginx' REVERT:a676d333fSquashed 'src/deps/src/modsecurity-nginx/' content from commit d59e4ad12 REVERT:7e8f4adc3Squashed 'src/deps/src/modsecurity/' content from commit 205dac0e8 REVERT:999fb6b8eMerge commit '7e8f4adc3b2b2a655640c73198fb920a5e8441d5' as 'src/deps/src/modsecurity' REVERT:6c0468f62Squashed 'src/deps/src/luajit/' content from commit 04f33ff0 REVERT:6d05b14ebMerge commit '6c0468f62b1120497a6fd0d21101dc41f29e7397' as 'src/deps/src/luajit' REVERT:1141afd20Fix install.sh for nginx dynamic modules REVERT:97406bff4Add libinjection deps back REVERT:a58ad9b50Remove duplicate lua-ffi-zlib in deps REVERT:831ae129cMake init_deps.sh executable REVERT:451648fa7Remove old deps temporarily except lua REVERT:185d75076Update how the deps are initialized REVERT:6a048e68fUpdate how the deps are managed REVERT:129e8f7e0Merge pull request #546 from bunkerity/dev REVERT:265123835Update python deps REVERT:b0bc9a1bfUpdate the documentation REVERT:2f7ed064fdocs - Fix typo in webhook link in plugins.md REVERT:7d6116163Merge pull request #544 from bunkerity/dev REVERT:deed39a1fUpdate lua-resty-openssl to version 0.8.23 REVERT:dd295729bAdd deps project submodules REVERT:b27f38349Update lua-resty-session to version 4.0.4 and remove lua-pack deps as it's no longer needed REVERT:aeca252d9Bump lua-resty-core version to 0.1.27 and lua-nginx-module version to 0.10.25 REVERT:1ec21261cRevert "Init work with submodules" REVERT:718a9305dRevert "Fix .gitmodules file" REVERT:a253f4a59Revert "Remove old folders that are now submodules" REVERT:2e1e9a08cRevert "Initialize submodules" REVERT:e2f1aba3cRevert "Add other projects to submodules" REVERT:d9a98c6faRevert "Update commit SHA for submodule libinjection" REVERT:5ed3ba1d5Revert "Fix path resolution for modules and remove nginx submodule" REVERT:b529d8525Revert "Update checkout part of workflow to include submodules" REVERT:43783edb9Revert "Add nginx as a submodule" REVERT:8417ed132Add nginx as a submodule REVERT:ded0ec66dMerge pull request #542 from bunkerity/dev REVERT:6cbbd0d56Update timeout for wordpress tests to 120 seconds REVERT:d687b228eFix PERMISSIONS_POLICY authorizing self and links to be aside without spaces REVERT:bcc9fdef9[#533] Fix SERVER_NAME regex to limit domains' size individually instead of the whole setting's value REVERT:524a140d2[#534] [#504] Update ALLOWED_METHODS regex to accept more methods REVERT:a197e20d2[#531] Fix typo in documentation about SSL REVERT:252a5831bMerge pull request #541 from bunkerity/dev REVERT:07ed136afUpdate setup-kubernetes of wordpress example REVERT:2eb73d15aMerge pull request #537 from bunkerity/dev REVERT:30fec8a14Remove python submodule, will add it back in the next major REVERT:4b4e0f8b3Update checkout part of workflow to include submodules REVERT:c2cfd4dd9Remove checkout from dev.yml REVERT:642da402bFix dev workflow REVERT:4bb6d40a5Update dev workflow to checkout the code and submodules first REVERT:3bcdd9ca2Merge pull request #536 from bunkerity/submodules REVERT:28d59221bFix path resolution for modules and remove nginx submodule REVERT:c8e25bcdeUpdate commit SHA for submodule libinjection REVERT:e1a5782a3Update how the dependencies are being cleaned up REVERT:68bea47edAdd other projects to submodules REVERT:2cd5c7f45Initialize submodules REVERT:d7d3e2429Remove old folders that are now submodules REVERT:a74727891Fix .gitmodules file REVERT:b5fffc1f3Init work with submodules REVERT:8c4c99e65Merge pull request #530 from bunkerity/dev REVERT:ddc337394Update log location for nginx and letsencrypt REVERT:1c362d078Remove the deletion of let's encrypt lib and log folders after the job is finished REVERT:95c9bad8eRemove unused enums in database model REVERT:7a972274fAdd database schema to concepts.md in the docs REVERT:561499536Revert "Update README.md links to use local branch files" REVERT:4536e328eUpdate README.md links to use local branch files REVERT:89070cfb7Merge pull request #529 from bunkerity/ui REVERT:d6942a46eUpdate where the scheduler copies its config REVERT:8a98da898Merge pull request #528 from bunkerity/ui REVERT:26f831cb4Merge branch 'dev' into ui REVERT:81f3914fcMerge pull request #527 from bunkerity/dev REVERT:162198bb9Update db core tests to ignore the added value for env custom configs REVERT:7a524b43eRevert back to 30 seconds of sleep in tests ui after creating a custom config REVERT:b007916d6Optimize the scheduler and gen even more (we love threads) REVERT:0661916ffUpdate ui tests to wait more after creating a custom config REVERT:2105dc0f3Update core db tests to use the right hash for plugins_page files REVERT:823119821Fix rare error when hashing dictionaries in the scheduler REVERT:1e62626acFix KeyError in scheduler REVERT:57eaedd8eMerge pull request #526 from bunkerity/dev REVERT:4d984f623Update CHANGELOG REVERT:d0fd6884cFix shinanigans with the custom configs and plugins jobs REVERT:8e6de2bdfAugment authelia timeout REVERT:3565dd7b3Update CHANGELOG.md REVERT:145df1df4Merge pull request #525 from bunkerity/dev REVERT:df1359e87Add possibility to download lists and plugins from a file path + Update python deps + Plugins now support tar and tar.gz as well REVERT:b756b2d7dLint py files REVERT:f57b6dad1fix cursor gap on ace editor REVERT:91c33f1d4Merge branch 'dev' into ui REVERT:ed2a54d16Merge pull request #524 from bunkerity/dev REVERT:3e871efedUpdate python deps REVERT:d27edab35Merge pull request #523 from bunkerity/dev REVERT:9982ec36dRemove useless import REVERT:80033642cAdd reverse proxy headers back REVERT:0836d4ee9Merge pull request #522 from bunkerity/dev REVERT:2a2b7b6f5Merge pull request #521 from bunkerity/staging REVERT:78236abe8Check Aqua Security REVERT:c5ff63a40Fix CVE CVE-2023-3138 REVERT:78ef5c482Fix problems when creating custom configs or plugins and removing them completely REVERT:2c190ee96add writeable /var/run/bunkerweb directory to hardened example REVERT:94867d0d6letsencrypt - use same job name when retrieving data from db REVERT:9e00b9dd1letsencrypt - use same job_name for both new and renew jobs REVERT:9adb209a8lua - fix missing multisite variables in LRU REVERT:fdd3367a6Merge branch 'staging' of github.com:bunkerity/bunkerweb into staging REVERT:dcf156135prepare for 1.5.1 🚀 REVERT:4023e6dc6road to v1.5.1 REVERT:af9e125c8linux - merge change for debian packager REVERT:ab6025ec9linux - fix missing zope modules REVERT:7e221eb89debian working REVERT:f1435f231Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:b14dba775bw - fix multiple variables not loaded in LUA REVERT:81bb9ede1Removing python 3.11 from linux REVERT:7e66c577fRemoving python 3.11 in linux REVERT:236572f58ui - remove python 3.11 import for Linux integrations REVERT:73060e42aFix limit core tests REVERT:df0c03cefFix UI wrong import REVERT:5d7ef69c9Update limit core tests to avoid false negative REVERT:855ae8936Update limit core tests to avoid false positive REVERT:16a1916dbRemove useless imports in lua code + lint REVERT:605e237fdRemove 404 from Bad behavior status codes REVERT:fc8d76f33Rollback on hcaptcha passive feature REVERT:c08e8d151Update settings.md REVERT:44097cad0Move the COEP, COOP and CORP headers to Cors plugin and change default values REVERT:3446e5f9bUpgrade antibot to add a custom CSP on each pages + update plugins order REVERT:70f227febFix error with multisite variables when requesting default server REVERT:f81b0bb4dFix multisite variables not being added in helpers REVERT:978697500Fix has_variable method of utils REVERT:5b0b183a4Remove no longer needed decode for plugin order from datastore REVERT:a2759e377Add small tweaks on the datastore REVERT:b6d879257Fix how we fetch plugins_order in the default server REVERT:94964a910Update how we handle custom configs REVERT:6a1ff499cFix Lets'encrypt plugin api and internal API REVERT:179a7aa34Fix lua sessions with antibot REVERT:a1385fe9bfix ctx usage in reverse proxy + remove useless log in limit REVERT:23f9f14a4Remove old CVEs fixes from Dockerfile REVERT:f77150bc2Test Aqua Security CVEs REVERT:ec48e6601Fix return value when no plugins have been found in api.lua REVERT:6ab48d9ddUpdate python image to tag 3.11.4-alpine REVERT:ce24a0482apply changes to current core REVERT:02d940393perf - ctx caching and per worker LRU for readonly variables REVERT:a7069bd60Update UI to stop using env variables but werkzeug middleware + Send X-Forwarded-Prefix headers to UI service REVERT:c39dd78aeUpdate cors plugin tests REVERT:3b459b0e2Fix shinanigans with API (again) REVERT:718310312Fix shinanigans with the API REVERT:5deeacc3dFix letsencrypt jobs REVERT:c18f743d4Fix PosixPath in jobs REVERT:85a53278eAdd a charset to cors Content-Type header REVERT:e01c14f11Add Cross-Origin-*-Policy headers management and default values REVERT:0b3c1a8a0Update KEEP_UPSTREAM_HEADERS setting's default value REVERT:95f673c1dUpdate doc about headers REVERT:cee7672b5Update settings.md in the doc REVERT:d5ea95da9Increase load-balancer example test timeout REVERT:39e6821a4Lint lua code REVERT:64aa12b70Update python deps REVERT:c392a0b5fUpdate mmdb files REVERT:f93dd34f6Extend KEEP_UPSTREAM_HEADERS setting to clientcache and reverseproxy core plugins REVERT:a23d189d3Merge pull request #516 from bunkerity/dev REVERT:df47ba0e9Merge pull request #515 from bunkerity/dev REVERT:0ca7de1deAdd CVEs fixes back REVERT:84fcfb726Test Aqua Security 2 REVERT:c20bd05d3Test Aqua Security REVERT:c85a4183dFix Strict-Transport-Security not being sent REVERT:654172f43Update headers core plugin lua code REVERT:afe6da4cfAutomatically add Content-Security-Policy header to response headers in the UI REVERT:5c7cd38b5Edit headers core plugins to use lua Code + Add new setting KEEP_UPSTREAM_HEADERS REVERT:299a0b5c2Remove apk update at beginning of each Dockerfile REVERT:6cc20efe7Update bad behavior test BAD_BEHAVIOR_COUNT_TIME to 30 seconds REVERT:e2a3bfb10Bad behavior core tests change the ban time to 60 seconds REVERT:4bbddf797Merge pull request #509 from bunkerity/dev REVERT:1eeefead9Core tests sleep between each request REVERT:9829ef752Update UI to automatically set SCRIPT_NAME and ABSOLUTE_URI REVERT:b27958a19Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:410a64810core - patch modsec to use access phase instead of preaccess REVERT:f7d986d6aChange the way linux starts and the scheduler REVERT:95d4f0f87Small tweaks on core jobs REVERT:4f324231dFix tmp variables path (again) REVERT:dc18f9884Edit start.sh REVERT:3b36965f4Fix tmp_variables_path in scheduler REVERT:ccc051e78Fix /var/run/bunkerweb in fpm args REVERT:8b2517cdfRemove ui cache download test - to much unstable REVERT:d1138855eFix gunicorn config for Docker and Linux REVERT:0c8bc97faFix UI on Linux not using the right user REVERT:a68fb0c06Refactor to make more sens and avoid specific errors REVERT:fff21746aCorrecting: Dockerfile-ubuntu End of statement block Jinja REVERT:3ab4a59b6Update debian Dockerfiles to avoid updating apt packages only once REVERT:760ec3b3bAdd /var/run/bunkerweb removal script when uninstalling BunkerWeb REVERT:be459d240Update pid files paths to /var/run/bunkerweb REVERT:8b697d87dFix Scheduler errors with the internal apis REVERT:89a3c8b0bUpdate bunkerweb-ui file according to the new gunicorn usage REVERT:5e237d0d0Update gunicorn to use a config file as well + Fix headers error + Small fixes REVERT:a424d59b1Add apk update at the beginning of each Dockerfile REVERT:1d14db7e1Update custom cert job to not duplicate certs if the cert is global REVERT:7efb82a7eUpdate python deps REVERT:e920cba43Fix CVE CVE-2023-2650 REVERT:413b75b04Fix customcert plugin to accept multisite certs as well REVERT:87a9545d9Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:c53394845various fixes REVERT:aca0d6da4Small refactor on the ApiCaller and the Scheduler REVERT:1bd40a877Removing vmware support in doc REVERT:612333d2aMerge pull request #508 from bunkerity/dev REVERT:474ecbb41Fix typo in phases list in plugin.lua REVERT:5fa21b3c8Fix CVE CVE-2023-29491 REVERT:16a459bf7Lint antibot html files REVERT:fd06a1e71Add Turnstile antibot REVERT:d5e64320cFix small typo in misc.lua REVERT:4d6d95037Merge pull request #507 from bunkerity/dev REVERT:b60657e21Merge pull request #506 from gin-gitaxias/patch-3 REVERT:1f2c973a3Fix docker-compose file for custom cert job REVERT:b314f4349Update integrations to add LOG_LEVEL=warning env variable to docker proxy REVERT:0edfb2db3Update example to add a LOG_LEVEL=warning to the docker proxy REVERT:83413aef2Remove open ports from core tests docker compose files REVERT:334be4346Fix custom-cert core plugin REVERT:953128be6Update scheduler changes check to reduce CPU usage REVERT:bb7dcda48Refactor paths resolutions for core plugins REVERT:108827952whitelist - remove unused IPs of duckduckgo crawler REVERT:665b110c6[#504] Fix ALLOWED_METHODS regex REVERT:5a2aa20bcUpdate plugins.md REVERT:168dfc439Refactor paths resolutions for UI + optimizations on the plugin upload REVERT:6e80c7b8dFix variable being ignored instead of saved inside the database when the value is empty REVERT:8dad7a0b7Starting work on paths resolution refactor REVERT:b5a78c3aaTest Acqua Security vulns (2) REVERT:ed6bee69cTest Acqua Security vulns REVERT:3dba058b4Fix custom configs not being cleared out once created REVERT:d9b093dabFix plugin example in documentation REVERT:162f1d978Merge pull request #502 from bunkerity/ui REVERT:1f2fa95e7Remove useless line in the head.html file + lint HTML files REVERT:1cd356781Add multiple plugin upload in one compressed folder support for the UI REVERT:29673f918fix font REVERT:180493616Fix CVE CVE-2023-1999 REVERT:7fe7a997fMerge pull request #501 from bunkerity/ui REVERT:5b75894d4Fix UI latest version checking & Fix conditions in quick settings for services REVERT:1f6b3d59aMerge pull request #500 from bunkerity/dev REVERT:548630e3eUpdate python deps REVERT:aa299f085Update plugin update and add to get only the necessary keys REVERT:f0126b6d6Fix update-check job REVERT:8585007bcdeps/gha: bump scaleway/action-scw REVERT:a7535c300docs - fix yt preview in readme REVERT:340b4a492change arm server flavor REVERT:e7ea3952bui - add missing dep for docker/x86 REVERT:a586b5b6bdeps/gha: bump docker/build-push-action from 3 to 4 REVERT:3b7d8b6c1Merge branch 'staging' into dev REVERT:6666a25fcedit version, update images on docs and fix bug in Linux script REVERT:f84af3402Add error ignoring when using the rmtree function REVERT:0b082bdabAdd handling of stderr being None in the scheduler REVERT:1f2b550f6ci/cd - fix swarm examples and init work on release workflow REVERT:d5fcc6969Merge branch 'dev' into staging REVERT:eda275589Merge pull request #485 from bunkerity/dev REVERT:7506768c4Merge branch 'ui' into dev REVERT:be3d40f18Fix CLIENT_CACHE_CONTROL setting's regex to also work with JS REVERT:41059fb28Merge pull request #484 from Hado-K3n/patch-16 REVERT:88f85b282Merge branch 'dev' into patch-16 REVERT:e5e031b6bMerge pull request #483 from Hado-K3n/patch-15 REVERT:2dbadbd29Merge pull request #482 from Hado-K3n/patch-14 REVERT:95c7b5410Merge pull request #481 from Hado-K3n/patch-13 REVERT:00739a5abMerge pull request #480 from Hado-K3n/patch-12 REVERT:a9f4be475Merge pull request #479 from Hado-K3n/patch-11 REVERT:f85f73678Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:f1efe06e9ci/cd - fix /opt/actions-runner perms for self-hosted runners REVERT:ad71be460login now use local font REVERT:dcb800d2bUpdate k8s.postgres.ui.yml REVERT:5a7f7f3c6Update k8s.postgres.yml REVERT:e1f60127eUpdate k8s.postgres.ui.yml REVERT:7553ffb63fix client_cache_control regex REVERT:9324648f2Update k8s.mysql.yml REVERT:eafe006a6Update k8s.mysql.ui.yml REVERT:62a8ec975Update k8s.mysql.ui.yml REVERT:dfcaba9adMerge pull request #478 from bunkerity/dev REVERT:737b999cdSet CLIENT_CACHE_CONTROL setting's regex REVERT:9339af44cMerge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:78f7570e1core - Fix bwcli condition when checking bans REVERT:40e30ed44use shared redis connection pool in cachestore when we can REVERT:d6ca98ed1Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:10a4cefd0update lua-resty-openssl deps and replace nginx -s calls with signals REVERT:97723185bcore - Add bwcli tests REVERT:ab3b3ea8fui-tests - update waiting time after creating a custom conf REVERT:5adec84d5fix redis not contacted in subsequent phases and reflect changes on stream configs REVERT:1624c4e76Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:eea6d32cdshare common objects during the phase and add threading to DNSBL and reverse scan REVERT:99f8f69faMerge pull request #477 from bunkerity/ui REVERT:9b58b397cFix ui tests (again) REVERT:ace88d865Fix plugins fetching for the UI REVERT:69b35636eFix UI tests (once again) REVERT:5dfe35b7bUpdate how the plugins are being fetched by the UI REVERT:b75690fdfChange the way python deps are installed REVERT:b19ebbe6aMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:c0c646aaeMerge pull request #476 from bunkerity/dev REVERT:edd6e2dedimproved session management and add IP/UA checks REVERT:c7ca5a822Fix Database overriding services_settings if a global_value is set REVERT:e1883a04bMerge pull request #475 from bunkerity/dev REVERT:af19cc226core - Add redis tests REVERT:0087ae583Update python deps REVERT:8133c134ecore - Fix db tests by removing "order" key check REVERT:f725d0fe6Update keys name in datastore REVERT:05c478e83Edit COOKIE_FLAGS regex REVERT:b5aaf6266add forward reverse DNS to whitelist, disable redis in cachestore when sockets are not enabled, fix typo in cachestore and improve dns/rdns caching REVERT:8a8dd6fb7db - remove order from plugin model REVERT:93c766e56Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:179beea4dimproved core plugin execution order REVERT:1d126e1d0core - fix cors tests with the preflight request REVERT:dbb884099core - Update allowed_methods test method to GET REVERT:62cb85453core - Remove cert verification when testing allowed methods in misc tests REVERT:04919e8a0Fix multiple CVEs REVERT:b32f31891Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:4962f786bfix wrong env parsing in init phase, bypass modsec/crs when method is not allowed, refactor ALLOWED_METHODS and improve error page management REVERT:10bdf551acore - Add misc tests REVERT:7158e7e9acore - Optimize cors tests REVERT:3f51f59bcAdd check when plugins are configured + Add Semaphore to accelerate jobs execution + Code optimization REVERT:4c4fa44fbci/cd - fix core/cors tests REVERT:84d43c84dMerge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:b58798746Update mmdb download to check the checksum at start REVERT:a9be973d5use PCRE regex instead of LUA pattern and edit cors doc REVERT:4378f18ccfix typo in bunkernet.lua, add missing Origin header in cors tests and fix allow origin expected value REVERT:7d84e03a1fix header plugin phase not called for internal request (fixes CORS), fix bunkernet init_worker bug where ngx.ctx.bw is not available, add CORS_DENY_REQUEST setting and edit values for core/cors tests REVERT:838662141Lint Lua code REVERT:36fdec105core - fix sessions tests REVERT:ab54b18e0core - fix reverse scan cache retrieval REVERT:9c6ca6a86cors - various improvements REVERT:991f7ff8dFix tests core reverse scan wasn't using the image REVERT:9c77f77faFix test core DB REVERT:9ee74aef4Add up back when retrying to up the stack + remove useless print REVERT:7bf4c11bcWhen docker up fails in core tests retry one time REVERT:82aadfa38Update core db tests to add the settings.json file and optimizations REVERT:2a78d2c05ci/cd - perform all core tests even if one failed REVERT:e3fc55be9deps - add missing hash for python dep async-timeout REVERT:5f668aecaci/cd - fix syntax error in test core wf REVERT:e5e336c4fMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:9a2e37984ci/cd core tests and antibot refactoring REVERT:2ac77ee49Fix deps not being synced REVERT:394f5fe4bMove back to images in the whitelist tests REVERT:b06210bdfRemove unused files in tests core REVERT:e6bb9fb55Add tests for core plugins REVERT:29f020f15Update python deps REVERT:051923b6ffix deprecated external network in compose files, various fixes in the documentation and add ipv6 to doc REVERT:2e1296d9ashow useful info in BW logs after startup/reload and reduce container images size REVERT:a686562f1performance - cache empty rdns results REVERT:e36c743c7performance - cache dns responses REVERT:75f3d6490init IPv6 support, add missing healthcheck script in UI and purge local cache on init REVERT:a258612e4add global data on settings filter REVERT:bc3ea0ed3change select method check REVERT:ab71c484eadd global condition for disabled state REVERT:5c415afa1various fixes - ttl on /bans api, dnsbl undercover bug, greylist, whitelist and wrong path in realip job REVERT:5c50f57f1Revert "regular inp and multiple global=true are enabled" REVERT:9ceaaa874regular inp and multiple global=true are enabled REVERT:3dde3ac0aFix no longer save SERVER_NAME when MULTISITE is set to "no" REVERT:c01b493c9Increase compression level of tar files being saved in the database REVERT:4f4a8b508Fix default global values being added to database when MULTISITE is set to "no" REVERT:408806718Add external plugins being updated at the start of the scheduler REVERT:402ff16c8Add "global" key to settings when fetching methods as well REVERT:dcdb43cf0Merge pull request #473 from bunkerity/dev REVERT:ca8c56aaaRemove unused function in UI src.Config REVERT:905946463Fix scheduler restarting for no reason when having an external database REVERT:8a308b1a8Fix database not providing the right SERVER_NAME setting value REVERT:cf26d7aa2Fix database saving default values to global_values when multisite was set to "no" REVERT:8bb6f63faMerge pull request #472 from bunkerity/dev REVERT:64789276aUpdate python deps REVERT:30194f959Fix Access-Control-Allow-Credentials not being set to the right value when deactivated REVERT:50ee37db0cors - refactoring REVERT:b8d89fe79Fix customcert plugin REVERT:63f4e44c6Fix CORS when sending an OPTIONS request REVERT:ac2e4dd64Merge branch 'staging' into dev REVERT:e14475de4ci/cd - fix missing version in linux package name REVERT:136f68cd3ci/cd - fix typo in beta wf REVERT:d83730cf7ci/cd - fix linux package name in upload/download steps REVERT:ae042854fFix blacklist download jobs where ignore urls were not being downloaded REVERT:86053d3dcUpdate RDNS regex in jobs files REVERT:b2e26fc8fRevert "Revert "Update RDNS regex"" REVERT:48354fb26Revert "Update RDNS regex" REVERT:a544f18e2Update update-check job to add stars so that the end of line shows REVERT:c6f304b37Update RDNS regex REVERT:14ca85cdbci/cd - fix package.sh name in linux build wf REVERT:dc1cb6a6fci/cd - fix scp command in linux build wf REVERT:73acbe085ci/cd - fix typo in linux build wf REVERT:45c90527cci/cd - fix linux package generation when arch is ARM REVERT:f4590749dlinux - fix arch in rhel package image REVERT:141f5a1d5ci/cd - fix typo in beta wf (again) REVERT:6e82fde8aci/cd - fix typo in beta wf REVERT:00ba46ebfprepare for 1.5.0-beta update REVERT:9a1c09c56Merge branch 'staging' into beta REVERT:df787c75dlinux - add pcre dep to fedora package REVERT:93e567bb6linux - fix fedora deps name and add architecture to fpm config REVERT:8b6d788c2ci/cd - fix bitnami chart values REVERT:541b64698increase drupal delay time for tests, fix tmp dir not created for realip-download job and fix has_*_variable check when multisite is yes REVERT:59324526cspeedup build process for python deps and fix default env value for autoconf/k8s REVERT:a58e5c60cdeps - upgrade python dependencies REVERT:27b1dddb0linux - pin pip version REVERT:fd056102dfix centos repo command in rhel dockerfiles and fix delete infras order for staging wf REVERT:fb0373343ci/cd - use single quote in linux build wf REVERT:43cbc79c7ci/cd - move ARM_* to secrets in linux build wf REVERT:7592e5a84ci/cd - fix typo in staging.yml REVERT:39ace8175fix load-balancer example and add server_name to cache keys when required REVERT:48d7e72e5Merge branch 'dev' into ui REVERT:66921b007Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:819ad60a4fix hcaptcha antibot and refactor ci/cd for staging REVERT:20913808cAdd .mypy_cache to .gitignore file REVERT:a086ff690Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:a286e7bd3fix wrong container in autoconf/k8s, init work on linux arm and ci/cd refactoring REVERT:5a233ff90Fix Database model types REVERT:18b3d7148Update db model to use SmallIntegers REVERT:b36cd924fAdd `bw_` prefix to database table names REVERT:63ce1afcdHandle errors more gently when API requests fails REVERT:d4934cfeeRemove test-ui service in the main docker compose file as it's been extracted REVERT:500d58e50Separate the compose file back REVERT:21dc67b68Update test.sh for ui-tests an the compose file REVERT:75d2be7dbUpdate tests-ui to fix them REVERT:041b7f71eUpdate ui-tests to make a valid password REVERT:1245b8b01Update regex in ui + Add regex module to requirements REVERT:913e9a2c2Merge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:97dc6540eci/cd - fix typo in dev wf REVERT:b75ba601bMerge branch 'staging' into dev REVERT:573fe8feeChange UI admin password check to a regex REVERT:51514df57Remove not needed file in linux scripts REVERT:9ff64426bFix ui tests with the external plugins REVERT:74fe9d5c1Lint jobs py files REVERT:97b362bb1Fix let's encrypt error when deactivated REVERT:964d31893Fix wrong attribute value when checking for external plugins REVERT:914686e78Fix often occurring bug when testing the web UI REVERT:58db1352fRevert "Fix often occurring bug when testing UI" REVERT:987af951dFix often occurring bug when testing UI REVERT:1c74c5d8dci/cd - refactoring REVERT:1cc9f5773prepare for v1.5.0-beta fixes REVERT:ac94e5072fix double .conf suffix in custom conf, migrate /etc/letsencrypt to /var/cache/letsencrypt, fix bunkernet jobs and lua code and fix reload for jobs REVERT:773874154move /etc/letsencrypt to /var/cache/bunkerweb/letsencrypt (wip) REVERT:75ca603b7WIP - fix bunkernet and missing reload for scheduled jobs REVERT:027605452Fix bunkernet initial message when checking connection + add TODO REVERT:bddfb58a0Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:c7ab00208Merge pull request #462 from bunkerity/testmmdb REVERT:ef551846bci/cd Update mmdb - Let only the schedule and change branch to push on REVERT:f41c096ecMerge branch 'testmmdb' of https://github.com/bunkerity/bunkerweb into testmmdb REVERT:a7b7c2031ci/cd Update mmdb - Add check for curl commands REVERT:fb5529566Monthly mmdb update REVERT:0afb250b9ci/cd mmdb update - Changed branch to push on REVERT:019a927b0ci/cd remove secret required for auto mmdb update REVERT:283a63f16ci/cd try fixing workflow auto download mmdb REVERT:42707ad46ci/cd test mmdb update REVERT:cd57eb423ci/cd - fix automatic push of doc REVERT:01fbacf0fci/cd - fix pdf path for draft release + fix missing git fetch before deploying doc REVERT:d693d065fci/cd - allow to update release tag, add PDF to release and fix multiline CHANGELOG in release REVERT:aa2ada0a0ci/cd - update git user/mail for push doc wf REVERT:a47d7df40ci/cd - execute apt install as root for doc to pdf workflow REVERT:c4093a2d7ci/cd - increase ARM node storage REVERT:01e599493ci/cd - concurrent builds for ARM + fix version string for RPM packages REVERT:aaa070165linux - fix VERSION path in package script REVERT:0b93c6e10ci/cd - add more cores to ARM instance REVERT:88db3fa34ci/cd - fix build rhel var REVERT:5c01bd3f7ci/cd - various fixes for push workflows REVERT:604d4c1a0Merge pull request #459 from bunkerity/dev REVERT:bed6d742fDecrease the compression level when sending configs to BunkerWeb REVERT:57cb6e9c4Update python deps REVERT:0d1580cffSmall code refactor of the jobs and the scheduler's function that generates configs REVERT:766ca0e9cMerge pull request #458 from bunkerity/dev REVERT:0ab07678dMerge pull request #457 from bunkerity/ui REVERT:5412e6d24fix logs checkbox REVERT:ba7422218ci/cd - fix push workflows REVERT:fda2948e0ci/cd - fix typo in push docker wf REVERT:59e5b1d54ci/cd - fix push workflows REVERT:7ca7d7847Merge branch 'beta' of github.com:bunkerity/bunkerweb into beta REVERT:939545644add missing postgresql-dev build deps for ARM images REVERT:0b5746abaci/cd - add missing inputs for build arm REVERT:94dc501c1ci/cd - remove load image in buildkit for ARM archs because of docker limitation REVERT:8ffaa7cf7ci/cd - force shutdown when deleting ARM node REVERT:6e99e7a98cicd - fix docker buildx arm driver REVERT:2eef2b8bbci/cd - fix variable share for ARM (again) REVERT:406c686e4ci/cd - fix variable share for ARM REVERT:6cecc70c3ci/cd - fix ssh command for ARM builder REVERT:2f992baabLint py files with black REVERT:7befd927dUpdate python deps REVERT:a4ae0d517Update cached mmdb files REVERT:c3d0d7ca7Add workflow that automatically update cached mmdb files REVERT:d4ceb7c10Remove dev comments for ui tests REVERT:b37c86e62Fix ui tests problem with the logs page REVERT:a7b07c959Fix wrong condition when fetching the logs on Docker REVERT:3b237ed3cFix UI tests REVERT:a55a0df5dci/cd - remove useless condition in create ARM workflow REVERT:ae33ca52eci/cd - fix wait-on variable REVERT:8867eb23bci/cd - fix wrong json keys from scw api REVERT:1b79e291eci/cd - various fixes for arm build REVERT:98ce5041dci/cd - use fixed sha1 commit for scw action in rm arm workflow REVERT:66d7216dcci/cd - fix typo in create arm workflow REVERT:45fa4d1c2ci/cd - ignore /root/.cargo dir for security checks, use fixed sha1 commit for scw actions and add missing deps for ui/arm REVERT:9cd13990eci/cd - pass ARM ID as secret REVERT:266383abbci/cd - dynamic arm build node REVERT:4e0d2fce5add missing dependencies when prebuilt crypto package is not present REVERT:823c09195ci/cd - add missing var for ARM builds REVERT:e71dc132eci/cd - fix typo in container build workflow REVERT:0db5f7cf0ci/cd - fix typo in beta workflow REVERT:4bfc5b693ci/cd - fix wrong cache name in container build workflow REVERT:93d0a991aci/cd - fix typo in push doc workflow REVERT:1c178ed75ci/cd - fix version output for beta/release workflows REVERT:ab7e1f624ci/cd - add missing runs-on in beta/release workflows REVERT:0f499c9d3ci/cd - fix typo in push packagecloud workflow REVERT:d0f6d59f6road to v1.5.0-beta 🚀 REVERT:408662869ci/cd - fix typo in doc-to-pdf REVERT:312757594ci/cd - fix typo in beta/release (again) REVERT:11f86ea75ci/cd - fix typo in beta/release REVERT:ad1606742use proper links in docs, automatic doc push and add pdf to releases REVERT:08e1d157dFix ui-tests by removing no longer present checks REVERT:c8908695bRemove unnecessary prints REVERT:641a27f5eci/cd - remove useless needs for ui branch REVERT:468407081ci/cd - fix typo in staging workflow REVERT:6784bd691ci/cd - fix wrong condition for container-build workflow REVERT:ef1897de8ci/cd - add missing needs to tests-ui staging REVERT:9815f22d7ci/cd fix typo in container-build workflow REVERT:65c6e48e9Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:14a4db8bduse current_bw_version for docs, add automatic tests to ui branch and fix letsencrypt permissions for linux REVERT:f6b8d23fbFix ui tests by editing the attributes name to the new ones REVERT:58fd04430ci/cd - fix typo in staging.yml REVERT:54a17c775init work on CI/CD for generic beta releases, remove useless autoconf examples and fix linux postinstall script REVERT:4f2c58bd7temp disable authelia test for k8s and add missing folders for LE on Linux REVERT:5e4ce4579various fixes REVERT:fa67c5d7bci/cd - fix missing arg for copytree REVERT:04db308c9ci/cd - edit staging workflow REVERT:5d2045803ci/cd - edit staging workflow REVERT:e7717ba7fMerge branch 'ui' into dev REVERT:bbaaad848docs - last polish REVERT:0658230e2enhance responsive REVERT:f5c28b27dMerge branch 'ui' into dev REVERT:575312336harmonize all titles dark color REVERT:2f336be77enhance file manager and jobs svg REVERT:81a37a377enhance actions btns REVERT:c3119f04edocs - plugins REVERT:ffa91933edocs - add YT demo REVERT:5741dce6dMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:7695a839fdocs - web UI REVERT:5fe0e0bfdMerge pull request #454 from Hado-K3n/patch-7 REVERT:8c71f7d27Merge pull request #455 from Hado-K3n/patch-8 REVERT:124378d7cMerge pull request #456 from Hado-K3n/patch-9 REVERT:c6a184d90fix ui integrations and fix stream support in db REVERT:d8b7db167merge from ui REVERT:ddd83a808docs - add stream support info and plugin description to settings page REVERT:289b58567docs - add stream support info on security tuning page REVERT:4dda54a11enhance style REVERT:0ca473c69fix style issue between load and page transition REVERT:1145b798ffix filter setting from custom selectors REVERT:63e7ccf13better centering loading logo with text REVERT:001a63efccontinue custom selectors + fix script + style REVERT:4144faa93fix create service issue + remove stash REVERT:72bc9e4bbstart creating custom selectors REVERT:98de3fc2fdocs - quickstart REVERT:f118f992fmerge from ui REVERT:5285a2f4aforce stash REVERT:1d354c9c6docs - quickstart (wip) REVERT:55a7c8feeforce stash REVERT:64a9fe4dbfix checkbox + style issues + script duplicate REVERT:a90d9e627ui - fix default value for inputs REVERT:7e1efcbc6Merge branch 'ui' into dev REVERT:b5f0fe856docks quickstart wip REVERT:01d8c65c9remove hidden input checkbox + fix script REVERT:b7f63450eadd special method for mode REVERT:bc47f1fa5Merge branch 'ui' into dev REVERT:7089e8b4dfix checked state REVERT:d4fd4c473fix checkbox + template REVERT:db5789fcbMerge branch 'ui' into dev REVERT:ab20f83b2Update k8s.postgres.ui.yml REVERT:bbea8ba3fUpdate k8s.mysql.ui.yml REVERT:9a2005d1aUpdate k8s.mariadb.ui.yml REVERT:9512de630docs - quickstart guide (wip) REVERT:956a7bd23Merge pull request #453 from gin-gitaxias/patch-2 REVERT:f8c5543fdUpdate plugins.md REVERT:667bb3003docs - quickstart guide (wip) REVERT:6b76596a8Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:78c2e16eaadd missing cluster config for ui/k8s and start quickstart guide doc REVERT:1e6cfe8b0fix filter disabled issue + reset on modal open REVERT:574ecbd6bLower the environnement variable for the mode REVERT:aa3ce13a8Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:6f39fce6ddocs - integrations REVERT:92fc5d981Remove ascii art showing in UI logs REVERT:ae7e3ddd9Fix how the ApiCaller is initialized for UI instances REVERT:df94bc4afMerge pull request #452 from bunkerity/dev REVERT:bf29fa2f9Show how many plugins there are correctly in the home page REVERT:509bd21b0Add log when deleting plugin REVERT:1530745a7Merge pull request #451 from bunkerity/ui REVERT:a87abf3ceupdate home dark mode + variable REVERT:8a5836dd9add popup darkmode REVERT:3a4a6ee5fnew service doesn't force method="default" REVERT:1321a76c0update service submit name for new or edit action REVERT:53e145b91show method involved in disabled setting on hover REVERT:ceec21faaupdate web-ui INTERCEPTED_ERROR_CODES REVERT:63ba00180Fix logic when saving a service in the UI REVERT:479f18b17Merge pull request #450 from bunkerity/ui REVERT:ab43bf84aMake it so the UI and the scheduler no longer run as root in Linux REVERT:a7849a6e7Fix mic mac with config files and UI REVERT:9009859aaMerge pull request #449 from gin-gitaxias/patch-1 REVERT:0bf2116c4docs - concepts REVERT:3616a9f20Update security-tuning.md REVERT:435aae7cfdocs - index and migrating REVERT:c0e649d68fix logs + select custom REVERT:1c3bbf1bcstream - add example and fix ssl support REVERT:37ebde363fix logs and plugins dropdown + margin REVERT:b64e55f75Add bigger timeout to loading.html REVERT:da4bb8dceFix condition in helpers.lua REVERT:ab509c270Fix UI with Linux REVERT:6916a81c5bunkerweb is now W3C friendly REVERT:c7bc493e3stream - fix various errors REVERT:bc1dbe18aMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:bd577cfb2country fix (again) and init work on stream REVERT:a829528c3Add bwcli to scheduler and fix it for the autoconf REVERT:9d829ebcaFinish updating bwcli REVERT:94b97a6bbMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:780c0c8c5api - fix errors in calls and use ngx.ctx instead of ngx.var REVERT:5fb0be70aMerge pull request #447 from Hado-K3n/patch-6 REVERT:6843902dbMerge pull request #446 from Hado-K3n/patch-5 REVERT:3419dca98Update k8s.postgres.ui.yml REVERT:38c71cf94Update k8s.mysql.ui.yml REVERT:b7c260561[WIP] Update bwcli REVERT:995ff250fUpdate python deps + add redis for the gen REVERT:a04490b47Replace unnecessary import REVERT:5112ed46eMerge pull request #445 from Hado-K3n/patch-4 REVERT:8558785b1Update k8s.mariadb.ui.yml REVERT:95e64d6c8bw - fix black/grey/whitelist rdns check and country check REVERT:8ea94a2e4Merge pull request #444 from bunkerity/dev REVERT:9f1405d69Remove unnecessary {-raw-} in index.html when loading REVERT:9a2f7e9abMerge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:93b471444Add marging to antibot files hcaptcha and recaptcha REVERT:93c0cd437Merge pull request #443 from bunkerity/ui REVERT:e7d61a67cupdate antibot and default template REVERT:5d05eaeaeMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:a77d233ecbw - add zlib dependency REVERT:9a69ca135Merge pull request #442 from bunkerity/ui REVERT:823c12823fix SERVER_NAME + fix delete form + enhance REVERT:52806afe7Merge pull request #441 from bunkerity/dev REVERT:2ea726c22Merge branch 'ui' into dev REVERT:dffc770a9fix and enhance REVERT:12f8b8197bw - add missing lua-ffi-zlib dependency, fix syntax error for white/black/greylist, fix error for dnsbl and fix limit request not working in local mode REVERT:4871a2104api - add missing ctx fill REVERT:bcc5e6bb5bw - add missing json decode in api and add missing require in country REVERT:83428d6ccbw - fix resolvers nil error when doing dns checks REVERT:7eefcb8f8antibot - manage direct access to challenge page REVERT:a372ffd52fix invalid session error handling and remove debug log in whitelist REVERT:e55912b34Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:5f9f1e54fload inline multisite values for white/black/grey list core REVERT:3b4882d82Revert "Remove no longer present CVEs fix because these are already fix in the images" REVERT:c2e0e5106limit - use atomic script for redis case REVERT:4bc0771d9Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:edf7e06e0various redis fixes and display ready log REVERT:a93d9a7d9Remove no longer present CVEs fix because these are already fix in the images REVERT:e4465d9a1Fix jobs cache when a database is used REVERT:c9af9457eFix wrong condition when sending files REVERT:17a3d933bMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:a60b6f3adbad behavior - fix 500 error and do not pass objects with another lifetime to timers REVERT:c0e8e93abFix documentation mistakes when soft merging 1.4 into dev REVERT:f1a868c66Fix when the cache from jobs is saved into DB + sleep 5 seconds when waiting for the database for the UI REVERT:d32102376Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:510938fc2antibot - fix bugs related to session REVERT:ed9605c10Update python script that generates settings.md REVERT:3dabd42dfUpdate python deps REVERT:834fbaf01remove antibot back btn + update raw REVERT:95c231515antibot - various fixes, not fully fixed yet REVERT:56028b087update antibot / loading / default page REVERT:502d4fcc0Add back the fact that we don't download the mmdb country if we don't blacklist or whitelist a country REVERT:ccd56d3b6change antibot and misc template style REVERT:c949c0232Update the security tuning's blacklist category according to the settings REVERT:671543e6eAdd more ignored variables for missing setting name warning REVERT:dbd5739abFix wrong setting names under `Custom certificate` category REVERT:5f26ebc69Fix php-cookie-flags example REVERT:bba26b548Reorder core plugins to stop having the warning at startup REVERT:db166c434Add small fixes and lint to the error.html page REVERT:08f3d93abUpdate jobs will now also check and save the cache in the db REVERT:63b1fb947Fix CVE CVE-2023-1255 REVERT:d5b11b8bbMerge pull request #440 from Hado-K3n/patch-3 REVERT:92744c091Merge pull request #439 from Hado-K3n/patch-2 REVERT:d46337f60Merge pull request #438 from Hado-K3n/patch-1 REVERT:9b52a5c3cclusterstore - various bug fixes REVERT:3f9d606e1Update k8s.postgres.ui.yml REVERT:7e2f53c8cUpdate k8s.msql.ui.yml REVERT:1f5d8bfabUpdate k8s.mariadb.ui.yml REVERT:7a7d83a75various fixes for redis/clusterstore - still WIP REVERT:a5e08e1c6refactor of session management REVERT:0fdb108fecore - do not execute init() if BW is in loading state REVERT:00b50c162various fixes for core plugins REVERT:4ba5d6659use ngx.ctx to store common values REVERT:860cc1a92Merge branch 'dev' into ui REVERT:881d3a00dfix git issue on windows REVERT:76a2ff656Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:28ef546a9refactor - start to use ngx.ctx for per-request data REVERT:ed495b99fAdd CODE_OF_CONDUCT.md REVERT:0bd3e273bUpdate compression_level of sent tarfiles to 5 instead of 9 REVERT:348ab7a1eAdd feature that allow the copy of code blocks in markdown + Update copyright REVERT:cf2938bf2Update web-ui docs according to the next major version REVERT:79a46e2cfUpdate the logic behind the check for linux os REVERT:9a325c7a9Add new check for integrations in BunkerNet job REVERT:707256076Add now the scheduler will pass his own env as well to jobs REVERT:9578ace02Remove not used INTEGRATION file in BunkerWeb container REVERT:8c919c676Update links in the home page of the web UI REVERT:ad64ce22eRemove no longer needed packages that were fixing old CVEs REVERT:29cb6fe16fix header phase and fix error template REVERT:d3d18e15aMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:a83254bf2fix wrong log in access REVERT:859343e18Merge pull request #437 from bunkerity/dev REVERT:50829293cMerge branch 'ui' into dev REVERT:8e22b1f21Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:9849ce10cfix wrong error check on phases and add missing ttl for *list cache items REVERT:3b5c083fcSoft merge branch "1.4" into "dev" + changing versions REVERT:4d95e32f1update error page REVERT:1da4b78f0Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:915b51c3bfix error pages for default http server REVERT:535f1a055Merge pull request #436 from bunkerity/staging REVERT:0afe038aaWIP Ui REVERT:3b6c3815efix default-server-http.conf REVERT:b5fa473aeMerge branch 'refactor' into staging REVERT:2fddbd862refactor - disable asn checks for non global IPs, use resty.template with antibot and various fixes REVERT:8d63e3974refactor - fix various errors and add missing dependencies REVERT:23725d483Update prod shields.io link in README.md REVERT:303f380c7Update demo.gif file REVERT:3c375039eOptimization on the download of mmdb files REVERT:a7773dae2Update intro-overview.svg REVERT:5eb884fe9Fix bug when showing cache files for services in the UI REVERT:3fac889ffRemove no longer used modsec rules for the UI REVERT:c3106e70eUpdate README.md and edit the demo GIF + edit the .prettierignore file REVERT:928ed2d6crefactoring and road to nginx 1.24.0 REVERT:34ab94640Update python image in Dockerfiles + Add gevent to requirements for the UI REVERT:aa96c8503update css REVERT:649d29b05change news base url REVERT:217d1aa50enhance style + menu script REVERT:e6ff51e20Refactoring and Linting of py files and json REVERT:666b7a1barefactor - blacklist, errors, greylist, letsencrypt and redis REVERT:496edb83aAdding thel documentation REVERT:ee83cea7fAdd ascii art showing randomly when starting REVERT:6d1914d62Update python deps REVERT:648f15e42Add new core plugin update-check REVERT:2075a5d4crefactor - badbehavior, blacklist, bunkernet, cache, cors, country and dnsbl REVERT:5dd52186bFully adding vagrant in the doc REVERT:3a03f07f1Changing vagrant integration REVERT:64997bae8Adding vagrant integration REVERT:03ec271e2refactor - improve clusterstore interface and automatically retrieve variables for plugins REVERT:29c57915cantibot inherit from plugin REVERT:840c29568continue work on refactoring REVERT:1ec83f256renamed session to sessions REVERT:8c2908157save work REVERT:afc0ac198init work on refactoring REVERT:4cd3fc644Merge pull request #434 from syrk4web/staging REVERT:bfc872be2change flash logic when login REVERT:049e9c1eaUpdate python deps REVERT:bf9b94ebfAvoid Autoconf from running in root REVERT:92e698458magento - fix docker example (again) REVERT:a771bdb18magento - fix docker example REVERT:7c21b3da2deps - update lua-resty-session to v4.0.3 REVERT:d4fae4b57session - add missing settings REVERT:a85044220init work on redis session REVERT:986f506e7add missing API_WHITELIST_IP in mattermost and moodle examples REVERT:41e8f5c93fix wrong init of counter in badbehavior and fix nextcloud/docker example REVERT:8e7205062ci/cd - reduce dynamic subdomains for k8s tests because of annotation size limit of 63 chars REVERT:1bc42204dci/cd - use dynamic random subdomains to bypass LE rate limit REVERT:a1e44f6e4Merge pull request #431 from gin-gitaxias/staging REVERT:7ccd3ef92fix moodle/swarm example and disable reverse-proxy-websocket test REVERT:8b54073a7fix missing backslashes in autoconf custom configs and add missing full reload after custom configs update REVERT:622f2eb2aautoconf - check if service exists before adding config REVERT:5d14813befix typos after basic testing REVERT:9f7060564autoconf - add missing import and fix double lock release REVERT:937cd10eerefactoring and various improvements REVERT:6af3b985afix deadlock in autoconf/swarm and fix missing favicon in default and loading pages REVERT:f6ed21b3bautoconf - fix global custom configs not supported in k8s/swarm mode REVERT:eee03c4aeautoconf - fix variable typo in k8s watch REVERT:ecf4e77b3autoconf - fix deadlock in watch loop REVERT:0b71819d2watch services for autoconf/k8s and support real IP in default http server REVERT:d3d0136bfvarious redis fixes and improvements REVERT:e80965ca9lua - fix wrong variable name in access REVERT:220374db4ci/cd - fix syntax error in jobs REVERT:9b8606d40fix redis hostname for k8s files and only append tasks with a desired state of running for autoconf/swarm REVERT:c843be074reverse proxy - allow all chars for URL settings REVERT:6a65104e7fix return value of clusterstore.connect and disable auth basic for LE challenges REVERT:b429201ecadd missing LUA import for clusterstore and fix prestashop docker example REVERT:a9ce32c26added a more precise scan response and modified .json like asked REVERT:f4442b642ci/cd - fix syntax error in k8s test class REVERT:1c3c0d63bci/cd - fix missing k8s create infra job REVERT:e8c6d04aaci/cd - various fixes for k8s tests REVERT:1caa9a1e7adding reverse-scan REVERT:5d41a5b98Merge pull request #1 from gin-gitaxias/reverse-scan REVERT:77fb8c420Add files via upload REVERT:1bb79b155linux - add geoip deps to rhel rpm REVERT:cf8644602Merge branch 'staging' of github.com:bunkerity/bunkerweb into staging REVERT:ea1394b04ci/cd - add linux/rhel tests, fix docker/behind-reverse-proxy, fix missing stream module for linux/fedora and remove placement constraints for swarm REVERT:87bd26da0Add threatmap to README REVERT:b3eb64745ci/cd - temp disable autoconf tests and add missing packages for linux/centos REVERT:202f21aabfix syntax error in ApiCaller REVERT:55a36f719fix docker/joomla, fix autoconf/nextcloud and fix API calls for swarm tasks REVERT:1c3f094cdci/cd - fix wrong yaml edit for swarm and append LE settings for k8s REVERT:f07c0e66aci/cd - various fixes REVERT:e8ee460effix CVE-2023-0464 and CVE-2023-0465 REVERT:dd2c8cbcdMerge branch 'staging' of github.com:bunkerity/bunkerweb into staging REVERT:2d11a1c72fix nextcloud modsec rule id, fix k8s pvc definition and remove useless logs from linux/start.sh REVERT:4f334a577Add sleep between BunkerNet registering and ping to the API to avoid being rate limited REVERT:283828e8fFix Now support WebDAV methods in the ALLOWED_METHODS setting's regex REVERT:e50c92250various fixes REVERT:b8b50b165Remove check for messages after creating the service - tests-UI REVERT:e88406b5dFix ui tests with the new UI REVERT:922b32b2eMerge pull request #429 from syrk4web/staging REVERT:671db37f7fix autoconf/cors, fix docker/wordpress, fix wrong image name for k8s/scheduler and upgrade tests instances for swarm/k8s REVERT:be71b0781format logs instance to avoid error REVERT:9e1876fealogs fix + checkbox fix REVERT:4d245f9fechange cache/download to jobs/download REVERT:6d16a766ffix service delete + change style REVERT:5e598e90cfix bw-data volume not reused between docker tests, fix wrong bw-data volume path for autoconf tests, add let's encrypt to autoconf tests and fix temp env not generated for linux REVERT:dc8b7dbe7fix form input REVERT:bf22faddcremove php-cookie-flags from tests, use HTTP(S)_PORT for temp nginx on linux and fix wrong volume path for autoconf tests REVERT:6c6845a79enhance some responsive + change api REVERT:461789aedci/cd - fix BW CVEs and fix Linux restart REVERT:318228e59change and fix service logic REVERT:fa7c7ac91ci/cd - add www volumes for autoconf REVERT:f88eced33Handle services settings sent to the UI better REVERT:357dc3e3aMerge pull request #428 from syrk4web/staging REVERT:283306a07Remove CVEs fix, it's no longer needed for now REVERT:276a96c55Merge branch 'staging' of github.com:bunkerity/bunkerweb into staging REVERT:19870f154various fixes for linux and get ui tests exit code from container REVERT:2485a47b2Update python deps REVERT:bd88f9743fix id rename error REVERT:82d8180d8Merge branch 'staging' of https://github.com/syrk4web/bunkerweb into staging REVERT:41f43c46dfix multiple REVERT:0f632803fMerge branch 'staging' of https://github.com/syrk4web/bunkerweb into staging REVERT:53f480a66enhance multiple logic + fix conflict REVERT:1cf4a5665disable healthy checks for docker-poryx and dummy app in ui tests, add --no-reload-linux flag to generator and fix missing self arg in autoconf REVERT:041142a4fadd healthchecks to ui and autoconf docker images REVERT:4f9748cc2earlier init autoconf in DB, healthcheck for scheduler and fix syntax error in linux/start.sh REVERT:54813ecd4Merge branch 'staging' of github.com:bunkerity/bunkerweb into staging REVERT:d97b5e104various fixes REVERT:8031c5060Start handling disabled checkboxes + multiples REVERT:58ab870b2increase cors/k8s/swarms timeout and fix tests/ui container names REVERT:cceda705bupdate flash count on remove REVERT:e91f3dc22Add a log when database is ready in UI + Small refactor of the Configurator REVERT:1e9a55c24Add small tweaks to the UI and scheduler Dockerfiles REVERT:7dc26dafaFix disabled checkboxes no longer always have the value no with the UI REVERT:7dc25b3a5fix redmine/docker example, remove double AUTOCONF_MODE in integrations, remove useless backslash in start.sh/linux, rename container for ui/tests REVERT:55d24a8d1Change mmdb-country job to download the file only if needed REVERT:9e009f7beMerge branch 'staging' of github.com:bunkerity/bunkerweb into staging REVERT:73b640bd3fix cors/docker example, add missing AUTOCONF_MODE=yes to integrations YMLs, proper save_config for Linux and fix image name for UI tests REVERT:87bccaad6Add `AUTOCONF_MODE` setting to scheduler in integrations examples REVERT:d331131c0increase timeout for php-multisite, add API_LISTEN_IP setting, edit default variables.env for Linux and add more logs for tests REVERT:578a1a8c8Add more precise logs in the jobs plugins REVERT:cb808c0adFix bunkernet-ip.list file not being created in case of an error (same as 1.4) REVERT:c8d39ba6bFix scheduler no longer running as root + Fix permission errors with downloaded plugins REVERT:4a67a5f56Merge pull request #426 from syrk4web/staging REVERT:4dea680acenhance style + some fix REVERT:d81088272Change the category if the user needs to log in in the UI REVERT:e003b751dFix when saving plugins with pages REVERT:b829e4edfFix false positive error with plugin page in web UI REVERT:fc3ef3346Add UI logs into console REVERT:ce85bc6b8Fix openssl no longer prints progression in the console REVERT:2e144bf46Merge pull request #424 from syrk4web/staging REVERT:defb2c333Change the way the error page is rendered REVERT:2ae37ce8dFix regex for ANTIBOT_HCAPTCHA_SITEKEY setting REVERT:f335364fcLint antibot.lua REVERT:16842fef1Fix errors with missing % symbol + fix errors because of the symbol REVERT:5f5a5a890Fix css in antibot html files REVERT:ccde5c74ffix real ip jobs REVERT:d3402ff3fchange loading, error and test files REVERT:a02218bc8end examples refactoring REVERT:5845446b9Revert "Fix errors regex, authorize same path for multiple errors" REVERT:be0df4160Fix errors regex, authorize same path for multiple errors REVERT:89812362acontinue examples refactoring REVERT:5d214497bFix don't try to add an instance when saving the configuration with the UI REVERT:808b7b220Update jobs connect to the database only when needed REVERT:aa0eff749Fix regex in redis plugin that was breaking the UI + fix ui.conf missing comma + remove unused variables in templates REVERT:1ac434a5bUpdate python deps REVERT:9c22f1e97Refactor the py files REVERT:cfe5c6063examples refactoring REVERT:e37e6c346Fix mixup of swarm and kubernetes when reading env variables + refactoring REVERT:0356250d9Fix problem with the bunkerweb container and plugins REVERT:548d157feFix check if the Database is on read-only before trying to write REVERT:7c5aa4897Update version string size to support new format REVERT:61b9517a8Fix error when multiple jobs are trying to write in db at the same time REVERT:8c67d08aeLint code REVERT:966f57ceainit work on examples refactoring REVERT:0210ddd88Add realip settings values to the initial BunkerWeb settings REVERT:6f29756ddci/cd - pull only interesting images for UI tests REVERT:2b1dbb1d4fix default cert path again and ignore pull errors for UI tests REVERT:74a11c2edfix wrong cert/key path for default server REVERT:b3769b6e3fix missing then in blacklist.lua, disable site search in redis.init(), remove counter from reverse-proxy/stream config and fix ui tests compose pull REVERT:c7d8b7dc1update resty core and http lua to support latest version of stream lua and various fixes related to ci/cd REVERT:a62ef9f54add missing init-stream-lua.conf and various fixes for ci/cd REVERT:65611020dfix duplicate datastore http/stream, fix missing /var/www/html for linux and various fixes in tests REVERT:b28668d68ci/cd - revert back to old condition for pulling images REVERT:706305917ci/cd - fix wrong autoconf local image name, add missing secrets for tests-ui, fix wrong IMAGE_TAG for tests-k8s and try to fix pcre issue on linux REVERT:2d440d26eci/cd - add missing runs-on for reusable tests-ui REVERT:93945f391ci/cd - add ui tests REVERT:5e31b6c4afix CVE-2022-1304 for autoconf, add missing load_module for ngx_stream_lua_module.so and fix missing -lpcre in configure step REVERT:01fab4162ci/cd - fix CVE-2022-1304 and wrong TEST_DOMAINS REVERT:aa614b75aci/cd - replace Test.py with latest one, fix yaml paths, print logs when k8s stack is not healthy and fix wrong linux docker image name REVERT:88a295517ci/cd - fix log() call REVERT:b95d1bc6dci/cd - add missing log() and fix TYPE for linux tests REVERT:2604d9a56ci/cd - trying a hack to support dynamic runs-on REVERT:ed4d94529ci/cd - trying to fix runs-on problem REVERT:53410e831ci/cd - remove steps REVERT:609210021ci/cd - inherit secrets for tests workflow REVERT:a168f2bceci/cd - fix rhel build and runs-on for tests REVERT:8bf211bc5ci/cd - fix linux package generation (again) REVERT:9250faa52ci/cd - fix linux package generation REVERT:139eaa2ddci/cd - add missing scripts REVERT:7149a34ccci/cd - add empty .trivyignore and rename redhat to rhel REVERT:5c5dbcfc7ci/cd - fix type in push-packagecloud workflow REVERT:e826c619fci/cd - fix wrong quotes in delete-infra workflow REVERT:b24cbf73dci/cd - fix wrong quotes in tests workflow REVERT:99e27c430ci/cd - add missing input in tests workflow REVERT:ee0e608deci/cd - fix negative conditions REVERT:10f9658f5ci/cd - fix wrong jobs name in needs REVERT:27bac0382ci/cd - trying to fix dynamic runs-on REVERT:97627cf83ci/cd - pass runs-on to reusable workflows REVERT:8969b1e72ci/cd - remove version from reusable workflows REVERT:8ca292fb3ci/cd - change reusable workflow paths REVERT:8e73eb87cci/cd - fix syntax errors REVERT:46e3078ddci/cd - crash test incoming REVERT:95c5e2e47ci/cd - move dynamic runs-on from reusable to staging workflow REVERT:131857a9bci/cd - fix wrong indent in staging/delete-infra-* REVERT:fc1cab1afci/cd - remove subfolder and continue work on staging REVERT:25729fda7ci/cd - init work REVERT:bb2d868faRefactor tests REVERT:5e3dadbfeRefactor ui REVERT:7fe168892Refactor scheduler REVERT:36b5c372eRefactor Instance and remove unused method REVERT:596258559Accept incoming changes for misc jobs REVERT:c5a10aaa3merge default-server-cert job REVERT:06acae405rename *CUSTOM_HTTPS* to *CUSTOM_SSL* and continue work on stream support REVERT:6bf59b59aRefactor the plugins jobs REVERT:7a8a75901Fix multiple CVEs (see comment) (finally) REVERT:10ec01e7bFix wrong env var name in realip plugin REVERT:947ecf81fstream - add is_stream variable to check if we are in stream or http mode REVERT:4f4c8ebf0init work on stream support REVERT:79036e975add ngx_devel_kit and lua-resty-env deps, support set_by_lua hook for plugins and init work on whitelisting support with modsecurity REVERT:c2402b118fix duplicate root error when bw is starting, add modesec rule to core ui and init work on k8s/swarm integration files REVERT:dbd052e9aRemove unnecessary import and use parent list of supported custom conf instead REVERT:fb917960bRevert changes on the custom conf regex for the autoconf REVERT:26de0a233Lint files REVERT:0faa34ac7Add a regex to the setting REDIS_HOST REVERT:1d9459202misc - add missing page.conf REVERT:1b113236aMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:29b373148misc - default pages for default server REVERT:6cb714be0Start adding integrations examples REVERT:99b85ec8aFix Apicaller error with swarm REVERT:37114ee2fMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:902fe6ad0bw - init work on redis REVERT:7bf034fc9Fix being able to delete autoconf services from UI (shouldn't be) REVERT:916caf2d6Merge (soft) 1.4 branch into dev branch REVERT:f8e31f287Update mattermost to use a static image REVERT:0f35c05eeIgnore multiple CVEs due to missing deps in python:3.11-alpine REVERT:846e26e41Fix multiple CVEs (again) REVERT:ebc7fbbceFix multiple CVEs (see comment) REVERT:f4081ebd3Handle more errors with Bunkernet job REVERT:3b01b5144Upgrade the way the jobs run_once are executed REVERT:8fa94d6a5Edit DockerController regex to handle more custom confs and fix modsec conf mixing REVERT:c92d4224fUpdate python deps + add cryptography for autoconf and MySQL REVERT:579975899Fix checkbox not being sent when unchecked + double settings tab in UI REVERT:935805721Fix CVE CVE-2023-22490 and CVE-2023-23946 REVERT:c671ccf7aAdd unauthorized_handler to UI REVERT:5ac64758eMerge pull request #417 from syrk4web/dev REVERT:fdd0da35dMerge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:34d12cd55Fix file manager always use the database now + create log file for UI if not exists REVERT:47ccd9f04Log events back in the UI REVERT:39b0f3f19fix + show one mult group REVERT:7828c0225add checkbox fallback + DL script REVERT:e425eef9aFix weird shinanigans when saving services config REVERT:b75bc0344Adjusting upgrade on file variables.env REVERT:79dabf763Change the way bunkernet check on which instance type it is REVERT:3f462fb3bOptimize logger REVERT:84f3a894fFix cache files not showing on UI REVERT:93933bde7Fix custom conf MODSEC CRS being interpreted as MODSEC only REVERT:c22bccc76Correcting nginx version for debian installation REVERT:8bedc9ce6Correcting doc REVERT:3a60b3463Modifying doc for packagecloud problem REVERT:9efa21709Correcting fedora packagecloud problem REVERT:e3410058fCorrecting Ubuntu/Debian REVERT:60ac00f5ffix inp value REVERT:6b13fbb84change svg REVERT:c89205016Adding Rhel integration REVERT:cb77a7010change logs datepicker REVERT:8b0d8a9d3remove log + fix service tab REVERT:facb597eefix float buttons REVERT:89930f1a3Remove encoding from Database engine args REVERT:6122d59d8Update python deps REVERT:d3a02be59Rhel cannot be supported yet REVERT:a51aa27e4Add some checks and solutions to rare syntax error REVERT:ae8e65057Fedora upgrade working Correcting backup during upgrade Database backuped TroubleShooting some errors with OS Centos working REVERT:77f41a059Backuping old confs working REVERT:8fcba30abUpgrade Debian/Ubuntu working REVERT:2e9a0c79efix select hover style REVERT:64961e395Remove unused imports REVERT:b662d8453Update python deps and remove oracledb REVERT:e9d981a56Fix checkbox being disabled every time REVERT:39418790afix popover content REVERT:3d96fdb34update dashboard REVERT:580f33e56new file el is hidden on nav REVERT:4f6244e74Lint code REVERT:1f2076756Update Python deps REVERT:dcf9e301eFix UI not exiting correctly with gunicorn REVERT:f1a28b01bMerge pull request #408 from syrk4web/dev REVERT:5739144e3Fix bwcli /bans command REVERT:df7bbb960Update VERSION to 1.5.0 REVERT:dd0f56bb0Add password type for settings REVERT:d83d3aa3dFedora working Modifying centos systemd Adding %postun to rpm Modifying postun deb Centos working REVERT:b85e6ee6bUpdating to Fedora 37 REVERT:ca0d88fccUpgrading script: Ubuntu & Debian working REVERT:835f85d5denhance input field style REVERT:c4b5ddb95Add setting to intercept specifics error codes REVERT:86c81a621Merge pull request #407 from syrk4web/dev REVERT:e6cb5b0b0Made the UI independent + update job download plugins REVERT:0ce5f216dhandle password inp REVERT:44ce5381cFix CVEs REVERT:12b4cfa22Merge pull request #406 from syrk4web/dev REVERT:d7ee3ad66fix file manager dropdown REVERT:efbcfd0e2Beginning of automation testing for linux packages REVERT:50b83790aMerge pull request #405 from syrk4web/dev REVERT:bf1d19f33remove prefix multiple input REVERT:4d49f2f4bImproving and correcting problems on packages REVERT:f5d87849aFix errors in the UI when a service have multiple domains REVERT:d6d1dd1ceMerge pull request #403 from syrk4web/dev REVERT:0f5a73430add condition for services REVERT:a5256dd80Fix IPv4/Ipv6 CIDR regex REVERT:591a20cd8Merge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:c56fccbf2Adjustements to upgrade REVERT:a3a5c1c74Add ui tests requirements to the updated python deps REVERT:b1c99e408Add tests for the UI REVERT:65f2bf09bRemove the idea to store logs inside the database REVERT:7beb400b4Fix stop gathering all the logs every time with the auto update REVERT:ab163ce13Fix services settings saves and plugins deletion REVERT:6932f3dedAdd a new script to update python deps and update python deps REVERT:d14372075Fix tar error when sending /etc/nginx to BW REVERT:9edf789abUpdate python deps REVERT:4b3b9b326Merge pull request #397 from syrk4web/dev REVERT:557db479crefactorise logs script REVERT:13f1dadf5Merge pull request #396 from syrk4web/dev REVERT:adf96cadcremove useless files REVERT:d2a634e7fplugins + global_config fix REVERT:1aaac2dcfAdd regex for settings.json REVERT:871807b80Add small fixes and tweaks REVERT:4c5172edaCorrection of problems REVERT:331d58324Fixing details REVERT:e9c1b0cf8Adjusting some details REVERT:c220e5997Linux UI fix REVERT:13fbbfb67Update job database while locking the threads REVERT:ea4ceae7bFix isPage logic in menu (UI) REVERT:8ee0ec88fRemove test files in UI REVERT:d81c52654Lint ui files and change .prettierignore file REVERT:5cc80d2baMerge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:a6295248cMerge pull request #394 from syrk4web/dev REVERT:38b59954aLint yml files REVERT:146338de6Refactor every .py file REVERT:fcd8d8746open another tab for doc REVERT:051192791change style REVERT:9c80cdb32add plugin page logic to menu REVERT:7689dac76Filter CVEs fixes in Dockerfiles REVERT:0c8dfaaabUpdate bw and autoconf Dockerfiles for let's encrypt REVERT:c5d3e77c1Fix letsencrypt permission error and optimize the ownership commands in scheduler REVERT:8304116fdSend more variables to the home page front REVERT:4379e21eaShow dirs of every services even if they don't have a custom config REVERT:148d9d2d4Remove user override in the job scheduler when executing jobs REVERT:c6498eda7Add new php-cookie-flags example REVERT:f97e056ffUpdate jobs REVERT:13fe4b6eeEdit core plugins regex + make COOKIE_FLAGS multiple + edit DB model accordingly REVERT:2b2eadf44Merge pull request #392 from syrk4web/dev REVERT:342fe956fchange data creating new service REVERT:bb7ca889cenhance darkmode + fix + factorisation REVERT:cdc3cfc81add toggle multiples + style REVERT:191c88238Merge pull request #388 from syrk4web/dev REVERT:dbe49bb8fUpdate intro image REVERT:7bdc46057Change how the edit works in the config (UI) REVERT:364ef13b5Fix error by calling a method on the wrong variable REVERT:1142ace55Fix rare error with the jobs return code REVERT:477e87a2fnews script + multiples groups REVERT:a04f983a0Merge pull request #385 from syrk4web/dev REVERT:e5574fbdcchange flash messages style REVERT:b1ca47253Small tweaks and handle services variables better REVERT:98bda4d1eRemove unused line in Templator REVERT:0b1be727fOptimized the storage in the Database REVERT:47526dc8aMerge pull request #384 from syrk4web/dev REVERT:00d3073b0get custom method and check disabled state REVERT:02d10f619Fix datepicker.js not being found because of the caps REVERT:da634af4aAccelerate send_files method REVERT:be0ee60cdhandle stop signals with the web-ui REVERT:064f9eef9Remove lines that will never be use in save_config REVERT:ec15a4e88Handle stop signals from Docker in the scheduler REVERT:c49f50da2Move BunkerWeb entrypoint to the correct dir REVERT:48bbb5e39Merge pull request #382 from syrk4web/dev REVERT:b944de9e8change service multiple script REVERT:07ab3deb0Remove unused lines in selfsigned job REVERT:a4e863f09Update authentik and migrate the example to the 1.5 REVERT:eeb810546Migrate authelia example to the 1.5 REVERT:e2b2505d8Fix saving config for multiple settings REVERT:a0c2db7a0Fix how the config is get from the database REVERT:4595295bdfix tab focus style + dark mode style REVERT:0bd6d5655add flash script to login + enhance style REVERT:6f5aab11dfix footer padding REVERT:37380b977fix get multiple settings only REVERT:3f6432f4bMerge pull request #381 from TheophileDiot/dev REVERT:ff84656cdUpdate examples + add static versions REVERT:0e29d9f1fenhance and fix REVERT:c195ffc86Fix autoconf not working properly with the shared volume REVERT:291d64e29Update community example + linting REVERT:4346322f7fix services settings on modal open REVERT:f2daf7368Merge pull request #380 from TheophileDiot/dev REVERT:ba9c16a5dMerge branch 'dev' into dev REVERT:0db1550f2Changed the way jobs' cache files are downloaded REVERT:fa54ebd49Made a few tweaks + change the plugins for the services modals REVERT:0290f509eadd plugin_name (change values) REVERT:77931b623add plugin_name REVERT:6560ca086test REVERT:0d0f1aa95Merge pull request #378 from TheophileDiot/dev REVERT:03e98985eMigrate more examples and lint REVERT:016a8cd6dchanges REVERT:5263be27dChange the way jobs are downloaded + folder created in configs REVERT:7813b51dbMerge pull request #377 from TheophileDiot/dev REVERT:c4bd535acAdd autogen back for docker and the autoconf REVERT:243c4ca78Merge pull request #376 from TheophileDiot/dev REVERT:e9687a5b1Remove unnecessary comments REVERT:8537eea89Merge pull request #375 from TheophileDiot/dev REVERT:3c9574daeLinux: Updating nginx to 1.22 REVERT:9f84e02d8refactoring services modal logic REVERT:b105896b2add rename form REVERT:ff83b342dfix issues REVERT:8e31672acMerge pull request #374 from TheophileDiot/dev REVERT:b3d80d7a6Generate requirements with python3.9 + use new resolver REVERT:6bbbe70eeMerge pull request #373 from TheophileDiot/dev REVERT:e33bad4b9Fix comments + updated passbolt to support the 1.5 REVERT:37f21c5d4Temporarily comment the post fetching REVERT:343d9d09eShow plugin pages even if there are none REVERT:0a4f0eb57Fix error with jobs wrapper REVERT:1d4998356Fix darkmode + Add new variables to pass to the front REVERT:547021e7bFix job fetching for never ran jobs REVERT:0954e82f4Fixes some bugs in the UI related to the plugins REVERT:3c5f6002dfilter script + manage files + fix css + enhance REVERT:e988aacf3Merge pull request #371 from TheophileDiot/dev REVERT:cce181a29Update customcert job REVERT:9ba06b64dUpdate README REVERT:7f2eadaccUpdate python version for the scheduler and requirements REVERT:8d6c3d0b8Fix db get_config REVERT:cc748a048enhance responsive + add loader REVERT:3bafe137drefactorisation REVERT:e9dfb59f3handle settings type multiple (fetch, add, remove) on services REVERT:8e5dda520Changed the way the config is get from db REVERT:368122181start multiple add and delete logic REVERT:fee59a51eseparate multiple from others inputs REVERT:50ba22914upload plugins + jobs template + global enhance REVERT:94b0e6a0dChanges on the flashed messages REVERT:2e0a733cdMerge pull request #370 from TheophileDiot/dev REVERT:103e4a0aeUpdate modsec CRS to v3.3.4 REVERT:f0f9d7dcfMerge pull request #369 from TheophileDiot/dev REVERT:4dabe6daeAdvancements in the examples migration to 1.5 REVERT:115bfbdc1Merge pull request #368 from TheophileDiot/dev REVERT:81ad9e9acUpdate examples and add docker-proxy REVERT:82ab6c7c4Revert "Remove unsafe deps in the requirements and install setuptools manually" REVERT:b578823a1Remove unsafe deps in the requirements and install setuptools manually REVERT:7fb61b5efNo longer dump the jobs to the front REVERT:37ece3de1Merge pull request #367 from TheophileDiot/dev REVERT:719d779e0Start updating the examples to the 1.5 REVERT:2889b2638Merge pull request #366 from TheophileDiot/dev REVERT:3c3bb7f20Fix the way we fetch the config from the database (with suffixes) REVERT:f0d0dac91Add the variables back instead of the "_" so it doesn't create an error REVERT:62ab9944cFix scheduler errors with sqlite in autoconf REVERT:739190051Make the bunkernet not run in a thread to avoid errors REVERT:840ef8cf8Fix typo in selfsigned job REVERT:5a95e6703Edit the way the UI updates the config REVERT:34b5aba1cMerge pull request #364 from TheophileDiot/dev REVERT:b7f60dbdcUpdate deps and requirements REVERT:a0634b573Merge pull request #363 from TheophileDiot/dev REVERT:c0efdf9c0Replace /usr/sbin/nginx with nginx REVERT:db35e575eRename variables so they make more sens REVERT:b22cc44d8Change the way jobs are sent from the database REVERT:4e96e57e0Make certbot compatible with 1.5 REVERT:aaeda5300Change the jobs logic + add support for arm REVERT:657722922enhance templates REVERT:844b06e28Fix how the jobs are sent to the front REVERT:3a0727b5clogin template done REVERT:0f5756cfbenhance logs + prepare jinja variables REVERT:08e7c2104plugins done + add name to settings REVERT:6b5d6e07eRevert changes on the check_settings function REVERT:3ccc12d78add dropdown + responsive REVERT:3ed3fbe99Autotonf now update the instances too REVERT:e56f96d04Update database model + Save instances to database + add the option to add logs into the database REVERT:c87c3637dstart plugins template REVERT:3a5d14952Made few tweaks with the home page + remove useless functions REVERT:55e76b280Fix path for dropzone's scripts REVERT:64d261accChange the way logs are parsed REVERT:f13455d11send timestamp with ms REVERT:7aac0c352fix ms REVERT:fb2e41c11logs params REVERT:2967ed98cfix fetch REVERT:4f9b2120etest REVERT:f1e614faechange ternary operator for fetch REVERT:fa5719db7fetch logs + liveUpdate filter REVERT:2a2f2f1e9Fix scheduler error REVERT:208716722Merge pull request #361 from TheophileDiot/dev REVERT:fa98003f2Thread the jobs run_once REVERT:89e8839bbOptimize the regex for the core lists REVERT:51c5836aechange logs script/template + continue jobs REVERT:f61b4428bMerge pull request #360 from TheophileDiot/1.5 REVERT:a96771881Change the logs date format + start editing the logs endpoint REVERT:d30adf670Changing rhel REVERT:bf19cfe3dMigrating Linux to 1.5. Still some details to adjust to be perfect REVERT:0cd6ed1afWhen downloading new plugins, update the database properly + update job every time now REVERT:8f75af3d6edit the .dockerignore REVERT:4f4beeef9Create the database variable even when passing the variables, just in case REVERT:7347fe9bcupdate jobs only once REVERT:b509ce16eCopy the files after installing the requirements REVERT:64601ebf5Remove useless warnings REVERT:c9238f993Merge custom configs generation to avoid repetition REVERT:192c6755cUpdate db for the jobs that are ran only once REVERT:c14765c6cChange the way jobs are sent and how we update external plugins REVERT:888bedd51Change how jobs are send from the database REVERT:babb1c72cRevert "indentation" REVERT:44c74f9beRevert "indentation" REVERT:984b6c5f0ci/cd - speedup codeql by ignoring some folders not containing python files REVERT:355c947a4start jobs template + enhance menu REVERT:272de0b8bci/cd - fix codeql config path REVERT:d9fc713c4ci/cd - move codeql config to file REVERT:c2503d63dci/cd - add codeql REVERT:b098478bdenhance service + darkmode script REVERT:fa1739439ci/cd - init work on dependabot REVERT:82df3f17fci/cd - init work REVERT:f02adf300indentation REVERT:c1031cb2cindentation REVERT:e8581ecb4enhance news/menu/base + logs scripts REVERT:eb99d00daRevert "enhance news, menu + end logs scripts" REVERT:a7d3d0452enhance news, menu + end logs scripts REVERT:c7556a39aMerge pull request #358 from TheophileDiot/1.5 REVERT:e02e9c9ecEdit how plugins work with the UI REVERT:f1d7add73Merge pull request #357 from TheophileDiot/1.5 REVERT:1252d1651Add the jobs feature and add the link when using sqlite REVERT:2154c7f54Update database default DATABASE_URI REVERT:7957f63b8Merge pull request #356 from TheophileDiot/1.5 REVERT:73668b476Optimize plugin gathering REVERT:b3cfc1f01Remove unnecessary lines and add plugins_errors endpoint REVERT:b57e50db2Send needed settings with the services in ui REVERT:a0e66ab30Change Database default path for the sqlite file REVERT:fdd393826add ui work in progress REVERT:6b9a6a7e3Merge branch '1.5' of https://github.com/TheophileDiot/bunkerweb into 1.5 REVERT:277e37bceRevert "add ui" REVERT:05d4b77bbMerge branch '1.5' of https://github.com/TheophileDiot/bunkerweb into 1.5 REVERT:e7e43e64dAdd dark_mode to ui REVERT:d40a93cb7Revert "add ui" REVERT:d102f027fadd ui REVERT:b70d97671add ui REVERT:7db7aee7cMerge pull request #355 from TheophileDiot/1.5 REVERT:70844ca60Fix database with autoconf REVERT:1a7d8978bMerge pull request #353 from TheophileDiot/1.5 REVERT:93c74154afix fedora python deps bug REVERT:f2eabc0dffix centos python dep bug REVERT:d199f124bremove exits in ingress controller REVERT:3ec15eb4bUpdate the docs from dev REVERT:5a8f81256Merge branch 'dev' (softly) REVERT:d214352b7Merge pull request #352 from TheophileDiot/1.5 REVERT:891757dabAdd support for arm + change scheduler python version REVERT:8dd377562Merge pull request #351 from TheophileDiot/1.5 REVERT:630cf8b88Change the way services are sent to the UI REVERT:b0c09b4deMerge pull request #350 from TheophileDiot/1.5 REVERT:fa655e6f0Remove no longer used install.sh and uninstall.sh REVERT:c8fbcbeaeMerge pull request #349 from TheophileDiot/1.5 REVERT:32101c3dcMove UI deps, Make the DB compatible with PostgreSQL, MySQL and Oracle REVERT:035eed8f6ui - add custom PYTHONPATH in Dockerfile REVERT:2a3e24bd2Merge pull request #348 from TheophileDiot/1.5 REVERT:3984c4b0dSeparate deps and change prettierignore file and pyproject REVERT:47afdc88eMerge pull request #347 from TheophileDiot/1.5 REVERT:01bb6f5e6Stop converting the files content to base64 when sending them to front REVERT:c35874797Return dumps of settings instead of the dict REVERT:a8f27ccb1Merge pull request #346 from TheophileDiot/1.5 REVERT:edce79936Update the structure and the paths REVERT:04578aab3Changing path Linux folder REVERT:5ae714fc7Merge pull request #344 from TheophileDiot/1.5 REVERT:f65a4cdd6SMall tweaks on the UI + edit the ConfigFiles edits REVERT:06aa73fcfMerge pull request #343 from TheophileDiot/1.5 REVERT:0811aad7fEdit scheduler and change DB REVERT:858f6e00fChange python version REVERT:b279d0240Fix BunkerWeb gen on start REVERT:ef7fa5b4fMerge pull request #342 from TheophileDiot/1.5 REVERT:11bcd9824Merge branch '1.5' into 1.5 REVERT:bacef768cAdd integration manually in bunkerweb REVERT:5ec179affThe UI get the custom configs from the database REVERT:0e6a5f3f9Merge pull request #341 from TheophileDiot/1.5 REVERT:eec00ba2bUpdate the Database and make it easier to gen REVERT:479b556fbMerge pull request #340 from TheophileDiot/1.5 REVERT:375776e7dFix UI path_to_dict with the cache files REVERT:df62fd410Merge pull request #339 from TheophileDiot/1.5 REVERT:1f58d0c51Edit dockerfiles REVERT:6c07f9967Merge pull request #338 from TheophileDiot/1.5 REVERT:069b45f37Add some tweaks REVERT:850530cd0Merge pull request #337 from TheophileDiot/1.5 REVERT:01b414552Make the Database support every feature + updates REVERT:a12d013fcMerge pull request #334 from TheophileDiot/1.5 REVERT:5f8353c11Adapt everything so that the UI can work with every integration (some more tests are needed) REVERT:fe8962592Merge pull request #333 from TheophileDiot/1.5 REVERT:66fb266f8Centralize Database and optimize requests REVERT:7a03ed33fUpdate pip in Dockerfiles every time REVERT:b09c05d3bUpdate BunkerWeb deps REVERT:9c02d5f9eMerge pull request #330 from TheophileDiot/1.5 REVERT:7d743e198Update the database and the core plugins accordingly REVERT:ce6f01cf0Merge pull request #329 from TheophileDiot/1.5 REVERT:9140dc324Optimize Database connection and ApiCaller REVERT:81307c82cMerge pull request #328 from TheophileDiot/1.5 REVERT:0edef7c52Use Python 3.11 where we can REVERT:fe774e000temp nginx is dead, long live to the IS_LOADING setting REVERT:0bf402fd7Merge pull request #327 from TheophileDiot/1.5 REVERT:48242b9a3Get all config with generator REVERT:0b73ea856Merge pull request #326 from TheophileDiot/1.5 REVERT:09378458ddb.get_config() get entire config and doesn't filter anymore REVERT:100849023Merge pull request #325 from TheophileDiot/1.5 REVERT:8b54762fcFix db init with autoconf REVERT:cfaeb1013Merge pull request #324 from TheophileDiot/1.5 REVERT:7e53bfe55Fix gen for Docker integration REVERT:54530d535Merge pull request #323 from TheophileDiot/1.5 REVERT:79eea0e99Linting + starting to migrate bunkerweb to the 1.5 REVERT:316b84ad3Merge pull request #318 from TheophileDiot/Feature-specific-order-for-plugins REVERT:ba56c9f55Merge pull request #317 from TheophileDiot/Fix-scheduler-error-reload-nginx-linux REVERT:a8f79e58fMerge pull request #303 from TheophileDiot/Fix-custom-conf-disappearing REVERT:b2a7e053bMerge pull request #314 from TheophileDiot/Feature-blacklist-ignore REVERT:96e656273fix indent REVERT:01cecf14eMerge pull request #313 from TheophileDiot/Feature-max-client-size-edit-modsec REVERT:873ccad9bAdd MODSECURITY_SEC_RULE_ENGINE and MODSECURITY_SEC_AUDIT_LOG_PARTS (#292) REVERT:97bf473e1deps - add update checker for deps (#293) REVERT:5af2fb778Complex example using autoconf (#271) REVERT:bd4c94e83Add specific order for core plugins and check them REVERT:a96a8a8c2Fix incorrect message while reloading nginx + more details on error REVERT:446ff93a4Add ignore blacklist feature REVERT:5fdcc9e58add g/G to the available file measurement units REVERT:d207aa4bfVariable MAX_CLIENT_SIZE change the SecRequestBodyLimit value REVERT:57ad9d7eeFix old custom configs where never deleted REVERT:7860aeab9Merge pull request #312 from TheophileDiot/dev REVERT:cac220023Fix small typo in autoconf integration REVERT:5d9dc88ccMerge pull request #307 from TheophileDiot/Restrict-access-IP-NET REVERT:40863f28aMerge branch 'dev' into Restrict-access-IP-NET REVERT:67d514b53Merge branch 'master' into dev REVERT:51e96416dMerge pull request #304 from TheophileDiot/Fix-Endless-loading-after-update-service REVERT:ace1dfca2Merge pull request #308 from TheophileDiot/Fix-doc REVERT:b9e5badd9Fix last typos REVERT:a9865f850Fix typo in plugins.md REVERT:e3d0120a0Fix minor typos in the doc REVERT:9214bb939Merge pull request #309 from TheophileDiot/Fix-flask-dev REVERT:80c1b225bReplace flask development server with gunicorn REVERT:de0954facFix typos in the docs REVERT:27b4ff330Add the greylisting feature REVERT:06f65ffe2Change the exposed port to 7000 REVERT:b0a887a15Fix errors and warnings when editing a service REVERT:803ff8cb5Fix CUSTOM_CONF_SERVER_HTTP disappearing after 60 minutes (autoconf) REVERT:94ce249d7[#290] Fix typos in docs REVERT:478e98018ci/cd - temp disable k8s test REVERT:8f44e108bci/cd - add docker system prune REVERT:72caf907aci/cd - temp disable swarm tests REVERT:01acb1cf3ci/cd - temp disable nextcloud/swarm REVERT:fc3c7892dci/cd - add missing prepare for prod tests REVERT:2a04a5642ci/cd - update ruby version for CentOS builder REVERT:6afdb298flua - fix pcall for asn/country mmdb lookup REVERT:04019a617tests - fix nextcloud/swarm REVERT:34649bf33docs - add Ansible to README REVERT:469a5343eci/cd - remove old linux packages before building REVERT:4244399ebroad to v1.4.3 🚀 REVERT:66029a316tests - edit prod workflow REVERT:d0c245ba8tests - fix bug when testing if a swarm stack is healthy REVERT:5633d5ff5tests - remove mongo-express/swarm REVERT:61d57b4ebtests - fix mongo-express/swarm REVERT:76f035e21fix wrong DENY_HTTP_STATUS setting in docs, fix autoconf ghost/prestashop tests and some UI warns/errors REVERT:b35dbdffctests - fix ghost/docker REVERT:7e226301dtests - fix prestashop/docker REVERT:8f273a929ci/cd - fix missing comment chars REVERT:45f4e06acroad to v1.4.3 REVERT:7fe58ddd5tests - disable systemd start limit REVERT:561e64a89tests - road to debian REVERT:29933fdebtests - add unzip package to linux container REVERT:7915da6dfdocker - fix CVE-2022-3209 REVERT:d8f6c2756tests - fix configs perms for linux REVERT:cb56e7d04tests - add chown for custom linux configs REVERT:e84734314tests - fix linux/drupal (again) REVERT:4caae414dtests - fix linux/drupal REVERT:8a23b96bftests - disable linux/moodle REVERT:a4fd701d5tests - temp disable linux/proxy-protocol REVERT:39ed524f0tests - add missing variables.env for moodle/linux REVERT:d0e3f3ae2tests - call cleanup-linux.sh REVERT:b0fa57b05tests - replace restart with stop+start for linux tests REVERT:ec1136085tests - print logs when setup_test fails REVERT:3be348ebetests - add haproxy cleanup for linux tests REVERT:884ca0f6dtests - add missing variables.env files for linux REVERT:e4321629ftests - road to linux tests 🚀 REVERT:c277a33e9tests - add missing which command for fedora REVERT:512c60c51tests - add some debug info when linux/setup fail REVERT:e64cc29a8tests - create /run/php folder for rpm linux distros REVERT:42d29743blinux - fix 755 perm on /opt/bunkerweb REVERT:505d5c2aetests - fix behind-reverse-proxy/linux REVERT:70992a0b5tests - fix haproxy logging again REVERT:7e5465c59tests - fix haproxy logging again REVERT:f5606b693tests - fix haproxy directive REVERT:265742cd9tests - haproxy add logs REVERT:0580662cclinux - copy current variables.env to make temp one REVERT:8e15e2a40linux - set /opt/bunkerweb permissions to 755 REVERT:17801caebtemp disable arm REVERT:552588adftemp disable arm REVERT:5849c66e6tests - fix www.conf REVERT:052dc2346tests - increase php logs verbosity for linux tests REVERT:331c7e954tests - add debug log file for PHP REVERT:f71ad0f65php - fix fastcgi_params path REVERT:34c648830trying to fix PHP bug in Linux REVERT:5c99a4b0erefactor linux/start.sh and fix tests/cors www copy REVERT:eb6f0d673tests - fix purging wrong folder for linux tests REVERT:6ea38b1f7bunkernet - fix wrong import in register job REVERT:b5c07dda0tests - add cleanup for linux tests REVERT:17b6b0fdctests - fix PHP www.conf for Linux REVERT:512ed7200tests - add cors/linux REVERT:d8071e4c4tests - install php-fpm REVERT:790fa37aetests - fix behind-reverse-proxy/linux REVERT:6005a8f73tests - fix behind-reverse-proxy/linux again and again REVERT:09f56a1c6tests - fix behind-reverse-proxy/linux again REVERT:0c4d2edf1tests - fix behind-reverse-proxy/linux REVERT:d53c54d4btests - add behind-reverse-proxy/linux REVERT:093d426bcbetter management of registration with BunkerNet and fix syntax error in LinuxTest REVERT:3762c3874tests - copy variables.env for Linux tests REVERT:55525abf1tests - fix mattermost/k8s REVERT:23f8ec957UI - fix container CVEs REVERT:a38ca5138docker - dont generate config if already present REVERT:e92938f00autoconf - fix container CVEs REVERT:c2ad79a79Docker - fix CVE-2022-37434 REVERT:8eefb4bf5examples - fix mattermost/k8s REVERT:6d1ef606fexamples - fix nextcloud/k8s REVERT:95c4ce723enable bad behavior on default server and various k8s fixes REVERT:e295b020etests - increase redmine timeout and add pvc cleanups REVERT:1e499db50examples - fix gogs/k8s REVERT:a64276136disable bad behavior if client is whitelisted and fix redmine/reverse-proxy-multisite examples REVERT:115d517c7tests - add delays REVERT:7c1474cd8examples - fix moodle/k8s port number REVERT:305870cc2examples - edit moodle/k8s port number REVERT:3df0f8505tests - add delay to moodle REVERT:897528b73tests - fix magento/k8s again REVERT:4f4c446f7examples - fix magento/k8s again REVERT:69848dcccexamples - fix magento/k8s REVERT:0516f0a83tests - assign bunkerweb-controller to srv1 REVERT:41524a9e3tests - force pv REVERT:0d44b098ftests - fix prestashop URL REVERT:0e315dc5ftests - edit prestashopHost value REVERT:5741391detests - change k8s service type of prestashop to clusterip REVERT:6adff9cebtests - increase timeout and remove pvc for prestashop/k8s REVERT:97a2caf06tests - fix Kubernetes missing variable assign REVERT:865f4f1b5tests - fix prestashop/kubernetes REVERT:e8305b0b6tests - fix missing prestashop/kubernetes.yml REVERT:840b875f7docs - edit plugins page REVERT:978bbe9caexamples - fix missing configs subfolder in nextcloud/bw-data REVERT:502c9f2feexamples - fix radarr/swarm REVERT:1c4f8bf55tests - automatic volumes prune for swarm tests REVERT:b6e2ad22atests - fix joomla/swarm REVERT:216686fc8tests - add delay parameter REVERT:d648b1fbetests - increase magento timeout REVERT:d3b725294tests - wait until swarm services are running REVERT:a48200bc0examples - fix reverse-proxy-singlesite/swarm REVERT:b429dd804tests - increase timeout for swarm healthy check REVERT:0440c61d0examples - fix gogs/swarm REVERT:ae36b9899docs - quick edit on PHP REVERT:9a83fadd8examples - fix gogs/setup.swarm.sh permissions REVERT:09141f204examples - fix magento/swarm REVERT:edf5421bfexamples - fix permissions for magento/setup-swarm.sh REVERT:c67564c7ctests - increase timeout when doing requests REVERT:b07637009examples - fix mongo-express/swarm REVERT:ec35b0a54examples - fix mattermost/autoconf REVERT:95e3022ebexamples - fix autoconf/reverse-proxy-singlesite REVERT:d63538fd5examples - fix wordpress custom conf variable name for docker/autoconf REVERT:e01b24072tests - ignore error when replacing patterns in files (binary files) REVERT:217924fe4examples - fix reverse-proxy-singlesite regex REVERT:bb6d02e0fexamples - escape dollars in reverse-proxy-singlesite compose files REVERT:5c42fb58dtests - fix reverse-proxy-singlesite REVERT:2f8c5a1e9examples - fix host for reverse-proxy-multisite REVERT:af866e825edit docs/integrations for ansible and fix examples/mongo-express compose file REVERT:e90d4cc7etests - fix json for reverse-proxy-multisite REVERT:70ac3c01btests - fix missing arg no_copy_container REVERT:07a962466tests - inline configs for docker/autoconf REVERT:87c57c67ctests - refactoring on the road, still needs some work REVERT:8fb03a317tests - on the road of refactoring REVERT:dc8570ca8tests - add status type REVERT:151378570tests - refactor mattermost example REVERT:4e7d795eatests - support custom cleanup-kubernetes.sh script and refactor some k8s tests with helm charts REVERT:cc9d228abupdate compose version to 3.3 for swarm examples so config directive is supported REVERT:181957147remove trailing space in DockerController and add missing bunkerweb prefix for autoconf-configs example REVERT:324feb593autoconf - fix missing configs update for DockerController REVERT:22398d567cors - fix typos in autoconf.yml REVERT:5119c8da7gogs - missing setting for autoconf REVERT:0fca93e3etests - sleep 30s between autoconf tests REVERT:17e14f4d5tests - fix wildcard with sudo REVERT:3a46d318etests - remove only content of subfolders REVERT:4eff0c3f9tests - fix behind reverse proxy url REVERT:bf58a17b8gogs - add setup-docker REVERT:08d8bc880tests - remove whole subfolders in bw-data REVERT:b38f7c54etests - add kubernetes-configs and fix missing s in urls REVERT:06f7fb096tests - fix docker-configs (again) REVERT:b7101eb47tests - fix docker-configs REVERT:a08b51bd0tests - fix gogs expected string REVERT:b2bcfb8c7tests - fix hardened expected string REVERT:d3014b42fexamples - refactoring in progress REVERT:7eae49719tests - prevent default rate limit REVERT:be21b3933tests - fix sudo cp again REVERT:7bb881aa3tests - fix rename REVERT:a607bd67ctests - replace python cp with sudo cp REVERT:6d06a32cctests - list example_data as root REVERT:c5526ef2fMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:75b2ae868tests - fix example_data path for docker REVERT:72965e230Merge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:201e2cf0fCorrection logs Linux REVERT:203397444tests - init cors and fix example_data path for autoconf REVERT:d8c8ceab3tests - fix LinuxTest setup and init work on integrating examples with the new test system REVERT:c02d888b3examples - rename setup scripts for drupal REVERT:9a9f9ebf3examples - fix linux-setup.sh for drupal REVERT:6e381ee02tests - disable copying bw-data files for k8s and swarm tests REVERT:0ee09d47dtests - force removing directories with AutoconfTest REVERT:da2f6cb4ftests - force removing directories with DockerTest REVERT:d1d2e51a3cleanup tests directory and init tests refactoring for drupal REVERT:c14b08faaexamples - edit authelia configuration.yml file for Linux integration REVERT:80fee58e4bunkernet - add default api server in jobs REVERT:37690a7a4configs - enable default server if TEMP_NGINX is set REVERT:b3fdd109alinux - fix wrong variables.env path when running jobs once REVERT:193449512Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:f5ede7897examples - fix authelia variables.env REVERT:767a7ab31Adjustements doc Ansible/Linux REVERT:81b370366wait until Linux test container is initialized and fix variables.env for authelia REVERT:44fbf0315authelia - extract tarball to tmp REVERT:02db54ce0examples - follow redirect when downloading authelia for linux REVERT:14d61854eadd sudo to linux dependencies and curl to linux test images REVERT:6f35561fatests - fix cp and end_fun for LinuxTest REVERT:2505bc015tests - add linux to authelia kinds REVERT:b1df38374tests - temp enable docker REVERT:410212b15tests - run docker cp in a shell REVERT:f2ac7bca7tests - fix typo in LinuxTest REVERT:a0948923etests - copy local files for Linux tests REVERT:458ebe07ftests - dynamically find deb/rpm name REVERT:2205043e7tests - fix LinuxTest.docker_exec() REVERT:d370f1b05tests - add missing chmod import to LinuxTest REVERT:bf6dd93aatests - replace rmdir with rmtree for LinuxTest REVERT:773517311Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:850a8057cignore CVE-2022-30065 until we have a fix REVERT:e6271ccd6Final proofreading FPM REVERT:f0ddb8328docker - fix CVE-2022-30065 for autoconf REVERT:f260bcf23Small adjustements REVERT:fa319ec10tests - fix argv len check REVERT:029406453tests - fix typo in LinuxTest REVERT:f47ab0adctests - integrated LinuxTest REVERT:eca010231FPM Linux/Ansible Doc REVERT:4d61e96e4tests - LinuxTest on the road REVERT:c9c730346tests - fix linux.sh REVERT:58a82ddcdtests - copy Linux packages to local directory REVERT:8062d043ctests - fix Linux dockerfile path REVERT:0a09f8a75fix CVE-2022-29458 REVERT:bb425bc36tests - init work on Linux tests REVERT:aa729daebexamples - remove double $ from kubernetes authelia REVERT:7edd55544fix k8s example for authelia and ignore error code when doing debug_fail for k8s tests REVERT:0fd77a809examples - fix typo in kubernetes authelia REVERT:720f36f47tests - init kubernetes refactoring REVERT:ea98b453dtests - use unique domains for swarm tests REVERT:4bd0129e4tests - also edit root domain REVERT:6e47b2991tests - add sleep in the end of SwarmTest.init() REVERT:abc500a4dtests - fix domains for SwarmTest REVERT:378047794examples - fix authelia swarm compose version REVERT:4a5e50005fix typo in SwarmTest and fix authelia swarm example REVERT:3b73c50c3tests - ignore docker stack ps return code REVERT:ba6fddb56tests - init swarm refactoring REVERT:9ecd2bd98examples - add missing network aliases to authelia autoconf REVERT:7bbf77b7afix authelia autoconf example and debug fail before cleaning tests REVERT:f02fe1ed9tests - remove only subdirectory on new tests and add cleanup when test failed REVERT:0383cadd6tests - fix compose filename for autoconf tests REVERT:aeba0ba72tests - add missing AutoconfTest object REVERT:67608a463tests - add missing decode REVERT:8b3b1291ctests - from replace/rename functions to class method REVERT:1c5c81d2ctests - add missing import REVERT:fa2d52d80tests - remove useless log and return boolean from Test.end REVERT:68bf5ef85tests - remove wrong cleanup call REVERT:424b37bectests - change permissions as root REVERT:2780ee190tests - add debug_fail function REVERT:07b0bb38ddocker - fix CVE-2022-29187 for ui and autoconf REVERT:b47c2696edocker - fix CVE-2022-29187 REVERT:fdb8ca3catests - replace internal _log with logger.log REVERT:eb59a9377tests - init refactoring for autoconf REVERT:2e0542dbbtests - ignore case when performing test REVERT:0a996bf12tests - replace match with search REVERT:48a6ba632tests - fix rm command REVERT:991ddb9ebtests - remove file as root REVERT:1e1d7d7f1tests - replace variable typo in get request REVERT:ebc94f515tests - add missing char when replacing Docker volumes REVERT:e4f6017d6tests - replace example domains with test domains REVERT:dfc5f2e79tests - export runner env REVERT:c07f85a42Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:ab57be657tests - fix missing copytree import and self parameter REVERT:5f79aea4bfpm single/multiple docker&autoconf REVERT:cc760a646tests - fix datetime import again REVERT:db2c35cb3tests - fix datetime import REVERT:28f1b4f73tests - rename variable REVERT:e1183a0d4fix tests.json for authelia and exit when test exception occurs REVERT:16573a397tests - do not run as root REVERT:de8cee491tests - add missing imports REVERT:56afbd457tests - run as root REVERT:590ad46cdtests - fix missing chmod import and Test.init log call REVERT:8d580bc16tests - fix missing Test import REVERT:a91fc7307tests - fix indent and isfile import REVERT:773a37d45Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:b64af8526tests - DockerTest on the road REVERT:0d3e1e2a1Update the plugins docs REVERT:85217b57cFix a typo in the plugin page in the docs REVERT:ba75154d0Add url_for function to custom plugins templates REVERT:c055ec7ecFix duplication in plugins REVERT:2c4efe9d0Add Plugin Pages feature REVERT:795dfc077Add static map files REVERT:8b4b3f3b0ansible docs REVERT:2e4758e94tests - DockerTest improvement REVERT:c155227ectests - init work on refactoring REVERT:dde185141tests - increase timeout for magento REVERT:e62523d1dlua - use pcall with mmdb functions REVERT:658ab7504docs - add ansible diagram REVERT:8d6397a6bMerge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:f5c86cc4eexamples - add cors example REVERT:8760110fbMerge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:cc4f0b26aQuickstart Ansible and integration REVERT:7b769361acors - init work on core plugin for CORS REVERT:97e607110linux - rename bunkerweb-ui.env to ui.env REVERT:c3ee7929bdocs - change target of the web UI demo link to blank REVERT:969a1e5d7Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev REVERT:5bf59c85ddocs - replace web UI gif with YT video REVERT:430f665cdMerge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev REVERT:5be21f9bfAdding www folder REVERT:afdd4de5afix regex checks with *_CUSTOM_CONF_* setting, add doc about DENY_STATUS_CODE REVERT:5586b3733misc - add DENY_HTTP_STATUS setting (403 or 444) REVERT:90e58f261fix ui.env path for Linux integration and add docs for autoconf with rootless docker REVERT:a00607af2docs - add instructions for podman REVERT:e880b7d59docs - add infos about Docker in rootless mode REVERT:fc925ccb1edit docs typo for UI and variable typo in autoconf REVERT:571422131ui - fix CVE-2022-2097 REVERT:287e763e0autoconf - fix CVE-2022-2097 REVERT:89f81140acontainer - fix CVE-2022-2097 (again) REVERT:a5c98f709container - fix CVE-2022-2097 REVERT:429214727tests - fix data folder permissions (again) REVERT:6b1c5a93etests - fix data folder permissions REVERT:fb85d1d2dautoconf - fix typo in variable REVERT:fdcbc8d36custom conf - fix wrong path with multisite configs REVERT:b2bb93bcfexamples - fix docker-configs again REVERT:2b59086f6examples - fix docker-configs REVERT:e09d4901econtainers - fix regex for *^CUSTOM_CONF_* REVERT:3594618e4examples - fix typo in docker-configs (again) REVERT:e44311281examples - fix typo in docker-configs REVERT:738e3b6e1containers - use python hack to get env var values from string REVERT:5ac80a135containers - replace compgen command with a python hack because compgen -e do not display var with dots REVERT:8f258486efix multiple CVE with curl/libcurl and add autoconf/docker CUSTOM_CONF configs examples REVERT:2dc18a794autoconf - support both configs from files and autoconf REVERT:e0a700506autoconf - init support of custom variables using labels REVERT:385b7c413docs - add docs for custom config using labels REVERT:e25babe3dcustom conf - docker REVERT:a5457a164custom conf - init setting support REVERT:0a1e8be71examples - add missing setup.sh for mattermost REVERT:70c60f2a9tests - add mattermost and radarr REVERT:f2dfb0172examples - edit mattermost and add radarr REVERT:1a8eef2c8fix autoconf import for IngressController and init work on mattermost example REVERT:cb106a112autoconf - fix indent in IngressController REVERT:492648eebautoconf - fix 410 exceptions (k8s) REVERT:1425ad0b4docs - update settings list REVERT:f7290b2c7v1.4.2 release REVERT:c0a8a356clinux - include bwcli in /usr/local/bin REVERT:40007b086add slack to official plugins and init work on EXTERNAL_PLUGIN_URLS setting REVERT:6478512e4scheduler - only send /data folder if apis are present REVERT:7aa6852d3autoconf - fix missing scheduler in autoconf mode and missing apis list REVERT:7bba81b16autoconf - fix wrong variable name for environment REVERT:5cb61380dautoconf - add missing call to ConfigCaller constructor REVERT:b2758cea7autoconf - init work on _get_static_services method REVERT:a18d77aeeautoconf - init work on static server configs as env var REVERT:4a699ef6cfix missing local Linux images import in ci/cd, and fix bug related to jobs in Linux integration REVERT:5690a58abfix IFS checking permissions REVERT:e55928a37fix bwcli commands when using Linux integration REVERT:0f2388b1ffix permissions check when file has space in the name REVERT:2b43a9cbfMerge branch 'dev' of https://github.com/bunkerity/bunkerized-nginx into dev REVERT:5ecf39ee0Fix web-ui example with X-Script-Name REVERT:ad091493cexamples - add various certbot-dns examples REVERT:a65606c36examples - add certbot-dns-ovh REVERT:cd0d70b8fcache dev Linux images in ci/cd and disable site config generation for autoconf/swarm/k8s REVERT:e21a35017plugins - support log_default() hook, same as log() but for default server REVERT:c563731e8autoconf - fix overwrite configs file when using Docker autoconf REVERT:3c417d2fflinux - fix fedora NGINX version in Dockerfile, fix missing arg when building DEB/RPM and force NGINX version DEB deps REVERT:970082f92linux - force NGINX version in RPM deps REVERT:4a2504c3breflect ci/cd changes to dev REVERT:fd0c7b1e5ci/cd - add automatic build for Linux images REVERT:1e6d62ce7fix packagecloud yank name REVERT:1a4e21481docs - edit supported architectures for prebuilt Docker images REVERT:bcaca6f03v1.4.1 release REVERT:424214fd5add changelog and add missing s in authentik url REVERT:82b42d5b9Merge pull request #259 from Brawdunoir/master REVERT:db4e2cf26update linux docs, minor fix in ingress example and update default value for bunkernet job REVERT:0ef82619btemp disable automatic tests for authentik and test automatic arm build on dedicated hardware REVERT:f2655e331remove arm build again, fix proxy_*_timeout directives and add authelia example REVERT:d51ae1c1bRemove USE_ before authbasic plugin settings REVERT:cd0438b8csupport REVERSE_PROXY_*_TIMEOUT settings, remove useless push in CI/CD and try to build arm on GH runners REVERT:f9a042526add docs about compiling BW from source on Linux, add docs about packages pinning on Linux and fix regex for REVERSE_PROXY_AUTH_REQUEST and REVERSE_PROXY_AUTH_REQUEST_SIGNIN_URL REVERT:15ac64b05let's encrypt - fix bug when AUTOCONF_MODE=yes REVERT:e0f8895e9init support for auth_request and add authentik example REVERT:e85229835don't send local IP to BunkerNet on default server, fix certbot new when MULTISITE=no and fix unknown reason in get_reason REVERT:972a284efdocker - drop support for prebuilt arm images REVERT:5258d8e58docs - edit linux install procedure REVERT:acb4bea97reflect CI/CD changes for master pushes REVERT:42067e864GHA - temp disable armv7 build until we have a fix for cryptography dependency REVERT:217bddabfGHA - different caches for armv7 and armv8 images REVERT:c5fba1367fix GHA typos REVERT:1b21f9eacfix UI tag in GHA jobs REVERT:389e05094fix links in docs and change cache location for GHA jobs REVERT:05a89c303fix registry URL in GHA jobs REVERT:a0ed8a27eadd debug flag to GHA buildx steps REVERT:d0ac5e305update GHA actions version REVERT:b16f8f11aupdate GHA actions version REVERT:a23ed06e6fix typo in GHA jobs REVERT:6b9be078brefactoring of GHA jobs REVERT:8e198ed82linux - fix documentation link in systemd unit files REVERT:c3b527afeactions - fix RPMs path REVERT:972e5471dactions - fix linux deb/rpm generation REVERT:b246c6d7efix wrong branch name in actions and image name for linux tests REVERT:b78fd5542fix freetype CVE REVERT:945241339actions - rename main branch to master REVERT:1af2264fatemp stop push to private repo REVERT:6f28708c1docs - add missing setting REVERT:a9f886804bunkerweb 1.4.0 REVERT:3a078326cMerge pull request #199 from Myzel394/patch-1 REVERT:d43b82b75remote API - only do action if 403 REVERT:3850cacb9prepare for v1.3.2 REVERT:c00c7f46alua - verify certs when doing HTTPS requests REVERT:163af4a49prepare for v1.3.2 REVERT:98e85eb99docs - update security tuning sections : distributed blacklist and request limit REVERT:2e63bb025docs - reflect kubernetes/swarm changes into the doc REVERT:6546a0edbdisable country ban if IP is local, update default values of PERMISSIONS_POLICY and FEATURE_POLICY, upgrade archlinux packages before testing REVERT:ab0038174ui - fix ROOT_FOLDER bug in serve-files.conf REVERT:9f7097de0request limit - fix some LUA code REVERT:24d6337a5limit req - multiple url support REVERT:bfb5319c1limit req - add burst and delay parameters REVERT:4c77a1482use annotations as env var in Ingress definition, fix cidr parsing for reserved ips, fix missing empty when job is external, fix ping check for remote api and init work hour/day support for request limit REVERT:4e45fa387integrations - acme without shared folder when using k8s/swarm REVERT:a9a26b82dfixed typo REVERT:00d91dcaajobs - move certbot hooks to python REVERT:650ad7ea4integrations - fix missing acme folder when using Swarm or Kubernetes REVERT:7045c0c2bjobs - fix encoding error on CentOS REVERT:f0f432487remote API - ban IP from distributed DB REVERT:fdc02be05remote API - basic send of bad IPs REVERT:fb799765ajobs - fix str/bytes hell REVERT:d53f02b5bapi - client side (untested) REVERT:7b9722facjobs - add remote API REVERT:31ed4ff83centos - update ca-certificates in install script REVERT:bc5f3ee88fix CVEs and add init to Debian test image REVERT:a6b21aae8fix typo in settings.json, bump Debian to bullseyes, init support of Arch Linux REVERT:64aa9c253init work remote API REVERT:5d94cc8f4docs - init changes about storageless REVERT:e7ee21cbbantibot - fix path for templates and data REVERT:a0f8cbdacantibot - fix LUA typo in recaptcha mode REVERT:178d7a684Merge pull request #182 from Nakinox/patch-2 REVERT:ca81535bbswarm/k8s - less storage, more API REVERT:062fa3e78integration - continue work on storageless config for k8s and swarm REVERT:95f2d2af9Update docker-compose.yml REVERT:e55dff812api - init work on storageless configuration REVERT:f0f1c79d4v1.3.1 release REVERT:3d2f5e238conf - add REVERSE_PROXY_KEEPALIVE REVERT:b079c99fbMerge branch 'patch-15' of github.com:thelittlefireman/bunkerized-nginx into keepalive REVERT:2e403c6ebconfig - add CUSTOM_HEADER REVERT:f75a05584config - add REVERSE_PROXY_BUFFERING REVERT:148edf681tests - add github token to trivy scanner REVERT:a19d8aa04Merge pull request #180 from vepito/vepito-patch-1 REVERT:480cff86bMerge pull request #179 from thelittlefireman/patch-16 REVERT:35df3423dmissing blank line REVERT:29f4069deswitch the use cases REVERT:72e438459Fix typo related to non-HTTP configuration REVERT:a4a264773jobs - fix docker reload and only do cron jobs when necessary REVERT:892e53369Missmatch in docs with modsec folder REVERT:a05614160deps - use ModSecurity v3.0.4 instead of v3.0.5 to avoid memory leak REVERT:0772a9ba8docs - edit badge version REVERT:33e0ffd5bMerge branch 'master' into dev REVERT:4cb3e089elinux - git SHA1 commit in install.sh REVERT:8808f161cdocs - dev to master links and VERSION upgrade REVERT:1c60ec980tests - fix volume wait with linux tests REVERT:b13ff3456add REDIRECT_TO_REQUEST_URI variable and edit environment variables docs REVERT:58f2926e9docs - various examples fixes REVERT:9de628f3eMissing proxy_set_header for keep alive REVERT:6cc1abc89Allow keep alive connection when ws is off REVERT:a824e1568linux - rename cron REVERT:fd52bb7c8linux - fix cron jobs REVERT:0938b20ebUI - use sudo for Linux integration REVERT:b948e08bdUI - use systemctl on Linux REVERT:fde14d162linux - fix unknown scheme error and do nginx reload as root in UI REVERT:8a4eb3f2aremove .site files (gen), uninstall remove folder at the end (linux) and run jobs when reloading local instances (UI) REVERT:2a0b84074ui - fix bug when Docker is used but Swarm is disabled, add jobs from API /reload and fix docker-compose doc REVERT:aec22d1a8ui - edit docs and fix CSRF REVERT:028fc61b4docs - add dns_resolvers and permissions to Linux REVERT:a903960b4docs - fix missing subfolder in Linux quickstart guide REVERT:a28f06f08linux - run temp nginx to solve let's encrypt challenges REVERT:6c8bc6b34tests - fix Linux systemd bug when writing to /tmp folder REVERT:2b3b4a5c3linux - systemd support REVERT:57e4247ealinux - systemd unit file REVERT:f9d4e9089docs - edit k8s php service port and append suffix to hosts REVERT:4f024ec56docs - add DNS_RESOLVERS for k8s integration REVERT:bc46fc3d4append suffix to ingress hosts REVERT:0be1da18aremove old conf before generation, dynamic DNS for PHP and reverse proxy and swarm fixes in quickstart guide REVERT:3cedc0ae1quickstart guide fixes REVERT:f1d5c07ccautoconf - various kubernetes fixes REVERT:c9a6b6c27autoconf - fixed infinite lock REVERT:b199464a7various bug fixes related to Swarm integration REVERT:4a9d64d9dadd favicon to web UI and fix some tech docs REVERT:31536a3felinux - reload as root REVERT:7b47c7304examples - minor fixes in architecture images REVERT:83e7ce9cdexamples - polishing before next release REVERT:0ad5159a3docs - add changelog for next version REVERT:6240d8e28ui - read variables.env when Linux is used REVERT:2f80f64dddocs - last polish REVERT:e98da9b63docs polishing and fix install.sh gpg --verify REVERT:d9f770696docs - web UI REVERT:75f299978docs - special folders REVERT:ef34b2cecdocs quickstart / multisite REVERT:9b9110214docs - quickstart guide / php REVERT:9e2a8070edocs - quickstart guide / reverse proxy REVERT:733136ac1docs - init quickstart REVERT:fa172ce5adocs - linux integration REVERT:f6a9184aedocs - k8s integration REVERT:d37dc2b62docs - swarm integration REVERT:f7c115edfdocs - add autoconf doc to Docker section REVERT:dfbb09136docs - init integrations/Docker REVERT:8e4a65fecfix global.env generation and add web UI gif to README REVERT:0573ba7b5ui - centering things without breaking sticky navbar and menu REVERT:bcd421de0ui - various bug fixes more or less related to UI REVERT:2ec28c79cdocs - fix README toc REVERT:fec60a4b1ui - minor styling fixes REVERT:dd7d1a2c7ui - fix example, subpath behind reverse proxy and add socket proxy rights for swarm REVERT:0c1883472docs - edit kubernetes overview image and add configuration section on the readme REVERT:4e6eab794docs - fix wrong swarm image REVERT:b23135b66docs - add docker and kubernetes images REVERT:ace9be397docs - add autoconf and swarm images REVERT:8958e5107docs - add overview image REVERT:b2cfc15c2security - add security policy REVERT:94bef079aexamples - add architecture images REVERT:50266c228examples - add the last missing README.md stubs REVERT:22e2fe869examples improvement - added some README.md stubs REVERT:55186bbefexamples improvement - hardened, joomla, kubernetes, load-balancer and moodle REVERT:d8286ced7examples improvement - certbot cloudflare and wildcard, clamav, crowdsec, ghost and gogs REVERT:44de2253dexamples improvement - traefik alternative, autoconf reverse proxy and basic website REVERT:6d73fbdedexamples - update authelia and autoconf-php REVERT:b6809266aautoconf - let's encrypt support for ingress controller REVERT:4e178b474autoconf - basic ingress controller support for kubernetes REVERT:021147f9dautoconf - fix wait and redis REVERT:5a26d06c8autoconf - fix infinite lock and honor DOCKER_HOST env var REVERT:bc01427deignore CVE-2021-36159 and redirect job logs as root when using autoconf REVERT:652614f41autoconf - use DNS for Swarm instances discovery REVERT:24d9cce82autoconf - various bug fixes in Swarm mode REVERT:f866ef632autoconf - minor fixes, prepare Swarm testing REVERT:1a32e7c02autoconf - various bug fixes with DockerController REVERT:7180378d0autoconf - init Config refactoring REVERT:6e66571fbvarious cleaning REVERT:f44e41cedjobs - lock and reload management REVERT:26db144dfautoconf refactoring and fix CVE-2021-36159 REVERT:a68ad53c3autoconf - controller classes REVERT:01bba1d3fautoconf - init refactoring before k8s integration REVERT:059707443k8s - init work on parsing ingress rules, helpers to setup on k8s, basic examples REVERT:bc3c17a2fexamples - init k8s example REVERT:556836b49autoconf - init annotations parser for k8s REVERT:22612f175minor edit on Linux tests and init work on k8s API REVERT:50c279617jobs - improved log and reload management REVERT:ef8969e2ccertbot - add USE_LETS_ENCRYPT_STAGING=yes/no env var for using staging or production servers of let's encrypt REVERT:0dc2a5ec2edit visibility of Job members and integration of a generic checker for nginx REVERT:9a207dfdcfix missing import in generator, expand networks to ips in jobs and init work on a generic checker with shared dict and redis support REVERT:a60fbbb5bhotfix - fix CVE-2021-33560 REVERT:a1b9010d9pull v1.2.8 fixes when applicable REVERT:3178545c2v1.2.8 release REVERT:36b8760d4resolve bugs on the stable version REVERT:8bb6676f5settings - fix PHP_* again REVERT:4234f82c0settings - edit EMAIL_LETS_ENCRYPT regex REVERT:b99fb27dffix missing parameter when calling reload in autoconf and edit REMOTE_PHP_PATH regex REVERT:876fcd181conf - add WORKER_PROCESSES REVERT:26dc79615jobs - fix line edit REVERT:280d18986jobs - avoid reload when not necessary REVERT:5f845680fjobs - edit referrers and user-agents data and init work on autoconf integration REVERT:d12369c90jobs - various bugs fixed and old files removed REVERT:366e39f59jobs - SelfSignedCert, runner and reloader REVERT:71741b2d3jobs - cache management REVERT:2fca4cd01jobs - logging and error management REVERT:fccf14627jobs - python stubs REVERT:b3684efafjobs - init work on refactoring REVERT:82548378acrowdsec - move as external plugin REVERT:b926b0db6examples - use example.com instead of website.com REVERT:6713f56eclinux - fix centos install REVERT:2b923c05ccompile and install LUA 5.1.5 to /opt/bunkerized-nginx/deps and introduced REDIRECT_TO feature REVERT:71cf3cf5cuse local sources when building Docker image, add LOCAL_PHP and LOCAL_PHP_REMOTE to settings.json and fix pip bug related to removed working directory REVERT:8e3dbf1c7fixed some fedora bugs, support LOCAL_PHP and LOCAL_PHP_PATH and sample variables.env REVERT:49ada6a8clinux - init work on fedora support REVERT:947e86f7clinux - uninstall script REVERT:a12561a85remove useless nginx-keys folder and add lua_package_cpath to http conf REVERT:6b19bd026deps - add cjson LUA files to deps folder REVERT:6738b28b9deps - move dependencies to dedicated /opt/bunkerized-nginx/deps folder to avoid messing with the system REVERT:010c0fd6drename gen/requirements.py to requirements.txt, add git/bash to Docker deps and fix typos in README REVERT:ecf30a71fdeps - init work on single install script REVERT:ffc4fc950deps - manual compile/install of libmaxmind and upgrade lua-resty-core REVERT:b9955699bMerge pull request #152 from thelittlefireman/patch-11 REVERT:860fd1aceUpgrade desps REVERT:eb5d13fb8Upgrade lua-nginx module to 0.10.20 REVERT:ca41987cdUpgrade corerules to 3.3.0 & modsecurity to 3.0.5 REVERT:3af1b397fUI - digging bugs from services, still some work to do REVERT:72a09eac6UI - add CSRF protection REVERT:0d3f7d392UI - admin authentication and bootstrap update REVERT:6be082e0aUI - init work on admin account REVERT:4947796c9UI - fix instances bugs REVERT:ba197dfa4UI - bind gunicorn to 127.0.0.1/0.0.0.0:5000 REVERT:4dd1ff847UI - copy from helpers, systemd service and instances page update REVERT:f771ec43fui - init Instances class to support Linux and API for Docker/Swarm REVERT:e241b0c93logs - move everything from /var/log to /var/log/nginx REVERT:d03a1a6e3linux - add jobs.log REVERT:2c9c9fb62linux - run master process as root REVERT:deb28c599autoconf - fix folders REVERT:2ea7331dajobs - disable post-jobs when SWARM_MODE=yes on SIGHUP REVERT:92ee40819whitelist - fix /.well-known/acme-challenge whitelist for let's encrypt REVERT:2ccfb26e8docker - fix CVE-2021-33560 REVERT:70f9f8417templates - add missing new line when necessary REVERT:c4aef1d60authelia - choose portal or auth basic mode REVERT:a385183d8authelia - various fixes REVERT:cec47f3a7body injection feature and add authelia to documentation REVERT:c894c8370authelia - add variables to settings.json REVERT:f73b088f7authelia - initial work REVERT:130c6752dMerge pull request #148 from aFresquetIntech/dev REVERT:f97ea6785Create .env REVERT:850429986Correction REVERT:4a8da40cfreverse-proxy-zammad REVERT:0114c7b09examples - edit basic PHP REVERT:bebe89afblinux - edit path for default errors, ignore comments in variables.env, install/prepare certbot REVERT:b2cceb608linux - fix centos REVERT:37f5e4ed7linux - fixed debian/ubuntu but still some work needed on centos REVERT:98568a57clinux - fix /var/log and typo in daemon directive REVERT:499192287linux - fix daemon directive and rights on /etc/nginx REVERT:bcb8acc36linux - add RX permissions to /opt REVERT:a9279053alinux - add executable right to gen/main.py REVERT:60057a17elinux - fix tests docker cp and pass single -c argument to su REVERT:d0366fcc0linux - started work on bunkerized-nginx command REVERT:b448d91caactions - fix centos test and docker image name when pushing REVERT:e309ce6fddocker - fix permissions on /opt REVERT:37090dc66actions - fix manifest error with buildx and load REVERT:6bb6facd8add load: true when autobuilding images and move from /bin/sh to /bin/bash REVERT:a1fcbd4b8fix actions and configure REVERT:09a2a4f9egithub actions refactoring REVERT:1e02368e8linux/docker - common /opt/bunkerized-nginx folder REVERT:bbb5134a3fix configure arguments and CRS include REVERT:b0f93fb84fix Dockerfile again REVERT:c892f037dfix Dockerfile REVERT:731c0f61dlinux - init work on installer REVERT:93543d396Linux - use the same dependencies script for Docker REVERT:5ec9e6ab4linux - CentOS 7 install REVERT:cc0d0af8dlinux - ubuntu installer REVERT:43d2097d1linux - nginx install on Debian REVERT:f880e5e2alinux - continued work on install helpers for Debian REVERT:9636013f5linux - started work on installer REVERT:15bdb076chotfix - fix docs get_git_branch REVERT:d62c4f466v1.2.7 release REVERT:ad52ef326autoconf - prevent race condition by checking health state REVERT:3bd3b6fd7Merge pull request #145 from thelittlefireman/patch-10 REVERT:e41acc20cUpgrade ModSecurity-nginx to v1.0.2 REVERT:3c721dc2aadd HEALTHCHECK to Dockerfile and append 10.0.0.0/8 to DNSBL whitelist REVERT:491d879fejobs - cleaning the mess when using autoconf without swarm mode REVERT:52534510efix bug when AUTO_LETS_ENCRYPT=yes and certbot can't resolve challenges REVERT:2c7337576jobs - fix syntax error REVERT:9e4961ccbdocs - rename sitemap to bypass rtd rewrite REVERT:01857d8acgen - display the reason when ignoring a variable REVERT:ab9f9e0a4jobs - fix jobs when MULTISITE=yes REVERT:29dc64ca3actions - add Docker cache to speedup auto build on the dev branch REVERT:b5cd4e037docker - build and push images from GitHub actions because of future DockerHub restrictions on autobuild REVERT:16101144cself-signed cert - fix bugs REVERT:95510e6e1settings - add underscore to CUSTOM_HTTPS_CERT/KEY regex REVERT:dd5890e76geoip - fix bug when using GeoIP REVERT:c3a437fa8docs - rename the sitemap to avoid conflicts ? REVERT:518ddd323docs - custom robots.txt REVERT:177a82ee6docs - automated sitemap.yml REVERT:39db7b368v1.2.6 release REVERT:9442e5914jobs - fix jobs in Swarm mode REVERT:fcc6b3b5evarious bug fixes related to Swarm REVERT:678ad70b0docs, various fixes and certbot-cloudflare example REVERT:e8f5db0b2docs - add plugins system REVERT:8295f6aebplugins - clamav example REVERT:388fc1a0eplugins - started basic plugin system REVERT:62217a321add contributing guidelines and license REVERT:53e433b1areadme - replace some badges REVERT:f640157b1Merge pull request #138 from bunkerity/feature-request-template REVERT:d646f3e5bUpdate issue templates REVERT:4b31d005ecrowdsec and generator fixes REVERT:d2135c19cdocs - road to v1.2.6 REVERT:8cda1baf7fix web ui multiple variables and add default error pages REVERT:445032406dnsbl - disable checks when IP is local REVERT:74fb01536web UI - init work on using docker-socket-proxy REVERT:ee178de6aweb ui - mostly finished templating integration (needs some testing) REVERT:7323525b6ui - show only multisite vars for settings REVERT:82e47f147ui - Dockerfile fixes and missing get_config function REVERT:2db967ad1templating - road to web ui REVERT:1d96620aetemplating - init integration into web ui REVERT:99c259bf1templating - prepare integration into ui REVERT:c7b81cfc1various bug fixes related to HTTPS REVERT:dfce0c06dautoconf - fixing various bug when SWARM_MODE=yes REVERT:0f8e56a66templating - fixing bugs with autoconf REVERT:f950abdc2templating - started integration into autoconf REVERT:4a73ae819various bug fixes on templates and nginx update to 1.20.1 REVERT:e2f02ee91templating - prepare integration for autoconf REVERT:a991b262eremove ClamAV because of GPL and started work on read-only filesystem REVERT:a8bc17e83templating - started integration into docker image REVERT:ec19f9308templating - added missing features in site templates REVERT:23aa05300templating - auth basic support REVERT:289ad106ctemplating - multisite support REVERT:bbc5bbc9etemplating - fix some site templates REVERT:633a07686templating - init work on site templates REVERT:996c45df4templating - init work on global templates REVERT:801530baftemplating - road to full jinja2 templates REVERT:c65dda391templating - init work on templating with jinja2 REVERT:ea891969ctemplating - updated settings.json with global settings REVERT:698ae17c4templating - init work on generic settings management REVERT:664563284antibot - basic pow with javascript REVERT:16e5ede13antibot - custom templates REVERT:8260746felogs/lua - add logger tool REVERT:de560490dfix LUA array variables and add LOG_LEVEL to the troubleshooting section REVERT:96db3a450log - add LOG_LEVEL variable REVERT:73543f4b0hardening - add no-new-privileges REVERT:d9bb97be5lua - move global vars from lua to site config (untested) REVERT:863283d09started work on moving variables from .lua to nginx REVERT:600484b16crowdsec - fix bugs and update example REVERT:7c6a13c54examples - improve nextcloud example so it works with webdav clients REVERT:b3bb4ec40remove unnecessary dependencies and update doc about certificate bundle REVERT:69f465720examples - fix typo BAD_BEHAVIOR_STATUS_CODES REVERT:d02985d21check permissions for missing volumes and add comment about permissions on examples REVERT:b0ca85ff7v1.2.5 - performance improvement REVERT:2f115c444Merge pull request #131 from bunkerity/issue-templates REVERT:7f15741eaUpdate issue templates REVERT:288b8eb85docs improvement + road to v1.2.5 REVERT:61c08fb97docs - troubleshooting REVERT:01ef47a66docs - security tuning improvement REVERT:71515a910doc - volumes list REVERT:a33d0658cdocs - road to a beautiful documentation REVERT:0b3ff6a9fbad behavior - move from fail2ban to pure lua REVERT:eb2d0d330performance - rsyslog and fail2ban removing REVERT:5bcbb3863doc - official document started REVERT:ca660b250init work on official doc REVERT:3a34436cdadd AquaeAtrae example for ROOT_SITE_SUBFOLDER REVERT:b1d03cd11performance - move bad user-agents and referrers checks from nginx to LUA with caching REVERT:42c3fb874add sandbox allow-downloads to the default value of CONTENT_SECURITY_POLICY REVERT:f1c043604add missing backslash in the quickstart guide and update autoconf examples with the depends_on directive REVERT:fd61df205performance - move external blacklists checks from nginx to LUA REVERT:009d6fb5achoose connection and nofile numbers, increase error_log level to get modsecurity rules, add MODSECURITY_SEC_AUDIT_ENGINE var REVERT:ba4185a42jobs - fix automatic reload REVERT:70976d0fbfix user-agent not blocking and add documentation on bundle when USE_CUSTOM_HTTPS=yes REVERT:062a39c63integrate AquaeAtrae work - add ROOT_SITE_SUBFOLDER REVERT:83841b290jobs - edit adren work on external blacklists REVERT:10dc58cb6Merge pull request #126 from adren/patch-6 REVERT:668754686Merge pull request #125 from adren/patch-5 REVERT:84b1933f6Merge pull request #124 from adren/patch-4 REVERT:15f6d0a32Merge pull request #123 from adren/patch-3 REVERT:e628361a8Merge pull request #122 from adren/patch-1 REVERT:f8d71e067improved way to generate user-agent file REVERT:02ae3b6bdchange IFS before subshell REVERT:2fb0e7c47deduplicate list of user-agents REVERT:9adcc2f1amore optimized way to generate map referrer file REVERT:7b98db4d1improve the generation of blocking file (abusers) REVERT:ddb2b8591improve generation of block file (Tor exit nodes) REVERT:da1a460a6huge improvement to generate blocking file REVERT:07be62684hotfix - fix API in autoconf swarm mode REVERT:3bb164395hotfix - move API_WHITELIST_IP edit to lua.sh REVERT:bc2568a17v1.2.4 - nginx 1.20.0 support REVERT:5ec74880dupdate README for v1.2.4 REVERT:f84fd7c9afix permissions issues for autoconf and fix volume for ghost example REVERT:6521d7a27fix client cache so it works in combination with reverse proxy and examples update REVERT:813607fbcimprove crowdsec example and disable modsec logging when not necessary REVERT:843644f80log - replace some WARN tags from LUA logs with NOTICE to avoid confusion REVERT:19fa0eb25log - print modsec_audit.log to make debugging easier REVERT:b4df28722log - send logs to remote syslog server REVERT:5ce41edc0api - whitelist IP/network for API REVERT:a3cfb50b4example - fix certbot wildcard REVERT:25494acacexample - wildcard certificate with certbot REVERT:a98dae1fbfix CVE-2021-20205 and examples update REVERT:1a7abab57nginx 1.20.0 support REVERT:42b7a57f0fix autoconf bug when removing config with multiple server name and increase default LIMIT_CONN_MAX for average website with HTTP2 REVERT:02f9fbe5fautoconf - fix certbot bug when multiple server_name for one service REVERT:69fe06677autoconf - fix bug when multiple server_name for one service REVERT:74417abc9fixing bugs - run as GID 101 instead of 0, different permissions checks in swarm mode and disable including server confs in swarm mode REVERT:ba7524a41fixed LUA bug REVERT:b55aafb99finding the LUA bug REVERT:deeb7a76aMerge pull request #117 from thelittlefireman/patch-9 REVERT:ee8aaa4e7fix lua crash 2 REVERT:605d59a45Fix lua mistake REVERT:b85c991b6bug fixes - /usr/local/lib/lua rights and syntax error in site-config REVERT:0d3658adfREVERSE_PROXY_HEADERS - use proxy_set_header instead of more_set_headers REVERT:0b22209c9documentation - userns remap feature REVERT:e44a1f3e1added the uri to limit_req_zone key to limit bruteforce attack on a specific resource instead of the whole service REVERT:aa614f82fprint error when permissions are wrong on common volumes REVERT:c03d410b0refactored whitelisting of user-agents REVERT:e190167bfCIDR support with whitelist/blacklist IP REVERT:31e72dce1fix /usr/local/lib/lua rights and multiple server_name support with autoconf REVERT:b8105fc55feature - whitelist URI REVERT:e73c10fd8crowdsec - fix permissions on /usr/local/lib/lua and on /var/log files REVERT:a122a259cminor fix on AutoConf logs and auto disable etag with reverse proxy REVERT:7c4894d3bautoconf - fix remove event, generate config from nginx vars, more logs REVERT:533c2a103fix sed script when writing site env REVERT:5611d544dremove reference to USE_PHP REVERT:397182f18add link to twitter account REVERT:c5c5fb17bv1.2.3 - swarm support REVERT:017a7780fREADME update, default cron update and new parameters to ui REVERT:34d9db7a8web ui - bug fixes REVERT:361c66ca6fixed bugs with MULTISITE variables and swarm example REVERT:afc667885road to v1.2.3 - fixing bugs REVERT:c40fb3317road to swarm - automatic reload after jobs REVERT:93ad3c0b5road to swarm - let's encrypt fix REVERT:ceed90488road to swarm - still some mess to fix REVERT:b8027d2baMerge pull request #102 from thelittlefireman/proxy_custom_headers REVERT:8d03a14a6Merge pull request #103 from thelittlefireman/fix_truncated_3 REVERT:d16f4517aEnhancement add custom proxy headers #97 REVERT:89ca91b3fFix truncated variables (last commit) REVERT:6a714e2ecroad to swarm - fix race condition on initial configuration REVERT:0d3da0353prepare /www directory, fix log socket path and whitelist acme challenges path REVERT:33163f65binit work on disabling root processes REVERT:a2543384croad to swarm - add openssl to autoconf, fix api_uri in LUA, fix file rights REVERT:3591715f2road to swarm - fixing things REVERT:95f7ca5b2road to swarm support - needs a lot of testing REVERT:816fa47cbintroducing SWARM_MODE env var REVERT:7756c2df3Merge pull request #98 from mromanelli9/fix/readme REVERT:7509ec2f2basic API to be used in swarm mode REVERT:6e93575e1remove ALLOWALL from X_FRAME_OPTIONS options REVERT:ba4c97755remove old anchor REVERT:781e4c8cbautoconf little work on swarm support REVERT:e04c783d1autoconf - init work on swarm mode REVERT:e12b656bdMerge branch 'patch-7' of https://github.com/thelittlefireman/bunkerized-nginx into dev REVERT:cae05447dcustom crontab values REVERT:4b58e2265Merge branch 'patch-5' of https://github.com/thelittlefireman/bunkerized-nginx into dev REVERT:6b56e21a0Merge branch 'whitelist_ua' of https://github.com/thelittlefireman/bunkerized-nginx into dev REVERT:544a09e8dUpdate lua-cs-bouncer REVERT:8386dd4a2custom config outside server block REVERT:f052a2516Merge branch 'pre_server_confs' of https://github.com/thelittlefireman/bunkerized-nginx into dev REVERT:43750f553Merge pull request #73 from thelittlefireman/patch-4 REVERT:9142afdb5Merge pull request #72 from thelittlefireman/patch-3 REVERT:66c4fed79Fix env variable with space are truncated 2 REVERT:f41846e9dFix env variable with space are truncated REVERT:92cc705b9Reduce memory usage : set cron tasks at different hours. REVERT:47fb3a05bUpgrade crowdsecurity/lua-cs-bouncer REVERT:5940f402cimprove default tls security REVERT:d9ca275d5Add before `server {}` config. REVERT:8353bd9c8Allow to add a whitelist by site on user-agent REVERT:d902e2f29Add last missing reverse proxy header REVERT:1a8b8043cAdd LIMIT_CONN var to server.conf REVERT:65120a7e9Add USE_CONN_LIMIT info to Readme.md REVERT:b093a4755Add default values for LIMIT_CONN REVERT:73dbf03c9add USE_LIMIT_CONN zone to global config REVERT:6ee746236Add USE_LIMIT_CONN to site-config REVERT:fa935eb6eedit nginx.conf to add limit_conn REVERT:cf231e13cAdd limit-conn.conf REVERT:d5d699252v1.2.2 - web UI (beta) REVERT:50f95420bREADME update - road to v1.2.2 REVERT:dc382c3e0various fixes - autoconf process order, multisite config and examples REVERT:0026328f2edit default FAIL2BAN_IGNOREIP subnets REVERT:9023ab5aeMerge pull request #67 from thelittlefireman/patch-2 REVERT:124474ad6Edit README.md to add FAIL2BAN_IGNOREIP REVERT:eac9c8f51Prepare FAIL2BAN_IGNOREIP to avoid self blocking REVERT:1ee490de6Prepare FAIL2BAN_IGNOREIP to avoid self blocking REVERT:825e6a747crowdsec v1 integrated REVERT:09a984c86started crowdsec v1 integration REVERT:fd7afa17bfix missing ';' in include REVERT:b9b7fdfccMerge pull request #63 from thelittlefireman/patch-1 REVERT:58e1d66bcUI - minor alert css fix REVERT:7026643f8UI - fix missing MULTISITE env var when managing services REVERT:06f688fe9fixed stop and reload operations REVERT:c65b78b1cUI - instances/services backend update (needs testing) REVERT:f9b9b9546UI - introduced multiple config parameters (like reverse proxy) in frontend REVERT:b5fe6335cUI - instances backend started REVERT:951f3957fUI - default service values REVERT:0f520b891UI - services backend started REVERT:569ad75c4UI - config.json refactoring REVERT:bd7b6af66UI - load config template from json REVERT:459bb8ea1UI services modals and default CSP update (fix new tab links) REVERT:208b5acb3UI - minor services list improvement REVERT:59b2fed41UI - basic services list REVERT:a4871a915Add missing proxy headers REVERT:026783f01Fix missing reverse proxy headers REVERT:811585345Fix missing proxy headers on site-config.sh REVERT:c5f283b00UI - minor front update REVERT:03ce7a648fix modsec double inclusion when MULTISITE=yes REVERT:3f7e2c54bJOBS - fixed some job script and right temp nginx reload REVERT:bb0f46d8aJOBS - fix job_log REVERT:c5b32dfc4fix CVE-2020-1971 again REVERT:9a4f96ad1fix CVE-2020-1971 REVERT:f258426f5JOBS - fallback to old conf in case reload failed REVERT:119e96361JOBS - be more verbose about jobs failure/success REVERT:373988670Merge pull request #54 from thelittlefireman/patch-4 REVERT:2a956f2cdFix #52 REVERT:15a37a868UI - minor UI improvement REVERT:3a3d52790UI - basic read fixes REVERT:e6b5f460cUI - basic read from docker API REVERT:002e3ed2bsecurity tests for autoconf and ui REVERT:7b55acbe8web UI example and CVE-2020-8231 fix again REVERT:559b7835dui - automated build REVERT:4ea01bd93print some logs when blocking bots REVERT:a73891a3bfix CVE-2020-8231 REVERT:26199f52cremove additional / in modsecurity include REVERT:5c3f94a84edit reverse proxy var name in README REVERT:043fcdc13autoconf - automated build REVERT:b86ded3d1autoconf - multi arch Dockerfile REVERT:92569679bdynamic reload of nginx by sending SIGHUP REVERT:15e74e486more work on standalone autoconf REVERT:fd0a6412dinit work on standalone autoconf REVERT:419fdfc86fix auth basic when MULTISITE=yes REVERT:0bc1f652bv1.2.1 - autoconf feature (beta) REVERT:6c7461e29integrate thelittlefireman work REVERT:d01bc5e01Merge branch 'patch-1' of https://github.com/thelittlefireman/bunkerized-nginx into dev REVERT:75c69c810last fixes before next release ? REVERT:e26b8482aAdd missing EMAIL_LETS_ENCRYPT parameter REVERT:f618c73e6road to v1.2.1 REVERT:78c1e5c67examples - same domains for internal tests REVERT:481e10d3ereverse proxy - websocket example REVERT:aae2a7198autoconf - php example REVERT:f3bf04e39dirty fix to disable default server when MULTISITE=yes REVERT:36cbb927cautoconf - various fixes REVERT:95153dbc5moved UA, referrer and country check after whitelist and blacklist check REVERT:26947179amoved UA and referrer check to LUA REVERT:88f27bfebautoconf - reverse proxy example and pass default vars REVERT:3cc1615c4fix user-agent script REVERT:8bacf722aMerge branch 'fix/variable-naming' of https://github.com/mromanelli9/bunkerized-nginx into dev REVERT:2bfc4b41ffirst work on automatic configuration REVERT:587d4a92eincorrect variable naming REVERT:c311d0c82add crawler-detecter bad UA REVERT:0d03f49ebwebsocket support with reverse proxy REVERT:2112c306acustom log format REVERT:8f9dcc5ablast fix ? REVERT:2fe05d3fdfixing scripts again and again REVERT:db04c0345fix referrers again REVERT:ed8bd902bfix referrers script REVERT:3a7aa5d9cblock bad referrers REVERT:9ec9de6camultiple lets encrypt certificates when MULTISITE=yes REVERT:791342cbefix LUA DNS code when answers is nil REVERT:2f23671c3fail2ban fix when MULTISITE=yes REVERT:e350a717ffix default DNS_RESOLVERS REVERT:e818acb0dprestashop example REVERT:b92f74ed9dirty fix for CVE-2020-28928 REVERT:9688e6650check all vulnerabilities with trivy REVERT:700dfc018v1.2.0 release REVERT:42e4298b5readme update - v1.2.0 changes REVERT:813b42cfaphp and nextcloud examples fix REVERT:58fcf0a72added Permissions-Policy header REVERT:587918380custom headers to remove REVERT:203259688automatic trivy scan REVERT:eaf817d57php config and examples fixes REVERT:dd7768c85whitelist/blacklist country at LUA level to avoid SEO issues REVERT:fe1d724c9country whitelist/blacklist REVERT:0635eb368various bug fixes REVERT:fbf81c94bcached blacklists data REVERT:ed451877aexamples update and multiple REVERSE_PROXY_* on single site REVERT:0f18e9c55reverse proxy support via env vars REVERT:8f7cb5318proxy caching support REVERT:60fbbc101move some http directives to server REVERT:0f0593456various fixes REVERT:8cdc155acmultisite examples and certbot renew fix REVERT:1abe1da89brotli support REVERT:f18c054b4gzip support REVERT:4dea1975eclient caching REVERT:c2b05c463fix BLOCK_COUNTRY bug and add support for ModSecurity custom confs when multisite=yes REVERT:2da51d92amultisite - bug fixes REVERT:bd7997497autotest through github actions REVERT:e89e34a84auto test fix REVERT:ff02878ddauto test setup REVERT:44b016be9road to multi server block support REVERT:36c4f3e06v1.1.2 - CrowdSec integration and custom ports REVERT:798f6c726examples - nextcloud fix and tomcat REVERT:761c14a0bcustom HTTP and HTTPS ports REVERT:4a07eca69crowdsec integration REVERT:e1274a608passbolt example REVERT:3ec81cd84Fix broken line in README REVERT:95752ff0cv1.1.1 - TLS 1.2 support REVERT:8623510f8https fix REVERT:95a76b11fpeterkimzz integration and dhparam REVERT:b0e4740a7[New Features] - Added "HTTPS_PROTOCOLS" environment value to enable to customize TLS version. default value is "TLSv1.3". (because TLSv1.2 sometimes needed) - READMD.md REVERT:e84360857README update - v1.1.0 REVERT:2f6866789logrotate copytruncate REVERT:1d63838eeexamples - fix port number REVERT:e4bdd4af5examples - nextcloud fix and moodle REVERT:2c33463afrenamed logrotate script REVERT:9ff210bedwordpress and nextcloud examples REVERT:0b7301886install CRS by tag in compile.sh REVERT:e1356e3eblogrotate.conf update and some cleanup REVERT:34a0da444logging fix again REVERT:022a653ebdisplay fail2ban.log and logging bug fix REVERT:4c11a9125automatic docker tags with VERSION REVERT:88b52478cautomatic Secure flag on cookies REVERT:ce82e22dbremove integrated PHP REVERT:397415211antibot - check IP with sessions and recaptcha REVERT:68d798855tor hidden service example REVERT:16eab0f63README update REVERT:6a22f7711load balancer example REVERT:222426854Merge pull request #13 from FacundoAcevedo/patch-1 REVERT:d63c57985Fix typo in the link in the TOC REVERT:e19a7c693run master nginx process as non-root user REVERT:7a8795883dockerfile fix - compile REVERT:01095bd72gpg fix and secure git clone REVERT:0e6729c62check GPG signature of nginx sources REVERT:040b6a223Merge branch 'patch-1' of https://github.com/fabianmoronzirfas/bunkerized-nginx into dev REVERT:5f62120e4fix(typo): add missing »find« REVERT:e8503b9ccARM build fix REVERT:676571e4ause nginx:stable-alpine as base image REVERT:34254a09eexamples and DNS_RESOLVERS fix REVERT:81cff3648readme update REVERT:e166b1feaawesome gif resized REVERT:f08bba8ccawesome gif REVERT:ccf439228session secret fix REVERT:c1d44387bbasic antibot feature through recaptcha v3 REVERT:135126e3freadme fix REVERT:ac251b0f6Merge branch 'master' of https://github.com/ZILosoft/bunkerized-nginx into dev REVERT:ac242c977Update README.md REVERT:2909b7989basic antibot feature through captcha REVERT:446ee3761basic antibot using javascript REVERT:6e1c43c4cbasic antibot feature through cookie REVERT:652d8ac97fixed typo in manifest REVERT:de1952b5fREADME - toc update and title fix REVERT:16a458db2README improvement REVERT:f27d80e0dvarious fixes and lua logging REVERT:fc3d911ffimproved blacklist/whitelist/dnsbl with lua REVERT:ef7d842ffarm64v8 auto build and master manifest REVERT:0e5704983manifest for automated builds REVERT:aaef37007improved logging with rsyslog REVERT:6e3c2ddccintegrated ajarmoszuk work REVERT:919b418d5Added the ability to self generate SSL certificates REVERT:fb1a0182eAdded the ability to see Real IPs if Nginx is running under another proxy (such as Traefik). REVERT:2e0a8307di386 fix again REVERT:181003efei386 fix REVERT:fca7bb075automatic builds REVERT:764038d40README update REVERT:f4c43a214block proxies and abusers REVERT:3a9afa47bMerge pull request #5 from ajarmoszuk/patch-1 REVERT:2c12df3b9update default req_limit values REVERT:2f967a9f4Update entrypoint.sh REVERT:eba5f6280req limit REVERT:44155b5d6dnsbl ipairs fix REVERT:829c1c697some fixes and README update REVERT:f3721a50dsitewide auth basic REVERT:b56e4e765dnsbl feature REVERT:1654e913alua support REVERT:3e5ca583cremote PHP-FPM support REVERT:bcd17dbeaautomatic geoip update REVERT:14ec9f3e6logrotate and compile fixes REVERT:5b5e6e33aawesome logo REVERT:1aa1dcf50logrotate support REVERT:f30a06d94syslog integration and fail2ban improvement REVERT:cd19841ecreadme - details about modsec include order REVERT:94b29a6cafixed some include orders REVERT:bf605ce59custom root folder and little fixes REVERT:b14b09ad5default CSP update REVERT:4f5e5f013readme improve REVERT:76bd069f2php POST max size and custom HTTPS cert REVERT:1d6ab7275http basic auth fix REVERT:472ec31cdreadme fix REVERT:caa415e12http basic auth REVERT:8561d47becreate a customized image REVERT:4bede275ffix typo REVERT:efcf93710inspectFile fix REVERT:ccaaa8b57readme fix REVERT:b83111ad1realip, minor fixes and README REVERT:a2be2e8aeimproved README : format, modsec, fail2ban and clamav REVERT:48a0036d2updated readme REVERT:bf0bef289clamav support REVERT:193070b14fail2ban support REVERT:716e54e59custom http/server confs and better modsec customization REVERT:43403f69edisable default server REVERT:69ac95b29block country and various fixes REVERT:ecf2de8b7multiple let's encrypt domains REVERT:8427564f4user-agents escape fix REVERT:c56bde4f0fix certbot-renew.sh syntax REVERT:834afa132http to https redirect REVERT:d5f8c7647custom modules and write access REVERT:5bcdb0219f**k markup ? REVERT:3233f3b76fix readme REVERT:62eda8173improved README REVERT:09e6b50e5custom conf REVERT:5d16f6a8ffix README REVERT:1b5f6deb2cookie flags and maxmind update REVERT:ea1dbc617updated readme REVERT:0b703ea55content security policy REVERT:1e642e2f1initial readme REVERT:e90060ce6initial work REVERT:70f849fbbInitial commit git-subtree-dir: src/deps/src/lua-nginx-module git-subtree-split: c47084b5d719ce507d2419d8660f39544a9d1fea
8110 lines
370 KiB
Text
8110 lines
370 KiB
Text
= Name =
|
|
|
|
ngx_http_lua_module - Embed the power of Lua into Nginx HTTP Servers.
|
|
|
|
This module is a core component of [https://openresty.org OpenResty]. If you are using this module,
|
|
then you are essentially using OpenResty.
|
|
|
|
''This module is not distributed with the Nginx source.'' See
|
|
[[#Installation|the installation instructions]].
|
|
|
|
This is a core component of OpenResty. If you are using this module, then you are essentially using OpenResty :)
|
|
|
|
= Status =
|
|
|
|
Production ready.
|
|
|
|
= Version =
|
|
|
|
This document describes ngx_lua
|
|
[https://github.com/openresty/lua-nginx-module/tags v0.10.19], which was released
|
|
on 3 Nov, 2020.
|
|
|
|
= Videos =
|
|
|
|
* YouTube video "[Hello World HTTP Example with OpenResty/Lua](https://youtu.be/eSfYLvVQMxw)"
|
|
|
|
[](https://youtu.be/eSfYLvVQMxw)
|
|
|
|
* YouTube video "[Write Your Own Lua Modules in OpenResty/Nginx Applications](https://youtu.be/vfYxOMl5LVY)"
|
|
|
|
[](https://youtu.be/vfYxOMl5LVY)
|
|
|
|
* YouTube video "[OpenResty's resty Command-Line Utility Demo](https://youtu.be/L1c7aw4mSOo)"
|
|
|
|
[](https://youtu.be/L1c7aw4mSOo)
|
|
|
|
* YouTube video "[Measure Execution Time of Lua Code Correctly in OpenResty](https://youtu.be/VkRYW_qLoME)"
|
|
|
|
[](https://youtu.be/VkRYW_qLoME)
|
|
|
|
* YouTube video "[Precompile Lua Modules into LuaJIT Bytecode to Speedup OpenResty Startup](https://youtu.be/EP7c0BM2yNo)"
|
|
|
|
[](https://youtu.be/EP7c0BM2yNo)
|
|
|
|
You are welcome to subscribe to our [official YouTube channel, OpenResty](https://www.youtube.com/channel/UCXVmwF-UCScv2ftsGoMqxhw).
|
|
|
|
= Synopsis =
|
|
<geshi lang="nginx">
|
|
# set search paths for pure Lua external libraries (';;' is the default path):
|
|
lua_package_path '/foo/bar/?.lua;/blah/?.lua;;';
|
|
|
|
# set search paths for Lua external libraries written in C (can also use ';;'):
|
|
lua_package_cpath '/bar/baz/?.so;/blah/blah/?.so;;';
|
|
|
|
server {
|
|
location /lua_content {
|
|
# MIME type determined by default_type:
|
|
default_type 'text/plain';
|
|
|
|
content_by_lua_block {
|
|
ngx.say('Hello,world!')
|
|
}
|
|
}
|
|
|
|
location /nginx_var {
|
|
# MIME type determined by default_type:
|
|
default_type 'text/plain';
|
|
|
|
# try access /nginx_var?a=hello,world
|
|
content_by_lua_block {
|
|
ngx.say(ngx.var.arg_a)
|
|
}
|
|
}
|
|
|
|
location = /request_body {
|
|
client_max_body_size 50k;
|
|
client_body_buffer_size 50k;
|
|
|
|
content_by_lua_block {
|
|
ngx.req.read_body() -- explicitly read the req body
|
|
local data = ngx.req.get_body_data()
|
|
if data then
|
|
ngx.say("body data:")
|
|
ngx.print(data)
|
|
return
|
|
end
|
|
|
|
-- body may get buffered in a temp file:
|
|
local file = ngx.req.get_body_file()
|
|
if file then
|
|
ngx.say("body is in file ", file)
|
|
else
|
|
ngx.say("no body found")
|
|
end
|
|
}
|
|
}
|
|
|
|
# transparent non-blocking I/O in Lua via subrequests
|
|
# (well, a better way is to use cosockets)
|
|
location = /lua {
|
|
# MIME type determined by default_type:
|
|
default_type 'text/plain';
|
|
|
|
content_by_lua_block {
|
|
local res = ngx.location.capture("/some_other_location")
|
|
if res then
|
|
ngx.say("status: ", res.status)
|
|
ngx.say("body:")
|
|
ngx.print(res.body)
|
|
end
|
|
}
|
|
}
|
|
|
|
location = /foo {
|
|
rewrite_by_lua_block {
|
|
res = ngx.location.capture("/memc",
|
|
{ args = { cmd = "incr", key = ngx.var.uri } }
|
|
)
|
|
}
|
|
|
|
proxy_pass http://blah.blah.com;
|
|
}
|
|
|
|
location = /mixed {
|
|
rewrite_by_lua_file /path/to/rewrite.lua;
|
|
access_by_lua_file /path/to/access.lua;
|
|
content_by_lua_file /path/to/content.lua;
|
|
}
|
|
|
|
# use nginx var in code path
|
|
# CAUTION: contents in nginx var must be carefully filtered,
|
|
# otherwise there'll be great security risk!
|
|
location ~ ^/app/([-_a-zA-Z0-9/]+) {
|
|
set $path $1;
|
|
content_by_lua_file /path/to/lua/app/root/$path.lua;
|
|
}
|
|
|
|
location / {
|
|
client_max_body_size 100k;
|
|
client_body_buffer_size 100k;
|
|
|
|
access_by_lua_block {
|
|
-- check the client IP address is in our black list
|
|
if ngx.var.remote_addr == "132.5.72.3" then
|
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
end
|
|
|
|
-- check if the URI contains bad words
|
|
if ngx.var.uri and
|
|
string.match(ngx.var.request_body, "evil")
|
|
then
|
|
return ngx.redirect("/terms_of_use.html")
|
|
end
|
|
|
|
-- tests passed
|
|
}
|
|
|
|
# proxy_pass/fastcgi_pass/etc settings
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
= Description =
|
|
|
|
This module embeds [https://luajit.org/luajit.html LuaJIT 2.0/2.1] into Nginx.
|
|
It is a core component of [https://openresty.org OpenResty]. If you are using
|
|
this module, then you are essentially using OpenResty.
|
|
|
|
Since version <code>v0.10.16</code> of this module, the standard Lua
|
|
interpreter (also known as "PUC-Rio Lua") is not supported anymore. This
|
|
document interchangeably uses the terms "Lua" and "LuaJIT" to refer to the
|
|
LuaJIT interpreter.
|
|
|
|
By leveraging Nginx's subrequests, this module allows the integration of the
|
|
powerful Lua threads (known as Lua "coroutines") into the Nginx event model.
|
|
|
|
Unlike [https://httpd.apache.org/docs/trunk/mod/mod_lua.html Apache's mod_lua]
|
|
and [http://redmine.lighttpd.net/wiki/1/Docs:ModMagnet Lighttpd's mod_magnet],
|
|
Lua code executed using this module can be ''100% non-blocking'' on network
|
|
traffic as long as the [[#Nginx API for Lua|Nginx API for Lua]] provided by
|
|
this module is used to handle requests to upstream services such as MySQL,
|
|
PostgreSQL, Memcached, Redis, or upstream HTTP web services.
|
|
|
|
At least the following Lua libraries and Nginx modules can be used with this
|
|
module:
|
|
|
|
* [https://github.com/openresty/lua-resty-memcached lua-resty-memcached]
|
|
* [https://github.com/openresty/lua-resty-mysql lua-resty-mysql]
|
|
* [https://github.com/openresty/lua-resty-redis lua-resty-redis]
|
|
* [https://github.com/openresty/lua-resty-dns lua-resty-dns]
|
|
* [https://github.com/openresty/lua-resty-upload lua-resty-upload]
|
|
* [https://github.com/openresty/lua-resty-websocket lua-resty-websocket]
|
|
* [https://github.com/openresty/lua-resty-lock lua-resty-lock]
|
|
* [https://github.com/cloudflare/lua-resty-logger-socket lua-resty-logger-socket]
|
|
* [https://github.com/openresty/lua-resty-lrucache lua-resty-lrucache]
|
|
* [https://github.com/openresty/lua-resty-string lua-resty-string]
|
|
* [[HttpMemcModule|ngx_memc]]
|
|
* [https://github.com/FRiCKLE/ngx_postgres ngx_postgres]
|
|
* [[HttpRedis2Module|ngx_redis2]]
|
|
* [[HttpRedisModule|ngx_redis]]
|
|
* [[HttpProxyModule|ngx_proxy]]
|
|
* [[HttpFastcgiModule|ngx_fastcgi]]
|
|
|
|
Almost any Nginx modules can be used with this ngx_lua module by means of
|
|
[[#ngx.location.capture|ngx.location.capture]] or
|
|
[[#ngx.location.capture_multi|ngx.location.capture_multi]] but it is
|
|
recommended to use those <code>lua-resty-*</code> libraries instead of creating
|
|
subrequests to access the Nginx upstream modules because the former is usually
|
|
much more flexible and memory-efficient.
|
|
|
|
The Lua interpreter (also known as "Lua State" or "LuaJIT VM instance") is
|
|
shared across all the requests in a single Nginx worker process to minimize
|
|
memory use. Request contexts are segregated using lightweight Lua coroutines.
|
|
|
|
Loaded Lua modules persist in the Nginx worker process level resulting in a
|
|
small memory footprint in Lua even when under heavy loads.
|
|
|
|
This module is plugged into Nginx's "http" subsystem so it can only speaks
|
|
downstream communication protocols in the HTTP family (HTTP 0.9/1.0/1.1/2.0,
|
|
WebSockets, etc...). If you want to do generic TCP communications with the
|
|
downstream clients, then you should use the
|
|
[https://github.com/openresty/stream-lua-nginx-module#readme ngx_stream_lua]
|
|
module instead, which offers a compatible Lua API.
|
|
|
|
= Typical Uses =
|
|
|
|
Just to name a few:
|
|
|
|
* Mashup'ing and processing outputs of various Nginx upstream outputs (proxy, drizzle, postgres, redis, memcached, and etc) in Lua,
|
|
* doing arbitrarily complex access control and security checks in Lua before requests actually reach the upstream backends,
|
|
* manipulating response headers in an arbitrary way (by Lua)
|
|
* fetching backend information from external storage backends (like redis, memcached, mysql, postgresql) and use that information to choose which upstream backend to access on-the-fly,
|
|
* coding up arbitrarily complex web applications in a content handler using synchronous but still non-blocking access to the database backends and other storage,
|
|
* doing very complex URL dispatch in Lua at rewrite phase,
|
|
* using Lua to implement advanced caching mechanism for Nginx's subrequests and arbitrary locations.
|
|
|
|
The possibilities are unlimited as the module allows bringing together various
|
|
elements within Nginx as well as exposing the power of the Lua language to the
|
|
user. The module provides the full flexibility of scripting while offering
|
|
performance levels comparable with native C language programs both in terms of
|
|
CPU time as well as memory footprint thanks to LuaJIT 2.x.
|
|
|
|
Other scripting language implementations typically struggle to match this
|
|
performance level.
|
|
|
|
= Nginx Compatibility =
|
|
|
|
The latest version of this module is compatible with the following versions of Nginx:
|
|
|
|
* 1.19.x (last tested: 1.19.3)
|
|
* 1.17.x (last tested: 1.17.8)
|
|
* 1.15.x (last tested: 1.15.8)
|
|
* 1.14.x
|
|
* 1.13.x (last tested: 1.13.6)
|
|
* 1.12.x
|
|
* 1.11.x (last tested: 1.11.2)
|
|
* 1.10.x
|
|
* 1.9.x (last tested: 1.9.15)
|
|
* 1.8.x
|
|
* 1.7.x (last tested: 1.7.10)
|
|
* 1.6.x
|
|
|
|
Nginx cores older than 1.6.0 (exclusive) are *not* supported.
|
|
|
|
= Installation =
|
|
|
|
It is *highly* recommended to use [https://openresty.org OpenResty releases]
|
|
which bundle Nginx, ngx_lua (this module), LuaJIT, as well as other powerful
|
|
companion Nginx modules and Lua libraries.
|
|
|
|
It is discouraged to build this module with Nginx yourself since it is tricky
|
|
to set up exactly right.
|
|
|
|
Note that Nginx, LuaJIT, and OpenSSL official releases have various limitations
|
|
and long standing bugs that can cause some of this module's features to be
|
|
disabled, not work properly, or run slower. Official OpenResty releases are
|
|
recommended because they bundle [https://github.com/openresty/luajit2
|
|
OpenResty's optimized LuaJIT 2.1 fork] and
|
|
[https://github.com/openresty/openresty/tree/master/patches Nginx/OpenSSL
|
|
patches].
|
|
|
|
Alternatively, ngx_lua can be manually compiled into Nginx:
|
|
|
|
# LuaJIT can be downloaded from the [https://github.com/openresty/luajit2/releases latest release of OpenResty's LuaJIT fork]. The official LuaJIT 2.x releases are also supported, although performance will be significantly lower for reasons elaborated above
|
|
# Download the latest version of the ngx_devel_kit (NDK) module [https://github.com/simplresty/ngx_devel_kit/tags HERE]
|
|
# Download the latest version of ngx_lua [https://github.com/openresty/lua-nginx-module/tags HERE]
|
|
# Download the latest supported version of Nginx [https://nginx.org/ HERE] (See [[#Nginx Compatibility|Nginx Compatibility]])
|
|
# Download the latest version of the lua-resty-core [HERE](https://github.com/openresty/lua-resty-core)
|
|
# Download the latest version of the lua-resty-lrucache [HERE](https://github.com/openresty/lua-resty-lrucache)
|
|
|
|
Build the source with this module:
|
|
|
|
<geshi lang="bash">
|
|
wget 'https://openresty.org/download/nginx-1.19.3.tar.gz'
|
|
tar -xzvf nginx-1.19.3.tar.gz
|
|
cd nginx-1.19.3/
|
|
|
|
# tell nginx's build system where to find LuaJIT 2.0:
|
|
export LUAJIT_LIB=/path/to/luajit/lib
|
|
export LUAJIT_INC=/path/to/luajit/include/luajit-2.0
|
|
|
|
# tell nginx's build system where to find LuaJIT 2.1:
|
|
export LUAJIT_LIB=/path/to/luajit/lib
|
|
export LUAJIT_INC=/path/to/luajit/include/luajit-2.1
|
|
|
|
# Here we assume Nginx is to be installed under /opt/nginx/.
|
|
./configure --prefix=/opt/nginx \
|
|
--with-ld-opt="-Wl,-rpath,/path/to/luajit/lib" \
|
|
--add-module=/path/to/ngx_devel_kit \
|
|
--add-module=/path/to/lua-nginx-module
|
|
|
|
# Note that you may also want to add `./configure` options which are used in your
|
|
# current nginx build.
|
|
# You can get usually those options using command nginx -V
|
|
|
|
# you can change the parallelism number 2 below to fit the number of spare CPU cores in your
|
|
# machine.
|
|
make -j2
|
|
make install
|
|
|
|
# Note that this version of lug-nginx-module not allow to set `lua_load_resty_core off;` any more.
|
|
# So, you have to install `lua-resty-core` and `lua-resty-lrucache` manually as below.
|
|
|
|
cd lua-resty-core
|
|
make install PREFIX=/opt/nginx
|
|
cd lua-resty-lrucache
|
|
make install PREFIX=/opt/nginx
|
|
|
|
# add necessary `lua_package_path` directive to `nginx.conf`, in the http context
|
|
|
|
lua_package_path "/opt/nginx/lib/lua/?.lua;;";
|
|
</geshi>
|
|
|
|
== Building as a dynamic module ==
|
|
|
|
Starting from NGINX 1.9.11, you can also compile this module as a dynamic module, by using the <code>--add-dynamic-module=PATH</code> option instead of <code>--add-module=PATH</code> on the
|
|
<code>./configure</code> command line above. And then you can explicitly load the module in your <code>nginx.conf</code> via the [load_module](https://nginx.org/en/docs/ngx_core_module.html#load_module)
|
|
directive, for example,
|
|
|
|
<geshi lang="nginx">
|
|
load_module /path/to/modules/ndk_http_module.so; # assuming NDK is built as a dynamic module too
|
|
load_module /path/to/modules/ngx_http_lua_module.so;
|
|
</geshi>
|
|
|
|
== C Macro Configurations ==
|
|
|
|
While building this module either via OpenResty or with the Nginx core, you can define the following C macros via the C compiler options:
|
|
|
|
* <code>NGX_LUA_USE_ASSERT</code>
|
|
: When defined, will enable assertions in the ngx_lua C code base. Recommended for debugging or testing builds. It can introduce some (small) runtime overhead when enabled. This macro was first introduced in the <code>v0.9.10</code> release.
|
|
* <code>NGX_LUA_ABORT_AT_PANIC</code>
|
|
: When the LuaJIT VM panics, ngx_lua will instruct the current nginx worker process to quit gracefully by default. By specifying this C macro, ngx_lua will abort the current nginx worker process (which usually result in a core dump file) immediately. This option is useful for debugging VM panics. This option was first introduced in the <code>v0.9.8</code> release.
|
|
|
|
To enable one or more of these macros, just pass extra C compiler options to the <code>./configure</code> script of either Nginx or OpenResty. For instance,
|
|
|
|
<geshi>
|
|
./configure --with-cc-opt="-DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC"
|
|
</geshi>
|
|
|
|
= Community =
|
|
|
|
== English Mailing List ==
|
|
|
|
The [https://groups.google.com/group/openresty-en openresty-en] mailing list is for English speakers.
|
|
|
|
== Chinese Mailing List ==
|
|
|
|
The [https://groups.google.com/group/openresty openresty] mailing list is for Chinese speakers.
|
|
|
|
= Code Repository =
|
|
|
|
The code repository of this project is hosted on GitHub at
|
|
[https://github.com/openresty/lua-nginx-module openresty/lua-nginx-module].
|
|
|
|
= Bugs and Patches =
|
|
|
|
Please submit bug reports, wishlists, or patches by
|
|
|
|
# creating a ticket on the [https://github.com/openresty/lua-nginx-module/issues GitHub Issue Tracker],
|
|
# or posting to the [[#Community|OpenResty community]].
|
|
|
|
= LuaJIT bytecode support =
|
|
|
|
Watch YouTube video "[Measure Execution Time of Lua Code Correctly in OpenResty](https://youtu.be/VkRYW_qLoME)"
|
|
|
|
[](https://youtu.be/EP7c0BM2yNo)
|
|
|
|
As from the <code>v0.5.0rc32</code> release, all <code>*_by_lua_file</code> configure directives (such as [[#content_by_lua_file|content_by_lua_file]]) support loading LuaJIT 2.0/2.1 raw bytecode files directly:
|
|
|
|
<geshi lang="bash">
|
|
/path/to/luajit/bin/luajit -b /path/to/input_file.lua /path/to/output_file.ljbc
|
|
</geshi>
|
|
|
|
The <code>-bg</code> option can be used to include debug information in the LuaJIT bytecode file:
|
|
|
|
<geshi lang="bash">
|
|
/path/to/luajit/bin/luajit -bg /path/to/input_file.lua /path/to/output_file.ljbc
|
|
</geshi>
|
|
|
|
Please refer to the official LuaJIT documentation on the <code>-b</code> option for more details:
|
|
|
|
https://luajit.org/running.html#opt_b
|
|
|
|
Note that the bytecode files generated by LuaJIT 2.1 is ''not'' compatible with
|
|
LuaJIT 2.0, and vice versa. The support for LuaJIT 2.1 bytecode was first added
|
|
in ngx_lua v0.9.3.
|
|
|
|
Attempts to load standard Lua 5.1 bytecode files into ngx_lua instances linked
|
|
to LuaJIT 2.0/2.1 (or vice versa) will result in an Nginx error message such as
|
|
the one below:
|
|
|
|
<geshi lang="text">
|
|
[error] 13909#0: *1 failed to load Lua inlined code: bad byte-code header in /path/to/test_file.luac
|
|
</geshi>
|
|
|
|
Loading bytecode files via the Lua primitives like <code>require</code> and
|
|
<code>dofile</code> should always work as expected.
|
|
|
|
= System Environment Variable Support =
|
|
|
|
If you want to access the system environment variable, say, <code>foo</code>, in Lua via the standard Lua API [https://www.lua.org/manual/5.1/manual.html#pdf-os.getenv os.getenv], then you should also list this environment variable name in your <code>nginx.conf</code> file via the [https://nginx.org/en/docs/ngx_core_module.html#env env directive]. For example,
|
|
|
|
<geshi lang="nginx">
|
|
env foo;
|
|
</geshi>
|
|
|
|
= HTTP 1.0 support =
|
|
|
|
The HTTP 1.0 protocol does not support chunked output and requires an explicit <code>Content-Length</code> header when the response body is not empty in order to support the HTTP 1.0 keep-alive.
|
|
So when a HTTP 1.0 request is made and the [[#lua_http10_buffering|lua_http10_buffering]] directive is turned <code>on</code>, ngx_lua will buffer the
|
|
output of [[#ngx.say|ngx.say]] and [[#ngx.print|ngx.print]] calls and also postpone sending response headers until all the response body output is received.
|
|
At that time ngx_lua can calculate the total length of the body and construct a proper <code>Content-Length</code> header to return to the HTTP 1.0 client.
|
|
If the <code>Content-Length</code> response header is set in the running Lua code, however, this buffering will be disabled even if the [[#lua_http10_buffering|lua_http10_buffering]] directive is turned <code>on</code>.
|
|
|
|
For large streaming output responses, it is important to disable the [[#lua_http10_buffering|lua_http10_buffering]] directive to minimise memory usage.
|
|
|
|
Note that common HTTP benchmark tools such as <code>ab</code> and <code>http_load</code> issue HTTP 1.0 requests by default.
|
|
To force <code>curl</code> to send HTTP 1.0 requests, use the <code>-0</code> option.
|
|
|
|
= Statically Linking Pure Lua Modules =
|
|
|
|
With LuaJIT 2.x, it is possible to statically link the bytecode of pure Lua
|
|
modules into the Nginx executable.
|
|
|
|
You can use the <code>luajit</code> executable to compile <code>.lua</code> Lua
|
|
module files to <code>.o</code> object files containing the exported bytecode
|
|
data, and then link the <code>.o</code> files directly in your Nginx build.
|
|
|
|
Below is a trivial example to demonstrate this. Consider that we have the following <code>.lua</code> file named <code>foo.lua</code>:
|
|
|
|
<geshi lang="lua">
|
|
-- foo.lua
|
|
local _M = {}
|
|
|
|
function _M.go()
|
|
print("Hello from foo")
|
|
end
|
|
|
|
return _M
|
|
</geshi>
|
|
|
|
And then we compile this <code>.lua</code> file to <code>foo.o</code> file:
|
|
|
|
<geshi lang="bash">
|
|
/path/to/luajit/bin/luajit -bg foo.lua foo.o
|
|
</geshi>
|
|
|
|
What matters here is the name of the <code>.lua</code> file, which determines how you use this module later on the Lua land. The file name <code>foo.o</code> does not matter at all except the <code>.o</code> file extension (which tells <code>luajit</code> what output format is used). If you want to strip the Lua debug information from the resulting bytecode, you can just specify the <code>-b</code> option above instead of <code>-bg</code>.
|
|
|
|
Then when building Nginx or OpenResty, pass the <code>--with-ld-opt="foo.o"</code> option to the <code>./configure</code> script:
|
|
|
|
<geshi lang="bash">
|
|
./configure --with-ld-opt="/path/to/foo.o" ...
|
|
</geshi>
|
|
|
|
Finally, you can just do the following in any Lua code run by ngx_lua:
|
|
|
|
<geshi lang="lua">
|
|
local foo = require "foo"
|
|
foo.go()
|
|
</geshi>
|
|
|
|
And this piece of code no longer depends on the external <code>foo.lua</code> file any more because it has already been compiled into the <code>nginx</code> executable.
|
|
|
|
If you want to use dot in the Lua module name when calling <code>require</code>, as in
|
|
|
|
<geshi lang="lua">
|
|
local foo = require "resty.foo"
|
|
</geshi>
|
|
|
|
then you need to rename the <code>foo.lua</code> file to <code>resty_foo.lua</code> before compiling it down to a <code>.o</code> file with the <code>luajit</code> command-line utility.
|
|
|
|
It is important to use exactly the same version of LuaJIT when compiling <code>.lua</code> files to <code>.o</code> files as building nginx + ngx_lua. This is because the LuaJIT bytecode format may be incompatible between different LuaJIT versions. When the bytecode format is incompatible, you will see a Lua runtime error saying that the Lua module is not found.
|
|
|
|
When you have multiple <code>.lua</code> files to compile and link, then just specify their <code>.o</code> files at the same time in the value of the <code>--with-ld-opt</code> option. For instance,
|
|
|
|
<geshi lang="bash">
|
|
./configure --with-ld-opt="/path/to/foo.o /path/to/bar.o" ...
|
|
</geshi>
|
|
|
|
If you have too many <code>.o</code> files, then it might not be feasible to name them all in a single command. In this case, you can build a static library (or archive) for your <code>.o</code> files, as in
|
|
|
|
<geshi lang="bash">
|
|
ar rcus libmyluafiles.a *.o
|
|
</geshi>
|
|
|
|
then you can link the <code>myluafiles</code> archive as a whole to your nginx executable:
|
|
|
|
<geshi lang="bash">
|
|
./configure \
|
|
--with-ld-opt="-L/path/to/lib -Wl,--whole-archive -lmyluafiles -Wl,--no-whole-archive"
|
|
</geshi>
|
|
|
|
where <code>/path/to/lib</code> is the path of the directory containing the <code>libmyluafiles.a</code> file. It should be noted that the linker option <code>--whole-archive</code> is required here because otherwise our archive will be skipped because no symbols in our archive are mentioned in the main parts of the nginx executable.
|
|
|
|
= Data Sharing within an Nginx Worker =
|
|
|
|
To globally share data among all the requests handled by the same Nginx worker
|
|
process, encapsulate the shared data into a Lua module, use the Lua
|
|
<code>require</code> builtin to import the module, and then manipulate the
|
|
shared data in Lua. This works because required Lua modules are loaded only
|
|
once and all coroutines will share the same copy of the module (both its code
|
|
and data).
|
|
|
|
Note that the use of global Lua variables is *strongly discouraged*, as it may
|
|
lead to unexpected race conditions between concurrent requests.
|
|
|
|
Here is a small example on sharing data within an Nginx worker via a Lua module:
|
|
|
|
<geshi lang="lua">
|
|
-- mydata.lua
|
|
local _M = {}
|
|
|
|
local data = {
|
|
dog = 3,
|
|
cat = 4,
|
|
pig = 5,
|
|
}
|
|
|
|
function _M.get_age(name)
|
|
return data[name]
|
|
end
|
|
|
|
return _M
|
|
</geshi>
|
|
|
|
and then accessing it from <code>nginx.conf</code>:
|
|
|
|
<geshi lang="nginx">
|
|
location /lua {
|
|
content_by_lua_block {
|
|
local mydata = require "mydata"
|
|
ngx.say(mydata.get_age("dog"))
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
The <code>mydata</code> module in this example will only be loaded and run on the first request to the location <code>/lua</code>,
|
|
and all subsequent requests to the same Nginx worker process will use the reloaded instance of the
|
|
module as well as the same copy of the data in it, until a <code>HUP</code> signal is sent to the Nginx master process to force a reload.
|
|
This data sharing technique is essential for high performance Lua applications based on this module.
|
|
|
|
Note that this data sharing is on a ''per-worker'' basis and not on a ''per-server'' basis. That is, when there are multiple Nginx worker processes under an Nginx master, data sharing cannot cross the process boundary between these workers.
|
|
|
|
It is usually recommended to share read-only data this way. You can also share changeable data among all the concurrent requests of each Nginx worker process as
|
|
long as there is ''no'' nonblocking I/O operations (including [[#ngx.sleep|ngx.sleep]])
|
|
in the middle of your calculations. As long as you do not give the
|
|
control back to the Nginx event loop and ngx_lua's light thread
|
|
scheduler (even implicitly), there can never be any race conditions in
|
|
between. For this reason, always be very careful when you want to share changeable data on the
|
|
worker level. Buggy optimizations can easily lead to hard-to-debug
|
|
race conditions under load.
|
|
|
|
If server-wide data sharing is required, then use one or more of the following approaches:
|
|
|
|
# Use the [[#ngx.shared.DICT|ngx.shared.DICT]] API provided by this module.
|
|
# Use only a single Nginx worker and a single server (this is however not recommended when there is a multi core CPU or multiple CPUs in a single machine).
|
|
# Use data storage mechanisms such as <code>memcached</code>, <code>redis</code>, <code>MySQL</code> or <code>PostgreSQL</code>. [https://openresty.org The OpenResty official releases] come with a set of companion Nginx modules and Lua libraries that provide interfaces with these data storage mechanisms.
|
|
|
|
= Known Issues =
|
|
|
|
== TCP socket connect operation issues ==
|
|
|
|
The [[#tcpsock:connect|tcpsock:connect]] method may indicate <code>success</code> despite connection failures such as with <code>Connection Refused</code> errors.
|
|
|
|
However, later attempts to manipulate the cosocket object will fail and return the actual error status message generated by the failed connect operation.
|
|
|
|
This issue is due to limitations in the Nginx event model and only appears to affect Mac OS X.
|
|
|
|
== Lua Coroutine Yielding/Resuming ==
|
|
|
|
* Because Lua's <code>dofile</code> and <code>require</code> builtins are currently implemented as C functions in LuaJIT 2.0/2.1, if the Lua file being loaded by <code>dofile</code> or <code>require</code> invokes [[#ngx.location.capture|ngx.location.capture*]], [[#ngx.exec|ngx.exec]], [[#ngx.exit|ngx.exit]], or other API functions requiring yielding in the *top-level* scope of the Lua file, then the Lua error "attempt to yield across C-call boundary" will be raised. To avoid this, put these calls requiring yielding into your own Lua functions in the Lua file instead of the top-level scope of the file.
|
|
|
|
== Lua Variable Scope ==
|
|
|
|
Care must be taken when importing modules, and this form should be used:
|
|
|
|
<geshi lang="lua">
|
|
local xxx = require('xxx')
|
|
</geshi>
|
|
|
|
instead of the old deprecated form:
|
|
|
|
<geshi lang="lua">
|
|
require('xxx')
|
|
</geshi>
|
|
|
|
Here is the reason: by design, the global environment has exactly the same lifetime as the Nginx request handler associated with it. Each request handler has its own set of Lua global variables and that is the idea of request isolation. The Lua module is actually loaded by the first Nginx request handler and is cached by the <code>require()</code> built-in in the <code>package.loaded</code> table for later reference, and the <code>module()</code> builtin used by some Lua modules has the side effect of setting a global variable to the loaded module table. But this global variable will be cleared at the end of the request handler, and every subsequent request handler all has its own (clean) global environment. So one will get Lua exception for accessing the <code>nil</code> value.
|
|
|
|
The use of Lua global variables is a generally inadvisable in the ngx_lua context as:
|
|
|
|
# the misuse of Lua globals has detrimental side effects on concurrent requests when such variables should instead be local in scope,
|
|
# Lua global variables require Lua table look-ups in the global environment which is computationally expensive, and
|
|
# some Lua global variable references may include typing errors which make such difficult to debug.
|
|
|
|
It is therefore *highly* recommended to always declare such within an appropriate local scope instead.
|
|
|
|
<geshi lang="lua">
|
|
-- Avoid
|
|
foo = 123
|
|
-- Recommended
|
|
local foo = 123
|
|
|
|
-- Avoid
|
|
function foo() return 123 end
|
|
-- Recommended
|
|
local function foo() return 123 end
|
|
</geshi>
|
|
|
|
To find all instances of Lua global variables in your Lua code, run the [https://github.com/openresty/nginx-devel-utils/blob/master/lua-releng lua-releng tool] across all <code>.lua</code> source files:
|
|
<geshi lang="text">
|
|
$ lua-releng
|
|
Checking use of Lua global variables in file lib/foo/bar.lua ...
|
|
1 [1489] SETGLOBAL 7 -1 ; contains
|
|
55 [1506] GETGLOBAL 7 -3 ; setvar
|
|
3 [1545] GETGLOBAL 3 -4 ; varexpand
|
|
</geshi>
|
|
The output says that the line 1489 of file <code>lib/foo/bar.lua</code> writes to a global variable named <code>contains</code>, the line 1506 reads from the global variable <code>setvar</code>, and line 1545 reads the global <code>varexpand</code>.
|
|
|
|
This tool will guarantee that local variables in the Lua module functions are all declared with the <code>local</code> keyword, otherwise a runtime exception will be thrown. It prevents undesirable race conditions while accessing such variables. See [[#Data_Sharing_within_an_Nginx_Worker|Data Sharing within an Nginx Worker]] for the reasons behind this.
|
|
|
|
== Locations Configured by Subrequest Directives of Other Modules ==
|
|
|
|
The [[#ngx.location.capture|ngx.location.capture]] and [[#ngx.location.capture_multi|ngx.location.capture_multi]] directives cannot capture locations that include the [[HttpAdditionModule#add_before_body|add_before_body]], [[HttpAdditionModule#add_after_body|add_after_body]], [https://nginx.org/en/docs/http/ngx_http_auth_request_module.html#auth_request auth_request], [[HttpEchoModule#echo_location|echo_location]], [[HttpEchoModule#echo_location_async|echo_location_async]], [[HttpEchoModule#echo_subrequest|echo_subrequest]], or [[HttpEchoModule#echo_subrequest_async|echo_subrequest_async]] directives.
|
|
|
|
<geshi lang="nginx">
|
|
location /foo {
|
|
content_by_lua_block {
|
|
res = ngx.location.capture("/bar")
|
|
}
|
|
}
|
|
location /bar {
|
|
echo_location /blah;
|
|
}
|
|
location /blah {
|
|
echo "Success!";
|
|
}
|
|
</geshi>
|
|
|
|
<geshi lang="nginx">
|
|
$ curl -i http://example.com/foo
|
|
</geshi>
|
|
|
|
will not work as expected.
|
|
|
|
== Cosockets Not Available Everywhere ==
|
|
|
|
Due to internal limitations in the Nginx core, the cosocket API is disabled in the following contexts: [[#set_by_lua|set_by_lua*]], [[#log_by_lua|log_by_lua*]], [[#header_filter_by_lua|header_filter_by_lua*]], and [[#body_filter_by_lua|body_filter_by_lua]].
|
|
|
|
The cosockets are currently also disabled in the [[#init_by_lua|init_by_lua*]] and [[#init_worker_by_lua|init_worker_by_lua*]] directive contexts but we may add support for these contexts in the future because there is no limitation in the Nginx core (or the limitation might be worked around).
|
|
|
|
There exists a workaround, however, when the original context does *not* need to wait for the cosocket results. That is, creating a zero-delay timer via the [[#ngx.timer.at|ngx.timer.at]] API and do the cosocket results in the timer handler, which runs asynchronously as to the original context creating the timer.
|
|
|
|
== Special Escaping Sequences ==
|
|
|
|
'''NOTE''' Following the <code>v0.9.17</code> release, this pitfall can be avoided by using the <code>*_by_lua_block {}</code> configuration directives.
|
|
|
|
PCRE sequences such as <code>\d</code>, <code>\s</code>, or <code>\w</code>, require special attention because in string literals, the backslash character, <code>\</code>, is stripped out by both the Lua language parser and by the Nginx config file parser before processing if not within a <code>*_by_lua_block {}</code> directive. So the following snippet will not work as expected:
|
|
|
|
<geshi lang="nginx">
|
|
# nginx.conf
|
|
? location /test {
|
|
? content_by_lua '
|
|
? local regex = "\d+" -- THIS IS WRONG OUTSIDE OF A *_by_lua_block DIRECTIVE
|
|
? local m = ngx.re.match("hello, 1234", regex)
|
|
? if m then ngx.say(m[0]) else ngx.say("not matched!") end
|
|
? ';
|
|
? }
|
|
# evaluates to "not matched!"
|
|
</geshi>
|
|
|
|
To avoid this, ''double'' escape the backslash:
|
|
|
|
<geshi lang="nginx">
|
|
# nginx.conf
|
|
location /test {
|
|
content_by_lua '
|
|
local regex = "\\\\d+"
|
|
local m = ngx.re.match("hello, 1234", regex)
|
|
if m then ngx.say(m[0]) else ngx.say("not matched!") end
|
|
';
|
|
}
|
|
# evaluates to "1234"
|
|
</geshi>
|
|
|
|
Here, <code>\\\\d+</code> is stripped down to <code>\\d+</code> by the Nginx config file parser and this is further stripped down to <code>\d+</code> by the Lua language parser before running.
|
|
|
|
Alternatively, the regex pattern can be presented as a long-bracketed Lua string literal by encasing it in "long brackets", <code>[[...]]</code>, in which case backslashes have to only be escaped once for the Nginx config file parser.
|
|
|
|
<geshi lang="nginx">
|
|
# nginx.conf
|
|
location /test {
|
|
content_by_lua '
|
|
local regex = [[\\d+]]
|
|
local m = ngx.re.match("hello, 1234", regex)
|
|
if m then ngx.say(m[0]) else ngx.say("not matched!") end
|
|
';
|
|
}
|
|
# evaluates to "1234"
|
|
</geshi>
|
|
|
|
Here, <code>[[\\d+]]</code> is stripped down to <code>[[\d+]]</code> by the Nginx config file parser and this is processed correctly.
|
|
|
|
Note that a longer from of the long bracket, <code>[=[...]=]</code>, may be required if the regex pattern contains <code>[...]</code> sequences.
|
|
The <code>[=[...]=]</code> form may be used as the default form if desired.
|
|
|
|
<geshi lang="nginx">
|
|
# nginx.conf
|
|
location /test {
|
|
content_by_lua '
|
|
local regex = [=[[0-9]+]=]
|
|
local m = ngx.re.match("hello, 1234", regex)
|
|
if m then ngx.say(m[0]) else ngx.say("not matched!") end
|
|
';
|
|
}
|
|
# evaluates to "1234"
|
|
</geshi>
|
|
|
|
An alternative approach to escaping PCRE sequences is to ensure that Lua code is placed in external script files and executed using the various <code>*_by_lua_file</code> directives.
|
|
With this approach, the backslashes are only stripped by the Lua language parser and therefore only need to be escaped once each.
|
|
|
|
<geshi lang="lua">
|
|
-- test.lua
|
|
local regex = "\\d+"
|
|
local m = ngx.re.match("hello, 1234", regex)
|
|
if m then ngx.say(m[0]) else ngx.say("not matched!") end
|
|
-- evaluates to "1234"
|
|
</geshi>
|
|
|
|
Within external script files, PCRE sequences presented as long-bracketed Lua string literals do not require modification.
|
|
|
|
<geshi lang="lua">
|
|
-- test.lua
|
|
local regex = [[\d+]]
|
|
local m = ngx.re.match("hello, 1234", regex)
|
|
if m then ngx.say(m[0]) else ngx.say("not matched!") end
|
|
-- evaluates to "1234"
|
|
</geshi>
|
|
|
|
As noted earlier, PCRE sequences presented within <code>*_by_lua_block {}</code> directives (available following the <code>v0.9.17</code> release) do not require modification.
|
|
|
|
<geshi lang="nginx">
|
|
# nginx.conf
|
|
location /test {
|
|
content_by_lua_block {
|
|
local regex = [[\d+]]
|
|
local m = ngx.re.match("hello, 1234", regex)
|
|
if m then ngx.say(m[0]) else ngx.say("not matched!") end
|
|
}
|
|
}
|
|
# evaluates to "1234"
|
|
</geshi>
|
|
|
|
'''NOTE''' You are recommended to use `by_lua_file` when the Lua code is very long.
|
|
|
|
== Mixing with SSI Not Supported ==
|
|
|
|
Mixing SSI with ngx_lua in the same Nginx request is not supported at all. Just use ngx_lua exclusively. Everything you can do with SSI can be done atop ngx_lua anyway and it can be more efficient when using ngx_lua.
|
|
|
|
== SPDY Mode Not Fully Supported ==
|
|
|
|
Certain Lua APIs provided by ngx_lua do not work in Nginx's SPDY mode yet: [[#ngx.location.capture|ngx.location.capture]], [[#ngx.location.capture_multi|ngx.location.capture_multi]], and [[#ngx.req.socket|ngx.req.socket]].
|
|
|
|
== Missing data on short circuited requests ==
|
|
|
|
Nginx may terminate a request early with (at least):
|
|
|
|
* 400 (Bad Request)
|
|
* 405 (Not Allowed)
|
|
* 408 (Request Timeout)
|
|
* 413 (Request Entity Too Large)
|
|
* 414 (Request URI Too Large)
|
|
* 494 (Request Headers Too Large)
|
|
* 499 (Client Closed Request)
|
|
* 500 (Internal Server Error)
|
|
* 501 (Not Implemented)
|
|
|
|
This means that phases that normally run are skipped, such as the rewrite or
|
|
access phase. This also means that later phases that are run regardless, e.g.
|
|
[[#log_by_lua|log_by_lua]], will not have access to information that is normally set in those
|
|
phases.
|
|
|
|
= TODO =
|
|
|
|
* cosocket: implement LuaSocket's unconnected UDP API.
|
|
* cosocket: add support in the context of [[#init_by_lua|init_by_lua*]].
|
|
* cosocket: implement the <code>bind()</code> method for stream-typed cosockets.
|
|
* cosocket: review and merge aviramc's [https://github.com/openresty/lua-nginx-module/pull/290 patch] for adding the <code>bsdrecv</code> method.
|
|
* cosocket: add configure options for different strategies of handling the cosocket connection exceeding in the pools.
|
|
* review and apply vadim-pavlov's patch for [[#ngx.location.capture|ngx.location.capture]]'s <code>extra_headers</code> option
|
|
* use <code>ngx_hash_t</code> to optimize the built-in header look-up process for [[#ngx.req.set_header|ngx.req.set_header]], and etc.
|
|
* add <code>ignore_resp_headers</code>, <code>ignore_resp_body</code>, and <code>ignore_resp</code> options to [[#ngx.location.capture|ngx.location.capture]] and [[#ngx.location.capture_multi|ngx.location.capture_multi]] methods, to allow micro performance tuning on the user side.
|
|
* add automatic Lua code time slicing support by yielding and resuming the Lua VM actively via Lua's debug hooks.
|
|
* add <code>stat</code> mode similar to [https://httpd.apache.org/docs/trunk/mod/mod_lua.html mod_lua].
|
|
|
|
= Changes =
|
|
|
|
The changes made in every release of this module are listed in the change logs of the OpenResty bundle:
|
|
|
|
https://openresty.org/#Changes
|
|
|
|
= Test Suite =
|
|
|
|
The following dependencies are required to run the test suite:
|
|
|
|
* Nginx version >= 1.4.2
|
|
|
|
* Perl modules:
|
|
** Test::Nginx: https://github.com/openresty/test-nginx
|
|
|
|
* Nginx modules:
|
|
** [https://github.com/simplresty/ngx_devel_kit ngx_devel_kit]
|
|
** [https://github.com/openresty/set-misc-nginx-module ngx_set_misc]
|
|
** [http://mdounin.ru/files/ngx_http_auth_request_module-0.2.tar.gz ngx_auth_request] (this is not needed if you're using Nginx 1.5.4+.
|
|
** [https://github.com/openresty/echo-nginx-module ngx_echo]
|
|
** [https://github.com/openresty/memc-nginx-module ngx_memc]
|
|
** [https://github.com/openresty/srcache-nginx-module ngx_srcache]
|
|
** ngx_lua (i.e., this module)
|
|
** [https://github.com/openresty/lua-upstream-nginx-module ngx_lua_upstream]
|
|
** [https://github.com/openresty/headers-more-nginx-module ngx_headers_more]
|
|
** [https://github.com/openresty/drizzle-nginx-module ngx_drizzle]
|
|
** [https://github.com/openresty/rds-json-nginx-module ngx_rds_json]
|
|
** [https://github.com/FRiCKLE/ngx_coolkit ngx_coolkit]
|
|
** [https://github.com/openresty/redis2-nginx-module ngx_redis2]
|
|
|
|
The order in which these modules are added during configuration is important because the position of any filter module in the
|
|
filtering chain determines the final output, for example. The correct adding order is shown above.
|
|
|
|
* 3rd-party Lua libraries:
|
|
** [http://www.kyne.com.au/~mark/software/lua-cjson.php lua-cjson]
|
|
|
|
* Applications:
|
|
** mysql: create database 'ngx_test', grant all privileges to user 'ngx_test', password is 'ngx_test'
|
|
** memcached: listening on the default port, 11211.
|
|
** redis: listening on the default port, 6379.
|
|
|
|
See also the [https://github.com/openresty/lua-nginx-module/blob/master/util/build.sh developer build script] for more details on setting up the testing environment.
|
|
|
|
To run the whole test suite in the default testing mode:
|
|
<geshi lang="text">
|
|
cd /path/to/lua-nginx-module
|
|
export PATH=/path/to/your/nginx/sbin:$PATH
|
|
prove -I/path/to/test-nginx/lib -r t
|
|
</geshi>
|
|
|
|
To run specific test files:
|
|
<geshi lang="text">
|
|
cd /path/to/lua-nginx-module
|
|
export PATH=/path/to/your/nginx/sbin:$PATH
|
|
prove -I/path/to/test-nginx/lib t/002-content.t t/003-errors.t
|
|
</geshi>
|
|
|
|
To run a specific test block in a particular test file, add the line <code>--- ONLY</code> to the test block you want to run, and then use the <code>prove</code> utility to run that <code>.t</code> file.
|
|
|
|
There are also various testing modes based on mockeagain, valgrind, and etc. Refer to the [https://search.cpan.org/perldoc?Test::Nginx Test::Nginx documentation] for more details for various advanced testing modes. See also the test reports for the Nginx test cluster running on Amazon EC2: https://qa.openresty.org.
|
|
|
|
= Copyright and License =
|
|
|
|
This module is licensed under the BSD license.
|
|
|
|
Copyright (C) 2009-2017, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
|
|
|
|
Copyright (C) 2009-2019, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>, OpenResty Inc.
|
|
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
= See Also =
|
|
|
|
Blog posts:
|
|
|
|
* [Introduction to Lua-Land CPU Flame Graphs](https://blog.openresty.com/en/lua-cpu-flame-graph/?src=gh_ngxlua)
|
|
* [How OpenResty and Nginx Allocate and Manage Memory](https://blog.openresty.com/en//how-or-alloc-mem?src=gh_ngxlua)
|
|
* [How OpenResty and Nginx Shared Memory Zones Consume RAM](https://blog.openresty.com/en/how-nginx-shm-consume-ram/?src=gh_ngxlua)
|
|
* [Memory Fragmentation in OpenResty and Nginx's Shared Memory Zones](https://blog.openresty.com/en/nginx-shm-frag/?src=gh_ngxlua)
|
|
|
|
Other related modules and libraries:
|
|
|
|
* [https://github.com/openresty/stream-lua-nginx-module#readme ngx_stream_lua_module] for an official port of this module for the Nginx "stream" subsystem (doing generic downstream TCP communications).
|
|
* [https://github.com/openresty/lua-resty-memcached lua-resty-memcached] library based on ngx_lua cosocket.
|
|
* [https://github.com/openresty/lua-resty-redis lua-resty-redis] library based on ngx_lua cosocket.
|
|
* [https://github.com/openresty/lua-resty-mysql lua-resty-mysql] library based on ngx_lua cosocket.
|
|
* [https://github.com/openresty/lua-resty-upload lua-resty-upload] library based on ngx_lua cosocket.
|
|
* [https://github.com/openresty/lua-resty-dns lua-resty-dns] library based on ngx_lua cosocket.
|
|
* [https://github.com/openresty/lua-resty-websocket lua-resty-websocket] library for both WebSocket server and client, based on ngx_lua cosocket.
|
|
* [https://github.com/openresty/lua-resty-string lua-resty-string] library based on [https://luajit.org/ext_ffi.html LuaJIT FFI].
|
|
* [https://github.com/openresty/lua-resty-lock lua-resty-lock] library for a nonblocking simple lock API.
|
|
* [https://github.com/cloudflare/lua-resty-cookie lua-resty-cookie] library for HTTP cookie manipulation.
|
|
* [https://openresty.org/#RoutingMySQLQueriesBasedOnURIArgs Routing requests to different MySQL queries based on URI arguments]
|
|
* [https://openresty.org/#DynamicRoutingBasedOnRedis Dynamic Routing Based on Redis and Lua]
|
|
* [https://openresty.org/#UsingLuaRocks Using LuaRocks with ngx_lua]
|
|
* [https://github.com/openresty/lua-nginx-module/wiki/Introduction Introduction to ngx_lua]
|
|
* [https://github.com/simplresty/ngx_devel_kit ngx_devel_kit]
|
|
* [[HttpEchoModule]]
|
|
* [[HttpDrizzleModule]]
|
|
* [https://github.com/FRiCKLE/ngx_postgres postgres-nginx-module]
|
|
* [[HttpMemcModule]]
|
|
* [https://openresty.org The OpenResty bundle]
|
|
* [https://github.com/openresty/nginx-systemtap-toolkit Nginx Systemtap Toolkit]
|
|
|
|
= Directives =
|
|
|
|
<!-- inline-toc -->
|
|
|
|
The basic building blocks of scripting Nginx with Lua are directives. Directives are used to specify when the user Lua code is run and
|
|
how the result will be used. Below is a diagram showing the order in which directives are executed.
|
|
|
|

|
|
|
|
== lua_load_resty_core ==
|
|
|
|
'''syntax:''' ''lua_load_resty_core on|off''
|
|
|
|
'''default:''' ''lua_load_resty_core on''
|
|
|
|
'''context:''' ''http''
|
|
|
|
This directive is deprecated since the <code>v0.10.16</code> release of this
|
|
module. The <code>resty.core</code> module from
|
|
[https://github.com/openresty/lua-resty-core lua-resty-core] is now mandatorily
|
|
loaded during the Lua VM initialization. Specifying this directive will have no
|
|
effect.
|
|
|
|
This directive was first introduced in the <code>v0.10.15</code> release and
|
|
used to optionally load the <code>resty.core</code> module.
|
|
|
|
== lua_capture_error_log ==
|
|
|
|
'''syntax:''' ''lua_capture_error_log size''
|
|
|
|
'''default:''' ''none''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Enables a buffer of the specified <code>size</code> for capturing all the Nginx error log message data (not just those produced
|
|
by this module or the Nginx http subsystem, but everything) without touching files or disks.
|
|
|
|
You can use units like `k` and `m` in the <code>size</code> value, as in
|
|
|
|
<geshi lang="nginx">
|
|
lua_capture_error_log 100k;
|
|
</geshi>
|
|
|
|
As a rule of thumb, a 4KB buffer can usually hold about 20 typical error log messages. So do the maths!
|
|
|
|
This buffer never grows. If it is full, new error log messages will replace the oldest ones in the buffer.
|
|
|
|
The size of the buffer must be bigger than the maximum length of a single error log message (which is 4K in OpenResty and 2K in stock NGINX).
|
|
|
|
You can read the messages in the buffer on the Lua land via the
|
|
[https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/errlog.md#get_logs get_logs()]
|
|
function of the
|
|
[https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/errlog.md#readme ngx.errlog]
|
|
module of the [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/errlog.md#readme lua-resty-core]
|
|
library. This Lua API function will return the captured error log messages and
|
|
also remove these already read from the global capturing buffer, making room
|
|
for any new error log data. For this reason, the user should not configure this
|
|
buffer to be too big if the user read the buffered error log data fast enough.
|
|
|
|
Note that the log level specified in the standard [https://nginx.org/r/error_log error_log] directive
|
|
''does'' have effect on this capturing facility. It only captures log
|
|
messages of a level no lower than the specified log level in the [https://nginx.org/r/error_log error_log] directive.
|
|
The user can still choose to set an even higher filtering log level on the fly via the Lua API function
|
|
[https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/errlog.md#set_filter_level errlog.set_filter_level].
|
|
So it is more flexible than the static [https://nginx.org/r/error_log error_log] directive.
|
|
|
|
It is worth noting that there is no way to capture the debugging logs
|
|
without building OpenResty or Nginx with the <code>./configure</code>
|
|
option <code>--with-debug</code>. And enabling debugging logs is
|
|
strongly discouraged in production builds due to high overhead.
|
|
|
|
This directive was first introduced in the <code>v0.10.9</code> release.
|
|
|
|
== lua_use_default_type ==
|
|
|
|
'''syntax:''' ''lua_use_default_type on | off''
|
|
|
|
'''default:''' ''lua_use_default_type on''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
Specifies whether to use the MIME type specified by the [https://nginx.org/en/docs/http/ngx_http_core_module.html#default_type default_type] directive for the default value of the <code>Content-Type</code> response header. Deactivate this directive if a default <code>Content-Type</code> response header for Lua request handlers is not desired.
|
|
|
|
This directive is turned on by default.
|
|
|
|
This directive was first introduced in the <code>v0.9.1</code> release.
|
|
|
|
== lua_malloc_trim ==
|
|
|
|
'''syntax:''' ''lua_malloc_trim <request-count>''
|
|
|
|
'''default:''' ''lua_malloc_trim 1000''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Asks the underlying <code>libc</code> runtime library to release its cached free memory back to the operating system every
|
|
<code>N</code> requests processed by the Nginx core. By default, <code>N</code> is 1000. You can configure the request count
|
|
by using your own numbers. Smaller numbers mean more frequent releases, which may introduce higher CPU time consumption and
|
|
smaller memory footprint while larger numbers usually lead to less CPU time overhead and relatively larger memory footprint.
|
|
Just tune the number for your own use cases.
|
|
|
|
Configuring the argument to <code>0</code> essentially turns off the periodical memory trimming altogether.
|
|
|
|
<geshi lang="nginx">
|
|
lua_malloc_trim 0; # turn off trimming completely
|
|
</geshi>
|
|
|
|
The current implementation uses an Nginx log phase handler to do the request counting. So the appearance of the
|
|
[https://nginx.org/en/docs/http/ngx_http_core_module.html#log_subrequest log_subrequest on] directives in <code>nginx.conf</code>
|
|
may make the counting faster when subrequests are involved. By default, only "main requests" count.
|
|
|
|
Note that this directive does *not* affect the memory allocated by LuaJIT's own allocator based on the <code>mmap</code>
|
|
system call.
|
|
|
|
This directive was first introduced in the <code>v0.10.7</code> release.
|
|
|
|
== lua_code_cache ==
|
|
'''syntax:''' ''lua_code_cache on | off''
|
|
|
|
'''default:''' ''lua_code_cache on''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
Enables or disables the Lua code cache for Lua code in <code>*_by_lua_file</code> directives (like [[#set_by_lua_file|set_by_lua_file]] and
|
|
[[#content_by_lua_file|content_by_lua_file]]) and Lua modules.
|
|
|
|
When turning off, every request served by ngx_lua will run in a separate Lua VM instance, starting from the <code>0.9.3</code> release. So the Lua files referenced in [[#set_by_lua_file|set_by_lua_file]],
|
|
[[#content_by_lua_file|content_by_lua_file]], [[#access_by_lua_file|access_by_lua_file]],
|
|
and etc will not be cached
|
|
and all Lua modules used will be loaded from scratch. With this in place, developers can adopt an edit-and-refresh approach.
|
|
|
|
Please note however, that Lua code written inlined within nginx.conf
|
|
such as those specified by [[#set_by_lua|set_by_lua]], [[#content_by_lua|content_by_lua]],
|
|
[[#access_by_lua|access_by_lua]], and [[#rewrite_by_lua|rewrite_by_lua]] will not be updated when you edit the inlined Lua code in your <code>nginx.conf</code> file because only the Nginx config file parser can correctly parse the <code>nginx.conf</code>
|
|
file and the only way is to reload the config file
|
|
by sending a <code>HUP</code> signal or just to restart Nginx.
|
|
|
|
Even when the code cache is enabled, Lua files which are loaded by <code>dofile</code> or <code>loadfile</code>
|
|
in *_by_lua_file cannot be cached (unless you cache the results yourself). Usually you can either use the [[#init_by_lua|init_by_lua]]
|
|
or [[#init-by_lua_file|init_by_lua_file]] directives to load all such files or just make these Lua files true Lua modules
|
|
and load them via <code>require</code>.
|
|
|
|
The ngx_lua module does not support the <code>stat</code> mode available with the
|
|
Apache <code>mod_lua</code> module (yet).
|
|
|
|
Disabling the Lua code cache is strongly
|
|
discouraged for production use and should only be used during
|
|
development as it has a significant negative impact on overall performance. For example, the performance of a "hello world" Lua example can drop by an order of magnitude after disabling the Lua code cache.
|
|
|
|
== lua_thread_cache_max_entries ==
|
|
|
|
'''syntax:''' ''lua_thread_cache_max_entries <num>''
|
|
|
|
'''default:''' ''lua_thread_cache_max_entries 1024''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Specifies the maximum number of entries allowed in the worker process level lua thread object cache.
|
|
|
|
This cache recycles the lua thread GC objects among all our "light threads".
|
|
|
|
A zero value of `<num>` disables the cache.
|
|
|
|
Note that this feature requires OpenResty's LuaJIT with the new C API `lua_resetthread`.
|
|
|
|
This feature was first introduced in verson `v0.10.9`.
|
|
|
|
== lua_regex_cache_max_entries ==
|
|
|
|
'''syntax:''' ''lua_regex_cache_max_entries <num>''
|
|
|
|
'''default:''' ''lua_regex_cache_max_entries 1024''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Specifies the maximum number of entries allowed in the worker process level compiled regex cache.
|
|
|
|
The regular expressions used in [[#ngx.re.match|ngx.re.match]], [[#ngx.re.gmatch|ngx.re.gmatch]], [[#ngx.re.sub|ngx.re.sub]], and [[#ngx.re.gsub|ngx.re.gsub]] will be cached within this cache if the regex option <code>o</code> (i.e., compile-once flag) is specified.
|
|
|
|
The default number of entries allowed is 1024 and when this limit is reached, new regular expressions will not be cached (as if the <code>o</code> option was not specified) and there will be one, and only one, warning in the <code>error.log</code> file:
|
|
|
|
<geshi lang="text">
|
|
2011/08/27 23:18:26 [warn] 31997#0: *1 lua exceeding regex cache max entries (1024), ...
|
|
</geshi>
|
|
|
|
If you are using the <code>ngx.re.*</code> implementation of [lua-resty-core](https://github.com/openresty/lua-resty-core) by loading the <code>resty.core.regex</code> module (or just the <code>resty.core</code> module), then an LRU cache is used for the regex cache being used here.
|
|
|
|
Do not activate the <code>o</code> option for regular expressions (and/or <code>replace</code> string arguments for [[#ngx.re.sub|ngx.re.sub]] and [[#ngx.re.gsub|ngx.re.gsub]]) that are generated ''on the fly'' and give rise to infinite variations to avoid hitting the specified limit.
|
|
|
|
== lua_regex_match_limit ==
|
|
|
|
'''syntax:''' ''lua_regex_match_limit <num>''
|
|
|
|
'''default:''' ''lua_regex_match_limit 0''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Specifies the "match limit" used by the PCRE library when executing the [[#ngx.re.match|ngx.re API]]. To quote the PCRE manpage, "the limit ... has the effect of limiting the amount of backtracking that can take place."
|
|
|
|
When the limit is hit, the error string "pcre_exec() failed: -8" will be returned by the [[#ngx.re.match|ngx.re API]] functions on the Lua land.
|
|
|
|
When setting the limit to 0, the default "match limit" when compiling the PCRE library is used. And this is the default value of this directive.
|
|
|
|
This directive was first introduced in the <code>v0.8.5</code> release.
|
|
|
|
== lua_package_path ==
|
|
|
|
'''syntax:''' ''lua_package_path <lua-style-path-str>''
|
|
|
|
'''default:''' ''The content of LUA_PATH environment variable or Lua's compiled-in defaults.''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Sets the Lua module search path used by scripts specified by [[#set_by_lua|set_by_lua]],
|
|
[[#content_by_lua|content_by_lua]] and others. The path string is in standard Lua path form, and <code>;;</code>
|
|
can be used to stand for the original search paths.
|
|
|
|
As from the <code>v0.5.0rc29</code> release, the special notation <code>$prefix</code> or <code>${prefix}</code> can be used in the search path string to indicate the path of the <code>server prefix</code> usually determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
== lua_package_cpath ==
|
|
|
|
'''syntax:''' ''lua_package_cpath <lua-style-cpath-str>''
|
|
|
|
'''default:''' ''The content of LUA_CPATH environment variable or Lua's compiled-in defaults.''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Sets the Lua C-module search path used by scripts specified by [[#set_by_lua|set_by_lua]],
|
|
[[#content_by_lua|content_by_lua]] and others. The cpath string is in standard Lua cpath form, and <code>;;</code>
|
|
can be used to stand for the original cpath.
|
|
|
|
As from the <code>v0.5.0rc29</code> release, the special notation <code>$prefix</code> or <code>${prefix}</code> can be used in the search path string to indicate the path of the <code>server prefix</code> usually determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
== init_by_lua ==
|
|
|
|
'''syntax:''' ''init_by_lua <lua-script-str>''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''loading-config''
|
|
|
|
'''NOTE''' Use of this directive is ''discouraged'' following the <code>v0.9.17</code> release. Use the [[#init_by_lua_block|init_by_lua_block]] directive instead.
|
|
|
|
Similar to the [[#init_by_lua_block|init_by_lua_block]] directive, but accepts the Lua source directly in an Nginx string literal (which requires
|
|
special character escaping).
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
init_by_lua '
|
|
print("I need no extra escaping here, for example: \r\nblah")
|
|
'
|
|
</geshi>
|
|
|
|
This directive was first introduced in the <code>v0.5.5</code> release.
|
|
|
|
== init_by_lua_block ==
|
|
|
|
'''syntax:''' ''init_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''loading-config''
|
|
|
|
|
|
When Nginx receives the <code>HUP</code> signal and starts reloading the config file, the Lua VM will also be re-created and <code>init_by_lua_block</code> will run again on the new Lua VM. In case that the [[#lua_code_cache|lua_code_cache]] directive is turned off (default on), the <code>init_by_lua_block</code> handler will run upon every request because in this special mode a standalone Lua VM is always created for each request.
|
|
|
|
Usually you can pre-load Lua modules at server start-up by means of this hook and take advantage of modern operating systems' copy-on-write (COW) optimization. Here is an example for pre-loading Lua modules:
|
|
|
|
<geshi lang="nginx">
|
|
# this runs before forking out nginx worker processes:
|
|
init_by_lua_block { require "cjson" }
|
|
|
|
server {
|
|
location = /api {
|
|
content_by_lua_block {
|
|
-- the following require() will just return
|
|
-- the already loaded module from package.loaded:
|
|
ngx.say(require "cjson".encode{dog = 5, cat = 6})
|
|
}
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
You can also initialize the [[#lua_shared_dict|lua_shared_dict]] shm storage at this phase. Here is an example for this:
|
|
|
|
<geshi lang="nginx">
|
|
lua_shared_dict dogs 1m;
|
|
|
|
init_by_lua_block {
|
|
local dogs = ngx.shared.dogs
|
|
dogs:set("Tom", 56)
|
|
}
|
|
|
|
server {
|
|
location = /api {
|
|
content_by_lua_block {
|
|
local dogs = ngx.shared.dogs
|
|
ngx.say(dogs:get("Tom"))
|
|
}
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
But note that, the [[#lua_shared_dict|lua_shared_dict]]'s shm storage will not be cleared through a config reload (via the <code>HUP</code> signal, for example). So if you do ''not'' want to re-initialize the shm storage in your <code>init_by_lua_block</code> code in this case, then you just need to set a custom flag in the shm storage and always check the flag in your <code>init_by_lua_block</code> code.
|
|
|
|
Because the Lua code in this context runs before Nginx forks its worker processes (if any), data or code loaded here will enjoy the [https://en.wikipedia.org/wiki/Copy-on-write Copy-on-write (COW)] feature provided by many operating systems among all the worker processes, thus saving a lot of memory.
|
|
|
|
Do *not* initialize your own Lua global variables in this context because use of Lua global variables have performance penalties and can lead to global namespace pollution (see the [[#Lua_Variable_Scope|Lua Variable Scope]] section for more details). The recommended way is to use proper [https://www.lua.org/manual/5.1/manual.html#5.3 Lua module] files (but do not use the standard Lua function [https://www.lua.org/manual/5.1/manual.html#pdf-module module()] to define Lua modules because it pollutes the global namespace as well) and call [https://www.lua.org/manual/5.1/manual.html#pdf-require require()] to load your own module files in <code>init_by_lua_block</code> or other contexts ([https://www.lua.org/manual/5.1/manual.html#pdf-require require()] does cache the loaded Lua modules in the global <code>package.loaded</code> table in the Lua registry so your modules will only loaded once for the whole Lua VM instance).
|
|
|
|
Only a small set of the [[#Nginx API for Lua|Nginx API for Lua]] is supported in this context:
|
|
|
|
* Logging APIs: [[#ngx.log|ngx.log]] and [[#print|print]],
|
|
* Shared Dictionary API: [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
More Nginx APIs for Lua may be supported in this context upon future user requests.
|
|
|
|
Basically you can safely use Lua libraries that do blocking I/O in this very context because blocking the master process during server start-up is completely okay. Even the Nginx core does blocking I/O (at least on resolving upstream's host names) at the configure-loading phase.
|
|
|
|
You should be very careful about potential security vulnerabilities in your Lua code registered in this context because the Nginx master process is often run under the <code>root</code> account.
|
|
|
|
This directive was first introduced in the <code>v0.9.17</code> release.
|
|
|
|
See also the following blog posts for more details on OpenResty and Nginx's shared memory zones:
|
|
|
|
* [How OpenResty and Nginx Shared Memory Zones Consume RAM](https://blog.openresty.com/en/how-nginx-shm-consume-ram/?src=gh_ngxlua)
|
|
* [Memory Fragmentation in OpenResty and Nginx's Shared Memory Zones](https://blog.openresty.com/en/nginx-shm-frag/?src=gh_ngxlua)
|
|
|
|
== init_by_lua_file ==
|
|
|
|
'''syntax:''' ''init_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''loading-config''
|
|
|
|
Equivalent to [[#init_by_lua_block|init_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code or [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
This directive was first introduced in the <code>v0.5.5</code> release.
|
|
|
|
== init_worker_by_lua ==
|
|
|
|
'''syntax:''' ''init_worker_by_lua <lua-script-str>''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''starting-worker''
|
|
|
|
'''NOTE''' Use of this directive is ''discouraged'' following the <code>v0.9.17</code> release. Use the [[#init_worker_by_lua_block|init_worker_by_lua_block]] directive instead.
|
|
|
|
Similar to the [[#init_worker_by_lua_block|init_worker_by_lua_block]] directive, but accepts the Lua source directly in an Nginx string literal (which requires
|
|
special character escaping).
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
init_worker_by_lua '
|
|
print("I need no extra escaping here, for example: \r\nblah")
|
|
';
|
|
</geshi>
|
|
|
|
This directive was first introduced in the <code>v0.9.5</code> release.
|
|
|
|
This hook no longer runs in the cache manager and cache loader processes since the <code>v0.10.12</code> release.
|
|
|
|
== init_worker_by_lua_block ==
|
|
|
|
'''syntax:''' ''init_worker_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''starting-worker''
|
|
|
|
Runs the specified Lua code upon every Nginx worker process's startup when the master process is enabled. When the master process is disabled, this hook will just run after [[#init_by_lua_block|init_by_lua*]].
|
|
|
|
This hook is often used to create per-worker reoccurring timers (via the [[#ngx.timer.at|ngx.timer.at]] Lua API), either for backend health-check or other timed routine work. Below is an example,
|
|
|
|
<geshi lang="nginx">
|
|
init_worker_by_lua_block {
|
|
local delay = 3 -- in seconds
|
|
local new_timer = ngx.timer.at
|
|
local log = ngx.log
|
|
local ERR = ngx.ERR
|
|
local check
|
|
|
|
check = function(premature)
|
|
if not premature then
|
|
-- do the health check or other routine work
|
|
local ok, err = new_timer(delay, check)
|
|
if not ok then
|
|
log(ERR, "failed to create timer: ", err)
|
|
return
|
|
end
|
|
end
|
|
|
|
-- do something in timer
|
|
end
|
|
|
|
local hdl, err = new_timer(delay, check)
|
|
if not hdl then
|
|
log(ERR, "failed to create timer: ", err)
|
|
return
|
|
end
|
|
|
|
-- other job in init_worker_by_lua
|
|
}
|
|
</geshi>
|
|
|
|
This directive was first introduced in the <code>v0.9.17</code> release.
|
|
|
|
This hook no longer runs in the cache manager and cache loader processes since the <code>v0.10.12</code> release.
|
|
|
|
== init_worker_by_lua_file ==
|
|
|
|
'''syntax:''' ''init_worker_by_lua_file <lua-file-path>''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''starting-worker''
|
|
|
|
Similar to [[#init_worker_by_lua_block|init_worker_by_lua_block]], but accepts the file path to a Lua source file or Lua bytecode file.
|
|
|
|
This directive was first introduced in the <code>v0.9.5</code> release.
|
|
|
|
This hook no longer runs in the cache manager and cache loader processes since the <code>v0.10.12</code> release.
|
|
|
|
== exit_worker_by_lua_block ==
|
|
|
|
'''syntax:''' ''exit_worker_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''exiting-worker''
|
|
|
|
Runs the specified Lua code upon every Nginx worker process's exit when the master process is enabled. When the master process is disabled, this hook will run before the Nginx process exits.
|
|
|
|
This hook is often used to release resources allocated by each worker (e.g. resources allocated by [[#init_worker_by_lua_block|init_worker_by_lua*]]), or to prevent workers from exiting abnormally.
|
|
|
|
For example,
|
|
|
|
<geshi lang="nginx">
|
|
exit_worker_by_lua_block {
|
|
print("log from exit_worker_by_lua_block")
|
|
}
|
|
</geshi>
|
|
|
|
It's not allowed to create a timer (even a 0-delay timer) here since it runs after all timers have been processed.
|
|
|
|
This directive was first introduced in the <code>v0.10.18</code> release.
|
|
|
|
== exit_worker_by_lua_file ==
|
|
|
|
'''syntax:''' ''exit_worker_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''exiting-worker''
|
|
|
|
Similar to [[#exit_worker_by_lua_block|exit_worker_by_lua_block]], but accepts the file path to a Lua source file or Lua bytecode file.
|
|
|
|
This directive was first introduced in the <code>v0.10.18</code> release.
|
|
|
|
== set_by_lua ==
|
|
|
|
'''syntax:''' ''set_by_lua $res <lua-script-str> [$arg1 $arg2 ...]''
|
|
|
|
'''context:''' ''server, server if, location, location if''
|
|
|
|
'''phase:''' ''rewrite''
|
|
|
|
'''NOTE''' Use of this directive is ''discouraged'' following the <code>v0.9.17</code> release. Use the [[#set_by_lua_block|set_by_lua_block]] directive instead.
|
|
|
|
Similar to the [[#set_by_lua_block|set_by_lua_block]] directive, but accepts the Lua source directly in an Nginx string literal (which requires
|
|
special character escaping), and
|
|
# this directive support extra arguments after the Lua script.
|
|
|
|
For example,
|
|
|
|
<geshi lang="nginx">
|
|
set_by_lua $res ' return 32 + math.cos(32) ';
|
|
# $res now has the value "32.834223360507" or alike.
|
|
</geshi>
|
|
|
|
As from the <code>v0.5.0rc29</code> release, Nginx variable interpolation is disabled in the <code><lua-script-str></code> argument of this directive and therefore, the dollar sign character (<code>$</code>) can be used directly.
|
|
|
|
This directive requires the [https://github.com/simplresty/ngx_devel_kit ngx_devel_kit] module.
|
|
|
|
== set_by_lua_block ==
|
|
|
|
'''syntax:''' ''set_by_lua_block $res { lua-script }''
|
|
|
|
'''context:''' ''server, server if, location, location if''
|
|
|
|
'''phase:''' ''rewrite''
|
|
|
|
Executes code specified inside a pair of curly braces (<code>{}</code>), and returns string output to <code>$res</code>.
|
|
The code inside a pair of curly braces (<code>{}</code>) can make [[#Nginx API for Lua|API calls]] and can retrieve input arguments from the <code>ngx.arg</code> table (index starts from <code>1</code> and increases sequentially).
|
|
|
|
This directive is designed to execute short, fast running code blocks as the Nginx event loop is blocked during code execution. Time consuming code sequences should therefore be avoided.
|
|
|
|
This directive is implemented by injecting custom commands into the standard [[HttpRewriteModule]]'s command list. Because [[HttpRewriteModule]] does not support nonblocking I/O in its commands, Lua APIs requiring yielding the current Lua "light thread" cannot work in this directive.
|
|
|
|
At least the following API functions are currently disabled within the context of <code>set_by_lua_block</code>:
|
|
|
|
* Output API functions (e.g., [[#ngx.say|ngx.say]] and [[#ngx.send_headers|ngx.send_headers]])
|
|
* Control API functions (e.g., [[#ngx.exit|ngx.exit]])
|
|
* Subrequest API functions (e.g., [[#ngx.location.capture|ngx.location.capture]] and [[#ngx.location.capture_multi|ngx.location.capture_multi]])
|
|
* Cosocket API functions (e.g., [[#ngx.socket.tcp|ngx.socket.tcp]] and [[#ngx.req.socket|ngx.req.socket]]).
|
|
* Sleeping API function [[#ngx.sleep|ngx.sleep]].
|
|
|
|
In addition, note that this directive can only write out a value to a single Nginx variable at
|
|
a time. However, a workaround is possible using the [[#ngx.var.VARIABLE|ngx.var.VARIABLE]] interface.
|
|
|
|
<geshi lang="nginx">
|
|
location /foo {
|
|
set $diff ''; # we have to predefine the $diff variable here
|
|
|
|
set_by_lua_block $sum {
|
|
local a = 32
|
|
local b = 56
|
|
|
|
ngx.var.diff = a - b -- write to $diff directly
|
|
return a + b -- return the $sum value normally
|
|
}
|
|
|
|
echo "sum = $sum, diff = $diff";
|
|
}
|
|
</geshi>
|
|
|
|
This directive can be freely mixed with all directives of the [[HttpRewriteModule]], [[HttpSetMiscModule]], and [[HttpArrayVarModule]] modules. All of these directives will run in the same order as they appear in the config file.
|
|
|
|
<geshi lang="nginx">
|
|
set $foo 32;
|
|
set_by_lua_block $bar { return tonumber(ngx.var.foo) + 1 }
|
|
set $baz "bar: $bar"; # $baz == "bar: 33"
|
|
</geshi>
|
|
|
|
No special escaping is required in the Lua code block.
|
|
|
|
This directive requires the [https://github.com/simplresty/ngx_devel_kit ngx_devel_kit] module.
|
|
|
|
This directive was first introduced in the <code>v0.9.17</code> release.
|
|
|
|
== set_by_lua_file ==
|
|
|
|
'''syntax:''' ''set_by_lua_file $res <path-to-lua-script-file> [$arg1 $arg2 ...]''
|
|
|
|
'''context:''' ''server, server if, location, location if''
|
|
|
|
'''phase:''' ''rewrite''
|
|
|
|
Equivalent to [[#set_by_lua_block|set_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
Nginx variable interpolation is supported in the <code><path-to-lua-script-file></code> argument string of this directive. But special care must be taken for injection attacks.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached
|
|
and the Nginx config must be reloaded each time the Lua source file is modified.
|
|
The Lua code cache can be temporarily disabled during development by
|
|
switching [[#lua_code_cache|lua_code_cache]] <code>off</code> in <code>nginx.conf</code> to avoid reloading Nginx.
|
|
|
|
This directive requires the [https://github.com/simplresty/ngx_devel_kit ngx_devel_kit] module.
|
|
|
|
== content_by_lua ==
|
|
|
|
'''syntax:''' ''content_by_lua <lua-script-str>''
|
|
|
|
'''context:''' ''location, location if''
|
|
|
|
'''phase:''' ''content''
|
|
|
|
'''NOTE''' Use of this directive is ''discouraged'' following the <code>v0.9.17</code> release. Use the [[#content_by_lua_block|content_by_lua_block]] directive instead.
|
|
|
|
Similar to the [[#content_by_lua_block|content_by_lua_block]] directive, but accepts the Lua source directly in an Nginx string literal (which requires
|
|
special character escaping).
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
content_by_lua '
|
|
ngx.say("I need no extra escaping here, for example: \r\nblah")
|
|
';
|
|
</geshi>
|
|
|
|
== content_by_lua_block ==
|
|
|
|
'''syntax:''' ''content_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''location, location if''
|
|
|
|
'''phase:''' ''content''
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
content_by_lua_block {
|
|
ngx.say("I need no extra escaping here, for example: \r\nblah")
|
|
}
|
|
</geshi>
|
|
|
|
Acts as a "content handler" and executes Lua code string specified in <code>{ lua-script }</code> for every request.
|
|
The Lua code may make [[#Nginx API for Lua|API calls]] and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).
|
|
|
|
Do not use this directive and other content handler directives in the same location. For example, this directive and the [[HttpProxyModule#proxy_pass|proxy_pass]] directive should not be used in the same location.
|
|
|
|
This directive was first introduced in the <code>v0.9.17</code> release.
|
|
|
|
== content_by_lua_file ==
|
|
|
|
'''syntax:''' ''content_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''location, location if''
|
|
|
|
'''phase:''' ''content''
|
|
|
|
Equivalent to [[#content_by_lua_block|content_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
Nginx variables can be used in the <code><path-to-lua-script-file></code> string to provide flexibility. This however carries some risks and is not ordinarily recommended.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached
|
|
and the Nginx config must be reloaded each time the Lua source file is modified.
|
|
The Lua code cache can be temporarily disabled during development by
|
|
switching [[#lua_code_cache|lua_code_cache]] <code>off</code> in <code>nginx.conf</code> to avoid reloading Nginx.
|
|
|
|
Nginx variables are supported in the file path for dynamic dispatch, for example:
|
|
|
|
<geshi lang="nginx">
|
|
# CAUTION: contents in nginx var must be carefully filtered,
|
|
# otherwise there'll be great security risk!
|
|
location ~ ^/app/([-_a-zA-Z0-9/]+) {
|
|
set $path $1;
|
|
content_by_lua_file /path/to/lua/app/root/$path.lua;
|
|
}
|
|
</geshi>
|
|
|
|
But be very careful about malicious user inputs and always carefully validate or filter out the user-supplied path components.
|
|
|
|
== server_rewrite_by_lua_block ==
|
|
|
|
'''syntax:''' ''server_rewrite_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http, server''
|
|
|
|
'''phase:''' ''server rewrite''
|
|
|
|
Acts as a server rewrite phase handler and executes Lua code string specified in <code>{ lua-script }</code> for every request.
|
|
The Lua code may make [[#Nginx API for Lua|API calls]] and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).
|
|
|
|
<geshi lang="nginx">
|
|
server {
|
|
...
|
|
|
|
server_rewrite_by_lua_block {
|
|
ngx.ctx.a = "server_rewrite_by_lua_block in http"
|
|
}
|
|
|
|
location /lua {
|
|
content_by_lua_block {
|
|
ngx.say(ngx.ctx.a)
|
|
ngx.log(ngx.INFO, ngx.ctx.a)
|
|
}
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Just as any other rewrite phase handlers, [[#server_rewrite_by_lua_block|server_rewrite_by_lua_block]] also runs in subrequests.
|
|
|
|
<geshi lang="nginx">
|
|
server {
|
|
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")
|
|
}
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Note that when calling <code>ngx.exit(ngx.OK)</code> within a [[#server_rewrite_by_lua_block|server_rewrite_by_lua_block]] handler, the Nginx request processing control flow will still continue to the content handler. To terminate the current request from within a [[#server_rewrite_by_lua_block|server_rewrite_by_lua_block]] handler, call [[#ngx.exit|ngx.exit]] with status >= 200 (<code>ngx.HTTP_OK</code>) and status < 300 (<code>ngx.HTTP_SPECIAL_RESPONSE</code>) for successful quits and <code>ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)</code> (or its friends) for failures.
|
|
|
|
|
|
<geshi lang="nginx">
|
|
server_rewrite_by_lua_block {
|
|
ngx.exit(503)
|
|
}
|
|
|
|
location /bar {
|
|
...
|
|
# never exec
|
|
}
|
|
</geshi>
|
|
|
|
|
|
== server_rewrite_by_lua_file ==
|
|
|
|
'''syntax:''' ''server_rewrite_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http, server''
|
|
|
|
'''phase:''' ''server rewrite''
|
|
|
|
Equivalent to [[#server_rewrite_by_lua_block|server_rewrite_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.10.22</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
Nginx variables can be used in the <code><path-to-lua-script-file></code> string to provide flexibility. This however carries some risks and is not ordinarily recommended.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached and the Nginx config must be reloaded each time the Lua source file is modified. The Lua code cache can be temporarily disabled during development by switching [[#lua_code_cache|lua_code_cache]] <code>off</code> in <code>nginx.conf</code> to avoid reloading Nginx.
|
|
|
|
== rewrite_by_lua ==
|
|
|
|
'''syntax:''' ''rewrite_by_lua <lua-script-str>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''rewrite tail''
|
|
|
|
'''NOTE''' Use of this directive is ''discouraged'' following the <code>v0.9.17</code> release. Use the [[#rewrite_by_lua_block|rewrite_by_lua_block]] directive instead.
|
|
|
|
Similar to the [[#rewrite_by_lua_block|rewrite_by_lua_block]] directive, but accepts the Lua source directly in an Nginx string literal (which requires
|
|
special character escaping).
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
rewrite_by_lua '
|
|
do_something("hello, world!\nhiya\n")
|
|
';
|
|
</geshi>
|
|
|
|
== rewrite_by_lua_block ==
|
|
|
|
'''syntax:''' ''rewrite_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''rewrite tail''
|
|
|
|
Acts as a rewrite phase handler and executes Lua code string specified in <code>{ lua-script }</code> for every request.
|
|
The Lua code may make [[#Nginx API for Lua|API calls]] and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).
|
|
|
|
Note that this handler always runs ''after'' the standard [[HttpRewriteModule]]. So the following will work as expected:
|
|
|
|
<geshi lang="nginx">
|
|
location /foo {
|
|
set $a 12; # create and initialize $a
|
|
set $b ""; # create and initialize $b
|
|
rewrite_by_lua_block {
|
|
ngx.var.b = tonumber(ngx.var.a) + 1
|
|
}
|
|
echo "res = $b";
|
|
}
|
|
</geshi>
|
|
|
|
because <code>set $a 12</code> and <code>set $b ""</code> run ''before'' [[#rewrite_by_lua_block|rewrite_by_lua_block]].
|
|
|
|
On the other hand, the following will not work as expected:
|
|
|
|
<geshi lang="nginx">
|
|
? location /foo {
|
|
? set $a 12; # create and initialize $a
|
|
? set $b ''; # create and initialize $b
|
|
? rewrite_by_lua_block {
|
|
? ngx.var.b = tonumber(ngx.var.a) + 1
|
|
? }
|
|
? if ($b = '13') {
|
|
? rewrite ^ /bar redirect;
|
|
? break;
|
|
? }
|
|
?
|
|
? echo "res = $b";
|
|
? }
|
|
</geshi>
|
|
|
|
because <code>if</code> runs ''before'' [[#rewrite_by_lua_block|rewrite_by_lua_block]] even if it is placed after [[#rewrite_by_lua_block|rewrite_by_lua_block]] in the config.
|
|
|
|
The right way of doing this is as follows:
|
|
|
|
<geshi lang="nginx">
|
|
location /foo {
|
|
set $a 12; # create and initialize $a
|
|
set $b ''; # create and initialize $b
|
|
rewrite_by_lua_block {
|
|
ngx.var.b = tonumber(ngx.var.a) + 1
|
|
if tonumber(ngx.var.b) == 13 then
|
|
return ngx.redirect("/bar")
|
|
end
|
|
}
|
|
|
|
echo "res = $b";
|
|
}
|
|
</geshi>
|
|
|
|
Note that the [http://www.grid.net.ru/nginx/eval.en.html ngx_eval] module can be approximated by using [[#rewrite_by_lua_block|rewrite_by_lua_block]]. For example,
|
|
|
|
<geshi lang="nginx">
|
|
location / {
|
|
eval $res {
|
|
proxy_pass http://foo.com/check-spam;
|
|
}
|
|
|
|
if ($res = 'spam') {
|
|
rewrite ^ /terms-of-use.html redirect;
|
|
}
|
|
|
|
fastcgi_pass ...;
|
|
}
|
|
</geshi>
|
|
|
|
can be implemented in ngx_lua as:
|
|
|
|
<geshi lang="nginx">
|
|
location = /check-spam {
|
|
internal;
|
|
proxy_pass http://foo.com/check-spam;
|
|
}
|
|
|
|
location / {
|
|
rewrite_by_lua_block {
|
|
local res = ngx.location.capture("/check-spam")
|
|
if res.body == "spam" then
|
|
return ngx.redirect("/terms-of-use.html")
|
|
end
|
|
}
|
|
|
|
fastcgi_pass ...;
|
|
}
|
|
</geshi>
|
|
|
|
Just as any other rewrite phase handlers, [[#rewrite_by_lua_block|rewrite_by_lua_block]] also runs in subrequests.
|
|
|
|
Note that when calling <code>ngx.exit(ngx.OK)</code> within a [[#rewrite_by_lua_block|rewrite_by_lua_block]] handler, the Nginx request processing control flow will still continue to the content handler. To terminate the current request from within a [[#rewrite_by_lua_block|rewrite_by_lua_block]] handler, call [[#ngx.exit|ngx.exit]] with status >= 200 (<code>ngx.HTTP_OK</code>) and status < 300 (<code>ngx.HTTP_SPECIAL_RESPONSE</code>) for successful quits and <code>ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)</code> (or its friends) for failures.
|
|
|
|
If the [[HttpRewriteModule]]'s [[HttpRewriteModule#rewrite|rewrite]] directive is used to change the URI and initiate location re-lookups (internal redirections), then any [[#rewrite_by_lua_block|rewrite_by_lua_block]] or [[#rewrite_by_lua_file_block|rewrite_by_lua_file_block]] code sequences within the current location will not be executed. For example,
|
|
|
|
<geshi lang="nginx">
|
|
location /foo {
|
|
rewrite ^ /bar;
|
|
rewrite_by_lua_block {
|
|
ngx.exit(503)
|
|
}
|
|
}
|
|
location /bar {
|
|
...
|
|
}
|
|
</geshi>
|
|
|
|
Here the Lua code <code>ngx.exit(503)</code> will never run. This will be the case if <code>rewrite ^ /bar last</code> is used as this will similarly initiate an internal redirection. If the <code>break</code> modifier is used instead, there will be no internal redirection and the <code>rewrite_by_lua_block</code> code will be executed.
|
|
|
|
The <code>rewrite_by_lua_block</code> code will always run at the end of the <code>rewrite</code> request-processing phase unless [[#rewrite_by_lua_no_postpone|rewrite_by_lua_no_postpone]] is turned on.
|
|
|
|
This directive was first introduced in the <code>v0.9.17</code> release.
|
|
|
|
== rewrite_by_lua_file ==
|
|
|
|
'''syntax:''' ''rewrite_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''rewrite tail''
|
|
|
|
Equivalent to [[#rewrite_by_lua_block|rewrite_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
Nginx variables can be used in the <code><path-to-lua-script-file></code> string to provide flexibility. This however carries some risks and is not ordinarily recommended.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached and the Nginx config must be reloaded each time the Lua source file is modified. The Lua code cache can be temporarily disabled during development by switching [[#lua_code_cache|lua_code_cache]] <code>off</code> in <code>nginx.conf</code> to avoid reloading Nginx.
|
|
|
|
The <code>rewrite_by_lua_file</code> code will always run at the end of the <code>rewrite</code> request-processing phase unless [[#rewrite_by_lua_no_postpone|rewrite_by_lua_no_postpone]] is turned on.
|
|
|
|
Nginx variables are supported in the file path for dynamic dispatch just as in [[#content_by_lua_file|content_by_lua_file]].
|
|
|
|
== access_by_lua ==
|
|
|
|
'''syntax:''' ''access_by_lua <lua-script-str>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''access tail''
|
|
|
|
'''NOTE''' Use of this directive is ''discouraged'' following the <code>v0.9.17</code> release. Use the [[#access_by_lua_block|access_by_lua_block]] directive instead.
|
|
|
|
Similar to the [[#access_by_lua_block|access_by_lua_block]] directive, but accepts the Lua source directly in an Nginx string literal (which requires
|
|
special character escaping).
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
access_by_lua '
|
|
do_something("hello, world!\nhiya\n")
|
|
';
|
|
</geshi>
|
|
|
|
== access_by_lua_block ==
|
|
|
|
'''syntax:''' ''access_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''access tail''
|
|
|
|
Acts as an access phase handler and executes Lua code string specified in <code>{ <lua-script }</code> for every request.
|
|
The Lua code may make [[#Nginx API for Lua|API calls]] and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).
|
|
|
|
Note that this handler always runs ''after'' the standard [[HttpAccessModule]]. So the following will work as expected:
|
|
|
|
<geshi lang="nginx">
|
|
location / {
|
|
deny 192.168.1.1;
|
|
allow 192.168.1.0/24;
|
|
allow 10.1.1.0/16;
|
|
deny all;
|
|
|
|
access_by_lua_block {
|
|
local res = ngx.location.capture("/mysql", { ... })
|
|
...
|
|
}
|
|
|
|
# proxy_pass/fastcgi_pass/...
|
|
}
|
|
</geshi>
|
|
|
|
That is, if a client IP address is in the blacklist, it will be denied before the MySQL query for more complex authentication is executed by [[#access_by_lua_block|access_by_lua_block]].
|
|
|
|
Note that the [http://mdounin.ru/hg/ngx_http_auth_request_module/ ngx_auth_request] module can be approximated by using [[#access_by_lua_block|access_by_lua_block]]:
|
|
|
|
<geshi lang="nginx">
|
|
location / {
|
|
auth_request /auth;
|
|
|
|
# proxy_pass/fastcgi_pass/postgres_pass/...
|
|
}
|
|
</geshi>
|
|
|
|
can be implemented in ngx_lua as:
|
|
|
|
<geshi lang="nginx">
|
|
location / {
|
|
access_by_lua_block {
|
|
local res = ngx.location.capture("/auth")
|
|
|
|
if res.status == ngx.HTTP_OK then
|
|
return
|
|
end
|
|
|
|
if res.status == ngx.HTTP_FORBIDDEN then
|
|
ngx.exit(res.status)
|
|
end
|
|
|
|
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
|
|
}
|
|
|
|
# proxy_pass/fastcgi_pass/postgres_pass/...
|
|
}
|
|
</geshi>
|
|
|
|
As with other access phase handlers, [[#access_by_lua_block|access_by_lua_block]] will ''not'' run in subrequests.
|
|
|
|
Note that when calling <code>ngx.exit(ngx.OK)</code> within a [[#access_by_lua_block|access_by_lua_block]] handler, the Nginx request processing control flow will still continue to the content handler. To terminate the current request from within a [[#access_by_lua_block|access_by_lua_block]] handler, call [[#ngx.exit|ngx.exit]] with status >= 200 (<code>ngx.HTTP_OK</code>) and status < 300 (<code>ngx.HTTP_SPECIAL_RESPONSE</code>) for successful quits and <code>ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)</code> (or its friends) for failures.
|
|
|
|
Starting from the <code>v0.9.20</code> release, you can use the [[#access_by_lua_no_postpone|access_by_lua_no_postpone]]
|
|
directive to control when to run this handler inside the "access" request-processing phase
|
|
of Nginx.
|
|
|
|
This directive was first introduced in the <code>v0.9.17</code> release.
|
|
|
|
== access_by_lua_file ==
|
|
|
|
'''syntax:''' ''access_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''access tail''
|
|
|
|
Equivalent to [[#access_by_lua_block|access_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
Nginx variables can be used in the <code><path-to-lua-script-file></code> string to provide flexibility. This however carries some risks and is not ordinarily recommended.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached
|
|
and the Nginx config must be reloaded each time the Lua source file is modified.
|
|
The Lua code cache can be temporarily disabled during development by switching [[#lua_code_cache|lua_code_cache]] <code>off</code> in <code>nginx.conf</code> to avoid repeatedly reloading Nginx.
|
|
|
|
Nginx variables are supported in the file path for dynamic dispatch just as in [[#content_by_lua_file|content_by_lua_file]].
|
|
|
|
== header_filter_by_lua ==
|
|
|
|
'''syntax:''' ''header_filter_by_lua <lua-script-str>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''output-header-filter''
|
|
|
|
'''NOTE''' Use of this directive is ''discouraged'' following the <code>v0.9.17</code> release. Use the [[#header_filter_by_lua_block|header_filter_by_lua_block]] directive instead.
|
|
|
|
Similar to the [[#header_filter_by_lua_block|header_filter_by_lua_block]] directive, but accepts the Lua source directly in an Nginx string literal (which requires
|
|
special character escaping).
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
header_filter_by_lua '
|
|
ngx.header["content-length"] = nil
|
|
';
|
|
</geshi>
|
|
|
|
This directive was first introduced in the <code>v0.2.1rc20</code> release.
|
|
|
|
== header_filter_by_lua_block ==
|
|
|
|
'''syntax:''' ''header_filter_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''output-header-filter''
|
|
|
|
Uses Lua code specified in <code>{ lua-script }</code> to define an output header filter.
|
|
|
|
Note that the following API functions are currently disabled within this context:
|
|
|
|
* Output API functions (e.g., [[#ngx.say|ngx.say]] and [[#ngx.send_headers|ngx.send_headers]])
|
|
* Control API functions (e.g., [[#ngx.redirect|ngx.redirect]] and [[#ngx.exec|ngx.exec]])
|
|
* Subrequest API functions (e.g., [[#ngx.location.capture|ngx.location.capture]] and [[#ngx.location.capture_multi|ngx.location.capture_multi]])
|
|
* Cosocket API functions (e.g., [[#ngx.socket.tcp|ngx.socket.tcp]] and [[#ngx.req.socket|ngx.req.socket]]).
|
|
|
|
Here is an example of overriding a response header (or adding one if absent) in our Lua header filter:
|
|
|
|
<geshi lang="nginx">
|
|
location / {
|
|
proxy_pass http://mybackend;
|
|
header_filter_by_lua_block {
|
|
ngx.header.Foo = "blah"
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
This directive was first introduced in the <code>v0.9.17</code> release.
|
|
|
|
== header_filter_by_lua_file ==
|
|
|
|
'''syntax:''' ''header_filter_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''output-header-filter''
|
|
|
|
Equivalent to [[#header_filter_by_lua_block|header_filter_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
This directive was first introduced in the <code>v0.2.1rc20</code> release.
|
|
|
|
== body_filter_by_lua ==
|
|
|
|
'''syntax:''' ''body_filter_by_lua <lua-script-str>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''output-body-filter''
|
|
|
|
'''NOTE''' Use of this directive is ''discouraged'' following the <code>v0.9.17</code> release. Use the [[#body_filter_by_lua_block|body_filter_by_lua_block]] directive instead.
|
|
|
|
Similar to the [[#body_filter_by_lua_block|body_filter_by_lua_block]] directive, but accepts the Lua source directly in an Nginx string literal (which requires
|
|
special character escaping).
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
body_filter_by_lua '
|
|
local data, eof = ngx.arg[1], ngx.arg[2]
|
|
';
|
|
</geshi>
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc32</code> release.
|
|
|
|
== body_filter_by_lua_block ==
|
|
|
|
'''syntax:''' ''body_filter_by_lua_block { lua-script-str }''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''output-body-filter''
|
|
|
|
Uses Lua code specified in <code>{ lua-script }</code> to define an output body filter.
|
|
|
|
The input data chunk is passed via [[#ngx.arg|ngx.arg]][1] (as a Lua string value) and the "eof" flag indicating the end of the response body data stream is passed via [[#ngx.arg|ngx.arg]][2] (as a Lua boolean value).
|
|
|
|
Behind the scene, the "eof" flag is just the <code>last_buf</code> (for main requests) or <code>last_in_chain</code> (for subrequests) flag of the Nginx chain link buffers. (Before the <code>v0.7.14</code> release, the "eof" flag does not work at all in subrequests.)
|
|
|
|
The output data stream can be aborted immediately by running the following Lua statement:
|
|
|
|
<geshi lang="lua">
|
|
return ngx.ERROR
|
|
</geshi>
|
|
|
|
This will truncate the response body and usually result in incomplete and also invalid responses.
|
|
|
|
The Lua code can pass its own modified version of the input data chunk to the downstream Nginx output body filters by overriding [[#ngx.arg|ngx.arg]][1] with a Lua string or a Lua table of strings. For example, to transform all the lowercase letters in the response body, we can just write:
|
|
|
|
<geshi lang="nginx">
|
|
location / {
|
|
proxy_pass http://mybackend;
|
|
body_filter_by_lua_block {
|
|
ngx.arg[1] = string.upper(ngx.arg[1])
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
When setting <code>nil</code> or an empty Lua string value to <code>ngx.arg[1]</code>, no data chunk will be passed to the downstream Nginx output filters at all.
|
|
|
|
Likewise, new "eof" flag can also be specified by setting a boolean value to [[#ngx.arg|ngx.arg]][2]. For example,
|
|
|
|
<geshi lang="nginx">
|
|
location /t {
|
|
echo hello world;
|
|
echo hiya globe;
|
|
|
|
body_filter_by_lua_block {
|
|
local chunk = ngx.arg[1]
|
|
if string.match(chunk, "hello") then
|
|
ngx.arg[2] = true -- new eof
|
|
return
|
|
end
|
|
|
|
-- just throw away any remaining chunk data
|
|
ngx.arg[1] = nil
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Then <code>GET /t</code> will just return the output
|
|
|
|
<geshi lang="text">
|
|
hello world
|
|
</geshi>
|
|
|
|
That is, when the body filter sees a chunk containing the word "hello", then it will set the "eof" flag to true immediately, resulting in truncated but still valid responses.
|
|
|
|
When the Lua code may change the length of the response body, then it is required to always clear out the <code>Content-Length</code> response header (if any) in a header filter to enforce streaming output, as in
|
|
|
|
<geshi lang="nginx">
|
|
location /foo {
|
|
# fastcgi_pass/proxy_pass/...
|
|
|
|
header_filter_by_lua_block {
|
|
ngx.header.content_length = nil
|
|
}
|
|
body_filter_by_lua_block {
|
|
ngx.arg[1] = string.len(ngx.arg[1]) .. "\n"
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Note that the following API functions are currently disabled within this context due to the limitations in Nginx output filter's current implementation:
|
|
|
|
* Output API functions (e.g., [[#ngx.say|ngx.say]] and [[#ngx.send_headers|ngx.send_headers]])
|
|
* Control API functions (e.g., [[#ngx.exit|ngx.exit]] and [[#ngx.exec|ngx.exec]])
|
|
* Subrequest API functions (e.g., [[#ngx.location.capture|ngx.location.capture]] and [[#ngx.location.capture_multi|ngx.location.capture_multi]])
|
|
* Cosocket API functions (e.g., [[#ngx.socket.tcp|ngx.socket.tcp]] and [[#ngx.req.socket|ngx.req.socket]]).
|
|
|
|
Nginx output filters may be called multiple times for a single request because response body may be delivered in chunks. Thus, the Lua code specified by in this directive may also run multiple times in the lifetime of a single HTTP request.
|
|
|
|
This directive was first introduced in the <code>v0.9.17</code> release.
|
|
|
|
== body_filter_by_lua_file ==
|
|
|
|
'''syntax:''' ''body_filter_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''output-body-filter''
|
|
|
|
Equivalent to [[#body_filter_by_lua_block|body_filter_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc32</code> release.
|
|
|
|
== log_by_lua ==
|
|
|
|
'''syntax:''' ''log_by_lua <lua-script-str>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''log''
|
|
|
|
'''NOTE''' Use of this directive is ''discouraged'' following the <code>v0.9.17</code> release. Use the [[#log_by_lua_block|log_by_lua_block]] directive instead.
|
|
|
|
Similar to the [[#log_by_lua_block|log_by_lua_block]] directive, but accepts the Lua source directly in an Nginx string literal (which requires
|
|
special character escaping).
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
log_by_lua '
|
|
print("I need no extra escaping here, for example: \r\nblah")
|
|
';
|
|
</geshi>
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc31</code> release.
|
|
|
|
== log_by_lua_block ==
|
|
|
|
'''syntax:''' ''log_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''log''
|
|
|
|
Runs the Lua source code inlined as the <code>{ lua-script }</code> at the <code>log</code> request processing phase. This does not replace the current access logs, but runs before.
|
|
|
|
Note that the following API functions are currently disabled within this context:
|
|
|
|
* Output API functions (e.g., [[#ngx.say|ngx.say]] and [[#ngx.send_headers|ngx.send_headers]])
|
|
* Control API functions (e.g., [[#ngx.exit|ngx.exit]])
|
|
* Subrequest API functions (e.g., [[#ngx.location.capture|ngx.location.capture]] and [[#ngx.location.capture_multi|ngx.location.capture_multi]])
|
|
* Cosocket API functions (e.g., [[#ngx.socket.tcp|ngx.socket.tcp]] and [[#ngx.req.socket|ngx.req.socket]]).
|
|
|
|
Here is an example of gathering average data for [[HttpUpstreamModule#$upstream_response_time|$upstream_response_time]]:
|
|
|
|
<geshi lang="nginx">
|
|
lua_shared_dict log_dict 5M;
|
|
|
|
server {
|
|
location / {
|
|
proxy_pass http://mybackend;
|
|
|
|
log_by_lua_block {
|
|
local log_dict = ngx.shared.log_dict
|
|
local upstream_time = tonumber(ngx.var.upstream_response_time)
|
|
|
|
local sum = log_dict:get("upstream_time-sum") or 0
|
|
sum = sum + upstream_time
|
|
log_dict:set("upstream_time-sum", sum)
|
|
|
|
local newval, err = log_dict:incr("upstream_time-nb", 1)
|
|
if not newval and err == "not found" then
|
|
log_dict:add("upstream_time-nb", 0)
|
|
log_dict:incr("upstream_time-nb", 1)
|
|
end
|
|
}
|
|
}
|
|
|
|
location = /status {
|
|
content_by_lua_block {
|
|
local log_dict = ngx.shared.log_dict
|
|
local sum = log_dict:get("upstream_time-sum")
|
|
local nb = log_dict:get("upstream_time-nb")
|
|
|
|
if nb and sum then
|
|
ngx.say("average upstream response time: ", sum / nb,
|
|
" (", nb, " reqs)")
|
|
else
|
|
ngx.say("no data yet")
|
|
end
|
|
}
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
This directive was first introduced in the <code>v0.9.17</code> release.
|
|
|
|
== log_by_lua_file ==
|
|
|
|
'''syntax:''' ''log_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''log''
|
|
|
|
Equivalent to [[#log_by_lua_block|log_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc31</code> release.
|
|
|
|
== balancer_by_lua_block ==
|
|
|
|
'''syntax:''' ''balancer_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''upstream''
|
|
|
|
'''phase:''' ''content''
|
|
|
|
This directive runs Lua code as an upstream balancer for any upstream entities defined
|
|
by the <code>upstream {}</code> configuration block.
|
|
|
|
For instance,
|
|
|
|
<geshi lang="nginx">
|
|
upstream foo {
|
|
server 127.0.0.1;
|
|
balancer_by_lua_block {
|
|
-- use Lua to do something interesting here
|
|
-- as a dynamic balancer
|
|
}
|
|
}
|
|
|
|
server {
|
|
location / {
|
|
proxy_pass http://foo;
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
The resulting Lua load balancer can work with any existing Nginx upstream modules
|
|
like [https://nginx.org/en/docs/http/ngx_http_proxy_module.html ngx_proxy] and
|
|
[https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html ngx_fastcgi].
|
|
|
|
Also, the Lua load balancer can work with the standard upstream connection pool mechanism,
|
|
i.e., the standard [https://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive keepalive] directive.
|
|
Just ensure that the [https://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive keepalive] directive
|
|
is used *after* this <code>balancer_by_lua_block</code> directive in a single <code>upstream {}</code> configuration block.
|
|
|
|
The Lua load balancer can totally ignore the list of servers defined in the <code>upstream {}</code> block
|
|
and select peer from a completely dynamic server list (even changing per request) via the
|
|
[https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/balancer.md ngx.balancer] module
|
|
from the [https://github.com/openresty/lua-resty-core lua-resty-core] library.
|
|
|
|
The Lua code handler registered by this directive might get called more than once in a single
|
|
downstream request when the Nginx upstream mechanism retries the request on conditions
|
|
specified by directives like the [https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream proxy_next_upstream]
|
|
directive.
|
|
|
|
This Lua code execution context does not support yielding, so Lua APIs that may yield
|
|
(like cosockets and "light threads") are disabled in this context. One can usually work
|
|
around this limitation by doing such operations in an earlier phase handler (like
|
|
[[#access_by_lua|access_by_lua*]]) and passing along the result into this context
|
|
via the [[#ngx.ctx|ngx.ctx]] table.
|
|
|
|
This directive was first introduced in the <code>v0.10.0</code> release.
|
|
|
|
== balancer_by_lua_file ==
|
|
|
|
'''syntax:''' ''balancer_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''upstream''
|
|
|
|
'''phase:''' ''content''
|
|
|
|
Equivalent to [[#balancer_by_lua_block|balancer_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
This directive was first introduced in the <code>v0.10.0</code> release.
|
|
|
|
== lua_need_request_body ==
|
|
|
|
'''syntax:''' ''lua_need_request_body <on|off>''
|
|
|
|
'''default:''' ''off''
|
|
|
|
'''context:''' ''http, server, location, location if''
|
|
|
|
'''phase:''' ''depends on usage''
|
|
|
|
Determines whether to force the request body data to be read before running rewrite/access/content_by_lua* or not. The Nginx core does not read the client request body by default and if request body data is required, then this directive should be turned <code>on</code> or the [[#ngx.req.read_body|ngx.req.read_body]] function should be called within the Lua code.
|
|
|
|
To read the request body data within the [[HttpCoreModule#$request_body|$request_body]] variable,
|
|
[[HttpCoreModule#client_body_buffer_size|client_body_buffer_size]] must have the same value as [[HttpCoreModule#client_max_body_size|client_max_body_size]]. Because when the content length exceeds [[HttpCoreModule#client_body_buffer_size|client_body_buffer_size]] but less than [[HttpCoreModule#client_max_body_size|client_max_body_size]], Nginx will buffer the data into a temporary file on the disk, which will lead to empty value in the [[HttpCoreModule#$request_body|$request_body]] variable.
|
|
|
|
If the current location includes [[#rewrite_by_lua|rewrite_by_lua*]] directives,
|
|
then the request body will be read just before the [[#rewrite_by_lua|rewrite_by_lua*]] code is run (and also at the
|
|
<code>rewrite</code> phase). Similarly, if only [[#content_by_lua|content_by_lua]] is specified,
|
|
the request body will not be read until the content handler's Lua code is
|
|
about to run (i.e., the request body will be read during the content phase).
|
|
|
|
It is recommended however, to use the [[#ngx.req.read_body|ngx.req.read_body]] and [[#ngx.req.discard_body|ngx.req.discard_body]] functions for finer control over the request body reading process instead.
|
|
|
|
This also applies to [[#access_by_lua|access_by_lua*]].
|
|
|
|
== ssl_client_hello_by_lua_block ==
|
|
|
|
'''syntax:''' ''ssl_client_hello_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http, server''
|
|
|
|
'''phase:''' ''right-after-client-hello-message-was-processed''
|
|
|
|
This directive runs user Lua code when Nginx is about to post-process the SSL client hello message for the downstream
|
|
SSL (https) connections.
|
|
|
|
It is particularly useful for dynamically setting the SSL protocols according to the SNI.
|
|
|
|
It is also useful to do some custom operations according to the per-connection information in the client hello message.
|
|
|
|
For example, one can parse custom client hello extension and do the corresponding handling in pure Lua.
|
|
|
|
This Lua handler will always run whether the SSL session is resumed (via SSL session IDs or TLS session tickets) or not.
|
|
While the <code>ssl_certificate_by_lua*</code> Lua handler will only runs when initiating a full SSL handshake.
|
|
|
|
The [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl/clienthello.md ngx.ssl.clienthello] Lua modules
|
|
provided by the [https://github.com/openresty/lua-resty-core/#readme lua-resty-core]
|
|
library are particularly useful in this context.
|
|
|
|
Note that this handler runs in extremely early stage of SSL handshake, before the SSL client hello extensions are parsed.
|
|
So you can not use some Lua API like <code>ssl.server_name()</code> which is dependent on the later stage's processing.
|
|
|
|
Also note that only the directive in default server is valid for several virtual servers with the same IP address and port.
|
|
|
|
Below is a trivial example using the
|
|
[https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl/clienthello.md ngx.ssl.clienthello] module
|
|
at the same time:
|
|
|
|
<geshi lang="nginx">
|
|
server {
|
|
listen 443 ssl;
|
|
server_name test.com;
|
|
ssl_certificate /path/to/cert.crt;
|
|
ssl_certificate_key /path/to/key.key;
|
|
ssl_client_hello_by_lua_block {
|
|
local ssl_clt = require "ngx.ssl.clienthello"
|
|
local host, err = ssl_clt.get_client_hello_server_name()
|
|
if host == "test.com" then
|
|
ssl_clt.set_protocols({"TLSv1", "TLSv1.1"})
|
|
elseif host == "test2.com" then
|
|
ssl_clt.set_protocols({"TLSv1.2", "TLSv1.3"})
|
|
elseif not host then
|
|
ngx.log(ngx.ERR, "failed to get the SNI name: ", err)
|
|
ngx.exit(ngx.ERROR)
|
|
else
|
|
ngx.log(ngx.ERR, "unknown SNI name: ", host)
|
|
ngx.exit(ngx.ERROR)
|
|
end
|
|
}
|
|
...
|
|
}
|
|
server {
|
|
listen 443 ssl;
|
|
server_name test2.com;
|
|
ssl_certificate /path/to/cert.crt;
|
|
ssl_certificate_key /path/to/key.key;
|
|
...
|
|
}
|
|
</geshi>
|
|
|
|
See more information in the [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl/clienthello.md ngx.ssl.clienthello]
|
|
Lua modules' official documentation.
|
|
|
|
Uncaught Lua exceptions in the user Lua code immediately abort the current SSL session, so does the
|
|
[[#ngx.exit|ngx.exit]] call with an error code like <code>ngx.ERROR</code>.
|
|
|
|
This Lua code execution context *does* support yielding, so Lua APIs that may yield
|
|
(like cosockets, sleeping, and "light threads")
|
|
are enabled in this context
|
|
|
|
Note, you need to configure the [https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate ssl_certificate]
|
|
and [https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate_key ssl_certificate_key]
|
|
to avoid the following error while starting NGINX:
|
|
|
|
<geshi>
|
|
nginx: [emerg] no ssl configured for the server
|
|
</geshi>
|
|
|
|
This directive requires OpenSSL 1.1.1 or greater.
|
|
|
|
If you are using the [official pre-built
|
|
packages](https://openresty.org/en/linux-packages.html) for
|
|
[OpenResty](https://openresty.org/) 1.21.4.1 or later, then everything should
|
|
work out of the box.
|
|
|
|
If you are not using the Nginx core shipped with
|
|
[OpenResty](https://openresty.org) 1.21.4.1 or later, you will need to apply
|
|
patches to the standard Nginx core:
|
|
|
|
https://openresty.org/en/nginx-ssl-patches.html
|
|
|
|
This directive was first introduced in the <code>v0.10.21</code> release.
|
|
|
|
== ssl_client_hello_by_lua_file ==
|
|
|
|
'''syntax:''' ''ssl_client_hello_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http, server''
|
|
|
|
'''phase:''' ''right-after-client-hello-message-was-processed''
|
|
|
|
Equivalent to [[#ssl_client_hello_by_lua_block|ssl_client_hello_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
This directive was first introduced in the <code>v0.10.21</code> release.
|
|
|
|
== ssl_certificate_by_lua_block ==
|
|
|
|
'''syntax:''' ''ssl_certificate_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''server''
|
|
|
|
'''phase:''' ''right-before-SSL-handshake''
|
|
|
|
This directive runs user Lua code when Nginx is about to start the SSL handshake for the downstream
|
|
SSL (https) connections.
|
|
|
|
It is particularly useful for setting the SSL certificate chain and the corresponding private key on a per-request
|
|
basis. It is also useful to load such handshake configurations nonblockingly from the remote (for example,
|
|
with the [[#ngx.socket.tcp|cosocket]] API). And one can also do per-request OCSP stapling handling in pure
|
|
Lua here as well.
|
|
|
|
Another typical use case is to do SSL handshake traffic control nonblockingly in this context,
|
|
with the help of the [https://github.com/openresty/lua-resty-limit-traffic lua-resty-limit-traffic#readme]
|
|
library, for example.
|
|
|
|
One can also do interesting things with the SSL handshake requests from the client side, like
|
|
rejecting old SSL clients using the SSLv3 protocol or even below selectively.
|
|
|
|
The [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md ngx.ssl]
|
|
and [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ocsp.md ngx.ocsp] Lua modules
|
|
provided by the [https://github.com/openresty/lua-resty-core/#readme lua-resty-core]
|
|
library are particularly useful in this context. You can use the Lua API offered by these two Lua modules
|
|
to manipulate the SSL certificate chain and private key for the current SSL connection
|
|
being initiated.
|
|
|
|
This Lua handler does not run at all, however, when Nginx/OpenSSL successfully resumes
|
|
the SSL session via SSL session IDs or TLS session tickets for the current SSL connection. In
|
|
other words, this Lua handler only runs when Nginx has to initiate a full SSL handshake.
|
|
|
|
Below is a trivial example using the
|
|
[https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md ngx.ssl] module
|
|
at the same time:
|
|
|
|
<geshi lang="nginx">
|
|
server {
|
|
listen 443 ssl;
|
|
server_name test.com;
|
|
|
|
ssl_certificate_by_lua_block {
|
|
print("About to initiate a new SSL handshake!")
|
|
}
|
|
|
|
location / {
|
|
root html;
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
See more complicated examples in the [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md ngx.ssl]
|
|
and [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ocsp.md ngx.ocsp]
|
|
Lua modules' official documentation.
|
|
|
|
Uncaught Lua exceptions in the user Lua code immediately abort the current SSL session, so does the
|
|
[[#ngx.exit|ngx.exit]] call with an error code like <code>ngx.ERROR</code>.
|
|
|
|
This Lua code execution context *does* support yielding, so Lua APIs that may yield
|
|
(like cosockets, sleeping, and "light threads")
|
|
are enabled in this context.
|
|
|
|
Note, however, you still need to configure the [https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate ssl_certificate] and
|
|
[https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate_key ssl_certificate_key]
|
|
directives even though you will not use this static certificate and private key at all. This is
|
|
because the NGINX core requires their appearance otherwise you are seeing the following error
|
|
while starting NGINX:
|
|
|
|
<geshi>
|
|
nginx: [emerg] no ssl configured for the server
|
|
</geshi>
|
|
|
|
This directive requires OpenSSL 1.0.2e or greater.
|
|
|
|
If you are using the [official pre-built
|
|
packages](https://openresty.org/en/linux-packages.html) for
|
|
[OpenResty](https://openresty.org/) 1.9.7.2 or later, then everything should
|
|
work out of the box.
|
|
|
|
If you are not using the Nginx core shipped with
|
|
[OpenResty](https://openresty.org) 1.9.7.2 or later, you will need to apply
|
|
patches to the standard Nginx core:
|
|
|
|
https://openresty.org/en/nginx-ssl-patches.html
|
|
|
|
This directive was first introduced in the <code>v0.10.0</code> release.
|
|
|
|
== ssl_certificate_by_lua_file ==
|
|
|
|
'''syntax:''' ''ssl_certificate_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''server''
|
|
|
|
'''phase:''' ''right-before-SSL-handshake''
|
|
|
|
Equivalent to [[#ssl_certificate_by_lua_block|ssl_certificate_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or, as from the <code>v0.5.0rc32</code> release, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
This directive was first introduced in the <code>v0.10.0</code> release.
|
|
|
|
== ssl_session_fetch_by_lua_block ==
|
|
|
|
'''syntax:''' ''ssl_session_fetch_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''right-before-SSL-handshake''
|
|
|
|
This directive runs Lua code to look up and load the SSL session (if any) according to the session ID
|
|
provided by the current SSL handshake request for the downstream.
|
|
|
|
The Lua API for obtaining the current session ID and loading a cached SSL session data
|
|
is provided in the [ngx.ssl.session](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl/session.md)
|
|
Lua module shipped with the [lua-resty-core](https://github.com/openresty/lua-resty-core#readme)
|
|
library.
|
|
|
|
Lua APIs that may yield, like [[#ngx.sleep|ngx.sleep]] and [[#ngx.socket.tcp|cosockets]],
|
|
are enabled in this context.
|
|
|
|
This hook, together with the [[#ssl_session_store_by_lua_block|ssl_session_store_by_lua*]] hook,
|
|
can be used to implement distributed caching mechanisms in pure Lua (based
|
|
on the [[#ngx.socket.tcp|cosocket]] API, for example). If a cached SSL session is found
|
|
and loaded into the current SSL connection context,
|
|
SSL session resumption can then get immediately initiated and bypass the full SSL handshake process which is very expensive in terms of CPU time.
|
|
|
|
Please note that TLS session tickets are very different and it is the clients' responsibility
|
|
to cache the SSL session state when session tickets are used. SSL session resumptions based on
|
|
TLS session tickets would happen automatically without going through this hook (nor the
|
|
[[#ssl_session_store_by_lua_block|ssl_session_store_by_lua*]] hook). This hook is mainly
|
|
for older or less capable SSL clients that can only do SSL sessions by session IDs.
|
|
|
|
When [[#ssl_certificate_by_lua_block|ssl_certificate_by_lua*]] is specified at the same time,
|
|
this hook usually runs before [[#ssl_certificate_by_lua_block|ssl_certificate_by_lua*]].
|
|
When the SSL session is found and successfully loaded for the current SSL connection,
|
|
SSL session resumption will happen and thus bypass the [[#ssl_certificate_by_lua_block|ssl_certificate_by_lua*]]
|
|
hook completely. In this case, Nginx also bypasses the [[#ssl_session_store_by_lua_block|ssl_session_store_by_lua*]]
|
|
hook, for obvious reasons.
|
|
|
|
To easily test this hook locally with a modern web browser, you can temporarily put the following line
|
|
in your https server block to disable the TLS session ticket support:
|
|
|
|
ssl_session_tickets off;
|
|
|
|
But do not forget to comment this line out before publishing your site to the world.
|
|
|
|
If you are using the [official pre-built packages](https://openresty.org/en/linux-packages.html) for [OpenResty](https://openresty.org/)
|
|
1.11.2.1 or later, then everything should work out of the box.
|
|
|
|
If you are not using one of the [OpenSSL
|
|
packages](https://openresty.org/en/linux-packages.html) provided by
|
|
[OpenResty](https://openresty.org), you will need to apply patches to OpenSSL
|
|
in order to use this directive:
|
|
|
|
https://openresty.org/en/openssl-patches.html
|
|
|
|
Similarly, if you are not using the Nginx core shipped with
|
|
[OpenResty](https://openresty.org) 1.11.2.1 or later, you will need to apply
|
|
patches to the standard Nginx core:
|
|
|
|
https://openresty.org/en/nginx-ssl-patches.html
|
|
|
|
This directive was first introduced in the <code>v0.10.6</code> release.
|
|
|
|
Note that this directive can only be used in the '''http context''' starting
|
|
with the <code>v0.10.7</code> release since SSL session resumption happens
|
|
before server name dispatch.
|
|
|
|
== ssl_session_fetch_by_lua_file ==
|
|
|
|
'''syntax:''' ''ssl_session_fetch_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''right-before-SSL-handshake''
|
|
|
|
Equivalent to [[#ssl_session_fetch_by_lua_block|ssl_session_fetch_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or rather, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
This directive was first introduced in the <code>v0.10.6</code> release.
|
|
|
|
Note that: this directive is only allowed to used in '''http context''' from the <code>v0.10.7</code> release
|
|
(because SSL session resumption happens before server name dispatch).
|
|
|
|
== ssl_session_store_by_lua_block ==
|
|
|
|
'''syntax:''' ''ssl_session_store_by_lua_block { lua-script }''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''right-after-SSL-handshake''
|
|
|
|
This directive runs Lua code to fetch and save the SSL session (if any) according to the session ID
|
|
provided by the current SSL handshake request for the downstream. The saved or cached SSL
|
|
session data can be used for future SSL connections to resume SSL sessions without going
|
|
through the full SSL handshake process (which is very expensive in terms of CPU time).
|
|
|
|
Lua APIs that may yield, like [[#ngx.sleep|ngx.sleep]] and [[#ngx.socket.tcp|cosockets]],
|
|
are *disabled* in this context. You can still, however, use the [[#ngx.timer.at|ngx.timer.at]] API
|
|
to create 0-delay timers to save the SSL session data asynchronously to external services (like <code>redis</code> or <code>memcached</code>).
|
|
|
|
The Lua API for obtaining the current session ID and the associated session state data
|
|
is provided in the [ngx.ssl.session](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl/session.md#readme)
|
|
Lua module shipped with the [lua-resty-core](https://github.com/openresty/lua-resty-core#readme)
|
|
library.
|
|
|
|
To easily test this hook locally with a modern web browser, you can temporarily put the following line
|
|
in your https server block to disable the TLS session ticket support:
|
|
|
|
ssl_session_tickets off;
|
|
|
|
But do not forget to comment this line out before publishing your site to the world.
|
|
|
|
This directive was first introduced in the <code>v0.10.6</code> release.
|
|
|
|
Note that: this directive is only allowed to used in '''http context''' from the <code>v0.10.7</code> release
|
|
(because SSL session resumption happens before server name dispatch).
|
|
|
|
== ssl_session_store_by_lua_file ==
|
|
|
|
'''syntax:''' ''ssl_session_store_by_lua_file <path-to-lua-script-file>''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''right-after-SSL-handshake''
|
|
|
|
Equivalent to [[#ssl_session_store_by_lua_block|ssl_session_store_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or rather, the [[#LuaJIT bytecode support|LuaJIT bytecode]] to be executed.
|
|
|
|
When a relative path like <code>foo/bar.lua</code> is given, they will be turned into the absolute path relative to the <code>server prefix</code> path determined by the <code>-p PATH</code> command-line option while starting the Nginx server.
|
|
|
|
This directive was first introduced in the <code>v0.10.6</code> release.
|
|
|
|
Note that: this directive is only allowed to used in '''http context''' from the <code>v0.10.7</code> release
|
|
(because SSL session resumption happens before server name dispatch).
|
|
|
|
== lua_shared_dict ==
|
|
|
|
'''syntax:''' ''lua_shared_dict <name> <size>''
|
|
|
|
'''default:''' ''no''
|
|
|
|
'''context:''' ''http''
|
|
|
|
'''phase:''' ''depends on usage''
|
|
|
|
Declares a shared memory zone, <code><name></code>, to serve as storage for the shm based Lua dictionary <code>ngx.shared.<name></code>.
|
|
|
|
Shared memory zones are always shared by all the Nginx worker processes in the current Nginx server instance.
|
|
|
|
The <code><size></code> argument accepts size units such as <code>k</code> and <code>m</code>:
|
|
|
|
<geshi lang="nginx">
|
|
http {
|
|
lua_shared_dict dogs 10m;
|
|
...
|
|
}
|
|
</geshi>
|
|
|
|
The hard-coded minimum size is 8KB while the practical minimum size depends
|
|
on actual user data set (some people start with 12KB).
|
|
|
|
See [[#ngx.shared.DICT|ngx.shared.DICT]] for details.
|
|
|
|
This directive was first introduced in the <code>v0.3.1rc22</code> release.
|
|
|
|
== lua_socket_connect_timeout ==
|
|
|
|
'''syntax:''' ''lua_socket_connect_timeout <time>''
|
|
|
|
'''default:''' ''lua_socket_connect_timeout 60s''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
This directive controls the default timeout value used in TCP/unix-domain socket object's [[#tcpsock:connect|connect]] method and can be overridden by the [[#tcpsock:settimeout|settimeout]] or [[#tcpsock:settimeouts|settimeouts]] methods.
|
|
|
|
The <code><time></code> argument can be an integer, with an optional time unit, like <code>s</code> (second), <code>ms</code> (millisecond), <code>m</code> (minute). The default time unit is <code>s</code>, i.e., "second". The default setting is <code>60s</code>.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== lua_socket_send_timeout ==
|
|
|
|
'''syntax:''' ''lua_socket_send_timeout <time>''
|
|
|
|
'''default:''' ''lua_socket_send_timeout 60s''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Controls the default timeout value used in TCP/unix-domain socket object's [[#tcpsock:send|send]] method and can be overridden by the [[#tcpsock:settimeout|settimeout]] or [[#tcpsock:settimeouts|settimeouts]] methods.
|
|
|
|
The <code><time></code> argument can be an integer, with an optional time unit, like <code>s</code> (second), <code>ms</code> (millisecond), <code>m</code> (minute). The default time unit is <code>s</code>, i.e., "second". The default setting is <code>60s</code>.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== lua_socket_send_lowat ==
|
|
|
|
'''syntax:''' ''lua_socket_send_lowat <size>''
|
|
|
|
'''default:''' ''lua_socket_send_lowat 0''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Controls the <code>lowat</code> (low water) value for the cosocket send buffer.
|
|
|
|
== lua_socket_read_timeout ==
|
|
|
|
'''syntax:''' ''lua_socket_read_timeout <time>''
|
|
|
|
'''default:''' ''lua_socket_read_timeout 60s''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
'''phase:''' ''depends on usage''
|
|
|
|
This directive controls the default timeout value used in TCP/unix-domain socket object's [[#tcpsock:receive|receive]] method and iterator functions returned by the [[#tcpsock:receiveuntil|receiveuntil]] method. This setting can be overridden by the [[#tcpsock:settimeout|settimeout]] or [[#tcpsock:settimeouts|settimeouts]] methods.
|
|
|
|
The <code><time></code> argument can be an integer, with an optional time unit, like <code>s</code> (second), <code>ms</code> (millisecond), <code>m</code> (minute). The default time unit is <code>s</code>, i.e., "second". The default setting is <code>60s</code>.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== lua_socket_buffer_size ==
|
|
|
|
'''syntax:''' ''lua_socket_buffer_size <size>''
|
|
|
|
'''default:''' ''lua_socket_buffer_size 4k/8k''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Specifies the buffer size used by cosocket reading operations.
|
|
|
|
This buffer does not have to be that big to hold everything at the same time because cosocket supports 100% non-buffered reading and parsing. So even <code>1</code> byte buffer size should still work everywhere but the performance could be terrible.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== lua_socket_pool_size ==
|
|
|
|
'''syntax:''' ''lua_socket_pool_size <size>''
|
|
|
|
'''default:''' ''lua_socket_pool_size 30''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Specifies the size limit (in terms of connection count) for every cosocket connection pool associated with every remote server (i.e., identified by either the host-port pair or the unix domain socket file path).
|
|
|
|
Default to 30 connections for every pool.
|
|
|
|
When the connection pool exceeds the available size limit, the least recently used (idle) connection already in the pool will be closed to make room for the current connection.
|
|
|
|
Note that the cosocket connection pool is per Nginx worker process rather than per Nginx server instance, so size limit specified here also applies to every single Nginx worker process.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== lua_socket_keepalive_timeout ==
|
|
|
|
'''syntax:''' ''lua_socket_keepalive_timeout <time>''
|
|
|
|
'''default:''' ''lua_socket_keepalive_timeout 60s''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
This directive controls the default maximal idle time of the connections in the cosocket built-in connection pool. When this timeout reaches, idle connections will be closed and removed from the pool. This setting can be overridden by cosocket objects' [[#tcpsock:setkeepalive|setkeepalive]] method.
|
|
|
|
The <code><time></code> argument can be an integer, with an optional time unit, like <code>s</code> (second), <code>ms</code> (millisecond), <code>m</code> (minute). The default time unit is <code>s</code>, i.e., "second". The default setting is <code>60s</code>.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== lua_socket_log_errors ==
|
|
|
|
'''syntax:''' ''lua_socket_log_errors on|off''
|
|
|
|
'''default:''' ''lua_socket_log_errors on''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
This directive can be used to toggle error logging when a failure occurs for the TCP or UDP cosockets. If you are already doing proper error handling and logging in your Lua code, then it is recommended to turn this directive off to prevent data flushing in your Nginx error log files (which is usually rather expensive).
|
|
|
|
This directive was first introduced in the <code>v0.5.13</code> release.
|
|
|
|
== lua_ssl_ciphers ==
|
|
|
|
'''syntax:''' ''lua_ssl_ciphers <ciphers>''
|
|
|
|
'''default:''' ''lua_ssl_ciphers DEFAULT''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Specifies the enabled ciphers for requests to a SSL/TLS server in the [[#tcpsock:sslhandshake|tcpsock:sslhandshake]] method. The ciphers are specified in the format understood by the OpenSSL library.
|
|
|
|
The full list can be viewed using the “openssl ciphers” command.
|
|
|
|
This directive was first introduced in the <code>v0.9.11</code> release.
|
|
|
|
== lua_ssl_crl ==
|
|
|
|
'''syntax:''' ''lua_ssl_crl <file>''
|
|
|
|
'''default:''' ''no''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Specifies a file with revoked certificates (CRL) in the PEM format used to verify the certificate of the SSL/TLS server in the [[#tcpsock:sslhandshake|tcpsock:sslhandshake]] method.
|
|
|
|
This directive was first introduced in the <code>v0.9.11</code> release.
|
|
|
|
== lua_ssl_protocols ==
|
|
|
|
'''syntax:''' ''lua_ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2] [TLSv1.3]''
|
|
|
|
'''default:''' ''lua_ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Enables the specified protocols for requests to a SSL/TLS server in the [[#tcpsock:sslhandshake|tcpsock:sslhandshake]] method.
|
|
|
|
The support for the <code>TLSv1.3</code> parameter requires version <code>v0.10.12</code> *and* OpenSSL 1.1.1.
|
|
|
|
This directive was first introduced in the <code>v0.9.11</code> release.
|
|
|
|
== lua_ssl_trusted_certificate ==
|
|
|
|
'''syntax:''' ''lua_ssl_trusted_certificate <file>''
|
|
|
|
'''default:''' ''no''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Specifies a file path with trusted CA certificates in the PEM format used to verify the certificate of the SSL/TLS server in the [[#tcpsock:sslhandshake|tcpsock:sslhandshake]] method.
|
|
|
|
This directive was first introduced in the <code>v0.9.11</code> release.
|
|
|
|
See also [[#lua_ssl_verify_depth|lua_ssl_verify_depth]].
|
|
|
|
== lua_ssl_verify_depth ==
|
|
|
|
'''syntax:''' ''lua_ssl_verify_depth <number>''
|
|
|
|
'''default:''' ''lua_ssl_verify_depth 1''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Sets the verification depth in the server certificates chain.
|
|
|
|
This directive was first introduced in the <code>v0.9.11</code> release.
|
|
|
|
See also [[#lua_ssl_trusted_certificate|lua_ssl_trusted_certificate]].
|
|
|
|
== lua_ssl_conf_command ==
|
|
|
|
'''syntax:''' ''lua_ssl_conf_command <command>''
|
|
|
|
'''default:''' ''no''
|
|
|
|
'''context:''' ''http, server, location''
|
|
|
|
Sets arbitrary OpenSSL configuration [https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html commands].
|
|
|
|
The directive is supported when using OpenSSL 1.0.2 or higher and nginx 1.19.4 or higher. According to the specify command, higher OpenSSL version may be needed.
|
|
|
|
Several <code>lua_ssl_conf_command</code> directives can be specified on the same level:
|
|
|
|
<geshi lang="nginx">
|
|
lua_ssl_conf_command Options PrioritizeChaCha;
|
|
lua_ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
|
|
</geshi>
|
|
|
|
Configuration commands are applied after OpenResty own configuration for SSL, so they can be used to override anything set by OpenResty.
|
|
|
|
Note though that configuring OpenSSL directly with <code>lua_ssl_conf_command</code> might result in a behaviour OpenResty does not expect, and should be done with care.
|
|
|
|
This directive was first introduced in the <code>v0.10.21</code> release.
|
|
|
|
|
|
|
|
== lua_http10_buffering ==
|
|
|
|
'''syntax:''' ''lua_http10_buffering on|off''
|
|
|
|
'''default:''' ''lua_http10_buffering on''
|
|
|
|
'''context:''' ''http, server, location, location-if''
|
|
|
|
Enables or disables automatic response buffering for HTTP 1.0 (or older) requests. This buffering mechanism is mainly used for HTTP 1.0 keep-alive which relies on a proper <code>Content-Length</code> response header.
|
|
|
|
If the Lua code explicitly sets a <code>Content-Length</code> response header before sending the headers (either explicitly via [[#ngx.send_headers|ngx.send_headers]] or implicitly via the first [[#ngx.say|ngx.say]] or [[#ngx.print|ngx.print]] call), then the HTTP 1.0 response buffering will be disabled even when this directive is turned on.
|
|
|
|
To output very large response data in a streaming fashion (via the [[#ngx.flush|ngx.flush]] call, for example), this directive MUST be turned off to minimize memory usage.
|
|
|
|
This directive is turned <code>on</code> by default.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc19</code> release.
|
|
|
|
== rewrite_by_lua_no_postpone ==
|
|
|
|
'''syntax:''' ''rewrite_by_lua_no_postpone on|off''
|
|
|
|
'''default:''' ''rewrite_by_lua_no_postpone off''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Controls whether or not to disable postponing [[#rewrite_by_lua|rewrite_by_lua*]] directives to run at the end of the <code>rewrite</code> request-processing phase. By default, this directive is turned off and the Lua code is postponed to run at the end of the <code>rewrite</code> phase.
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc29</code> release.
|
|
|
|
== access_by_lua_no_postpone ==
|
|
|
|
'''syntax:''' ''access_by_lua_no_postpone on|off''
|
|
|
|
'''default:''' ''access_by_lua_no_postpone off''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Controls whether or not to disable postponing [[#access_by_lua|access_by_lua*]] directives to run at the end of the <code>access</code> request-processing phase. By default, this directive is turned off and the Lua code is postponed to run at the end of the <code>access</code> phase.
|
|
|
|
This directive was first introduced in the <code>v0.9.20</code> release.
|
|
|
|
== lua_transform_underscores_in_response_headers ==
|
|
|
|
'''syntax:''' ''lua_transform_underscores_in_response_headers on|off''
|
|
|
|
'''default:''' ''lua_transform_underscores_in_response_headers on''
|
|
|
|
'''context:''' ''http, server, location, location-if''
|
|
|
|
Controls whether to transform underscores (<code>_</code>) in the response header names specified in the [[#ngx.header.HEADER|ngx.header.HEADER]] API to hyphens (<code>-</code>).
|
|
|
|
This directive was first introduced in the <code>v0.5.0rc32</code> release.
|
|
|
|
== lua_check_client_abort ==
|
|
|
|
'''syntax:''' ''lua_check_client_abort on|off''
|
|
|
|
'''default:''' ''lua_check_client_abort off''
|
|
|
|
'''context:''' ''http, server, location, location-if''
|
|
|
|
This directive controls whether to check for premature client connection abortion.
|
|
|
|
When this directive is on, the ngx_lua module will monitor the premature connection close event on the downstream connections and when there is such an event, it will call the user Lua function callback (registered by [[#ngx.on_abort|ngx.on_abort]]) or just stop and clean up all the Lua "light threads" running in the current request's request handler when there is no user callback function registered.
|
|
|
|
According to the current implementation, however, if the client closes the connection before the Lua code finishes reading the request body data via [[#ngx.req.socket|ngx.req.socket]], then ngx_lua will neither stop all the running "light threads" nor call the user callback (if [[#ngx.on_abort|ngx.on_abort]] has been called). Instead, the reading operation on [[#ngx.req.socket|ngx.req.socket]] will just return the error message "client aborted" as the second return value (the first return value is surely <code>nil</code>).
|
|
|
|
When TCP keepalive is disabled, it is relying on the client side to close the socket gracefully (by sending a <code>FIN</code> packet or something like that). For (soft) real-time web applications, it is highly recommended to configure the [http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html TCP keepalive] support in your system's TCP stack implementation in order to detect "half-open" TCP connections in time.
|
|
|
|
For example, on Linux, you can configure the standard [[HttpCoreModule#listen|listen]] directive in your <code>nginx.conf</code> file like this:
|
|
|
|
<geshi lang="nginx">
|
|
listen 80 so_keepalive=2s:2s:8;
|
|
</geshi>
|
|
|
|
On FreeBSD, you can only tune the system-wide configuration for TCP keepalive, for example:
|
|
|
|
# sysctl net.inet.tcp.keepintvl=2000
|
|
# sysctl net.inet.tcp.keepidle=2000
|
|
|
|
This directive was first introduced in the <code>v0.7.4</code> release.
|
|
|
|
See also [[#ngx.on_abort|ngx.on_abort]].
|
|
|
|
== lua_max_pending_timers ==
|
|
|
|
'''syntax:''' ''lua_max_pending_timers <count>''
|
|
|
|
'''default:''' ''lua_max_pending_timers 1024''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Controls the maximum number of pending timers allowed.
|
|
|
|
Pending timers are those timers that have not expired yet.
|
|
|
|
When exceeding this limit, the [[#ngx.timer.at|ngx.timer.at]] call will immediately return <code>nil</code> and the error string "too many pending timers".
|
|
|
|
This directive was first introduced in the <code>v0.8.0</code> release.
|
|
|
|
== lua_max_running_timers ==
|
|
|
|
'''syntax:''' ''lua_max_running_timers <count>''
|
|
|
|
'''default:''' ''lua_max_running_timers 256''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Controls the maximum number of "running timers" allowed.
|
|
|
|
Running timers are those timers whose user callback functions are still running.
|
|
|
|
When exceeding this limit, Nginx will stop running the callbacks of newly expired timers and log an error message "N lua_max_running_timers are not enough" where "N" is the current value of this directive.
|
|
|
|
This directive was first introduced in the <code>v0.8.0</code> release.
|
|
|
|
== lua_sa_restart ==
|
|
|
|
'''syntax:''' ''lua_sa_restart on|off''
|
|
|
|
'''default:''' ''lua_sa_restart on''
|
|
|
|
'''context:''' ''http''
|
|
|
|
When enabled, this module will set the `SA_RESTART` flag on Nginx workers signal dispositions.
|
|
|
|
This allows Lua I/O primitives to not be interrupted by Nginx's handling of various signals.
|
|
|
|
This directive was first introduced in the <code>v0.10.14</code> release.
|
|
|
|
== lua_worker_thread_vm_pool_size ==
|
|
|
|
'''syntax:''' ''lua_worker_thread_vm_pool_size <size>''
|
|
|
|
'''default:''' ''lua_worker_thread_vm_pool_size 100''
|
|
|
|
'''context:''' ''http''
|
|
|
|
Specifies the size limit of the Lua VM pool (default 100) that will be used in the [ngx.run_worker_thread](#ngxrun_worker_thread) API.
|
|
|
|
Also, it is not allowed to create Lua VMs that exceeds the pool size limit.
|
|
|
|
The Lua VM in the VM pool is used to execute Lua code in separate thread.
|
|
|
|
The pool is global at Nginx worker level. And it is used to reuse Lua VMs between requests.
|
|
|
|
= Nginx API for Lua =
|
|
|
|
<!-- inline-toc -->
|
|
|
|
== Introduction ==
|
|
|
|
The various <code>*_by_lua</code>, <code>*_by_lua_block</code> and <code>*_by_lua_file</code> configuration directives serve as gateways to the Lua API within the <code>nginx.conf</code> file. The Nginx Lua API described below can only be called within the user Lua code run in the context of these configuration directives.
|
|
|
|
The API is exposed to Lua in the form of two standard packages <code>ngx</code> and <code>ndk</code>. These packages are in the default global scope within ngx_lua and are always available within ngx_lua directives.
|
|
|
|
The packages can be introduced into external Lua modules like this:
|
|
|
|
<geshi lang="lua">
|
|
local say = ngx.say
|
|
|
|
local _M = {}
|
|
|
|
function _M.foo(a)
|
|
say(a)
|
|
end
|
|
|
|
return _M
|
|
</geshi>
|
|
|
|
Use of the [https://www.lua.org/manual/5.1/manual.html#pdf-package.seeall package.seeall] flag is strongly discouraged due to its various bad side-effects.
|
|
|
|
It is also possible to directly require the packages in external Lua modules:
|
|
|
|
<geshi lang="lua">
|
|
local ngx = require "ngx"
|
|
local ndk = require "ndk"
|
|
</geshi>
|
|
|
|
The ability to require these packages was introduced in the <code>v0.2.1rc19</code> release.
|
|
|
|
Network I/O operations in user code should only be done through the Nginx Lua API calls as the Nginx event loop may be blocked and performance drop off dramatically otherwise. Disk operations with relatively small amount of data can be done using the standard Lua <code>io</code> library but huge file reading and writing should be avoided wherever possible as they may block the Nginx process significantly. Delegating all network and disk I/O operations to Nginx's subrequests (via the [[#ngx.location.capture|ngx.location.capture]] method and similar) is strongly recommended for maximum performance.
|
|
|
|
== ngx.arg ==
|
|
|
|
'''syntax:''' ''val = ngx.arg[index]''
|
|
|
|
'''context:''' ''set_by_lua*, body_filter_by_lua*''
|
|
|
|
When this is used in the context of the [[#set_by_lua|set_by_lua*]] directives, this table is read-only and holds the input arguments to the config directives:
|
|
|
|
<geshi lang="lua">
|
|
value = ngx.arg[n]
|
|
</geshi>
|
|
|
|
Here is an example
|
|
|
|
<geshi lang="nginx">
|
|
location /foo {
|
|
set $a 32;
|
|
set $b 56;
|
|
|
|
set_by_lua $sum
|
|
'return tonumber(ngx.arg[1]) + tonumber(ngx.arg[2])'
|
|
$a $b;
|
|
|
|
echo $sum;
|
|
}
|
|
</geshi>
|
|
|
|
that writes out <code>88</code>, the sum of <code>32</code> and <code>56</code>.
|
|
|
|
When this table is used in the context of [[#body_filter_by_lua|body_filter_by_lua*]], the first element holds the input data chunk to the output filter code and the second element holds the boolean flag for the "eof" flag indicating the end of the whole output data stream.
|
|
|
|
The data chunk and "eof" flag passed to the downstream Nginx output filters can also be overridden by assigning values directly to the corresponding table elements. When setting <code>nil</code> or an empty Lua string value to <code>ngx.arg[1]</code>, no data chunk will be passed to the downstream Nginx output filters at all.
|
|
|
|
== ngx.var.VARIABLE ==
|
|
|
|
'''syntax:''' ''ngx.var.VAR_NAME''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, balancer_by_lua*''
|
|
|
|
Read and write Nginx variable values.
|
|
|
|
<geshi lang="nginx">
|
|
value = ngx.var.some_nginx_variable_name
|
|
ngx.var.some_nginx_variable_name = value
|
|
</geshi>
|
|
|
|
Note that only already defined Nginx variables can be written to.
|
|
For example:
|
|
|
|
<geshi lang="nginx">
|
|
location /foo {
|
|
set $my_var ''; # this line is required to create $my_var at config time
|
|
content_by_lua_block {
|
|
ngx.var.my_var = 123
|
|
...
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
That is, Nginx variables cannot be created on-the-fly.
|
|
|
|
Some special Nginx variables like <code>$args</code> and <code>$limit_rate</code> can be assigned a value,
|
|
many others are not, like <code>$query_string</code>, <code>$arg_PARAMETER</code>, and <code>$http_NAME</code>.
|
|
|
|
Nginx regex group capturing variables <code>$1</code>, <code>$2</code>, <code>$3</code>, and etc, can be read by this
|
|
interface as well, by writing <code>ngx.var[1]</code>, <code>ngx.var[2]</code>, <code>ngx.var[3]</code>, and etc.
|
|
|
|
Setting <code>ngx.var.Foo</code> to a <code>nil</code> value will unset the <code>$Foo</code> Nginx variable.
|
|
|
|
<geshi lang="lua">
|
|
ngx.var.args = nil
|
|
</geshi>
|
|
|
|
'''CAUTION''' When reading from an Nginx variable, Nginx will allocate memory in the per-request memory pool which is freed only at request termination. So when you need to read from an Nginx variable repeatedly in your Lua code, cache the Nginx variable value to your own Lua variable, for example,
|
|
|
|
<geshi lang="lua">
|
|
local val = ngx.var.some_var
|
|
--- use the val repeatedly later
|
|
</geshi>
|
|
|
|
to prevent (temporary) memory leaking within the current request's lifetime. Another way of caching the result is to use the [[#ngx.ctx|ngx.ctx]] table.
|
|
|
|
Undefined Nginx variables are evaluated to <code>nil</code> while uninitialized (but defined) Nginx variables are evaluated to an empty Lua string.
|
|
|
|
This API requires a relatively expensive metamethod call and it is recommended to avoid using it on hot code paths.
|
|
|
|
== Core constants ==
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, *log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
<geshi lang="lua">
|
|
ngx.OK (0)
|
|
ngx.ERROR (-1)
|
|
ngx.AGAIN (-2)
|
|
ngx.DONE (-4)
|
|
ngx.DECLINED (-5)
|
|
</geshi>
|
|
|
|
Note that only three of these constants are utilized by the [[#Nginx API for Lua|Nginx API for Lua]] (i.e., [[#ngx.exit|ngx.exit]] accepts <code>ngx.OK</code>, <code>ngx.ERROR</code>, and <code>ngx.DECLINED</code> as input).
|
|
|
|
<geshi lang="lua">
|
|
ngx.null
|
|
</geshi>
|
|
|
|
The <code>ngx.null</code> constant is a <code>NULL</code> light userdata usually used to represent nil values in Lua tables etc and is similar to the [http://www.kyne.com.au/~mark/software/lua-cjson.php lua-cjson] library's <code>cjson.null</code> constant. This constant was first introduced in the <code>v0.5.0rc5</code> release.
|
|
|
|
The <code>ngx.DECLINED</code> constant was first introduced in the <code>v0.5.0rc19</code> release.
|
|
|
|
== HTTP method constants ==
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
<geshi lang="text">
|
|
ngx.HTTP_GET
|
|
ngx.HTTP_HEAD
|
|
ngx.HTTP_PUT
|
|
ngx.HTTP_POST
|
|
ngx.HTTP_DELETE
|
|
ngx.HTTP_OPTIONS (added in the v0.5.0rc24 release)
|
|
ngx.HTTP_MKCOL (added in the v0.8.2 release)
|
|
ngx.HTTP_COPY (added in the v0.8.2 release)
|
|
ngx.HTTP_MOVE (added in the v0.8.2 release)
|
|
ngx.HTTP_PROPFIND (added in the v0.8.2 release)
|
|
ngx.HTTP_PROPPATCH (added in the v0.8.2 release)
|
|
ngx.HTTP_LOCK (added in the v0.8.2 release)
|
|
ngx.HTTP_UNLOCK (added in the v0.8.2 release)
|
|
ngx.HTTP_PATCH (added in the v0.8.2 release)
|
|
ngx.HTTP_TRACE (added in the v0.8.2 release)
|
|
</geshi>
|
|
|
|
These constants are usually used in [[#ngx.location.capture|ngx.location.capture]] and [[#ngx.location.capture_multi|ngx.location.capture_multi]] method calls.
|
|
|
|
== HTTP status constants ==
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
<geshi lang="nginx">
|
|
value = ngx.HTTP_CONTINUE (100) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_SWITCHING_PROTOCOLS (101) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_OK (200)
|
|
value = ngx.HTTP_CREATED (201)
|
|
value = ngx.HTTP_ACCEPTED (202) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_NO_CONTENT (204) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_PARTIAL_CONTENT (206) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_SPECIAL_RESPONSE (300)
|
|
value = ngx.HTTP_MOVED_PERMANENTLY (301)
|
|
value = ngx.HTTP_MOVED_TEMPORARILY (302)
|
|
value = ngx.HTTP_SEE_OTHER (303)
|
|
value = ngx.HTTP_NOT_MODIFIED (304)
|
|
value = ngx.HTTP_TEMPORARY_REDIRECT (307) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_PERMANENT_REDIRECT (308)
|
|
value = ngx.HTTP_BAD_REQUEST (400)
|
|
value = ngx.HTTP_UNAUTHORIZED (401)
|
|
value = ngx.HTTP_PAYMENT_REQUIRED (402) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_FORBIDDEN (403)
|
|
value = ngx.HTTP_NOT_FOUND (404)
|
|
value = ngx.HTTP_NOT_ALLOWED (405)
|
|
value = ngx.HTTP_NOT_ACCEPTABLE (406) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_REQUEST_TIMEOUT (408) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_CONFLICT (409) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_GONE (410)
|
|
value = ngx.HTTP_UPGRADE_REQUIRED (426) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_TOO_MANY_REQUESTS (429) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_CLOSE (444) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_ILLEGAL (451) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_INTERNAL_SERVER_ERROR (500)
|
|
value = ngx.HTTP_NOT_IMPLEMENTED (501)
|
|
value = ngx.HTTP_METHOD_NOT_IMPLEMENTED (501) (kept for compatibility)
|
|
value = ngx.HTTP_BAD_GATEWAY (502) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_SERVICE_UNAVAILABLE (503)
|
|
value = ngx.HTTP_GATEWAY_TIMEOUT (504) (first added in the v0.3.1rc38 release)
|
|
value = ngx.HTTP_VERSION_NOT_SUPPORTED (505) (first added in the v0.9.20 release)
|
|
value = ngx.HTTP_INSUFFICIENT_STORAGE (507) (first added in the v0.9.20 release)
|
|
</geshi>
|
|
|
|
== Nginx log level constants ==
|
|
|
|
'''context:''' ''init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
<geshi lang="lua">
|
|
ngx.STDERR
|
|
ngx.EMERG
|
|
ngx.ALERT
|
|
ngx.CRIT
|
|
ngx.ERR
|
|
ngx.WARN
|
|
ngx.NOTICE
|
|
ngx.INFO
|
|
ngx.DEBUG
|
|
</geshi>
|
|
|
|
These constants are usually used by the [[#ngx.log|ngx.log]] method.
|
|
|
|
== print ==
|
|
|
|
'''syntax:''' ''print(...)''
|
|
|
|
'''context:''' ''init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Writes argument values into the Nginx <code>error.log</code> file with the <code>ngx.NOTICE</code> log level.
|
|
|
|
It is equivalent to
|
|
|
|
<geshi lang="lua">
|
|
ngx.log(ngx.NOTICE, ...)
|
|
</geshi>
|
|
|
|
Lua <code>nil</code> arguments are accepted and result in literal <code>"nil"</code> strings while Lua booleans result in literal <code>"true"</code> or <code>"false"</code> strings. And the <code>ngx.null</code> constant will yield the <code>"null"</code> string output.
|
|
|
|
There is a hard coded <code>2048</code> byte limitation on error message lengths in the Nginx core. This limit includes trailing newlines and leading time stamps. If the message size exceeds this limit, Nginx will truncate the message text accordingly. This limit can be manually modified by editing the <code>NGX_MAX_ERROR_STR</code> macro definition in the <code>src/core/ngx_log.h</code> file in the Nginx source tree.
|
|
|
|
== ngx.ctx ==
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, exit_worker_by_lua*''
|
|
|
|
This table can be used to store per-request Lua context data and has a life time identical to the current request (as with the Nginx variables).
|
|
|
|
Consider the following example,
|
|
|
|
<geshi lang="nginx">
|
|
location /test {
|
|
rewrite_by_lua_block {
|
|
ngx.ctx.foo = 76
|
|
}
|
|
access_by_lua_block {
|
|
ngx.ctx.foo = ngx.ctx.foo + 3
|
|
}
|
|
content_by_lua_block {
|
|
ngx.say(ngx.ctx.foo)
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Then <code>GET /test</code> will yield the output
|
|
|
|
<geshi lang="bash">
|
|
79
|
|
</geshi>
|
|
|
|
That is, the <code>ngx.ctx.foo</code> entry persists across the rewrite, access, and content phases of a request.
|
|
|
|
Every request, including subrequests, has its own copy of the table. For example:
|
|
|
|
<geshi lang="nginx">
|
|
location /sub {
|
|
content_by_lua_block {
|
|
ngx.say("sub pre: ", ngx.ctx.blah)
|
|
ngx.ctx.blah = 32
|
|
ngx.say("sub post: ", ngx.ctx.blah)
|
|
}
|
|
}
|
|
|
|
location /main {
|
|
content_by_lua_block {
|
|
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)
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Then <code>GET /main</code> will give the output
|
|
|
|
<geshi lang="bash">
|
|
main pre: 73
|
|
sub pre: nil
|
|
sub post: 32
|
|
main post: 73
|
|
</geshi>
|
|
|
|
Here, modification of the <code>ngx.ctx.blah</code> entry in the subrequest does not affect the one in the parent request. This is because they have two separate versions of <code>ngx.ctx.blah</code>.
|
|
|
|
Internal redirects (triggered by nginx configuration directives like `error_page`, `try_files`, `index` and etc) will destroy the original request <code>ngx.ctx</code> data (if any) and the new request will have an empty <code>ngx.ctx</code> table. For instance,
|
|
|
|
<geshi lang="nginx">
|
|
location /new {
|
|
content_by_lua_block {
|
|
ngx.say(ngx.ctx.foo)
|
|
}
|
|
}
|
|
|
|
location /orig {
|
|
content_by_lua_block {
|
|
ngx.ctx.foo = "hello"
|
|
ngx.exec("/new")
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Then <code>GET /orig</code> will give
|
|
|
|
<geshi lang="bash">
|
|
nil
|
|
</geshi>
|
|
|
|
rather than the original <code>"hello"</code> value.
|
|
|
|
Because HTTP request is created after SSL handshake, the <code>ngx.ctx</code> created
|
|
in [[#ssl_certificate_by_lua|ssl_certificate_by_lua*]], [[#ssl_session_store_by_lua|ssl_session_store_by_lua*]], [[#ssl_session_fetch_by_lua|ssl_session_fetch_by_lua*]] and [[#ssl_client_hello_by_lua|ssl_client_hello_by_lua*]]
|
|
is not available in the following phases like [[#rewrite_by_lua|rewrite_by_lua*]].
|
|
|
|
Since <code>v0.10.18</code>, the <code>ngx.ctx</code> created during a SSL handshake
|
|
will be inherited by the requests which share the same TCP connection established by the handshake.
|
|
Note that overwrite values in <code>ngx.ctx</code> in the http request phases (like `rewrite_by_lua*`) will only take affect in the current http request.
|
|
|
|
Arbitrary data values, including Lua closures and nested tables, can be inserted into this "magic" table. It also allows the registration of custom meta methods.
|
|
|
|
Overriding <code>ngx.ctx</code> with a new Lua table is also supported, for example,
|
|
|
|
<geshi lang="lua">
|
|
ngx.ctx = { foo = 32, bar = 54 }
|
|
</geshi>
|
|
|
|
When being used in the context of [[#init_worker_by_lua|init_worker_by_lua*]], this table just has the same lifetime of the current Lua handler.
|
|
|
|
The <code>ngx.ctx</code> lookup requires relatively expensive metamethod calls and it is much slower than explicitly passing per-request data along by your own function arguments. So do not abuse this API for saving your own function arguments because it usually has quite some performance impact.
|
|
|
|
Because of the metamethod magic, never "local" the <code>ngx.ctx</code> table outside your Lua function scope on the Lua module level due to [[#Data_Sharing_within_an_Nginx_Worker|worker-level data sharing]]. For example, the following is bad:
|
|
|
|
<geshi lang="lua">
|
|
-- mymodule.lua
|
|
local _M = {}
|
|
|
|
-- the following line is bad since ngx.ctx is a per-request
|
|
-- data while this <code>ctx</code> variable is on the Lua module level
|
|
-- and thus is per-nginx-worker.
|
|
local ctx = ngx.ctx
|
|
|
|
function _M.main()
|
|
ctx.foo = "bar"
|
|
end
|
|
|
|
return _M
|
|
</geshi>
|
|
|
|
Use the following instead:
|
|
|
|
<geshi lang="lua">
|
|
-- mymodule.lua
|
|
local _M = {}
|
|
|
|
function _M.main(ctx)
|
|
ctx.foo = "bar"
|
|
end
|
|
|
|
return _M
|
|
</geshi>
|
|
|
|
That is, let the caller pass the <code>ctx</code> table explicitly via a function argument.
|
|
|
|
== ngx.location.capture ==
|
|
|
|
'''syntax:''' ''res = ngx.location.capture(uri, options?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Issues a synchronous but still non-blocking ''Nginx Subrequest'' using <code>uri</code>.
|
|
|
|
Nginx's subrequests provide a powerful way to make non-blocking internal requests to other locations configured with disk file directory or ''any'' other Nginx C modules like <code>ngx_proxy</code>, <code>ngx_fastcgi</code>, <code>ngx_memc</code>,
|
|
<code>ngx_postgres</code>, <code>ngx_drizzle</code>, and even ngx_lua itself and etc etc etc.
|
|
|
|
Also note that subrequests just mimic the HTTP interface but there is ''no'' extra HTTP/TCP traffic ''nor'' IPC involved. Everything works internally, efficiently, on the C level.
|
|
|
|
Subrequests are completely different from HTTP 301/302 redirection (via [[#ngx.redirect|ngx.redirect]]) and internal redirection (via [[#ngx.exec|ngx.exec]]).
|
|
|
|
You should always read the request body (by either calling [[#ngx.req.read_body|ngx.req.read_body]] or configuring [[#lua_need_request_body|lua_need_request_body]] on) before initiating a subrequest.
|
|
|
|
This API function (as well as [[#ngx.location.capture_multi|ngx.location.capture_multi]]) always buffers the whole response body of the subrequest in memory. Thus, you should use [[#ngx.socket.tcp|cosockets]]
|
|
and streaming processing instead if you have to handle large subrequest responses.
|
|
|
|
Here is a basic example:
|
|
|
|
<geshi lang="lua">
|
|
res = ngx.location.capture(uri)
|
|
</geshi>
|
|
|
|
Returns a Lua table with 4 slots: <code>res.status</code>, <code>res.header</code>, <code>res.body</code>, and <code>res.truncated</code>.
|
|
|
|
<code>res.status</code> holds the response status code for the subrequest response.
|
|
|
|
<code>res.header</code> holds all the response headers of the
|
|
subrequest and it is a normal Lua table. For multi-value response headers,
|
|
the value is a Lua (array) table that holds all the values in the order that
|
|
they appear. For instance, if the subrequest response headers contain the following
|
|
lines:
|
|
|
|
<geshi lang="bash">
|
|
Set-Cookie: a=3
|
|
Set-Cookie: foo=bar
|
|
Set-Cookie: baz=blah
|
|
</geshi>
|
|
|
|
Then <code>res.header["Set-Cookie"]</code> will be evaluated to the table value
|
|
<code>{"a=3", "foo=bar", "baz=blah"}</code>.
|
|
|
|
<code>res.body</code> holds the subrequest's response body data, which might be truncated. You always need to check the <code>res.truncated</code> boolean flag to see if <code>res.body</code> contains truncated data. The data truncation here can only be caused by those unrecoverable errors in your subrequests like the cases that the remote end aborts the connection prematurely in the middle of the response body data stream or a read timeout happens when your subrequest is receiving the response body data from the remote.
|
|
|
|
URI query strings can be concatenated to URI itself, for instance,
|
|
|
|
<geshi lang="lua">
|
|
res = ngx.location.capture('/foo/bar?a=3&b=4')
|
|
</geshi>
|
|
|
|
Named locations like <code>@foo</code> are not allowed due to a limitation in
|
|
the Nginx core. Use normal locations combined with the <code>internal</code> directive to
|
|
prepare internal-only locations.
|
|
|
|
An optional option table can be fed as the second
|
|
argument, which supports the options:
|
|
|
|
* <code>method</code>
|
|
: specify the subrequest's request method, which only accepts constants like <code>ngx.HTTP_POST</code>.
|
|
* <code>body</code>
|
|
: specify the subrequest's request body (string value only).
|
|
* <code>args</code>
|
|
: specify the subrequest's URI query arguments (both string value and Lua tables are accepted)
|
|
* <code>ctx</code>
|
|
: specify a Lua table to be the [[#ngx.ctx|ngx.ctx]] table for the subrequest. It can be the current request's [[#ngx.ctx|ngx.ctx]] table, which effectively makes the parent and its subrequest to share exactly the same context table. This option was first introduced in the <code>v0.3.1rc25</code> release.
|
|
* <code>vars</code>
|
|
: take a Lua table which holds the values to set the specified Nginx variables in the subrequest as this option's value. This option was first introduced in the <code>v0.3.1rc31</code> release.
|
|
* <code>copy_all_vars</code>
|
|
: specify whether to copy over all the Nginx variable values of the current request to the subrequest in question. modifications of the Nginx variables in the subrequest will not affect the current (parent) request. This option was first introduced in the <code>v0.3.1rc31</code> release.
|
|
* <code>share_all_vars</code>
|
|
: specify whether to share all the Nginx variables of the subrequest with the current (parent) request. modifications of the Nginx variables in the subrequest will affect the current (parent) request. Enabling this option may lead to hard-to-debug issues due to bad side-effects and is considered bad and harmful. Only enable this option when you completely know what you are doing.
|
|
* <code>always_forward_body</code>
|
|
: when set to true, the current (parent) request's request body will always be forwarded to the subrequest being created if the <code>body</code> option is not specified. The request body read by either [[#ngx.req.read_body|ngx.req.read_body()]] or [[#lua_need_request_body|lua_need_request_body on]] will be directly forwarded to the subrequest without copying the whole request body data when creating the subrequest (no matter the request body data is buffered in memory buffers or temporary files). By default, this option is <code>false</code> and when the <code>body</code> option is not specified, the request body of the current (parent) request is only forwarded when the subrequest takes the <code>PUT</code> or <code>POST</code> request method.
|
|
|
|
Issuing a POST subrequest, for example, can be done as follows
|
|
|
|
<geshi lang="lua">
|
|
res = ngx.location.capture(
|
|
'/foo/bar',
|
|
{ method = ngx.HTTP_POST, body = 'hello, world' }
|
|
)
|
|
</geshi>
|
|
|
|
See HTTP method constants methods other than POST.
|
|
The <code>method</code> option is <code>ngx.HTTP_GET</code> by default.
|
|
|
|
The <code>args</code> option can specify extra URI arguments, for instance,
|
|
|
|
<geshi lang="lua">
|
|
ngx.location.capture('/foo?a=1',
|
|
{ args = { b = 3, c = ':' } }
|
|
)
|
|
</geshi>
|
|
|
|
is equivalent to
|
|
|
|
<geshi lang="lua">
|
|
ngx.location.capture('/foo?a=1&b=3&c=%3a')
|
|
</geshi>
|
|
|
|
that is, this method will escape argument keys and values according to URI rules and
|
|
concatenate them together into a complete query string. The format for the Lua table passed as the <code>args</code> argument is identical to the format used in the [[#ngx.encode_args|ngx.encode_args]] method.
|
|
|
|
The <code>args</code> option can also take plain query strings:
|
|
|
|
<geshi lang="lua">
|
|
ngx.location.capture('/foo?a=1',
|
|
{ args = 'b=3&c=%3a' }
|
|
)
|
|
</geshi>
|
|
|
|
This is functionally identical to the previous examples.
|
|
|
|
The <code>share_all_vars</code> option controls whether to share Nginx variables among the current request and its subrequests.
|
|
If this option is set to <code>true</code>, then the current request and associated subrequests will share the same Nginx variable scope. Hence, changes to Nginx variables made by a subrequest will affect the current request.
|
|
|
|
Care should be taken in using this option as variable scope sharing can have unexpected side effects. The <code>args</code>, <code>vars</code>, or <code>copy_all_vars</code> options are generally preferable instead.
|
|
|
|
This option is set to <code>false</code> by default
|
|
|
|
<geshi lang="nginx">
|
|
location /other {
|
|
set $dog "$dog world";
|
|
echo "$uri dog: $dog";
|
|
}
|
|
|
|
location /lua {
|
|
set $dog 'hello';
|
|
content_by_lua_block {
|
|
res = ngx.location.capture("/other",
|
|
{ share_all_vars = true })
|
|
|
|
ngx.print(res.body)
|
|
ngx.say(ngx.var.uri, ": ", ngx.var.dog)
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Accessing location <code>/lua</code> gives
|
|
|
|
<geshi lang="text">
|
|
/other dog: hello world
|
|
/lua: hello world
|
|
</geshi>
|
|
|
|
The <code>copy_all_vars</code> option provides a copy of the parent request's Nginx variables to subrequests when such subrequests are issued. Changes made to these variables by such subrequests will not affect the parent request or any other subrequests sharing the parent request's variables.
|
|
|
|
<geshi lang="nginx">
|
|
location /other {
|
|
set $dog "$dog world";
|
|
echo "$uri dog: $dog";
|
|
}
|
|
|
|
location /lua {
|
|
set $dog 'hello';
|
|
content_by_lua_block {
|
|
res = ngx.location.capture("/other",
|
|
{ copy_all_vars = true })
|
|
|
|
ngx.print(res.body)
|
|
ngx.say(ngx.var.uri, ": ", ngx.var.dog)
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Request <code>GET /lua</code> will give the output
|
|
|
|
<geshi lang="text">
|
|
/other dog: hello world
|
|
/lua: hello
|
|
</geshi>
|
|
|
|
Note that if both <code>share_all_vars</code> and <code>copy_all_vars</code> are set to true, then <code>share_all_vars</code> takes precedence.
|
|
|
|
In addition to the two settings above, it is possible to specify
|
|
values for variables in the subrequest using the <code>vars</code> option. These
|
|
variables are set after the sharing or copying of variables has been
|
|
evaluated, and provides a more efficient method of passing specific
|
|
values to a subrequest over encoding them as URL arguments and
|
|
unescaping them in the Nginx config file.
|
|
|
|
<geshi lang="nginx">
|
|
location /other {
|
|
content_by_lua_block {
|
|
ngx.say("dog = ", ngx.var.dog)
|
|
ngx.say("cat = ", ngx.var.cat)
|
|
}
|
|
}
|
|
|
|
location /lua {
|
|
set $dog '';
|
|
set $cat '';
|
|
content_by_lua_block {
|
|
res = ngx.location.capture("/other",
|
|
{ vars = { dog = "hello", cat = 32 }})
|
|
|
|
ngx.print(res.body)
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Accessing <code>/lua</code> will yield the output
|
|
|
|
<geshi lang="text">
|
|
dog = hello
|
|
cat = 32
|
|
</geshi>
|
|
|
|
The <code>ctx</code> option can be used to specify a custom Lua table to serve as the [[#ngx.ctx|ngx.ctx]] table for the subrequest.
|
|
|
|
<geshi lang="nginx">
|
|
location /sub {
|
|
content_by_lua_block {
|
|
ngx.ctx.foo = "bar";
|
|
}
|
|
}
|
|
location /lua {
|
|
content_by_lua_block {
|
|
local ctx = {}
|
|
res = ngx.location.capture("/sub", { ctx = ctx })
|
|
|
|
ngx.say(ctx.foo)
|
|
ngx.say(ngx.ctx.foo)
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Then request <code>GET /lua</code> gives
|
|
|
|
<geshi lang="text">
|
|
bar
|
|
nil
|
|
</geshi>
|
|
|
|
It is also possible to use this <code>ctx</code> option to share the same [[#ngx.ctx|ngx.ctx]] table between the current (parent) request and the subrequest:
|
|
|
|
<geshi lang="nginx">
|
|
location /sub {
|
|
content_by_lua_block {
|
|
ngx.ctx.foo = "bar"
|
|
}
|
|
}
|
|
location /lua {
|
|
content_by_lua_block {
|
|
res = ngx.location.capture("/sub", { ctx = ngx.ctx })
|
|
ngx.say(ngx.ctx.foo)
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Request <code>GET /lua</code> yields the output
|
|
|
|
<geshi lang="text">
|
|
bar
|
|
</geshi>
|
|
|
|
Note that subrequests issued by [[#ngx.location.capture|ngx.location.capture]] inherit all the
|
|
request headers of the current request by default and that this may have unexpected side effects on the
|
|
subrequest responses. For example, when using the standard <code>ngx_proxy</code> module to serve
|
|
subrequests, an "Accept-Encoding: gzip" header in the main request may result
|
|
in gzipped responses that cannot be handled properly in Lua code. Original request headers should be ignored by setting
|
|
[[HttpProxyModule#proxy_pass_request_headers|proxy_pass_request_headers]] to <code>off</code> in subrequest locations.
|
|
|
|
When the <code>body</code> option is not specified and the <code>always_forward_body</code> option is false (the default value), the <code>POST</code> and <code>PUT</code> subrequests will inherit the request bodies of the parent request (if any).
|
|
|
|
There is a hard-coded upper limit on the number of subrequests possible for every main request. In older versions of Nginx, the limit was <code>50</code> concurrent subrequests and in more recent versions, Nginx <code>1.9.5</code> onwards, the same limit is changed to limit the depth of recursive subrequests. When this limit is exceeded, the following error message is added to the <code>error.log</code> file:
|
|
|
|
<geshi lang="text">
|
|
[error] 13983#0: *1 subrequests cycle while processing "/uri"
|
|
</geshi>
|
|
|
|
The limit can be manually modified if required by editing the definition of the <code>NGX_HTTP_MAX_SUBREQUESTS</code> macro in the <code>nginx/src/http/ngx_http_request.h</code> file in the Nginx source tree.
|
|
|
|
Please also refer to restrictions on capturing locations configured by [[#Locations_Configured_by_Subrequest_Directives_of_Other_Modules|subrequest directives of other modules]].
|
|
|
|
== ngx.location.capture_multi ==
|
|
|
|
'''syntax:''' ''res1, res2, ... = ngx.location.capture_multi({ {uri, options?}, {uri, options?}, ... })''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Just like [[#ngx.location.capture|ngx.location.capture]], but supports multiple subrequests running in parallel.
|
|
|
|
This function issues several parallel subrequests specified by the input table and returns their results in the same order. For example,
|
|
|
|
<geshi lang="lua">
|
|
res1, res2, res3 = ngx.location.capture_multi{
|
|
{ "/foo", { args = "a=3&b=4" } },
|
|
{ "/bar" },
|
|
{ "/baz", { method = ngx.HTTP_POST, body = "hello" } },
|
|
}
|
|
|
|
if res1.status == ngx.HTTP_OK then
|
|
...
|
|
end
|
|
|
|
if res2.body == "BLAH" then
|
|
...
|
|
end
|
|
</geshi>
|
|
|
|
This function will not return until all the subrequests terminate.
|
|
The total latency is the longest latency of the individual subrequests rather than the sum.
|
|
|
|
Lua tables can be used for both requests and responses when the number of subrequests to be issued is not known in advance:
|
|
|
|
<geshi lang="lua">
|
|
-- construct the requests table
|
|
local reqs = {}
|
|
table.insert(reqs, { "/mysql" })
|
|
table.insert(reqs, { "/postgres" })
|
|
table.insert(reqs, { "/redis" })
|
|
table.insert(reqs, { "/memcached" })
|
|
|
|
-- issue all the requests at once and wait until they all return
|
|
local resps = {
|
|
ngx.location.capture_multi(reqs)
|
|
}
|
|
|
|
-- loop over the responses table
|
|
for i, resp in ipairs(resps) do
|
|
-- process the response table "resp"
|
|
end
|
|
</geshi>
|
|
|
|
The [[#ngx.location.capture|ngx.location.capture]] function is just a special form
|
|
of this function. Logically speaking, the [[#ngx.location.capture|ngx.location.capture]] can be implemented like this
|
|
|
|
<geshi lang="lua">
|
|
ngx.location.capture =
|
|
function (uri, args)
|
|
return ngx.location.capture_multi({ {uri, args} })
|
|
end
|
|
</geshi>
|
|
|
|
Please also refer to restrictions on capturing locations configured by [[#Locations_Configured_by_Subrequest_Directives_of_Other_Modules|subrequest directives of other modules]].
|
|
|
|
== ngx.status ==
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*''
|
|
|
|
Read and write the current request's response status. This should be called
|
|
before sending out the response headers.
|
|
|
|
<geshi lang="lua">
|
|
ngx.status = ngx.HTTP_CREATED
|
|
status = ngx.status
|
|
</geshi>
|
|
|
|
Setting <code>ngx.status</code> after the response header is sent out has no effect but leaving an error message in your Nginx's error log file:
|
|
|
|
<geshi lang="text">
|
|
attempt to set ngx.status after sending out response headers
|
|
</geshi>
|
|
|
|
== ngx.header.HEADER ==
|
|
|
|
'''syntax:''' ''ngx.header.HEADER = VALUE''
|
|
|
|
'''syntax:''' ''value = ngx.header.HEADER''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*''
|
|
|
|
Set, add to, or clear the current request's <code>HEADER</code> response header that is to be sent.
|
|
|
|
Underscores (<code>_</code>) in the header names will be replaced by hyphens (<code>-</code>) by default. This transformation can be turned off via the [[#lua_transform_underscores_in_response_headers|lua_transform_underscores_in_response_headers]] directive.
|
|
|
|
The header names are matched case-insensitively.
|
|
|
|
<geshi lang="lua">
|
|
-- equivalent to ngx.header["Content-Type"] = 'text/plain'
|
|
ngx.header.content_type = 'text/plain'
|
|
|
|
ngx.header["X-My-Header"] = 'blah blah'
|
|
</geshi>
|
|
|
|
Multi-value headers can be set this way:
|
|
|
|
<geshi lang="lua">
|
|
ngx.header['Set-Cookie'] = {'a=32; path=/', 'b=4; path=/'}
|
|
</geshi>
|
|
|
|
will yield
|
|
|
|
<geshi lang="bash">
|
|
Set-Cookie: a=32; path=/
|
|
Set-Cookie: b=4; path=/
|
|
</geshi>
|
|
|
|
in the response headers.
|
|
|
|
Only Lua tables are accepted (Only the last element in the table will take effect for standard headers such as <code>Content-Type</code> that only accept a single value).
|
|
|
|
<geshi lang="lua">
|
|
ngx.header.content_type = {'a', 'b'}
|
|
</geshi>
|
|
|
|
is equivalent to
|
|
|
|
<geshi lang="lua">
|
|
ngx.header.content_type = 'b'
|
|
</geshi>
|
|
|
|
Setting a slot to <code>nil</code> effectively removes it from the response headers:
|
|
|
|
<geshi lang="lua">
|
|
ngx.header["X-My-Header"] = nil
|
|
</geshi>
|
|
|
|
The same applies to assigning an empty table:
|
|
|
|
<geshi lang="lua">
|
|
ngx.header["X-My-Header"] = {}
|
|
</geshi>
|
|
|
|
Setting <code>ngx.header.HEADER</code> after sending out response headers (either explicitly with [[#ngx.send_headers|ngx.send_headers]] or implicitly with [[#ngx.print|ngx.print]] and similar) will log an error message.
|
|
|
|
Reading <code>ngx.header.HEADER</code> will return the value of the response header named <code>HEADER</code>.
|
|
|
|
Underscores (<code>_</code>) in the header names will also be replaced by dashes (<code>-</code>) and the header names will be matched case-insensitively. If the response header is not present at all, <code>nil</code> will be returned.
|
|
|
|
This is particularly useful in the context of [[#header_filter_by_lua|header_filter_by_lua*]], for example,
|
|
|
|
<geshi lang="nginx">
|
|
location /test {
|
|
set $footer '';
|
|
|
|
proxy_pass http://some-backend;
|
|
|
|
header_filter_by_lua_block {
|
|
if ngx.header["X-My-Header"] == "blah" then
|
|
ngx.var.footer = "some value"
|
|
end
|
|
}
|
|
|
|
echo_after_body $footer;
|
|
}
|
|
</geshi>
|
|
|
|
For multi-value headers, all of the values of header will be collected in order and returned as a Lua table. For example, response headers
|
|
|
|
<geshi lang="text">
|
|
Foo: bar
|
|
Foo: baz
|
|
</geshi>
|
|
|
|
will result in
|
|
|
|
<geshi lang="lua">
|
|
{"bar", "baz"}
|
|
</geshi>
|
|
|
|
to be returned when reading <code>ngx.header.Foo</code>.
|
|
|
|
Note that <code>ngx.header</code> is not a normal Lua table and as such, it is not possible to iterate through it using the Lua <code>ipairs</code> function.
|
|
|
|
Note: this function throws a Lua error if <code>HEADER</code> or
|
|
<code>VALUE</code> contain unsafe characters (control characters).
|
|
|
|
For reading ''request'' headers, use the [[#ngx.req.get_headers|ngx.req.get_headers]] function instead.
|
|
|
|
== ngx.resp.get_headers ==
|
|
|
|
'''syntax:''' ''headers, err = ngx.resp.get_headers(max_headers?, raw?)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, balancer_by_lua*''
|
|
|
|
Returns a Lua table holding all the current response headers for the current request.
|
|
|
|
<geshi lang="lua">
|
|
local h, err = ngx.resp.get_headers()
|
|
|
|
if err == "truncated" then
|
|
-- one can choose to ignore or reject the current response here
|
|
end
|
|
|
|
for k, v in pairs(h) do
|
|
...
|
|
end
|
|
</geshi>
|
|
|
|
This function has the same signature as [[#ngx.req.get_headers|ngx.req.get_headers]] except getting response headers instead of request headers.
|
|
|
|
Note that a maximum of 100 response headers are parsed by default (including those with the same name) and that additional response headers are silently discarded to guard against potential denial of service attacks. Since <code>v0.10.13</code>, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
|
|
|
|
This API was first introduced in the <code>v0.9.5</code> release.
|
|
|
|
== ngx.req.is_internal ==
|
|
|
|
'''syntax:''' ''is_internal = ngx.req.is_internal()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*''
|
|
|
|
Returns a boolean indicating whether the current request is an "internal request", i.e.,
|
|
a request initiated from inside the current Nginx server instead of from the client side.
|
|
|
|
Subrequests are all internal requests and so are requests after internal redirects.
|
|
|
|
This API was first introduced in the <code>v0.9.20</code> release.
|
|
|
|
== ngx.req.start_time ==
|
|
|
|
'''syntax:''' ''secs = ngx.req.start_time()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*''
|
|
|
|
Returns a floating-point number representing the timestamp (including milliseconds as the decimal part) when the current request was created.
|
|
|
|
The following example emulates the <code>$request_time</code> variable value (provided by [[HttpLogModule]]) in pure Lua:
|
|
|
|
<geshi lang="lua">
|
|
local request_time = ngx.now() - ngx.req.start_time()
|
|
</geshi>
|
|
|
|
This function was first introduced in the <code>v0.7.7</code> release.
|
|
|
|
See also [[#ngx.now|ngx.now]] and [[#ngx.update_time|ngx.update_time]].
|
|
|
|
== ngx.req.http_version ==
|
|
|
|
'''syntax:''' ''num = ngx.req.http_version()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*''
|
|
|
|
Returns the HTTP version number for the current request as a Lua number.
|
|
|
|
Current possible values are 2.0, 1.0, 1.1, and 0.9. Returns <code>nil</code> for unrecognized values.
|
|
|
|
This method was first introduced in the <code>v0.7.17</code> release.
|
|
|
|
== ngx.req.raw_header ==
|
|
|
|
'''syntax:''' ''str = ngx.req.raw_header(no_request_line?)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*''
|
|
|
|
Returns the original raw HTTP protocol header received by the Nginx server.
|
|
|
|
By default, the request line and trailing <code>CR LF</code> terminator will also be included. For example,
|
|
|
|
<geshi lang="lua">
|
|
ngx.print(ngx.req.raw_header())
|
|
</geshi>
|
|
|
|
gives something like this:
|
|
|
|
<geshi lang="text">
|
|
GET /t HTTP/1.1
|
|
Host: localhost
|
|
Connection: close
|
|
Foo: bar
|
|
|
|
</geshi>
|
|
|
|
You can specify the optional
|
|
<code>no_request_line</code> argument as a <code>true</code> value to exclude the request line from the result. For example,
|
|
|
|
<geshi lang="lua">
|
|
ngx.print(ngx.req.raw_header(true))
|
|
</geshi>
|
|
|
|
outputs something like this:
|
|
|
|
<geshi lang="text">
|
|
Host: localhost
|
|
Connection: close
|
|
Foo: bar
|
|
|
|
</geshi>
|
|
|
|
This method was first introduced in the <code>v0.7.17</code> release.
|
|
|
|
This method does not work in HTTP/2 requests yet.
|
|
|
|
== ngx.req.get_method ==
|
|
|
|
'''syntax:''' ''method_name = ngx.req.get_method()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, balancer_by_lua*, log_by_lua*''
|
|
|
|
Retrieves the current request's request method name. Strings like <code>"GET"</code> and <code>"POST"</code> are returned instead of numerical [[#HTTP method constants|method constants]].
|
|
|
|
If the current request is an Nginx subrequest, then the subrequest's method name will be returned.
|
|
|
|
This method was first introduced in the <code>v0.5.6</code> release.
|
|
|
|
See also [[#ngx.req.set_method|ngx.req.set_method]].
|
|
|
|
== ngx.req.set_method ==
|
|
|
|
'''syntax:''' ''ngx.req.set_method(method_id)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*''
|
|
|
|
Overrides the current request's request method with the <code>method_id</code> argument. Currently only numerical [[#HTTP method constants|method constants]] are supported, like <code>ngx.HTTP_POST</code> and <code>ngx.HTTP_GET</code>.
|
|
|
|
If the current request is an Nginx subrequest, then the subrequest's method will be overridden.
|
|
|
|
This method was first introduced in the <code>v0.5.6</code> release.
|
|
|
|
See also [[#ngx.req.get_method|ngx.req.get_method]].
|
|
|
|
== ngx.req.set_uri ==
|
|
|
|
'''syntax:''' ''ngx.req.set_uri(uri, jump?, binary?)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*''
|
|
|
|
Rewrite the current request's (parsed) URI by the <code>uri</code> argument. The <code>uri</code> argument must be a Lua string and cannot be of zero length, or a Lua exception will be thrown.
|
|
|
|
The optional boolean <code>jump</code> argument can trigger location rematch (or location jump) as [[HttpRewriteModule]]'s [[HttpRewriteModule#rewrite|rewrite]] directive, that is, when <code>jump</code> is <code>true</code> (default to <code>false</code>), this function will never return and it will tell Nginx to try re-searching locations with the new URI value at the later <code>post-rewrite</code> phase and jumping to the new location.
|
|
|
|
Location jump will not be triggered otherwise, and only the current request's URI will be modified, which is also the default behavior. This function will return but with no returned values when the <code>jump</code> argument is <code>false</code> or absent altogether.
|
|
|
|
For example, the following Nginx config snippet
|
|
|
|
<geshi lang="nginx">
|
|
rewrite ^ /foo last;
|
|
</geshi>
|
|
|
|
can be coded in Lua like this:
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.set_uri("/foo", true)
|
|
</geshi>
|
|
|
|
Similarly, Nginx config
|
|
|
|
<geshi lang="nginx">
|
|
rewrite ^ /foo break;
|
|
</geshi>
|
|
|
|
can be coded in Lua as
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.set_uri("/foo", false)
|
|
</geshi>
|
|
|
|
or equivalently,
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.set_uri("/foo")
|
|
</geshi>
|
|
|
|
The <code>jump</code> argument can only be set to <code>true</code> in [[#rewrite_by_lua|rewrite_by_lua*]]. Use of jump in other contexts is prohibited and will throw out a Lua exception.
|
|
|
|
A more sophisticated example involving regex substitutions is as follows
|
|
|
|
<geshi lang="nginx">
|
|
location /test {
|
|
rewrite_by_lua_block {
|
|
local uri = ngx.re.sub(ngx.var.uri, "^/test/(.*)", "/$1", "o")
|
|
ngx.req.set_uri(uri)
|
|
}
|
|
proxy_pass http://my_backend;
|
|
}
|
|
</geshi>
|
|
|
|
which is functionally equivalent to
|
|
|
|
<geshi lang="nginx">
|
|
location /test {
|
|
rewrite ^/test/(.*) /$1 break;
|
|
proxy_pass http://my_backend;
|
|
}
|
|
</geshi>
|
|
|
|
Note: this function throws a Lua error if the <code>uri</code> argument
|
|
contains unsafe characters (control characters).
|
|
|
|
Note that it is not possible to use this interface to rewrite URI arguments and that [[#ngx.req.set_uri_args|ngx.req.set_uri_args]] should be used for this instead. For instance, Nginx config
|
|
|
|
<geshi lang="nginx">
|
|
rewrite ^ /foo?a=3? last;
|
|
</geshi>
|
|
|
|
can be coded as
|
|
|
|
<geshi lang="nginx">
|
|
ngx.req.set_uri_args("a=3")
|
|
ngx.req.set_uri("/foo", true)
|
|
</geshi>
|
|
|
|
or
|
|
|
|
<geshi lang="nginx">
|
|
ngx.req.set_uri_args({a = 3})
|
|
ngx.req.set_uri("/foo", true)
|
|
</geshi>
|
|
|
|
Starting from <code>0.10.16</code> of this module, this function accepts an
|
|
optional boolean <code>binary</code> argument to allow arbitrary binary URI
|
|
data. By default, this <code>binary</code> argument is false and this function
|
|
will throw out a Lua error such as the one below when the <code>uri</code>
|
|
argument contains any control characters (ASCII Code 0 ~ 0x08, 0x0A ~ 0x1F and 0x7F).
|
|
|
|
<geshi lang="text">
|
|
[error] 23430#23430: *1 lua entry thread aborted: runtime error:
|
|
content_by_lua(nginx.conf:44):3: ngx.req.set_uri unsafe byte "0x00"
|
|
in "\x00foo" (maybe you want to set the 'binary' argument?)
|
|
</geshi>
|
|
|
|
This interface was first introduced in the <code>v0.3.1rc14</code> release.
|
|
|
|
== ngx.req.set_uri_args ==
|
|
|
|
'''syntax:''' ''ngx.req.set_uri_args(args)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*''
|
|
|
|
Rewrite the current request's URI query arguments by the <code>args</code> argument. The <code>args</code> argument can be either a Lua string, as in
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.set_uri_args("a=3&b=hello%20world")
|
|
</geshi>
|
|
|
|
or a Lua table holding the query arguments' key-value pairs, as in
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.set_uri_args({ a = 3, b = "hello world" })
|
|
</geshi>
|
|
|
|
In the former case, i.e., when the whole query-string is provided directly,
|
|
the input Lua string should already be well-formed with the URI encoding.
|
|
For security considerations, this method will automatically escape any control and
|
|
whitespace characters (ASCII code 0x00 ~ 0x20 and 0x7F) in the Lua string.
|
|
|
|
In the latter case, this method will escape argument keys and values according to the URI escaping rule.
|
|
|
|
Multi-value arguments are also supported:
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.set_uri_args({ a = 3, b = {5, 6} })
|
|
</geshi>
|
|
|
|
which will result in a query string like <code>a=3&b=5&b=6</code>.
|
|
|
|
This interface was first introduced in the <code>v0.3.1rc13</code> release.
|
|
|
|
See also [[#ngx.req.set_uri|ngx.req.set_uri]].
|
|
|
|
== ngx.req.get_uri_args ==
|
|
|
|
'''syntax:''' ''args, err = ngx.req.get_uri_args(max_args?, tab?)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, balancer_by_lua*''
|
|
|
|
Returns a Lua table holding all the current request URL query arguments. An optional <code>tab</code> argument
|
|
can be used to reuse the table returned by this method.
|
|
|
|
<geshi lang="nginx">
|
|
location = /test {
|
|
content_by_lua_block {
|
|
local args, err = ngx.req.get_uri_args()
|
|
|
|
if err == "truncated" then
|
|
-- one can choose to ignore or reject the current request here
|
|
end
|
|
|
|
for key, val in pairs(args) do
|
|
if type(val) == "table" then
|
|
ngx.say(key, ": ", table.concat(val, ", "))
|
|
else
|
|
ngx.say(key, ": ", val)
|
|
end
|
|
end
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Then <code>GET /test?foo=bar&bar=baz&bar=blah</code> will yield the response body
|
|
|
|
<geshi lang="bash">
|
|
foo: bar
|
|
bar: baz, blah
|
|
</geshi>
|
|
|
|
Multiple occurrences of an argument key will result in a table value holding all the values for that key in order.
|
|
|
|
Keys and values are unescaped according to URI escaping rules. In the settings above, <code>GET /test?a%20b=1%61+2</code> will yield:
|
|
|
|
<geshi lang="bash">
|
|
a b: 1a 2
|
|
</geshi>
|
|
|
|
Arguments without the <code>=<value></code> parts are treated as boolean arguments. <code>GET /test?foo&bar</code> will yield:
|
|
|
|
<geshi lang="bash">
|
|
foo: true
|
|
bar: true
|
|
</geshi>
|
|
|
|
That is, they will take Lua boolean values <code>true</code>. However, they are different from arguments taking empty string values. <code>GET /test?foo=&bar=</code> will give something like
|
|
|
|
<geshi lang="bash">
|
|
foo:
|
|
bar:
|
|
</geshi>
|
|
|
|
Empty key arguments are discarded. <code>GET /test?=hello&=world</code> will yield an empty output for instance.
|
|
|
|
Updating query arguments via the Nginx variable <code>$args</code> (or <code>ngx.var.args</code> in Lua) at runtime is also supported:
|
|
|
|
<geshi lang="lua">
|
|
ngx.var.args = "a=3&b=42"
|
|
local args, err = ngx.req.get_uri_args()
|
|
</geshi>
|
|
|
|
Here the <code>args</code> table will always look like
|
|
|
|
<geshi lang="lua">
|
|
{a = 3, b = 42}
|
|
</geshi>
|
|
|
|
regardless of the actual request query string.
|
|
|
|
Note that a maximum of 100 request arguments are parsed by default (including those with the same name) and that additional request arguments are silently discarded to guard against potential denial of service attacks. Since <code>v0.10.13</code>, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
|
|
|
|
However, the optional <code>max_args</code> function argument can be used to override this limit:
|
|
|
|
<geshi lang="lua">
|
|
local args, err = ngx.req.get_uri_args(10)
|
|
if err == "truncated" then
|
|
-- one can choose to ignore or reject the current request here
|
|
end
|
|
</geshi>
|
|
|
|
This argument can be set to zero to remove the limit and to process all request arguments received:
|
|
|
|
<geshi lang="lua">
|
|
local args, err = ngx.req.get_uri_args(0)
|
|
</geshi>
|
|
|
|
Removing the <code>max_args</code> cap is strongly discouraged.
|
|
|
|
== ngx.req.get_post_args ==
|
|
|
|
'''syntax:''' ''args, err = ngx.req.get_post_args(max_args?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*''
|
|
|
|
Returns a Lua table holding all the current request POST query arguments (of the MIME type <code>application/x-www-form-urlencoded</code>). Call [[#ngx.req.read_body|ngx.req.read_body]] to read the request body first or turn on the [[#lua_need_request_body|lua_need_request_body]] directive to avoid errors.
|
|
|
|
<geshi lang="nginx">
|
|
location = /test {
|
|
content_by_lua_block {
|
|
ngx.req.read_body()
|
|
local args, err = ngx.req.get_post_args()
|
|
|
|
if err == "truncated" then
|
|
-- one can choose to ignore or reject the current request here
|
|
end
|
|
|
|
if not args then
|
|
ngx.say("failed to get post args: ", err)
|
|
return
|
|
end
|
|
for key, val in pairs(args) do
|
|
if type(val) == "table" then
|
|
ngx.say(key, ": ", table.concat(val, ", "))
|
|
else
|
|
ngx.say(key, ": ", val)
|
|
end
|
|
end
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Then
|
|
|
|
<geshi lang="bash">
|
|
# Post request with the body 'foo=bar&bar=baz&bar=blah'
|
|
$ curl --data 'foo=bar&bar=baz&bar=blah' localhost/test
|
|
</geshi>
|
|
|
|
will yield the response body like
|
|
|
|
<geshi lang="bash">
|
|
foo: bar
|
|
bar: baz, blah
|
|
</geshi>
|
|
|
|
Multiple occurrences of an argument key will result in a table value holding all of the values for that key in order.
|
|
|
|
Keys and values will be unescaped according to URI escaping rules.
|
|
|
|
With the settings above,
|
|
|
|
<geshi lang="bash">
|
|
# POST request with body 'a%20b=1%61+2'
|
|
$ curl -d 'a%20b=1%61+2' localhost/test
|
|
</geshi>
|
|
|
|
will yield:
|
|
|
|
<geshi lang="bash">
|
|
a b: 1a 2
|
|
</geshi>
|
|
|
|
Arguments without the <code>=<value></code> parts are treated as boolean arguments. <code>POST /test</code> with the request body <code>foo&bar</code> will yield:
|
|
|
|
<geshi lang="bash">
|
|
foo: true
|
|
bar: true
|
|
</geshi>
|
|
|
|
That is, they will take Lua boolean values <code>true</code>. However, they are different from arguments taking empty string values. <code>POST /test</code> with request body <code>foo=&bar=</code> will return something like
|
|
|
|
<geshi lang="bash">
|
|
foo:
|
|
bar:
|
|
</geshi>
|
|
|
|
Empty key arguments are discarded. <code>POST /test</code> with body <code>=hello&=world</code> will yield empty outputs for instance.
|
|
|
|
Note that a maximum of 100 request arguments are parsed by default (including those with the same name) and that additional request arguments are silently discarded to guard against potential denial of service attacks. Since <code>v0.10.13</code>, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
|
|
|
|
However, the optional <code>max_args</code> function argument can be used to override this limit:
|
|
|
|
<geshi lang="lua">
|
|
local args, err = ngx.req.get_post_args(10)
|
|
if err == "truncated" then
|
|
-- one can choose to ignore or reject the current request here
|
|
end
|
|
</geshi>
|
|
|
|
This argument can be set to zero to remove the limit and to process all request arguments received:
|
|
|
|
<geshi lang="lua">
|
|
local args, err = ngx.req.get_post_args(0)
|
|
</geshi>
|
|
|
|
Removing the <code>max_args</code> cap is strongly discouraged.
|
|
|
|
== ngx.req.get_headers ==
|
|
|
|
'''syntax:''' ''headers, err = ngx.req.get_headers(max_headers?, raw?)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*''
|
|
|
|
Returns a Lua table holding all the current request headers.
|
|
|
|
<geshi lang="lua">
|
|
local h, err = ngx.req.get_headers()
|
|
|
|
if err == "truncated" then
|
|
-- one can choose to ignore or reject the current request here
|
|
end
|
|
|
|
for k, v in pairs(h) do
|
|
...
|
|
end
|
|
</geshi>
|
|
|
|
To read an individual header:
|
|
|
|
<geshi lang="lua">
|
|
ngx.say("Host: ", ngx.req.get_headers()["Host"])
|
|
</geshi>
|
|
|
|
Note that the [[#ngx.var.VARIABLE|ngx.var.HEADER]] API call, which uses core [[HttpCoreModule#$http_HEADER|$http_HEADER]] variables, may be more preferable for reading individual request headers.
|
|
|
|
For multiple instances of request headers such as:
|
|
|
|
<geshi lang="bash">
|
|
Foo: foo
|
|
Foo: bar
|
|
Foo: baz
|
|
</geshi>
|
|
|
|
the value of <code>ngx.req.get_headers()["Foo"]</code> will be a Lua (array) table such as:
|
|
|
|
<geshi lang="lua">
|
|
{"foo", "bar", "baz"}
|
|
</geshi>
|
|
|
|
Note that a maximum of 100 request headers are parsed by default (including those with the same name) and that additional request headers are silently discarded to guard against potential denial of service attacks. Since <code>v0.10.13</code>, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
|
|
|
|
However, the optional <code>max_headers</code> function argument can be used to override this limit:
|
|
|
|
<geshi lang="lua">
|
|
local headers, err = ngx.req.get_headers(10)
|
|
|
|
if err == "truncated" then
|
|
-- one can choose to ignore or reject the current request here
|
|
end
|
|
</geshi>
|
|
|
|
This argument can be set to zero to remove the limit and to process all request headers received:
|
|
|
|
<geshi lang="lua">
|
|
local headers, err = ngx.req.get_headers(0)
|
|
</geshi>
|
|
|
|
Removing the <code>max_headers</code> cap is strongly discouraged.
|
|
|
|
Since the <code>0.6.9</code> release, all the header names in the Lua table returned are converted to the pure lower-case form by default, unless the <code>raw</code> argument is set to <code>true</code> (default to <code>false</code>).
|
|
|
|
Also, by default, an <code>__index</code> metamethod is added to the resulting Lua table and will normalize the keys to a pure lowercase form with all underscores converted to dashes in case of a lookup miss. For example, if a request header <code>My-Foo-Header</code> is present, then the following invocations will all pick up the value of this header correctly:
|
|
|
|
<geshi lang="lua">
|
|
ngx.say(headers.my_foo_header)
|
|
ngx.say(headers["My-Foo-Header"])
|
|
ngx.say(headers["my-foo-header"])
|
|
</geshi>
|
|
|
|
The <code>__index</code> metamethod will not be added when the <code>raw</code> argument is set to <code>true</code>.
|
|
|
|
== ngx.req.set_header ==
|
|
|
|
'''syntax:''' ''ngx.req.set_header(header_name, header_value)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*''
|
|
|
|
Set the current request's request header named <code>header_name</code> to value <code>header_value</code>, overriding any existing ones.
|
|
|
|
The input Lua string `header_name` and `header_value` should already be well-formed with the URI encoding.
|
|
For security considerations, this method will automatically escape " ", """, "(", ")", ",", "/", ":", ";", "?",
|
|
"<", "=", ">", "?", "@", "[", "]", "\", "{", "}", 0x00-0x1F, 0x7F-0xFF in `header_name` and automatically escape
|
|
"0x00-0x08, 0x0A-0x0F, 0x7F in `header_value`.
|
|
|
|
By default, all the subrequests subsequently initiated by [[#ngx.location.capture|ngx.location.capture]] and [[#ngx.location.capture_multi|ngx.location.capture_multi]] will inherit the new header.
|
|
|
|
It is not a Lua's equivalent of nginx `proxy_set_header` directive (same is true about [ngx.req.clear_header](#ngxreqclear_header)). `proxy_set_header` only affects the upstream request while `ngx.req.set_header` change the incoming request. Record the http headers in the access log file will show the difference. But you still can use it as an alternative of nginx `proxy_set_header` directive as long as you know the difference.
|
|
|
|
Here is an example of setting the <code>Content-Type</code> header:
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.set_header("Content-Type", "text/css")
|
|
</geshi>
|
|
|
|
The <code>header_value</code> can take an array list of values,
|
|
for example,
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.set_header("Foo", {"a", "abc"})
|
|
</geshi>
|
|
|
|
will produce two new request headers:
|
|
|
|
<geshi lang="bash">
|
|
Foo: a
|
|
Foo: abc
|
|
</geshi>
|
|
|
|
and old <code>Foo</code> headers will be overridden if there is any.
|
|
|
|
When the <code>header_value</code> argument is <code>nil</code>, the request header will be removed. So
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.set_header("X-Foo", nil)
|
|
</geshi>
|
|
|
|
is equivalent to
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.clear_header("X-Foo")
|
|
</geshi>
|
|
|
|
Note: this function throws a Lua error if <code>header_name</code> or
|
|
<code>header_value</code> contain unsafe characters (control characters).
|
|
|
|
== ngx.req.clear_header ==
|
|
|
|
'''syntax:''' ''ngx.req.clear_header(header_name)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*''
|
|
|
|
Clears the current request's request header named <code>header_name</code>. None of the current request's existing subrequests will be affected but subsequently initiated subrequests will inherit the change by default.
|
|
|
|
== ngx.req.read_body ==
|
|
|
|
'''syntax:''' ''ngx.req.read_body()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Reads the client request body synchronously without blocking the Nginx event loop.
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.read_body()
|
|
local args = ngx.req.get_post_args()
|
|
</geshi>
|
|
|
|
If the request body is already read previously by turning on [[#lua_need_request_body|lua_need_request_body]] or by using other modules, then this function does not run and returns immediately.
|
|
|
|
If the request body has already been explicitly discarded, either by the [[#ngx.req.discard_body|ngx.req.discard_body]] function or other modules, this function does not run and returns immediately.
|
|
|
|
In case of errors, such as connection errors while reading the data, this method will throw out a Lua exception ''or'' terminate the current request with a 500 status code immediately.
|
|
|
|
The request body data read using this function can be retrieved later via [[#ngx.req.get_body_data|ngx.req.get_body_data]] or, alternatively, the temporary file name for the body data cached to disk using [[#ngx.req.get_body_file|ngx.req.get_body_file]]. This depends on
|
|
|
|
# whether the current request body is already larger than the [[HttpCoreModule#client_body_buffer_size|client_body_buffer_size]],
|
|
# and whether [[HttpCoreModule#client_body_in_file_only|client_body_in_file_only]] has been switched on.
|
|
|
|
In cases where current request may have a request body and the request body data is not required, The [[#ngx.req.discard_body|ngx.req.discard_body]] function must be used to explicitly discard the request body to avoid breaking things under HTTP 1.1 keepalive or HTTP 1.1 pipelining.
|
|
|
|
This function was first introduced in the <code>v0.3.1rc17</code> release.
|
|
|
|
== ngx.req.discard_body ==
|
|
|
|
'''syntax:''' ''ngx.req.discard_body()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Explicitly discard the request body, i.e., read the data on the connection and throw it away immediately (without using the request body by any means).
|
|
|
|
This function is an asynchronous call and returns immediately.
|
|
|
|
If the request body has already been read, this function does nothing and returns immediately.
|
|
|
|
This function was first introduced in the <code>v0.3.1rc17</code> release.
|
|
|
|
See also [[#ngx.req.read_body|ngx.req.read_body]].
|
|
|
|
== ngx.req.get_body_data ==
|
|
|
|
'''syntax:''' ''data = ngx.req.get_body_data()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, log_by_lua*''
|
|
|
|
Retrieves in-memory request body data. It returns a Lua string rather than a Lua table holding all the parsed query arguments. Use the [[#ngx.req.get_post_args|ngx.req.get_post_args]] function instead if a Lua table is required.
|
|
|
|
This function returns <code>nil</code> if
|
|
|
|
# the request body has not been read,
|
|
# the request body has been read into disk temporary files,
|
|
# or the request body has zero size.
|
|
|
|
If the request body has not been read yet, call [[#ngx.req.read_body|ngx.req.read_body]] first (or turn on [[#lua_need_request_body|lua_need_request_body]] to force this module to read the request body. This is not recommended however).
|
|
|
|
If the request body has been read into disk files, try calling the [[#ngx.req.get_body_file|ngx.req.get_body_file]] function instead.
|
|
|
|
To force in-memory request bodies, try setting [[HttpCoreModule#client_body_buffer_size|client_body_buffer_size]] to the same size value in [[HttpCoreModule#client_max_body_size|client_max_body_size]].
|
|
|
|
Note that calling this function instead of using <code>ngx.var.request_body</code> or <code>ngx.var.echo_request_body</code> is more efficient because it can save one dynamic memory allocation and one data copy.
|
|
|
|
This function was first introduced in the <code>v0.3.1rc17</code> release.
|
|
|
|
See also [[#ngx.req.get_body_file|ngx.req.get_body_file]].
|
|
|
|
== ngx.req.get_body_file ==
|
|
|
|
'''syntax:''' ''file_name = ngx.req.get_body_file()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Retrieves the file name for the in-file request body data. Returns <code>nil</code> if the request body has not been read or has been read into memory.
|
|
|
|
The returned file is read only and is usually cleaned up by Nginx's memory pool. It should not be manually modified, renamed, or removed in Lua code.
|
|
|
|
If the request body has not been read yet, call [[#ngx.req.read_body|ngx.req.read_body]] first (or turn on [[#lua_need_request_body|lua_need_request_body]] to force this module to read the request body. This is not recommended however).
|
|
|
|
If the request body has been read into memory, try calling the [[#ngx.req.get_body_data|ngx.req.get_body_data]] function instead.
|
|
|
|
To force in-file request bodies, try turning on [[HttpCoreModule#client_body_in_file_only|client_body_in_file_only]].
|
|
|
|
This function was first introduced in the <code>v0.3.1rc17</code> release.
|
|
|
|
See also [[#ngx.req.get_body_data|ngx.req.get_body_data]].
|
|
|
|
== ngx.req.set_body_data ==
|
|
|
|
'''syntax:''' ''ngx.req.set_body_data(data)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Set the current request's request body using the in-memory data specified by the <code>data</code> argument.
|
|
|
|
If the request body has not been read yet, call [[#ngx.req.read_body|ngx.req.read_body]] first (or turn on [[#lua_need_request_body|lua_need_request_body]] to force this module to read the request body. This is not recommended however). Additionally, the request body must not have been previously discarded by [[#ngx.req.discard_body|ngx.req.discard_body]].
|
|
|
|
Whether the previous request body has been read into memory or buffered into a disk file, it will be freed or the disk file will be cleaned up immediately, respectively.
|
|
|
|
This function was first introduced in the <code>v0.3.1rc18</code> release.
|
|
|
|
See also [[#ngx.req.set_body_file|ngx.req.set_body_file]].
|
|
|
|
== ngx.req.set_body_file ==
|
|
|
|
'''syntax:''' ''ngx.req.set_body_file(file_name, auto_clean?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Set the current request's request body using the in-file data specified by the <code>file_name</code> argument.
|
|
|
|
If the request body has not been read yet, call [[#ngx.req.read_body|ngx.req.read_body]] first (or turn on [[#lua_need_request_body|lua_need_request_body]] to force this module to read the request body. This is not recommended however). Additionally, the request body must not have been previously discarded by [[#ngx.req.discard_body|ngx.req.discard_body]].
|
|
|
|
If the optional <code>auto_clean</code> argument is given a <code>true</code> value, then this file will be removed at request completion or the next time this function or [[#ngx.req.set_body_data|ngx.req.set_body_data]] are called in the same request. The <code>auto_clean</code> is default to <code>false</code>.
|
|
|
|
Please ensure that the file specified by the <code>file_name</code> argument exists and is readable by an Nginx worker process by setting its permission properly to avoid Lua exception errors.
|
|
|
|
Whether the previous request body has been read into memory or buffered into a disk file, it will be freed or the disk file will be cleaned up immediately, respectively.
|
|
|
|
This function was first introduced in the <code>v0.3.1rc18</code> release.
|
|
|
|
See also [[#ngx.req.set_body_data|ngx.req.set_body_data]].
|
|
|
|
== ngx.req.init_body ==
|
|
|
|
'''syntax:''' ''ngx.req.init_body(buffer_size?)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Creates a new blank request body for the current request and initializes the buffer for later request body data writing via the [[#ngx.req.append_body|ngx.req.append_body]] and [[#ngx.req.finish_body|ngx.req.finish_body]] APIs.
|
|
|
|
If the <code>buffer_size</code> argument is specified, then its value will be used for the size of the memory buffer for body writing with [[#ngx.req.append_body|ngx.req.append_body]]. If the argument is omitted, then the value specified by the standard [[HttpCoreModule#client_body_buffer_size|client_body_buffer_size]] directive will be used instead.
|
|
|
|
When the data can no longer be hold in the memory buffer for the request body, then the data will be flushed onto a temporary file just like the standard request body reader in the Nginx core.
|
|
|
|
It is important to always call the [[#ngx.req.finish_body|ngx.req.finish_body]] after all the data has been appended onto the current request body. Also, when this function is used together with [[#ngx.req.socket|ngx.req.socket]], it is required to call [[#ngx.req.socket|ngx.req.socket]] ''before'' this function, or you will get the "request body already exists" error message.
|
|
|
|
The usage of this function is often like this:
|
|
|
|
<geshi lang="lua">
|
|
ngx.req.init_body(128 * 1024) -- buffer is 128KB
|
|
for chunk in next_data_chunk() do
|
|
ngx.req.append_body(chunk) -- each chunk can be 4KB
|
|
end
|
|
ngx.req.finish_body()
|
|
</geshi>
|
|
|
|
This function can be used with [[#ngx.req.append_body|ngx.req.append_body]], [[#ngx.req.finish_body|ngx.req.finish_body]], and [[#ngx.req.socket|ngx.req.socket]] to implement efficient input filters in pure Lua (in the context of [[#rewrite_by_lua|rewrite_by_lua*]] or [[#access_by_lua|access_by_lua*]]), which can be used with other Nginx content handler or upstream modules like [[HttpProxyModule]] and [[HttpFastcgiModule]].
|
|
|
|
This function was first introduced in the <code>v0.5.11</code> release.
|
|
|
|
== ngx.req.append_body ==
|
|
|
|
'''syntax:''' ''ngx.req.append_body(data_chunk)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Append new data chunk specified by the <code>data_chunk</code> argument onto the existing request body created by the [[#ngx.req.init_body|ngx.req.init_body]] call.
|
|
|
|
When the data can no longer be hold in the memory buffer for the request body, then the data will be flushed onto a temporary file just like the standard request body reader in the Nginx core.
|
|
|
|
It is important to always call the [[#ngx.req.finish_body|ngx.req.finish_body]] after all the data has been appended onto the current request body.
|
|
|
|
This function can be used with [[#ngx.req.init_body|ngx.req.init_body]], [[#ngx.req.finish_body|ngx.req.finish_body]], and [[#ngx.req.socket|ngx.req.socket]] to implement efficient input filters in pure Lua (in the context of [[#rewrite_by_lua|rewrite_by_lua*]] or [[#access_by_lua|access_by_lua*]]), which can be used with other Nginx content handler or upstream modules like [[HttpProxyModule]] and [[HttpFastcgiModule]].
|
|
|
|
This function was first introduced in the <code>v0.5.11</code> release.
|
|
|
|
See also [[#ngx.req.init_body|ngx.req.init_body]].
|
|
|
|
== ngx.req.finish_body ==
|
|
|
|
'''syntax:''' ''ngx.req.finish_body()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Completes the construction process of the new request body created by the [[#ngx.req.init_body|ngx.req.init_body]] and [[#ngx.req.append_body|ngx.req.append_body]] calls.
|
|
|
|
This function can be used with [[#ngx.req.init_body|ngx.req.init_body]], [[#ngx.req.append_body|ngx.req.append_body]], and [[#ngx.req.socket|ngx.req.socket]] to implement efficient input filters in pure Lua (in the context of [[#rewrite_by_lua|rewrite_by_lua*]] or [[#access_by_lua|access_by_lua*]]), which can be used with other Nginx content handler or upstream modules like [[HttpProxyModule]] and [[HttpFastcgiModule]].
|
|
|
|
This function was first introduced in the <code>v0.5.11</code> release.
|
|
|
|
See also [[#ngx.req.init_body|ngx.req.init_body]].
|
|
|
|
== ngx.req.socket ==
|
|
|
|
'''syntax:''' ''tcpsock, err = ngx.req.socket()''
|
|
|
|
'''syntax:''' ''tcpsock, err = ngx.req.socket(raw)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Returns a read-only cosocket object that wraps the downstream connection. Only [[#tcpsock:receive|receive]], [[#tcpsock:receiveany|receiveany]] and [[#tcpsock:receiveuntil|receiveuntil]] methods are supported on this object.
|
|
|
|
In case of error, <code>nil</code> will be returned as well as a string describing the error.
|
|
|
|
The socket object returned by this method is usually used to read the current request's body in a streaming fashion. Do not turn on the [[#lua_need_request_body|lua_need_request_body]] directive, and do not mix this call with [[#ngx.req.read_body|ngx.req.read_body]] and [[#ngx.req.discard_body|ngx.req.discard_body]].
|
|
|
|
If any request body data has been pre-read into the Nginx core request header buffer, the resulting cosocket object will take care of this to avoid potential data loss resulting from such pre-reading.
|
|
Chunked request bodies are not yet supported in this API.
|
|
|
|
Since the <code>v0.9.0</code> release, this function accepts an optional boolean <code>raw</code> argument. When this argument is <code>true</code>, this function returns a full-duplex cosocket object wrapping around the raw downstream connection socket, upon which you can call the [[#tcpsock:receive|receive]], [[#tcpsock:receiveany|receiveany]], [[#tcpsock:receiveuntil|receiveuntil]], and [[#tcpsock:send|send]] methods.
|
|
|
|
When the <code>raw</code> argument is <code>true</code>, it is required that no pending data from any previous [[#ngx.say|ngx.say]], [[#ngx.print|ngx.print]], or [[#ngx.send_headers|ngx.send_headers]] calls exists. So if you have these downstream output calls previously, you should call [[#ngx.flush|ngx.flush(true)]] before calling <code>ngx.req.socket(true)</code> to ensure that there is no pending output data. If the request body has not been read yet, then this "raw socket" can also be used to read the request body.
|
|
|
|
You can use the "raw request socket" returned by <code>ngx.req.socket(true)</code> to implement fancy protocols like [https://en.wikipedia.org/wiki/WebSocket WebSocket], or just emit your own raw HTTP response header or body data. You can refer to the [https://github.com/openresty/lua-resty-websocket lua-resty-websocket library] for a real world example.
|
|
|
|
This function was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== ngx.exec ==
|
|
|
|
'''syntax:''' ''ngx.exec(uri, args?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Does an internal redirect to <code>uri</code> with <code>args</code> and is similar to the [[HttpEchoModule#echo_exec|echo_exec]] directive of the [[HttpEchoModule]].
|
|
|
|
<geshi lang="lua">
|
|
ngx.exec('/some-location')
|
|
ngx.exec('/some-location', 'a=3&b=5&c=6')
|
|
ngx.exec('/some-location?a=3&b=5', 'c=6')
|
|
</geshi>
|
|
|
|
The optional second <code>args</code> can be used to specify extra URI query arguments, for example:
|
|
|
|
<geshi lang="lua">
|
|
ngx.exec("/foo", "a=3&b=hello%20world")
|
|
</geshi>
|
|
|
|
Alternatively, a Lua table can be passed for the <code>args</code> argument for ngx_lua to carry out URI escaping and string concatenation.
|
|
|
|
<geshi lang="lua">
|
|
ngx.exec("/foo", { a = 3, b = "hello world" })
|
|
</geshi>
|
|
|
|
The result is exactly the same as the previous example.
|
|
|
|
The format for the Lua table passed as the <code>args</code> argument is identical to the format used in the [[#ngx.encode_args|ngx.encode_args]] method.
|
|
|
|
Named locations are also supported but the second <code>args</code> argument will be ignored if present and the querystring for the new target is inherited from the referring location (if any).
|
|
|
|
<code>GET /foo/file.php?a=hello</code> will return "hello" and not "goodbye" in the example below
|
|
|
|
<geshi lang="nginx">
|
|
location /foo {
|
|
content_by_lua_block {
|
|
ngx.exec("@bar", "a=goodbye")
|
|
}
|
|
}
|
|
|
|
location @bar {
|
|
content_by_lua_block {
|
|
local args = ngx.req.get_uri_args()
|
|
for key, val in pairs(args) do
|
|
if key == "a" then
|
|
ngx.say(val)
|
|
end
|
|
end
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Note that the <code>ngx.exec</code> method is different from [[#ngx.redirect|ngx.redirect]] in that
|
|
it is purely an internal redirect and that no new external HTTP traffic is involved.
|
|
|
|
Also note that this method call terminates the processing of the current request and that it ''must'' be called before [[#ngx.send_headers|ngx.send_headers]] or explicit response body
|
|
outputs by either [[#ngx.print|ngx.print]] or [[#ngx.say|ngx.say]].
|
|
|
|
It is recommended that a coding style that combines this method call with the <code>return</code> statement, i.e., <code>return ngx.exec(...)</code> be adopted when this method call is used in contexts other than [[#header_filter_by_lua|header_filter_by_lua*]] to reinforce the fact that the request processing is being terminated.
|
|
|
|
== ngx.redirect ==
|
|
|
|
'''syntax:''' ''ngx.redirect(uri, status?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Issue an <code>HTTP 301</code> or <code>302</code> redirection to <code>uri</code>.
|
|
|
|
Note: this function throws a Lua error if the <code>uri</code> argument
|
|
contains unsafe characters (control characters).
|
|
|
|
The optional <code>status</code> parameter specifies the HTTP status code to be used. The following status codes are supported right now:
|
|
|
|
* <code>301</code>
|
|
* <code>302</code> (default)
|
|
* <code>303</code>
|
|
* <code>307</code>
|
|
* <code>308</code>
|
|
|
|
It is <code>302</code> (<code>ngx.HTTP_MOVED_TEMPORARILY</code>) by default.
|
|
|
|
Here is an example assuming the current server name is <code>localhost</code> and that it is listening on port 1984:
|
|
|
|
<geshi lang="lua">
|
|
return ngx.redirect("/foo")
|
|
</geshi>
|
|
|
|
which is equivalent to
|
|
|
|
<geshi lang="lua">
|
|
return ngx.redirect("/foo", ngx.HTTP_MOVED_TEMPORARILY)
|
|
</geshi>
|
|
|
|
Redirecting arbitrary external URLs is also supported, for example:
|
|
|
|
<geshi lang="lua">
|
|
return ngx.redirect("http://www.google.com")
|
|
</geshi>
|
|
|
|
We can also use the numerical code directly as the second <code>status</code> argument:
|
|
|
|
<geshi lang="lua">
|
|
return ngx.redirect("/foo", 301)
|
|
</geshi>
|
|
|
|
This method is similar to the [[HttpRewriteModule#rewrite|rewrite]] directive with the <code>redirect</code> modifier in the standard
|
|
[[HttpRewriteModule]], for example, this <code>nginx.conf</code> snippet
|
|
|
|
<geshi lang="nginx">
|
|
rewrite ^ /foo? redirect; # nginx config
|
|
</geshi>
|
|
|
|
is equivalent to the following Lua code
|
|
|
|
<geshi lang="lua">
|
|
return ngx.redirect('/foo') -- Lua code
|
|
</geshi>
|
|
|
|
while
|
|
|
|
<geshi lang="nginx">
|
|
rewrite ^ /foo? permanent; # nginx config
|
|
</geshi>
|
|
|
|
is equivalent to
|
|
|
|
<geshi lang="lua">
|
|
return ngx.redirect('/foo', ngx.HTTP_MOVED_PERMANENTLY) -- Lua code
|
|
</geshi>
|
|
|
|
URI arguments can be specified as well, for example:
|
|
|
|
<geshi lang="lua">
|
|
return ngx.redirect('/foo?a=3&b=4')
|
|
</geshi>
|
|
|
|
Note that this method call terminates the processing of the current request and that it ''must'' be called before [[#ngx.send_headers|ngx.send_headers]] or explicit response body
|
|
outputs by either [[#ngx.print|ngx.print]] or [[#ngx.say|ngx.say]].
|
|
|
|
It is recommended that a coding style that combines this method call with the <code>return</code> statement, i.e., <code>return ngx.redirect(...)</code> be adopted when this method call is used in contexts other than [[#header_filter_by_lua|header_filter_by_lua*]] to reinforce the fact that the request processing is being terminated.
|
|
|
|
== ngx.send_headers ==
|
|
|
|
'''syntax:''' ''ok, err = ngx.send_headers()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Explicitly send out the response headers.
|
|
|
|
Since <code>v0.8.3</code> this function returns <code>1</code> on success, or returns <code>nil</code> and a string describing the error otherwise.
|
|
|
|
Note that there is normally no need to manually send out response headers as ngx_lua will automatically send headers out
|
|
before content is output with [[#ngx.say|ngx.say]] or [[#ngx.print|ngx.print]] or when [[#content_by_lua|content_by_lua*]] exits normally.
|
|
|
|
== ngx.headers_sent ==
|
|
|
|
'''syntax:''' ''value = ngx.headers_sent''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Returns <code>true</code> if the response headers have been sent (by ngx_lua), and <code>false</code> otherwise.
|
|
|
|
This API was first introduced in ngx_lua v0.3.1rc6.
|
|
|
|
== ngx.print ==
|
|
|
|
'''syntax:''' ''ok, err = ngx.print(...)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Emits arguments concatenated to the HTTP client (as response body). If response headers have not been sent, this function will send headers out first and then output body data.
|
|
|
|
Since <code>v0.8.3</code> this function returns <code>1</code> on success, or returns <code>nil</code> and a string describing the error otherwise.
|
|
|
|
Lua <code>nil</code> values will output <code>"nil"</code> strings and Lua boolean values will output <code>"true"</code> and <code>"false"</code> literal strings respectively.
|
|
|
|
Nested arrays of strings are permitted and the elements in the arrays will be sent one by one:
|
|
|
|
<geshi lang="lua">
|
|
local table = {
|
|
"hello, ",
|
|
{"world: ", true, " or ", false,
|
|
{": ", nil}}
|
|
}
|
|
ngx.print(table)
|
|
</geshi>
|
|
|
|
will yield the output
|
|
|
|
<geshi lang="bash">
|
|
hello, world: true or false: nil
|
|
</geshi>
|
|
|
|
Non-array table arguments will cause a Lua exception to be thrown.
|
|
|
|
The <code>ngx.null</code> constant will yield the <code>"null"</code> string output.
|
|
|
|
This is an asynchronous call and will return immediately without waiting for all the data to be written into the system send buffer. To run in synchronous mode, call <code>ngx.flush(true)</code> after calling <code>ngx.print</code>. This can be particularly useful for streaming output. See [[#ngx.flush|ngx.flush]] for more details.
|
|
|
|
Please note that both <code>ngx.print</code> and [[#ngx.say|ngx.say]] will always invoke the whole Nginx output body filter chain, which is an expensive operation. So be careful when calling either of these two in a tight loop; buffer the data yourself in Lua and save the calls.
|
|
|
|
== ngx.say ==
|
|
|
|
'''syntax:''' ''ok, err = ngx.say(...)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Just as [[#ngx.print|ngx.print]] but also emit a trailing newline.
|
|
|
|
== ngx.log ==
|
|
|
|
'''syntax:''' ''ngx.log(log_level, ...)''
|
|
|
|
'''context:''' ''init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Log arguments concatenated to error.log with the given logging level.
|
|
|
|
Lua <code>nil</code> arguments are accepted and result in literal <code>"nil"</code> string while Lua booleans result in literal <code>"true"</code> or <code>"false"</code> string outputs. And the <code>ngx.null</code> constant will yield the <code>"null"</code> string output.
|
|
|
|
The <code>log_level</code> argument can take constants like <code>ngx.ERR</code> and <code>ngx.WARN</code>. Check out [[#Nginx log level constants|Nginx log level constants]] for details.
|
|
|
|
There is a hard coded <code>2048</code> byte limitation on error message lengths in the Nginx core. This limit includes trailing newlines and leading time stamps. If the message size exceeds this limit, Nginx will truncate the message text accordingly. This limit can be manually modified by editing the <code>NGX_MAX_ERROR_STR</code> macro definition in the <code>src/core/ngx_log.h</code> file in the Nginx source tree.
|
|
|
|
== ngx.flush ==
|
|
|
|
'''syntax:''' ''ok, err = ngx.flush(wait?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Flushes response output to the client.
|
|
|
|
<code>ngx.flush</code> accepts an optional boolean <code>wait</code> argument (Default: <code>false</code>) first introduced in the <code>v0.3.1rc34</code> release. When called with the default argument, it issues an asynchronous call (Returns immediately without waiting for output data to be written into the system send buffer). Calling the function with the <code>wait</code> argument set to <code>true</code> switches to synchronous mode.
|
|
|
|
In synchronous mode, the function will not return until all output data has been written into the system send buffer or until the [[HttpCoreModule#send_timeout|send_timeout]] setting has expired. Note that using the Lua coroutine mechanism means that this function does not block the Nginx event loop even in the synchronous mode.
|
|
|
|
When <code>ngx.flush(true)</code> is called immediately after [[#ngx.print|ngx.print]] or [[#ngx.say|ngx.say]], it causes the latter functions to run in synchronous mode. This can be particularly useful for streaming output.
|
|
|
|
Note that <code>ngx.flush</code> is not functional when in the HTTP 1.0 output buffering mode. See [[#HTTP 1.0 support|HTTP 1.0 support]].
|
|
|
|
Since <code>v0.8.3</code> this function returns <code>1</code> on success, or returns <code>nil</code> and a string describing the error otherwise.
|
|
|
|
== ngx.exit ==
|
|
|
|
'''syntax:''' ''ngx.exit(status)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
When <code>status >= 200</code> (i.e., <code>ngx.HTTP_OK</code> and above), it will interrupt the execution of the current request and return status code to Nginx.
|
|
|
|
When <code>status == 0</code> (i.e., <code>ngx.OK</code>), it will only quit the current phase handler (or the content handler if the [[#content_by_lua|content_by_lua*]] directive is used) and continue to run later phases (if any) for the current request.
|
|
|
|
The <code>status</code> argument can be <code>ngx.OK</code>, <code>ngx.ERROR</code>, <code>ngx.HTTP_NOT_FOUND</code>,
|
|
<code>ngx.HTTP_MOVED_TEMPORARILY</code>, or other [[#HTTP status constants|HTTP status constants]].
|
|
|
|
To return an error page with custom contents, use code snippets like this:
|
|
|
|
<geshi lang="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)
|
|
</geshi>
|
|
|
|
The effect in action:
|
|
|
|
<geshi lang="bash">
|
|
$ curl -i http://localhost/test
|
|
HTTP/1.1 410 Gone
|
|
Server: nginx/1.0.6
|
|
Date: Thu, 15 Sep 2011 00:51:48 GMT
|
|
Content-Type: text/plain
|
|
Transfer-Encoding: chunked
|
|
Connection: keep-alive
|
|
|
|
This is our own content
|
|
</geshi>
|
|
|
|
Number literals can be used directly as the argument, for instance,
|
|
|
|
<geshi lang="lua">
|
|
ngx.exit(501)
|
|
</geshi>
|
|
|
|
Note that while this method accepts all [[#HTTP status constants|HTTP status constants]] as input, it only accepts <code>ngx.OK</code> and <code>ngx.ERROR</code> of the [[#core constants|core constants]].
|
|
|
|
Also note that this method call terminates the processing of the current request and that it is recommended that a coding style that combines this method call with the <code>return</code> statement, i.e., <code>return ngx.exit(...)</code> be used to reinforce the fact that the request processing is being terminated.
|
|
|
|
When being used in the contexts of [[#header_filter_by_lua|header_filter_by_lua*]], [[#balancer_by_lua_block|balancer_by_lua*]], and
|
|
[[#ssl_session_store_by_lua_block|ssl_session_store_by_lua*]], <code>ngx.exit()</code> is
|
|
an asynchronous operation and will return immediately. This behavior may change in future and it is recommended that users always use <code>return</code> in combination as suggested above.
|
|
|
|
== ngx.eof ==
|
|
|
|
'''syntax:''' ''ok, err = ngx.eof()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Explicitly specify the end of the response output stream. In the case of HTTP 1.1 chunked encoded output, it will just trigger the Nginx core to send out the "last chunk".
|
|
|
|
When you disable the HTTP 1.1 keep-alive feature for your downstream connections, you can rely on well written HTTP clients to close the connection actively for you when you call this method. This trick can be used do back-ground jobs without letting the HTTP clients to wait on the connection, as in the following example:
|
|
|
|
<geshi lang="nginx">
|
|
location = /async {
|
|
keepalive_timeout 0;
|
|
content_by_lua_block {
|
|
ngx.say("got the task!")
|
|
ngx.eof() -- well written HTTP clients will close the connection at this point
|
|
-- access MySQL, PostgreSQL, Redis, Memcached, and etc here...
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
But if you create subrequests to access other locations configured by Nginx upstream modules, then you should configure those upstream modules to ignore client connection abortions if they are not by default. For example, by default the standard [[HttpProxyModule]] will terminate both the subrequest and the main request as soon as the client closes the connection, so it is important to turn on the [[HttpProxyModule#proxy_ignore_client_abort|proxy_ignore_client_abort]] directive in your location block configured by [[HttpProxyModule]]:
|
|
|
|
<geshi lang="nginx">
|
|
proxy_ignore_client_abort on;
|
|
</geshi>
|
|
|
|
A better way to do background jobs is to use the [[#ngx.timer.at|ngx.timer.at]] API.
|
|
|
|
Since <code>v0.8.3</code> this function returns <code>1</code> on success, or returns <code>nil</code> and a string describing the error otherwise.
|
|
|
|
== ngx.sleep ==
|
|
|
|
'''syntax:''' ''ngx.sleep(seconds)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Sleeps for the specified seconds without blocking. One can specify time resolution up to 0.001 seconds (i.e., one millisecond).
|
|
|
|
Behind the scene, this method makes use of the Nginx timers.
|
|
|
|
Since the <code>0.7.20</code> release, The <code>0</code> time argument can also be specified.
|
|
|
|
This method was introduced in the <code>0.5.0rc30</code> release.
|
|
|
|
== ngx.escape_uri ==
|
|
|
|
'''syntax:''' ''newstr = ngx.escape_uri(str, type?)''
|
|
|
|
'''context:''' ''init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Since `v0.10.16`, this function accepts an optional <code>type</code> argument.
|
|
It accepts the following values (defaults to `2`):
|
|
|
|
* `0`: escapes <code>str</code> as a full URI. And the characters
|
|
<code> </code> (space), <code>#</code>, <code>%</code>,
|
|
`?`, 0x00 ~ 0x1F, 0x7F ~ 0xFF will be escaped.
|
|
* `2`: escape <code>str</code> as a URI component. All characters except
|
|
alphabetic characters, digits, <code>-</code>, <code>.</code>, <code>_</code>,
|
|
<code>~</code> will be encoded as `%XX`.
|
|
|
|
== ngx.unescape_uri ==
|
|
|
|
'''syntax:''' ''newstr = ngx.unescape_uri(str)''
|
|
|
|
'''context:''' ''init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Unescape <code>str</code> as an escaped URI component.
|
|
|
|
For example,
|
|
|
|
<geshi lang="lua">
|
|
ngx.say(ngx.unescape_uri("b%20r56+7"))
|
|
</geshi>
|
|
|
|
gives the output
|
|
|
|
<geshi lang="text">
|
|
b r56 7
|
|
</geshi>
|
|
|
|
Invalid escaping sequences are handled in a conventional way: `%`s are left unchanged. Also, characters that should not appear in escaped string are simply left unchanged.
|
|
|
|
For example,
|
|
|
|
<geshi lang="lua">
|
|
ngx.say(ngx.unescape_uri("try %search%%20%again%"))
|
|
</geshi>
|
|
|
|
gives the output
|
|
|
|
<geshi lang="text">
|
|
try %search% %again%
|
|
</geshi>
|
|
|
|
(Note that `%20` following `%` got unescaped, even it can be considered a part of invalid sequence.)
|
|
|
|
== ngx.encode_args ==
|
|
|
|
'''syntax:''' ''str = ngx.encode_args(table)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Encode the Lua table to a query args string according to the URI encoded rules.
|
|
|
|
For example,
|
|
|
|
<geshi lang="lua">
|
|
ngx.encode_args({foo = 3, ["b r"] = "hello world"})
|
|
</geshi>
|
|
|
|
yields
|
|
|
|
<geshi lang="text">
|
|
foo=3&b%20r=hello%20world
|
|
</geshi>
|
|
|
|
The table keys must be Lua strings.
|
|
|
|
Multi-value query args are also supported. Just use a Lua table for the argument's value, for example:
|
|
|
|
<geshi lang="lua">
|
|
ngx.encode_args({baz = {32, "hello"}})
|
|
</geshi>
|
|
|
|
gives
|
|
|
|
<geshi lang="text">
|
|
baz=32&baz=hello
|
|
</geshi>
|
|
|
|
If the value table is empty and the effect is equivalent to the <code>nil</code> value.
|
|
|
|
Boolean argument values are also supported, for instance,
|
|
|
|
<geshi lang="lua">
|
|
ngx.encode_args({a = true, b = 1})
|
|
</geshi>
|
|
|
|
yields
|
|
|
|
<geshi lang="text">
|
|
a&b=1
|
|
</geshi>
|
|
|
|
If the argument value is <code>false</code>, then the effect is equivalent to the <code>nil</code> value.
|
|
|
|
This method was first introduced in the <code>v0.3.1rc27</code> release.
|
|
|
|
== ngx.decode_args ==
|
|
|
|
'''syntax:''' ''table, err = ngx.decode_args(str, max_args?)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Decodes a URI encoded query-string into a Lua table. This is the inverse function of [[#ngx.encode_args|ngx.encode_args]].
|
|
|
|
The optional <code>max_args</code> argument can be used to specify the maximum number of arguments parsed from the <code>str</code> argument. By default, a maximum of 100 request arguments are parsed (including those with the same name) and that additional URI arguments are silently discarded to guard against potential denial of service attacks. Since <code>v0.10.13</code>, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
|
|
|
|
This argument can be set to zero to remove the limit and to process all request arguments received:
|
|
|
|
<geshi lang="lua">
|
|
local args = ngx.decode_args(str, 0)
|
|
</geshi>
|
|
|
|
Removing the <code>max_args</code> cap is strongly discouraged.
|
|
|
|
This method was introduced in the <code>v0.5.0rc29</code>.
|
|
|
|
== ngx.encode_base64 ==
|
|
|
|
'''syntax:''' ''newstr = ngx.encode_base64(str, no_padding?)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Encodes <code>str</code> to a base64 digest.
|
|
|
|
Since the <code>0.9.16</code> release, an optional boolean-typed <code>no_padding</code> argument can be specified to control whether the base64 padding should be appended to the resulting digest (default to <code>false</code>, i.e., with padding enabled).
|
|
|
|
== ngx.decode_base64 ==
|
|
|
|
'''syntax:''' ''newstr = ngx.decode_base64(str)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Decodes the <code>str</code> argument as a base64 digest to the raw form. Returns <code>nil</code> if <code>str</code> is not well formed.
|
|
|
|
== ngx.crc32_short ==
|
|
|
|
'''syntax:''' ''intval = ngx.crc32_short(str)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Calculates the CRC-32 (Cyclic Redundancy Code) digest for the <code>str</code> argument.
|
|
|
|
This method performs better on relatively short <code>str</code> inputs (i.e., less than 30 ~ 60 bytes), as compared to [[#ngx.crc32_long|ngx.crc32_long]]. The result is exactly the same as [[#ngx.crc32_long|ngx.crc32_long]].
|
|
|
|
Behind the scene, it is just a thin wrapper around the <code>ngx_crc32_short</code> function defined in the Nginx core.
|
|
|
|
This API was first introduced in the <code>v0.3.1rc8</code> release.
|
|
|
|
== ngx.crc32_long ==
|
|
|
|
'''syntax:''' ''intval = ngx.crc32_long(str)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Calculates the CRC-32 (Cyclic Redundancy Code) digest for the <code>str</code> argument.
|
|
|
|
This method performs better on relatively long <code>str</code> inputs (i.e., longer than 30 ~ 60 bytes), as compared to [[#ngx.crc32_short|ngx.crc32_short]]. The result is exactly the same as [[#ngx.crc32_short|ngx.crc32_short]].
|
|
|
|
Behind the scene, it is just a thin wrapper around the <code>ngx_crc32_long</code> function defined in the Nginx core.
|
|
|
|
This API was first introduced in the <code>v0.3.1rc8</code> release.
|
|
|
|
== ngx.hmac_sha1 ==
|
|
|
|
'''syntax:''' ''digest = ngx.hmac_sha1(secret_key, str)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Computes the [https://en.wikipedia.org/wiki/HMAC HMAC-SHA1] digest of the argument <code>str</code> and turns the result using the secret key <code><secret_key></code>.
|
|
|
|
The raw binary form of the <code>HMAC-SHA1</code> digest will be generated, use [[#ngx.encode_base64|ngx.encode_base64]], for example, to encode the result to a textual representation if desired.
|
|
|
|
For example,
|
|
|
|
<geshi lang="lua">
|
|
local key = "thisisverysecretstuff"
|
|
local src = "some string we want to sign"
|
|
local digest = ngx.hmac_sha1(key, src)
|
|
ngx.say(ngx.encode_base64(digest))
|
|
</geshi>
|
|
|
|
yields the output
|
|
|
|
<geshi lang="text">
|
|
R/pvxzHC4NLtj7S+kXFg/NePTmk=
|
|
</geshi>
|
|
|
|
This API requires the OpenSSL library enabled in the Nginx build (usually by passing the <code>--with-http_ssl_module</code> option to the <code>./configure</code> script).
|
|
|
|
This function was first introduced in the <code>v0.3.1rc29</code> release.
|
|
|
|
== ngx.md5 ==
|
|
|
|
'''syntax:''' ''digest = ngx.md5(str)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns the hexadecimal representation of the MD5 digest of the <code>str</code> argument.
|
|
|
|
For example,
|
|
|
|
<geshi lang="nginx">
|
|
location = /md5 {
|
|
content_by_lua_block {
|
|
ngx.say(ngx.md5("hello"))
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
yields the output
|
|
|
|
<geshi lang="text">
|
|
5d41402abc4b2a76b9719d911017c592
|
|
</geshi>
|
|
|
|
See [[#ngx.md5_bin|ngx.md5_bin]] if the raw binary MD5 digest is required.
|
|
|
|
== ngx.md5_bin ==
|
|
|
|
'''syntax:''' ''digest = ngx.md5_bin(str)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns the binary form of the MD5 digest of the <code>str</code> argument.
|
|
|
|
See [[#ngx.md5|ngx.md5]] if the hexadecimal form of the MD5 digest is required.
|
|
|
|
== ngx.sha1_bin ==
|
|
|
|
'''syntax:''' ''digest = ngx.sha1_bin(str)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns the binary form of the SHA-1 digest of the <code>str</code> argument.
|
|
|
|
This function requires SHA-1 support in the Nginx build. (This usually just means OpenSSL should be installed while building Nginx).
|
|
|
|
This function was first introduced in the <code>v0.5.0rc6</code>.
|
|
|
|
== ngx.quote_sql_str ==
|
|
|
|
'''syntax:''' ''quoted_value = ngx.quote_sql_str(raw_value)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns a quoted SQL string literal according to the MySQL quoting rules.
|
|
|
|
== ngx.today ==
|
|
|
|
'''syntax:''' ''str = ngx.today()''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns current date (in the format <code>yyyy-mm-dd</code>) from the Nginx cached time (no syscall involved unlike Lua's date library).
|
|
|
|
This is the local time.
|
|
|
|
== ngx.time ==
|
|
|
|
'''syntax:''' ''secs = ngx.time()''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns the elapsed seconds from the epoch for the current time stamp from the Nginx cached time (no syscall involved unlike Lua's date library).
|
|
|
|
Updates of the Nginx time cache can be forced by calling [[#ngx.update_time|ngx.update_time]] first.
|
|
|
|
== ngx.now ==
|
|
|
|
'''syntax:''' ''secs = ngx.now()''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns a floating-point number for the elapsed time in seconds (including milliseconds as the decimal part) from the epoch for the current time stamp from the Nginx cached time (no syscall involved unlike Lua's date library).
|
|
|
|
You can forcibly update the Nginx time cache by calling [[#ngx.update_time|ngx.update_time]] first.
|
|
|
|
This API was first introduced in <code>v0.3.1rc32</code>.
|
|
|
|
== ngx.update_time ==
|
|
|
|
'''syntax:''' ''ngx.update_time()''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Forcibly updates the Nginx current time cache. This call involves a syscall and thus has some overhead, so do not abuse it.
|
|
|
|
This API was first introduced in <code>v0.3.1rc32</code>.
|
|
|
|
== ngx.localtime ==
|
|
|
|
'''syntax:''' ''str = ngx.localtime()''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns the current time stamp (in the format <code>yyyy-mm-dd hh:mm:ss</code>) of the Nginx cached time (no syscall involved unlike Lua's [https://www.lua.org/manual/5.1/manual.html#pdf-os.date os.date] function).
|
|
|
|
This is the local time.
|
|
|
|
== ngx.utctime ==
|
|
|
|
'''syntax:''' ''str = ngx.utctime()''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns the current time stamp (in the format <code>yyyy-mm-dd hh:mm:ss</code>) of the Nginx cached time (no syscall involved unlike Lua's [https://www.lua.org/manual/5.1/manual.html#pdf-os.date os.date] function).
|
|
|
|
This is the UTC time.
|
|
|
|
== ngx.cookie_time ==
|
|
|
|
'''syntax:''' ''str = ngx.cookie_time(sec)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns a formatted string can be used as the cookie expiration time. The parameter <code>sec</code> is the time stamp in seconds (like those returned from [[#ngx.time|ngx.time]]).
|
|
|
|
<geshi lang="nginx">
|
|
ngx.say(ngx.cookie_time(1290079655))
|
|
-- yields "Thu, 18-Nov-10 11:27:35 GMT"
|
|
</geshi>
|
|
|
|
== ngx.http_time ==
|
|
|
|
'''syntax:''' ''str = ngx.http_time(sec)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns a formated string can be used as the http header time (for example, being used in <code>Last-Modified</code> header). The parameter <code>sec</code> is the time stamp in seconds (like those returned from [[#ngx.time|ngx.time]]).
|
|
|
|
<geshi lang="nginx">
|
|
ngx.say(ngx.http_time(1290079655))
|
|
-- yields "Thu, 18 Nov 2010 11:27:35 GMT"
|
|
</geshi>
|
|
|
|
== ngx.parse_http_time ==
|
|
|
|
'''syntax:''' ''sec = ngx.parse_http_time(str)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Parse the http time string (as returned by [[#ngx.http_time|ngx.http_time]]) into seconds. Returns the seconds or <code>nil</code> if the input string is in bad forms.
|
|
|
|
<geshi lang="nginx">
|
|
local time = ngx.parse_http_time("Thu, 18 Nov 2010 11:27:35 GMT")
|
|
if time == nil then
|
|
...
|
|
end
|
|
</geshi>
|
|
|
|
== ngx.is_subrequest ==
|
|
|
|
'''syntax:''' ''value = ngx.is_subrequest''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*''
|
|
|
|
Returns <code>true</code> if the current request is an Nginx subrequest, or <code>false</code> otherwise.
|
|
|
|
== ngx.re.match ==
|
|
|
|
'''syntax:''' ''captures, err = ngx.re.match(subject, regex, options?, ctx?, res_table?)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Matches the <code>subject</code> string using the Perl compatible regular expression <code>regex</code> with the optional <code>options</code>.
|
|
|
|
Only the first occurrence of the match is returned, or <code>nil</code> if no match is found. In case of errors, like seeing a bad regular expression or exceeding the PCRE stack limit, <code>nil</code> and a string describing the error will be returned.
|
|
|
|
When a match is found, a Lua table <code>captures</code> is returned, where <code>captures[0]</code> holds the whole substring being matched, and <code>captures[1]</code> holds the first parenthesized sub-pattern's capturing, <code>captures[2]</code> the second, and so on.
|
|
|
|
<geshi lang="lua">
|
|
local m, err = ngx.re.match("hello, 1234", "[0-9]+")
|
|
if m then
|
|
-- m[0] == "1234"
|
|
|
|
else
|
|
if err then
|
|
ngx.log(ngx.ERR, "error: ", err)
|
|
return
|
|
end
|
|
|
|
ngx.say("match not found")
|
|
end
|
|
</geshi>
|
|
|
|
<geshi lang="lua">
|
|
local m, err = ngx.re.match("hello, 1234", "([0-9])[0-9]+")
|
|
-- m[0] == "1234"
|
|
-- m[1] == "1"
|
|
</geshi>
|
|
|
|
Named captures are also supported since the <code>v0.7.14</code> release
|
|
and are returned in the same Lua table as key-value pairs as the numbered captures.
|
|
|
|
<geshi lang="lua">
|
|
local m, err = ngx.re.match("hello, 1234", "([0-9])(?<remaining>[0-9]+)")
|
|
-- m[0] == "1234"
|
|
-- m[1] == "1"
|
|
-- m[2] == "234"
|
|
-- m["remaining"] == "234"
|
|
</geshi>
|
|
|
|
Unmatched subpatterns will have <code>false</code> values in their <code>captures</code> table fields.
|
|
|
|
<geshi lang="lua">
|
|
local m, err = ngx.re.match("hello, world", "(world)|(hello)|(?<named>howdy)")
|
|
-- m[0] == "hello"
|
|
-- m[1] == false
|
|
-- m[2] == "hello"
|
|
-- m[3] == false
|
|
-- m["named"] == false
|
|
</geshi>
|
|
|
|
Specify <code>options</code> to control how the match operation will be performed. The following option characters are supported:
|
|
|
|
<geshi lang="text">
|
|
a anchored mode (only match from the beginning)
|
|
|
|
d enable the DFA mode (or the longest token match semantics).
|
|
this requires PCRE 6.0+ or else a Lua exception will be thrown.
|
|
first introduced in ngx_lua v0.3.1rc30.
|
|
|
|
D enable duplicate named pattern support. This allows named
|
|
subpattern names to be repeated, returning the captures in
|
|
an array-like Lua table. for example,
|
|
local m = ngx.re.match("hello, world",
|
|
"(?<named>\w+), (?<named>\w+)",
|
|
"D")
|
|
-- m["named"] == {"hello", "world"}
|
|
this option was first introduced in the v0.7.14 release.
|
|
this option requires at least PCRE 8.12.
|
|
|
|
i case insensitive mode (similar to Perl's /i modifier)
|
|
|
|
j enable PCRE JIT compilation, this requires PCRE 8.21+ which
|
|
must be built with the --enable-jit option. for optimum performance,
|
|
this option should always be used together with the 'o' option.
|
|
first introduced in ngx_lua v0.3.1rc30.
|
|
|
|
J enable the PCRE Javascript compatible mode. this option was
|
|
first introduced in the v0.7.14 release. this option requires
|
|
at least PCRE 8.12.
|
|
|
|
m multi-line mode (similar to Perl's /m modifier)
|
|
|
|
o compile-once mode (similar to Perl's /o modifier),
|
|
to enable the worker-process-level compiled-regex cache
|
|
|
|
s single-line mode (similar to Perl's /s modifier)
|
|
|
|
u UTF-8 mode. this requires PCRE to be built with
|
|
the --enable-utf8 option or else a Lua exception will be thrown.
|
|
|
|
U similar to "u" but disables PCRE's UTF-8 validity check on
|
|
the subject string. first introduced in ngx_lua v0.8.1.
|
|
|
|
x extended mode (similar to Perl's /x modifier)
|
|
</geshi>
|
|
|
|
These options can be combined:
|
|
|
|
<geshi lang="nginx">
|
|
local m, err = ngx.re.match("hello, world", "HEL LO", "ix")
|
|
-- m[0] == "hello"
|
|
</geshi>
|
|
|
|
<geshi lang="nginx">
|
|
local m, err = ngx.re.match("hello, 美好生活", "HELLO, (.{2})", "iu")
|
|
-- m[0] == "hello, 美好"
|
|
-- m[1] == "美好"
|
|
</geshi>
|
|
|
|
The <code>o</code> option is useful for performance tuning, because the regex pattern in question will only be compiled once, cached in the worker-process level, and shared among all requests in the current Nginx worker process. The upper limit of the regex cache can be tuned via the [[#lua_regex_cache_max_entries|lua_regex_cache_max_entries]] directive.
|
|
|
|
The optional fourth argument, <code>ctx</code>, can be a Lua table holding an optional <code>pos</code> field. When the <code>pos</code> field in the <code>ctx</code> table argument is specified, <code>ngx.re.match</code> will start matching from that offset (starting from 1). Regardless of the presence of the <code>pos</code> field in the <code>ctx</code> table, <code>ngx.re.match</code> will always set this <code>pos</code> field to the position ''after'' the substring matched by the whole pattern in case of a successful match. When match fails, the <code>ctx</code> table will be left intact.
|
|
|
|
<geshi lang="lua">
|
|
local ctx = {}
|
|
local m, err = ngx.re.match("1234, hello", "[0-9]+", "", ctx)
|
|
-- m[0] = "1234"
|
|
-- ctx.pos == 5
|
|
</geshi>
|
|
|
|
<geshi lang="lua">
|
|
local ctx = { pos = 2 }
|
|
local m, err = ngx.re.match("1234, hello", "[0-9]+", "", ctx)
|
|
-- m[0] = "234"
|
|
-- ctx.pos == 5
|
|
</geshi>
|
|
|
|
The <code>ctx</code> table argument combined with the <code>a</code> regex modifier can be used to construct a lexer atop <code>ngx.re.match</code>.
|
|
|
|
Note that, the <code>options</code> argument is not optional when the <code>ctx</code> argument is specified and that the empty Lua string (<code>""</code>) must be used as placeholder for <code>options</code> if no meaningful regex options are required.
|
|
|
|
This method requires the PCRE library enabled in Nginx ([[#Special Escaping Sequences|Known Issue With Special Escaping Sequences]]).
|
|
|
|
To confirm that PCRE JIT is enabled, activate the Nginx debug log by adding the <code>--with-debug</code> option to Nginx or OpenResty's <code>./configure</code> script. Then, enable the "debug" error log level in <code>error_log</code> directive. The following message will be generated if PCRE JIT is enabled:
|
|
|
|
<geshi lang="text">
|
|
pcre JIT compiling result: 1
|
|
</geshi>
|
|
|
|
Starting from the <code>0.9.4</code> release, this function also accepts a 5th argument, <code>res_table</code>, for letting the caller supply the Lua table used to hold all the capturing results. Starting from <code>0.9.6</code>, it is the caller's responsibility to ensure this table is empty. This is very useful for recycling Lua tables and saving GC and table allocation overhead.
|
|
|
|
This feature was introduced in the <code>v0.2.1rc11</code> release.
|
|
|
|
== ngx.re.find ==
|
|
|
|
'''syntax:''' ''from, to, err = ngx.re.find(subject, regex, options?, ctx?, nth?)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Similar to [[#ngx.re.match|ngx.re.match]] but only returns the beginning index (<code>from</code>) and end index (<code>to</code>) of the matched substring. The returned indexes are 1-based and can be fed directly into the [https://www.lua.org/manual/5.1/manual.html#pdf-string.sub string.sub] API function to obtain the matched substring.
|
|
|
|
In case of errors (like bad regexes or any PCRE runtime errors), this API function returns two <code>nil</code> values followed by a string describing the error.
|
|
|
|
If no match is found, this function just returns a <code>nil</code> value.
|
|
|
|
Below is an example:
|
|
|
|
<geshi lang="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)
|
|
return
|
|
end
|
|
ngx.say("not matched!")
|
|
end
|
|
</geshi>
|
|
|
|
This example produces the output
|
|
|
|
from: 8
|
|
to: 11
|
|
matched: 1234
|
|
|
|
Because this API function does not create new Lua strings nor new Lua tables, it is much faster than [[#ngx.re.match|ngx.re.match]]. It should be used wherever possible.
|
|
|
|
Since the <code>0.9.3</code> release, an optional 5th argument, <code>nth</code>, is supported to specify which (submatch) capture's indexes to return. When <code>nth</code> is 0 (which is the default), the indexes for the whole matched substring is returned; when <code>nth</code> is 1, then the 1st submatch capture's indexes are returned; when <code>nth</code> is 2, then the 2nd submatch capture is returned, and so on. When the specified submatch does not have a match, then two <code>nil</code> values will be returned. Below is an example for this:
|
|
|
|
<geshi lang="lua">
|
|
local str = "hello, 1234"
|
|
local from, to = ngx.re.find(str, "([0-9])([0-9]+)", "jo", nil, 2)
|
|
if from then
|
|
ngx.say("matched 2nd submatch: ", string.sub(str, from, to)) -- yields "234"
|
|
end
|
|
</geshi>
|
|
|
|
This API function was first introduced in the <code>v0.9.2</code> release.
|
|
|
|
== ngx.re.gmatch ==
|
|
|
|
'''syntax:''' ''iterator, err = ngx.re.gmatch(subject, regex, options?)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Similar to [[#ngx.re.match|ngx.re.match]], but returns a Lua iterator instead, so as to let the user programmer iterate all the matches over the <code><subject></code> string argument with the PCRE <code>regex</code>.
|
|
|
|
In case of errors, like seeing an ill-formed regular expression, <code>nil</code> and a string describing the error will be returned.
|
|
|
|
Here is a small example to demonstrate its basic usage:
|
|
|
|
<geshi lang="lua">
|
|
local iterator, err = ngx.re.gmatch("hello, world!", "([a-z]+)", "i")
|
|
if not iterator then
|
|
ngx.log(ngx.ERR, "error: ", err)
|
|
return
|
|
end
|
|
|
|
local m
|
|
m, err = iterator() -- m[0] == m[1] == "hello"
|
|
if err then
|
|
ngx.log(ngx.ERR, "error: ", err)
|
|
return
|
|
end
|
|
|
|
m, err = iterator() -- m[0] == m[1] == "world"
|
|
if err then
|
|
ngx.log(ngx.ERR, "error: ", err)
|
|
return
|
|
end
|
|
|
|
m, err = iterator() -- m == nil
|
|
if err then
|
|
ngx.log(ngx.ERR, "error: ", err)
|
|
return
|
|
end
|
|
</geshi>
|
|
|
|
More often we just put it into a Lua loop:
|
|
|
|
<geshi lang="lua">
|
|
local it, err = ngx.re.gmatch("hello, world!", "([a-z]+)", "i")
|
|
if not it then
|
|
ngx.log(ngx.ERR, "error: ", err)
|
|
return
|
|
end
|
|
|
|
while true do
|
|
local m, err = it()
|
|
if err then
|
|
ngx.log(ngx.ERR, "error: ", err)
|
|
return
|
|
end
|
|
|
|
if not m then
|
|
-- no match found (any more)
|
|
break
|
|
end
|
|
|
|
-- found a match
|
|
ngx.say(m[0])
|
|
ngx.say(m[1])
|
|
end
|
|
</geshi>
|
|
|
|
The optional <code>options</code> argument takes exactly the same semantics as the [[#ngx.re.match|ngx.re.match]] method.
|
|
|
|
The current implementation requires that the iterator returned should only be used in a single request. That is, one should ''not'' assign it to a variable belonging to persistent namespace like a Lua package.
|
|
|
|
This method requires the PCRE library enabled in Nginx ([[#Special Escaping Sequences|Known Issue With Special Escaping Sequences]]).
|
|
|
|
This feature was first introduced in the <code>v0.2.1rc12</code> release.
|
|
|
|
== ngx.re.sub ==
|
|
|
|
'''syntax:''' ''newstr, n, err = ngx.re.sub(subject, regex, replace, options?)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Substitutes the first match of the Perl compatible regular expression <code>regex</code> on the <code>subject</code> argument string with the string or function argument <code>replace</code>. The optional <code>options</code> argument has exactly the same meaning as in [[#ngx.re.match|ngx.re.match]].
|
|
|
|
This method returns the resulting new string as well as the number of successful substitutions. In case of failures, like syntax errors in the regular expressions or the <code><replace></code> string argument, it will return <code>nil</code> and a string describing the error.
|
|
|
|
When the <code>replace</code> is a string, then it is treated as a special template for string replacement. For example,
|
|
|
|
<geshi lang="lua">
|
|
local newstr, n, err = ngx.re.sub("hello, 1234", "([0-9])[0-9]", "[$0][$1]")
|
|
if not newstr then
|
|
ngx.log(ngx.ERR, "error: ", err)
|
|
return
|
|
end
|
|
|
|
-- newstr == "hello, [12][1]34"
|
|
-- n == 1
|
|
</geshi>
|
|
|
|
where <code>$0</code> referring to the whole substring matched by the pattern and <code>$1</code> referring to the first parenthesized capturing substring.
|
|
|
|
Curly braces can also be used to disambiguate variable names from the background string literals:
|
|
|
|
<geshi lang="lua">
|
|
local newstr, n, err = ngx.re.sub("hello, 1234", "[0-9]", "${0}00")
|
|
-- newstr == "hello, 100234"
|
|
-- n == 1
|
|
</geshi>
|
|
|
|
Literal dollar sign characters (<code>$</code>) in the <code>replace</code> string argument can be escaped by another dollar sign, for instance,
|
|
|
|
<geshi lang="lua">
|
|
local newstr, n, err = ngx.re.sub("hello, 1234", "[0-9]", "$$")
|
|
-- newstr == "hello, $234"
|
|
-- n == 1
|
|
</geshi>
|
|
|
|
Do not use backlashes to escape dollar signs; it will not work as expected.
|
|
|
|
When the <code>replace</code> argument is of type "function", then it will be invoked with the "match table" as the argument to generate the replace string literal for substitution. The "match table" fed into the <code>replace</code> function is exactly the same as the return value of [[#ngx.re.match|ngx.re.match]]. Here is an example:
|
|
|
|
<geshi lang="lua">
|
|
local func = function (m)
|
|
return "[" .. m[0] .. "][" .. m[1] .. "]"
|
|
end
|
|
|
|
local newstr, n, err = ngx.re.sub("hello, 1234", "( [0-9] ) [0-9]", func, "x")
|
|
-- newstr == "hello, [12][1]34"
|
|
-- n == 1
|
|
</geshi>
|
|
|
|
The dollar sign characters in the return value of the <code>replace</code> function argument are not special at all.
|
|
|
|
This method requires the PCRE library enabled in Nginx ([[#Special Escaping Sequences|Known Issue With Special Escaping Sequences]]).
|
|
|
|
This feature was first introduced in the <code>v0.2.1rc13</code> release.
|
|
|
|
== ngx.re.gsub ==
|
|
|
|
'''syntax:''' ''newstr, n, err = ngx.re.gsub(subject, regex, replace, options?)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Just like [[#ngx.re.sub|ngx.re.sub]], but does global substitution.
|
|
|
|
Here is some examples:
|
|
|
|
<geshi lang="lua">
|
|
local newstr, n, err = ngx.re.gsub("hello, world", "([a-z])[a-z]+", "[$0,$1]", "i")
|
|
if not newstr then
|
|
ngx.log(ngx.ERR, "error: ", err)
|
|
return
|
|
end
|
|
|
|
-- newstr == "[hello,h], [world,w]"
|
|
-- n == 2
|
|
</geshi>
|
|
|
|
<geshi lang="lua">
|
|
local func = function (m)
|
|
return "[" .. m[0] .. "," .. m[1] .. "]"
|
|
end
|
|
local newstr, n, err = ngx.re.gsub("hello, world", "([a-z])[a-z]+", func, "i")
|
|
-- newstr == "[hello,h], [world,w]"
|
|
-- n == 2
|
|
</geshi>
|
|
|
|
This method requires the PCRE library enabled in Nginx ([[#Special Escaping Sequences|Known Issue With Special Escaping Sequences]]).
|
|
|
|
This feature was first introduced in the <code>v0.2.1rc15</code> release.
|
|
|
|
== ngx.shared.DICT ==
|
|
|
|
'''syntax:''' ''dict = ngx.shared.DICT''
|
|
|
|
'''syntax:''' ''dict = ngx.shared[name_var]''
|
|
|
|
'''context:''' ''init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Fetching the shm-based Lua dictionary object for the shared memory zone named <code>DICT</code> defined by the [[#lua_shared_dict|lua_shared_dict]] directive.
|
|
|
|
Shared memory zones are always shared by all the Nginx worker processes in the current Nginx server instance.
|
|
|
|
The resulting object <code>dict</code> has the following methods:
|
|
|
|
* [[#ngx.shared.DICT.get|get]]
|
|
* [[#ngx.shared.DICT.get_stale|get_stale]]
|
|
* [[#ngx.shared.DICT.set|set]]
|
|
* [[#ngx.shared.DICT.safe_set|safe_set]]
|
|
* [[#ngx.shared.DICT.add|add]]
|
|
* [[#ngx.shared.DICT.safe_add|safe_add]]
|
|
* [[#ngx.shared.DICT.replace|replace]]
|
|
* [[#ngx.shared.DICT.delete|delete]]
|
|
* [[#ngx.shared.DICT.incr|incr]]
|
|
* [[#ngx.shared.DICT.lpush|lpush]]
|
|
* [[#ngx.shared.DICT.rpush|rpush]]
|
|
* [[#ngx.shared.DICT.lpop|lpop]]
|
|
* [[#ngx.shared.DICT.rpop|rpop]]
|
|
* [[#ngx.shared.DICT.llen|llen]]
|
|
* [[#ngx.shared.DICT.ttl|ttl]]
|
|
* [[#ngx.shared.DICT.expire|expire]]
|
|
* [[#ngx.shared.DICT.flush_all|flush_all]]
|
|
* [[#ngx.shared.DICT.flush_expired|flush_expired]]
|
|
* [[#ngx.shared.DICT.get_keys|get_keys]]
|
|
* [[#ngx.shared.DICT.capacity|capacity]]
|
|
* [[#ngx.shared.DICT.free_space|free_space]]
|
|
|
|
All these methods are ''atomic'' operations, that is, safe from concurrent accesses from multiple Nginx worker processes for the same <code>lua_shared_dict</code> zone.
|
|
|
|
Here is an example:
|
|
|
|
<geshi lang="nginx">
|
|
http {
|
|
lua_shared_dict dogs 10m;
|
|
server {
|
|
location /set {
|
|
content_by_lua_block {
|
|
local dogs = ngx.shared.dogs
|
|
dogs:set("Jim", 8)
|
|
ngx.say("STORED")
|
|
}
|
|
}
|
|
location /get {
|
|
content_by_lua_block {
|
|
local dogs = ngx.shared.dogs
|
|
ngx.say(dogs:get("Jim"))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Let us test it:
|
|
|
|
<geshi lang="bash">
|
|
$ curl localhost/set
|
|
STORED
|
|
|
|
$ curl localhost/get
|
|
8
|
|
|
|
$ curl localhost/get
|
|
8
|
|
</geshi>
|
|
|
|
The number <code>8</code> will be consistently output when accessing <code>/get</code> regardless of how many Nginx workers there are because the <code>dogs</code> dictionary resides in the shared memory and visible to ''all'' of the worker processes.
|
|
|
|
The shared dictionary will retain its contents through a server config reload (either by sending the <code>HUP</code> signal to the Nginx process or by using the <code>-s reload</code> command-line option).
|
|
|
|
The contents in the dictionary storage will be lost, however, when the Nginx server quits.
|
|
|
|
This feature was first introduced in the <code>v0.3.1rc22</code> release.
|
|
|
|
== ngx.shared.DICT.get ==
|
|
|
|
'''syntax:''' ''value, flags = ngx.shared.DICT:get(key)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Retrieving the value in the dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] for the key <code>key</code>. If the key does not exist or has expired, then <code>nil</code> will be returned.
|
|
|
|
In case of errors, <code>nil</code> and a string describing the error will be returned.
|
|
|
|
The value returned will have the original data type when they were inserted into the dictionary, for example, Lua booleans, numbers, or strings.
|
|
|
|
The first argument to this method must be the dictionary object itself, for example,
|
|
|
|
<geshi lang="lua">
|
|
local cats = ngx.shared.cats
|
|
local value, flags = cats.get(cats, "Marry")
|
|
</geshi>
|
|
|
|
or use Lua's syntactic sugar for method calls:
|
|
|
|
<geshi lang="lua">
|
|
local cats = ngx.shared.cats
|
|
local value, flags = cats:get("Marry")
|
|
</geshi>
|
|
|
|
These two forms are fundamentally equivalent.
|
|
|
|
If the user flags is <code>0</code> (the default), then no flags value will be returned.
|
|
|
|
This feature was first introduced in the <code>v0.3.1rc22</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.get_stale ==
|
|
|
|
'''syntax:''' ''value, flags, stale = ngx.shared.DICT:get_stale(key)''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Similar to the [[#ngx.shared.DICT.get|get]] method but returns the value even if the key has already expired.
|
|
|
|
Returns a 3rd value, <code>stale</code>, indicating whether the key has expired or not.
|
|
|
|
Note that the value of an expired key is not guaranteed to be available so one should never rely on the availability of expired items.
|
|
|
|
This method was first introduced in the <code>0.8.6</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.set ==
|
|
|
|
'''syntax:''' ''success, err, forcible = ngx.shared.DICT:set(key, value, exptime?, flags?)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Unconditionally sets a key-value pair into the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]]. Returns three values:
|
|
|
|
* <code>success</code>: boolean value to indicate whether the key-value pair is stored or not.
|
|
* <code>err</code>: textual error message, can be <code>"no memory"</code>.
|
|
* <code>forcible</code>: a boolean value to indicate whether other valid items have been removed forcibly when out of storage in the shared memory zone.
|
|
|
|
The <code>value</code> argument inserted can be Lua booleans, numbers, strings, or <code>nil</code>. Their value type will also be stored into the dictionary and the same data type can be retrieved later via the [[#ngx.shared.DICT.get|get]] method.
|
|
|
|
The optional <code>exptime</code> argument specifies expiration time (in seconds) for the inserted key-value pair. The time resolution is <code>0.001</code> seconds. If the <code>exptime</code> takes the value <code>0</code> (which is the default), then the item will never expire.
|
|
|
|
The optional <code>flags</code> argument specifies a user flags value associated with the entry to be stored. It can also be retrieved later with the value. The user flags is stored as an unsigned 32-bit integer internally. Defaults to <code>0</code>. The user flags argument was first introduced in the <code>v0.5.0rc2</code> release.
|
|
|
|
When it fails to allocate memory for the current key-value item, then <code>set</code> will try removing existing items in the storage according to the Least-Recently Used (LRU) algorithm. Note that, LRU takes priority over expiration time here. If up to tens of existing items have been removed and the storage left is still insufficient (either due to the total capacity limit specified by [[#lua_shared_dict|lua_shared_dict]] or memory segmentation), then the <code>err</code> return value will be <code>no memory</code> and <code>success</code> will be <code>false</code>.
|
|
|
|
If the sizes of items in the dictionary are not multiples or even powers of a certain value (like 2), it is easier to encounter <code>no memory</code> error because of memory fragmentation. It is recommended to use different dictionaries for different sizes of items.
|
|
|
|
When you encounter <code>no memory</code> error, you can also evict more least-recently-used items by retrying this method call more times to to make room for the current item.
|
|
|
|
If this method succeeds in storing the current item by forcibly removing other not-yet-expired items in the dictionary via LRU, the <code>forcible</code> return value will be <code>true</code>. If it stores the item without forcibly removing other valid items, then the return value <code>forcible</code> will be <code>false</code>.
|
|
|
|
The first argument to this method must be the dictionary object itself, for example,
|
|
|
|
<geshi lang="lua">
|
|
local cats = ngx.shared.cats
|
|
local succ, err, forcible = cats.set(cats, "Marry", "it is a nice cat!")
|
|
</geshi>
|
|
|
|
or use Lua's syntactic sugar for method calls:
|
|
|
|
<geshi lang="lua">
|
|
local cats = ngx.shared.cats
|
|
local succ, err, forcible = cats:set("Marry", "it is a nice cat!")
|
|
</geshi>
|
|
|
|
These two forms are fundamentally equivalent.
|
|
|
|
This feature was first introduced in the <code>v0.3.1rc22</code> release.
|
|
|
|
Please note that while internally the key-value pair is set atomically, the atomicity does not go across the method call boundary.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.safe_set ==
|
|
|
|
'''syntax:''' ''ok, err = ngx.shared.DICT:safe_set(key, value, exptime?, flags?)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Similar to the [[#ngx.shared.DICT.set|set]] method, but never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return <code>nil</code> and the string "no memory".
|
|
|
|
This feature was first introduced in the <code>v0.7.18</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.add ==
|
|
|
|
'''syntax:''' ''success, err, forcible = ngx.shared.DICT:add(key, value, exptime?, flags?)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Just like the [[#ngx.shared.DICT.set|set]] method, but only stores the key-value pair into the dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] if the key does ''not'' exist.
|
|
|
|
If the <code>key</code> argument already exists in the dictionary (and not expired for sure), the <code>success</code> return value will be <code>false</code> and the <code>err</code> return value will be <code>"exists"</code>.
|
|
|
|
This feature was first introduced in the <code>v0.3.1rc22</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.safe_add ==
|
|
|
|
'''syntax:''' ''ok, err = ngx.shared.DICT:safe_add(key, value, exptime?, flags?)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Similar to the [[#ngx.shared.DICT.add|add]] method, but never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return <code>nil</code> and the string "no memory".
|
|
|
|
This feature was first introduced in the <code>v0.7.18</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.replace ==
|
|
|
|
'''syntax:''' ''success, err, forcible = ngx.shared.DICT:replace(key, value, exptime?, flags?)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Just like the [[#ngx.shared.DICT.set|set]] method, but only stores the key-value pair into the dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] if the key ''does'' exist.
|
|
|
|
If the <code>key</code> argument does ''not'' exist in the dictionary (or expired already), the <code>success</code> return value will be <code>false</code> and the <code>err</code> return value will be <code>"not found"</code>.
|
|
|
|
This feature was first introduced in the <code>v0.3.1rc22</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.delete ==
|
|
|
|
'''syntax:''' ''ngx.shared.DICT:delete(key)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Unconditionally removes the key-value pair from the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
It is equivalent to <code>ngx.shared.DICT:set(key, nil)</code>.
|
|
|
|
This feature was first introduced in the <code>v0.3.1rc22</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.incr ==
|
|
|
|
'''syntax:''' ''newval, err, forcible? = ngx.shared.DICT:incr(key, value, init?, init_ttl?)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
'''optional requirement:''' <code>resty.core.shdict</code> or <code>resty.core</code>
|
|
|
|
Increments the (numerical) value for <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] by the step value <code>value</code>. Returns the new resulting number if the operation is successfully completed or <code>nil</code> and an error message otherwise.
|
|
|
|
When the key does not exist or has already expired in the shared dictionary,
|
|
|
|
# if the <code>init</code> argument is not specified or takes the value <code>nil</code>, this method will return <code>nil</code> and the error string <code>"not found"</code>, or
|
|
# if the <code>init</code> argument takes a number value, this method will create a new <code>key</code> with the value <code>init + value</code>.
|
|
|
|
Like the [[#ngx.shared.DICT.add|add]] method, it also overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone.
|
|
|
|
The optional <code>init_ttl</code> argument specifies expiration time (in seconds) of the value when it is initialized via the <code>init</code> argument. The time resolution is <code>0.001</code> seconds. If <code>init_ttl</code> takes the value <code>0</code> (which is the default), then the item will never expire. This argument cannot be provided without providing the <code>init</code> argument as well, and has no effect if the value already exists (e.g., if it was previously inserted via [[#ngx.shared.DICT.set|set]] or the likes).
|
|
|
|
'''Note:''' Usage of the <code>init_ttl</code> argument requires the <code>resty.core.shdict</code> or <code>resty.core</code> modules from the [https://github.com/openresty/lua-resty-core lua-resty-core] library. Example:
|
|
|
|
<geshi lang="lua">
|
|
require "resty.core"
|
|
|
|
local cats = ngx.shared.cats
|
|
local newval, err = cats:incr("black_cats", 1, 0, 0.1)
|
|
|
|
print(newval) -- 1
|
|
|
|
ngx.sleep(0.2)
|
|
|
|
local val, err = cats:get("black_cats")
|
|
print(val) -- nil
|
|
</geshi>
|
|
|
|
The <code>forcible</code> return value will always be <code>nil</code> when the <code>init</code> argument is not specified.
|
|
|
|
If this method succeeds in storing the current item by forcibly removing other not-yet-expired items in the dictionary via LRU, the <code>forcible</code> return value will be <code>true</code>. If it stores the item without forcibly removing other valid items, then the return value <code>forcible</code> will be <code>false</code>.
|
|
|
|
If the original value is not a valid Lua number in the dictionary, it will return <code>nil</code> and <code>"not a number"</code>.
|
|
|
|
The <code>value</code> argument and <code>init</code> argument can be any valid Lua numbers, like negative numbers or floating-point numbers.
|
|
|
|
This method was first introduced in the <code>v0.3.1rc22</code> release.
|
|
|
|
The optional <code>init</code> parameter was first added in the <code>v0.10.6</code> release.
|
|
|
|
The optional <code>init_ttl</code> parameter was introduced in the <code>v0.10.12rc2</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.lpush ==
|
|
|
|
'''syntax:''' ''length, err = ngx.shared.DICT:lpush(key, value)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Inserts the specified (numerical or string) <code>value</code> at the head of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]]. Returns the number of elements in the list after the push operation.
|
|
|
|
If <code>key</code> does not exist, it is created as an empty list before performing the push operation. When the <code>key</code> already takes a value that is not a list, it will return <code>nil</code> and <code>"value not a list"</code>.
|
|
|
|
It never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return <code>nil</code> and the string "no memory".
|
|
|
|
This feature was first introduced in the <code>v0.10.6</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.rpush ==
|
|
|
|
'''syntax:''' ''length, err = ngx.shared.DICT:rpush(key, value)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Similar to the [[#ngx.shared.DICT.lpush|lpush]] method, but inserts the specified (numerical or string) <code>value</code> at the tail of the list named <code>key</code>.
|
|
|
|
This feature was first introduced in the <code>v0.10.6</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.lpop ==
|
|
|
|
'''syntax:''' ''val, err = ngx.shared.DICT:lpop(key)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Removes and returns the first element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
If <code>key</code> does not exist, it will return <code>nil</code>. When the <code>key</code> already takes a value that is not a list, it will return <code>nil</code> and <code>"value not a list"</code>.
|
|
|
|
This feature was first introduced in the <code>v0.10.6</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.rpop ==
|
|
|
|
'''syntax:''' ''val, err = ngx.shared.DICT:rpop(key)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Removes and returns the last element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
If <code>key</code> does not exist, it will return <code>nil</code>. When the <code>key</code> already takes a value that is not a list, it will return <code>nil</code> and <code>"value not a list"</code>.
|
|
|
|
This feature was first introduced in the <code>v0.10.6</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.llen ==
|
|
|
|
'''syntax:''' ''len, err = ngx.shared.DICT:llen(key)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns the number of elements in the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
If key does not exist, it is interpreted as an empty list and 0 is returned. When the <code>key</code> already takes a value that is not a list, it will return <code>nil</code> and <code>"value not a list"</code>.
|
|
|
|
This feature was first introduced in the <code>v0.10.6</code> release.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.ttl ==
|
|
|
|
'''syntax:''' ''ttl, err = ngx.shared.DICT:ttl(key)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
|
|
|
|
Retrieves the remaining TTL (time-to-live in seconds) of a key-value pair in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]]. Returns the TTL as a number if the operation is successfully completed or <code>nil</code> and an error message otherwise.
|
|
|
|
If the key does not exist (or has already expired), this method will return <code>nil</code> and the error string <code>"not found"</code>.
|
|
|
|
The TTL is originally determined by the <code>exptime</code> argument of the [[#ngx.shared.DICT.set|set]], [[#ngx.shared.DICT.add|add]], [[#ngx.shared.DICT.replace|replace]] (and the likes) methods. It has a time resolution of <code>0.001</code> seconds. A value of <code>0</code> means that the item will never expire.
|
|
|
|
Example:
|
|
|
|
<geshi lang="lua">
|
|
require "resty.core"
|
|
|
|
local cats = ngx.shared.cats
|
|
local succ, err = cats:set("Marry", "a nice cat", 0.5)
|
|
|
|
ngx.sleep(0.2)
|
|
|
|
local ttl, err = cats:ttl("Marry")
|
|
ngx.say(ttl) -- 0.3
|
|
</geshi>
|
|
|
|
This feature was first introduced in the <code>v0.10.11</code> release.
|
|
|
|
'''Note:''' This method requires the <code>resty.core.shdict</code> or <code>resty.core</code> modules from the [https://github.com/openresty/lua-resty-core lua-resty-core] library.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.expire ==
|
|
|
|
'''syntax:''' ''success, err = ngx.shared.DICT:expire(key, exptime)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
|
|
|
|
Updates the <code>exptime</code> (in second) of a key-value pair in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]]. Returns a boolean indicating success if the operation completes or <code>nil</code> and an error message otherwise.
|
|
|
|
If the key does not exist, this method will return <code>nil</code> and the error string <code>"not found"</code>.
|
|
|
|
The <code>exptime</code> argument has a resolution of <code>0.001</code> seconds. If <code>exptime</code> is <code>0</code>, then the item will never expire.
|
|
|
|
Example:
|
|
|
|
<geshi lang="lua">
|
|
require "resty.core"
|
|
|
|
local cats = ngx.shared.cats
|
|
local succ, err = cats:set("Marry", "a nice cat", 0.1)
|
|
|
|
succ, err = cats:expire("Marry", 0.5)
|
|
|
|
ngx.sleep(0.2)
|
|
|
|
local val, err = cats:get("Marry")
|
|
ngx.say(val) -- "a nice cat"
|
|
</geshi>
|
|
|
|
This feature was first introduced in the <code>v0.10.11</code> release.
|
|
|
|
'''Note:''' This method requires the <code>resty.core.shdict</code> or <code>resty.core</code> modules from the [https://github.com/openresty/lua-resty-core lua-resty-core] library.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.flush_all ==
|
|
|
|
'''syntax:''' ''ngx.shared.DICT:flush_all()''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Flushes out all the items in the dictionary. This method does not actually free up all the memory blocks in the dictionary but just marks all the existing items as expired.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc17</code> release.
|
|
|
|
See also [[#ngx.shared.DICT.flush_expired|ngx.shared.DICT.flush_expired]] and [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.flush_expired ==
|
|
|
|
'''syntax:''' ''flushed = ngx.shared.DICT:flush_expired(max_count?)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Flushes out the expired items in the dictionary, up to the maximal number specified by the optional <code>max_count</code> argument. When the <code>max_count</code> argument is given <code>0</code> or not given at all, then it means unlimited. Returns the number of items that have actually been flushed.
|
|
|
|
Unlike the [[#ngx.shared.DICT.flush_all|flush_all]] method, this method actually frees up the memory used by the expired items.
|
|
|
|
This feature was first introduced in the <code>v0.6.3</code> release.
|
|
|
|
See also [[#ngx.shared.DICT.flush_all|ngx.shared.DICT.flush_all]] and [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.get_keys ==
|
|
|
|
'''syntax:''' ''keys = ngx.shared.DICT:get_keys(max_count?)''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Fetch a list of the keys from the dictionary, up to <code><max_count></code>.
|
|
|
|
By default, only the first 1024 keys (if any) are returned. When the <code><max_count></code> argument is given the value <code>0</code>, then all the keys will be returned even there is more than 1024 keys in the dictionary.
|
|
|
|
'''CAUTION''' Avoid calling this method on dictionaries with a very large number of keys as it may lock the dictionary for significant amount of time and block Nginx worker processes trying to access the dictionary.
|
|
|
|
This feature was first introduced in the <code>v0.7.3</code> release.
|
|
|
|
== ngx.shared.DICT.capacity ==
|
|
|
|
'''syntax:''' ''capacity_bytes = ngx.shared.DICT:capacity()''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
|
|
|
|
Retrieves the capacity in bytes for the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] declared with
|
|
the [[#lua_shared_dict|lua_shared_dict]] directive.
|
|
|
|
Example:
|
|
|
|
<geshi lang="lua">
|
|
require "resty.core.shdict"
|
|
|
|
local cats = ngx.shared.cats
|
|
local capacity_bytes = cats:capacity()
|
|
</geshi>
|
|
|
|
This feature was first introduced in the <code>v0.10.11</code> release.
|
|
|
|
'''Note:''' This method requires the <code>resty.core.shdict</code> or <code>resty.core</code> modules from the [https://github.com/openresty/lua-resty-core lua-resty-core] library.
|
|
|
|
This feature requires at least Nginx core version <code>0.7.3</code>.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.shared.DICT.free_space ==
|
|
|
|
'''syntax:''' ''free_page_bytes = ngx.shared.DICT:free_space()''
|
|
|
|
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
|
|
|
|
Retrieves the free page size in bytes for the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
'''Note:''' The memory for ngx.shared.DICT is allocated via the Nginx slab allocator which has each slot for
|
|
data size ranges like \~8, 9\~16, 17\~32, ..., 1025\~2048, 2048\~ bytes. And pages are assigned to a slot if there
|
|
is no room in already assigned pages for the slot.
|
|
|
|
So even if the return value of the <code>free_space</code> method is zero, there may be room in already assigned pages, so
|
|
you may successfully set a new key value pair to the shared dict without getting <code>true</code> for <code>forcible</code> or
|
|
non nil <code>err</code> from the <code>ngx.shared.DICT.set</code>.
|
|
|
|
On the other hand, if already assigned pages for a slot are full and a new key value pair is added to the
|
|
slot and there is no free page, you may get <code>true</code> for <code>forcible</code> or non nil <code>err</code> from the
|
|
<code>ngx.shared.DICT.set</code> method.
|
|
|
|
Example:
|
|
|
|
<geshi lang="lua">
|
|
require "resty.core.shdict"
|
|
|
|
local cats = ngx.shared.cats
|
|
local free_page_bytes = cats:free_space()
|
|
</geshi>
|
|
|
|
This feature was first introduced in the <code>v0.10.11</code> release.
|
|
|
|
'''Note:''' This method requires the <code>resty.core.shdict</code> or <code>resty.core</code> modules from the [https://github.com/openresty/lua-resty-core lua-resty-core] library.
|
|
|
|
This feature requires at least Nginx core version <code>1.11.7</code>.
|
|
|
|
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
|
|
|
|
== ngx.socket.udp ==
|
|
|
|
'''syntax:''' ''udpsock = ngx.socket.udp()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Creates and returns a UDP or datagram-oriented unix domain socket object (also known as one type of the "cosocket" objects). The following methods are supported on this object:
|
|
|
|
* [[#udpsock:setpeername|setpeername]]
|
|
* [[#udpsock:send|send]]
|
|
* [[#udpsock:receive|receive]]
|
|
* [[#udpsock:close|close]]
|
|
* [[#udpsock:settimeout|settimeout]]
|
|
|
|
It is intended to be compatible with the UDP API of the [http://w3.impa.br/~diego/software/luasocket/udp.html LuaSocket] library but is 100% nonblocking out of the box.
|
|
|
|
This feature was first introduced in the <code>v0.5.7</code> release.
|
|
|
|
See also [[#ngx.socket.tcp|ngx.socket.tcp]].
|
|
|
|
== udpsock:setpeername ==
|
|
|
|
'''syntax:''' ''ok, err = udpsock:setpeername(host, port)''
|
|
|
|
'''syntax:''' ''ok, err = udpsock:setpeername("unix:/path/to/unix-domain.socket")''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Attempts to connect a UDP socket object to a remote server or to a datagram unix domain socket file. Because the datagram protocol is actually connection-less, this method does not really establish a "connection", but only just set the name of the remote peer for subsequent read/write operations.
|
|
|
|
Both IP addresses and domain names can be specified as the <code>host</code> argument. In case of domain names, this method will use Nginx core's dynamic resolver to parse the domain name without blocking and it is required to configure the [[HttpCoreModule#resolver|resolver]] directive in the <code>nginx.conf</code> file like this:
|
|
|
|
<geshi lang="nginx">
|
|
resolver 8.8.8.8; # use Google's public DNS nameserver
|
|
</geshi>
|
|
|
|
If the nameserver returns multiple IP addresses for the host name, this method will pick up one randomly.
|
|
|
|
In case of error, the method returns <code>nil</code> followed by a string describing the error. In case of success, the method returns <code>1</code>.
|
|
|
|
Here is an example for connecting to a UDP (memcached) server:
|
|
|
|
<geshi lang="nginx">
|
|
location /test {
|
|
resolver 8.8.8.8;
|
|
|
|
content_by_lua_block {
|
|
local sock = ngx.socket.udp()
|
|
local ok, err = sock:setpeername("my.memcached.server.domain", 11211)
|
|
if not ok then
|
|
ngx.say("failed to connect to memcached: ", err)
|
|
return
|
|
end
|
|
ngx.say("successfully connected to memcached!")
|
|
sock:close()
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Since the <code>v0.7.18</code> release, connecting to a datagram unix domain socket file is also possible on Linux:
|
|
|
|
<geshi lang="lua">
|
|
local sock = ngx.socket.udp()
|
|
local ok, err = sock:setpeername("unix:/tmp/some-datagram-service.sock")
|
|
if not ok then
|
|
ngx.say("failed to connect to the datagram unix domain socket: ", err)
|
|
return
|
|
end
|
|
|
|
-- do something after connect
|
|
-- such as sock:send or sock:receive
|
|
</geshi>
|
|
|
|
assuming the datagram service is listening on the unix domain socket file <code>/tmp/some-datagram-service.sock</code> and the client socket will use the "autobind" feature on Linux.
|
|
|
|
Calling this method on an already connected socket object will cause the original connection to be closed first.
|
|
|
|
This method was first introduced in the <code>v0.5.7</code> release.
|
|
|
|
== udpsock:send ==
|
|
|
|
'''syntax:''' ''ok, err = udpsock:send(data)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Sends data on the current UDP or datagram unix domain socket object.
|
|
|
|
In case of success, it returns <code>1</code>. Otherwise, it returns <code>nil</code> and a string describing the error.
|
|
|
|
The input argument <code>data</code> can either be a Lua string or a (nested) Lua table holding string fragments. In case of table arguments, this method will copy all the string elements piece by piece to the underlying Nginx socket send buffers, which is usually optimal than doing string concatenation operations on the Lua land.
|
|
|
|
This feature was first introduced in the <code>v0.5.7</code> release.
|
|
|
|
== udpsock:receive ==
|
|
|
|
'''syntax:''' ''data, err = udpsock:receive(size?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Receives data from the UDP or datagram unix domain socket object with an optional receive buffer size argument, <code>size</code>.
|
|
|
|
This method is a synchronous operation and is 100% nonblocking.
|
|
|
|
In case of success, it returns the data received; in case of error, it returns <code>nil</code> with a string describing the error.
|
|
|
|
If the <code>size</code> argument is specified, then this method will use this size as the receive buffer size. But when this size is greater than <code>8192</code>, then <code>8192</code> will be used instead.
|
|
|
|
If no argument is specified, then the maximal buffer size, <code>8192</code> is assumed.
|
|
|
|
Timeout for the reading operation is controlled by the [[#lua_socket_read_timeout|lua_socket_read_timeout]] config directive and the [[#udpsock:settimeout|settimeout]] method. And the latter takes priority. For example:
|
|
|
|
<geshi lang="lua">
|
|
sock:settimeout(1000) -- one second timeout
|
|
local data, err = sock:receive()
|
|
if not data then
|
|
ngx.say("failed to read a packet: ", err)
|
|
return
|
|
end
|
|
ngx.say("successfully read a packet: ", data)
|
|
</geshi>
|
|
|
|
It is important here to call the [[#udpsock:settimeout|settimeout]] method ''before'' calling this method.
|
|
|
|
This feature was first introduced in the <code>v0.5.7</code> release.
|
|
|
|
== udpsock:close ==
|
|
|
|
'''syntax:''' ''ok, err = udpsock:close()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Closes the current UDP or datagram unix domain socket. It returns the <code>1</code> in case of success and returns <code>nil</code> with a string describing the error otherwise.
|
|
|
|
Socket objects that have not invoked this method (and associated connections) will be closed when the socket object is released by the Lua GC (Garbage Collector) or the current client HTTP request finishes processing.
|
|
|
|
This feature was first introduced in the <code>v0.5.7</code> release.
|
|
|
|
== udpsock:settimeout ==
|
|
|
|
'''syntax:''' ''udpsock:settimeout(time)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Set the timeout value in milliseconds for subsequent socket operations (like [[#udpsock:receive|receive]]).
|
|
|
|
Settings done by this method takes priority over those config directives, like [[#lua_socket_read_timeout|lua_socket_read_timeout]].
|
|
|
|
This feature was first introduced in the <code>v0.5.7</code> release.
|
|
|
|
== ngx.socket.stream ==
|
|
|
|
Just an alias to [[#ngx.socket.tcp|ngx.socket.tcp]]. If the stream-typed cosocket may also connect to a unix domain
|
|
socket, then this API name is preferred.
|
|
|
|
This API function was first added to the <code>v0.10.1</code> release.
|
|
|
|
== ngx.socket.tcp ==
|
|
|
|
'''syntax:''' ''tcpsock = ngx.socket.tcp()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Creates and returns a TCP or stream-oriented unix domain socket object (also known as one type of the "cosocket" objects). The following methods are supported on this object:
|
|
|
|
* [[#tcpsock:bind|bind]]
|
|
* [[#tcpsock:connect|connect]]
|
|
* [[#tcpsock:setclientcert|setclientcert]]
|
|
* [[#tcpsock:sslhandshake|sslhandshake]]
|
|
* [[#tcpsock:send|send]]
|
|
* [[#tcpsock:receive|receive]]
|
|
* [[#tcpsock:close|close]]
|
|
* [[#tcpsock:settimeout|settimeout]]
|
|
* [[#tcpsock:settimeouts|settimeouts]]
|
|
* [[#tcpsock:setoption|setoption]]
|
|
* [[#tcpsock:receiveany|receiveany]]
|
|
* [[#tcpsock:receiveuntil|receiveuntil]]
|
|
* [[#tcpsock:setkeepalive|setkeepalive]]
|
|
* [[#tcpsock:getreusedtimes|getreusedtimes]]
|
|
|
|
It is intended to be compatible with the TCP API of the [http://w3.impa.br/~diego/software/luasocket/tcp.html LuaSocket] library but is 100% nonblocking out of the box. Also, we introduce some new APIs to provide more functionalities.
|
|
|
|
The cosocket object created by this API function has exactly the same lifetime as the Lua handler creating it. So never pass the cosocket object to any other Lua handler (including ngx.timer callback functions) and never share the cosocket object between different Nginx requests.
|
|
|
|
For every cosocket object's underlying connection, if you do not
|
|
explicitly close it (via [[#tcpsock:close|close]]) or put it back to the connection
|
|
pool (via [[#tcpsock:setkeepalive|setkeepalive]]), then it is automatically closed when one of
|
|
the following two events happens:
|
|
|
|
* the current request handler completes, or
|
|
* the Lua cosocket object value gets collected by the Lua GC.
|
|
|
|
Fatal errors in cosocket operations always automatically close the current
|
|
connection (note that, read timeout error is the only error that is
|
|
not fatal), and if you call [[#tcpsock:close|close]] on a closed connection, you will get
|
|
the "closed" error.
|
|
|
|
Starting from the <code>0.9.9</code> release, the cosocket object here is full-duplex, that is, a reader "light thread" and a writer "light thread" can operate on a single cosocket object simultaneously (both "light threads" must belong to the same Lua handler though, see reasons above). But you cannot have two "light threads" both reading (or writing or connecting) the same cosocket, otherwise you might get an error like "socket busy reading" when calling the methods of the cosocket object.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
See also [[#ngx.socket.udp|ngx.socket.udp]].
|
|
|
|
== tcpsock:bind ==
|
|
'''syntax:''' ''ok, err = tcpsock:bind(address)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*''
|
|
|
|
Just like the standard [[HttpProxyModule#proxy_bind|proxy_bind]] directive, this api makes the outgoing connection to a upstream server originate from the specified local IP address.
|
|
|
|
Only IP addresses can be specified as the <code>address</code> argument.
|
|
|
|
Here is an example for connecting to a TCP server from the specified local IP address:
|
|
|
|
<geshi lang="nginx">
|
|
location /test {
|
|
content_by_lua_block {
|
|
local sock = ngx.socket.tcp()
|
|
-- assume "192.168.1.10" is the local ip address
|
|
local ok, err = sock:bind("192.168.1.10")
|
|
if not ok then
|
|
ngx.say("failed to bind")
|
|
return
|
|
end
|
|
local ok, err = sock:connect("192.168.1.67", 80)
|
|
if not ok then
|
|
ngx.say("failed to connect server: ", err)
|
|
return
|
|
end
|
|
ngx.say("successfully connected!")
|
|
sock:close()
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
== tcpsock:connect ==
|
|
|
|
'''syntax:''' ''ok, err = tcpsock:connect(host, port, options_table?)''
|
|
|
|
'''syntax:''' ''ok, err = tcpsock:connect("unix:/path/to/unix-domain.socket", options_table?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Attempts to connect a TCP socket object to a remote server or to a stream unix domain socket file without blocking.
|
|
|
|
Before actually resolving the host name and connecting to the remote backend, this method will always look up the connection pool for matched idle connections created by previous calls of this method (or the [[#ngx.socket.connect|ngx.socket.connect]] function).
|
|
|
|
Both IP addresses and domain names can be specified as the <code>host</code> argument. In case of domain names, this method will use Nginx core's dynamic resolver to parse the domain name without blocking and it is required to configure the [[HttpCoreModule#resolver|resolver]] directive in the <code>nginx.conf</code> file like this:
|
|
|
|
<geshi lang="nginx">
|
|
resolver 8.8.8.8; # use Google's public DNS nameserver
|
|
</geshi>
|
|
|
|
If the nameserver returns multiple IP addresses for the host name, this method will pick up one randomly.
|
|
|
|
In case of error, the method returns <code>nil</code> followed by a string describing the error. In case of success, the method returns <code>1</code>.
|
|
|
|
Here is an example for connecting to a TCP server:
|
|
|
|
<geshi lang="nginx">
|
|
location /test {
|
|
resolver 8.8.8.8;
|
|
|
|
content_by_lua_block {
|
|
local sock = ngx.socket.tcp()
|
|
local ok, err = sock:connect("www.google.com", 80)
|
|
if not ok then
|
|
ngx.say("failed to connect to google: ", err)
|
|
return
|
|
end
|
|
ngx.say("successfully connected to google!")
|
|
sock:close()
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
Connecting to a Unix Domain Socket file is also possible:
|
|
|
|
<geshi lang="lua">
|
|
local sock = ngx.socket.tcp()
|
|
local ok, err = sock:connect("unix:/tmp/memcached.sock")
|
|
if not ok then
|
|
ngx.say("failed to connect to the memcached unix domain socket: ", err)
|
|
return
|
|
end
|
|
|
|
-- do something after connect
|
|
-- such as sock:send or sock:receive
|
|
</geshi>
|
|
|
|
assuming memcached (or something else) is listening on the unix domain socket file <code>/tmp/memcached.sock</code>.
|
|
|
|
Timeout for the connecting operation is controlled by the [[#lua_socket_connect_timeout|lua_socket_connect_timeout]] config directive and the [[#tcpsock:settimeout|settimeout]] method. And the latter takes priority. For example:
|
|
|
|
<geshi lang="lua">
|
|
local sock = ngx.socket.tcp()
|
|
sock:settimeout(1000) -- one second timeout
|
|
local ok, err = sock:connect(host, port)
|
|
</geshi>
|
|
|
|
It is important here to call the [[#tcpsock:settimeout|settimeout]] method ''before'' calling this method.
|
|
|
|
Calling this method on an already connected socket object will cause the original connection to be closed first.
|
|
|
|
An optional Lua table can be specified as the last argument to this method to specify various connect options:
|
|
|
|
* <code>pool</code>
|
|
: specify a custom name for the connection pool being used. If omitted, then the connection pool name will be generated from the string template <code>"<host>:<port>"</code> or <code>"<unix-socket-path>"</code>.
|
|
|
|
* <code>pool_size</code>
|
|
: specify the size of the connection pool. If omitted and no
|
|
: <code>backlog</code> option was provided, no pool will be created. If omitted
|
|
: but <code>backlog</code> was provided, the pool will be created with a default
|
|
: size equal to the value of the [[#lua_socket_pool_size|lua_socket_pool_size]]
|
|
: directive.
|
|
: The connection pool holds up to <code>pool_size</code> alive connections
|
|
: ready to be reused by subsequent calls to [[#tcpsock:connect|connect]], but
|
|
: note that there is no upper limit to the total number of opened connections
|
|
: outside of the pool. If you need to restrict the total number of opened
|
|
: connections, specify the <code>backlog</code> option.
|
|
: When the connection pool would exceed its size limit, the least recently used
|
|
: (kept-alive) connection already in the pool will be closed to make room for
|
|
: the current connection.
|
|
: Note that the cosocket connection pool is per Nginx worker process rather
|
|
: than per Nginx server instance, so the size limit specified here also applies
|
|
: to every single Nginx worker process. Also note that the size of the connection
|
|
: pool cannot be changed once it has been created.
|
|
: This option was first introduced in the <code>v0.10.14</code> release.
|
|
|
|
* <code>backlog</code>
|
|
: if specified, this module will limit the total number of opened connections
|
|
: for this pool. No more connections than <code>pool_size</code> can be opened
|
|
: for this pool at any time. If the connection pool is full, subsequent
|
|
: connect operations will be queued into a queue equal to this option's
|
|
: value (the "backlog" queue).
|
|
: If the number of queued connect operations is equal to <code>backlog</code>,
|
|
: subsequent connect operations will fail and return <code>nil</code> plus the
|
|
: error string <code>"too many waiting connect operations"</code>.
|
|
: The queued connect operations will be resumed once the number of connections
|
|
: in the pool is less than <code>pool_size</code>.
|
|
: The queued connect operation will abort once they have been queued for more
|
|
: than <code>connect_timeout</code>, controlled by
|
|
: [[#tcpsock:settimeouts|settimeouts]], and will return <code>nil</code> plus
|
|
: the error string <code>"timeout"</code>.
|
|
: This option was first introduced in the <code>v0.10.14</code> release.
|
|
|
|
The support for the options table argument was first introduced in the <code>v0.5.7</code> release.
|
|
|
|
This method was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== tcpsock:setclientcert ==
|
|
|
|
'''syntax:''' ''ok, err = tcpsock:setclientcert(cert, pkey)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Set client certificate chain and corresponding private key to the TCP socket object.
|
|
The certificate chain and private key provided will be used later by the [tcpsock:sslhandshake](#tcpsocksslhandshake) method.
|
|
|
|
* <code>cert</code> specify a client certificate chain cdata object that will be used while handshaking with
|
|
remote server. These objects can be created using [ngx.ssl.parse\_pem\_cert](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md#parse_pem_cert)
|
|
function provided by lua-resty-core. Note that specifying the <code>cert</code> option requires
|
|
corresponding <code>pkey</code> be provided too. See below.
|
|
* <code>pkey</code> specify a private key corresponds to the <code>cert</code> option above.
|
|
These objects can be created using [ngx.ssl.parse\_pem\_priv\_key](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md#parse_pem_priv_key)
|
|
function provided by lua-resty-core.
|
|
|
|
If both of <code>cert</code> and <code>pkey</code> are <code>nil</code>, this method will clear any existing client certificate and private key
|
|
that was previously set on the cosocket object.
|
|
|
|
This method was first introduced in the `v0.10.22` release.
|
|
|
|
== tcpsock:sslhandshake ==
|
|
|
|
'''syntax:''' ''session, err = tcpsock:sslhandshake(reused_session?, server_name?, ssl_verify?, send_status_req?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Does SSL/TLS handshake on the currently established connection.
|
|
|
|
The optional <code>reused_session</code> argument can take a former SSL
|
|
session userdata returned by a previous <code>sslhandshake</code>
|
|
call for exactly the same target. For short-lived connections, reusing SSL
|
|
sessions can usually speed up the handshake by one order by magnitude but it
|
|
is not so useful if the connection pool is enabled. This argument defaults to
|
|
<code>nil</code>. If this argument takes the boolean <code>false</code> value, no SSL session
|
|
userdata would return by this call and only a Lua boolean will be returned as
|
|
the first return value; otherwise the current SSL session will
|
|
always be returned as the first argument in case of successes.
|
|
|
|
The optional <code>server_name</code> argument is used to specify the server
|
|
name for the new TLS extension Server Name Indication (SNI). Use of SNI can
|
|
make different servers share the same IP address on the server side. Also,
|
|
when SSL verification is enabled, this <code>server_name</code> argument is
|
|
also used to validate the server name specified in the server certificate sent from
|
|
the remote.
|
|
|
|
The optional <code>ssl_verify</code> argument takes a Lua boolean value to
|
|
control whether to perform SSL verification. When set to <code>true</code>, the server
|
|
certificate will be verified according to the CA certificates specified by
|
|
the [[#lua_ssl_trusted_certificate|lua_ssl_trusted_certificate]] directive.
|
|
You may also need to adjust the [[#lua_ssl_verify_depth|lua_ssl_verify_depth]]
|
|
directive to control how deep we should follow along the certificate chain.
|
|
Also, when the <code>ssl_verify</code> argument is true and the
|
|
<code>server_name</code> argument is also specified, the latter will be used
|
|
to validate the server name in the server certificate.
|
|
|
|
The optional <code>send_status_req</code> argument takes a boolean that controls whether to send
|
|
the OCSP status request in the SSL handshake request (which is for requesting OCSP stapling).
|
|
|
|
For connections that have already done SSL/TLS handshake, this method returns
|
|
immediately.
|
|
|
|
This method was first introduced in the <code>v0.9.11</code> release.
|
|
|
|
== tcpsock:send ==
|
|
|
|
'''syntax:''' ''bytes, err = tcpsock:send(data)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Sends data without blocking on the current TCP or Unix Domain Socket connection.
|
|
|
|
This method is a synchronous operation that will not return until ''all'' the data has been flushed into the system socket send buffer or an error occurs.
|
|
|
|
In case of success, it returns the total number of bytes that have been sent. Otherwise, it returns <code>nil</code> and a string describing the error.
|
|
|
|
The input argument <code>data</code> can either be a Lua string or a (nested) Lua table holding string fragments. In case of table arguments, this method will copy all the string elements piece by piece to the underlying Nginx socket send buffers, which is usually optimal than doing string concatenation operations on the Lua land.
|
|
|
|
Timeout for the sending operation is controlled by the [[#lua_socket_send_timeout|lua_socket_send_timeout]] config directive and the [[#tcpsock:settimeout|settimeout]] method. And the latter takes priority. For example:
|
|
|
|
<geshi lang="lua">
|
|
sock:settimeout(1000) -- one second timeout
|
|
local bytes, err = sock:send(request)
|
|
</geshi>
|
|
|
|
It is important here to call the [[#tcpsock:settimeout|settimeout]] method ''before'' calling this method.
|
|
|
|
In case of any connection errors, this method always automatically closes the current connection.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== tcpsock:receive ==
|
|
|
|
'''syntax:''' ''data, err, partial = tcpsock:receive(size)''
|
|
|
|
'''syntax:''' ''data, err, partial = tcpsock:receive(pattern?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Receives data from the connected socket according to the reading pattern or size.
|
|
|
|
This method is a synchronous operation just like the [[#tcpsock:send|send]] method and is 100% nonblocking.
|
|
|
|
In case of success, it returns the data received; in case of error, it returns <code>nil</code> with a string describing the error and the partial data received so far.
|
|
|
|
If a number-like argument is specified (including strings that look like numbers), then it is interpreted as a size. This method will not return until it reads exactly this size of data or an error occurs.
|
|
|
|
If a non-number-like string argument is specified, then it is interpreted as a "pattern". The following patterns are supported:
|
|
|
|
* <code>'*a'</code>: reads from the socket until the connection is closed. No end-of-line translation is performed;
|
|
* <code>'*l'</code>: reads a line of text from the socket. The line is terminated by a <code>Line Feed</code> (LF) character (ASCII 10), optionally preceded by a <code>Carriage Return</code> (CR) character (ASCII 13). The CR and LF characters are not included in the returned line. In fact, all CR characters are ignored by the pattern.
|
|
|
|
If no argument is specified, then it is assumed to be the pattern <code>'*l'</code>, that is, the line reading pattern.
|
|
|
|
Timeout for the reading operation is controlled by the [[#lua_socket_read_timeout|lua_socket_read_timeout]] config directive and the [[#tcpsock:settimeout|settimeout]] method. And the latter takes priority. For example:
|
|
|
|
<geshi lang="lua">
|
|
sock:settimeout(1000) -- one second timeout
|
|
local line, err, partial = sock:receive()
|
|
if not line then
|
|
ngx.say("failed to read a line: ", err)
|
|
return
|
|
end
|
|
ngx.say("successfully read a line: ", line)
|
|
</geshi>
|
|
|
|
It is important here to call the [[#tcpsock:settimeout|settimeout]] method ''before'' calling this method.
|
|
|
|
Since the <code>v0.8.8</code> release, this method no longer automatically closes the current connection when the read timeout error happens. For other connection errors, this method always automatically closes the connection.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== tcpsock:receiveany ==
|
|
|
|
'''syntax:''' ''data, err = tcpsock:receiveany(max)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns any data received by the connected socket, at most <code>max</code> bytes.
|
|
|
|
This method is a synchronous operation just like the [[#tcpsock:send|send]] method and is 100% nonblocking.
|
|
|
|
In case of success, it returns the data received; in case of error, it returns <code>nil</code> with a string describing the error.
|
|
|
|
If the received data is more than this size, this method will return with exactly this size of data.
|
|
The remaining data in the underlying receive buffer could be returned in the next reading operation.
|
|
|
|
Timeout for the reading operation is controlled by the [[#lua_socket_read_timeout|lua_socket_read_timeout]] config directive and the [[#tcpsock:settimeouts|settimeouts]] method. And the latter takes priority. For example:
|
|
|
|
<geshi lang="lua">
|
|
sock:settimeouts(1000, 1000, 1000) -- one second timeout for connect/read/write
|
|
local data, err = sock:receiveany(10 * 1024) -- read any data, at most 10K
|
|
if not data then
|
|
ngx.say("failed to read any data: ", err)
|
|
return
|
|
end
|
|
ngx.say("successfully read: ", data)
|
|
</geshi>
|
|
|
|
This method doesn't automatically close the current connection when the read timeout error occurs. For other connection errors, this method always automatically closes the connection.
|
|
|
|
This feature was first introduced in the <code>v0.10.14</code> release.
|
|
|
|
== tcpsock:receiveuntil ==
|
|
|
|
'''syntax:''' ''iterator = tcpsock:receiveuntil(pattern, options?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
This method returns an iterator Lua function that can be called to read the data stream until it sees the specified pattern or an error occurs.
|
|
|
|
Here is an example for using this method to read a data stream with the boundary sequence <code>--abcedhb</code>:
|
|
|
|
<geshi lang="lua">
|
|
local reader = sock:receiveuntil("\r\n--abcedhb")
|
|
local data, err, partial = reader()
|
|
if not data then
|
|
ngx.say("failed to read the data stream: ", err)
|
|
end
|
|
ngx.say("read the data stream: ", data)
|
|
</geshi>
|
|
|
|
When called without any argument, the iterator function returns the received data right ''before'' the specified pattern string in the incoming data stream. So for the example above, if the incoming data stream is <code>'hello, world! -agentzh\r\n--abcedhb blah blah'</code>, then the string <code>'hello, world! -agentzh'</code> will be returned.
|
|
|
|
In case of error, the iterator function will return <code>nil</code> along with a string describing the error and the partial data bytes that have been read so far.
|
|
|
|
The iterator function can be called multiple times and can be mixed safely with other cosocket method calls or other iterator function calls.
|
|
|
|
The iterator function behaves differently (i.e., like a real iterator) when it is called with a <code>size</code> argument. That is, it will read that <code>size</code> of data on each invocation and will return <code>nil</code> at the last invocation (either sees the boundary pattern or meets an error). For the last successful invocation of the iterator function, the <code>err</code> return value will be <code>nil</code> too. The iterator function will be reset after the last successful invocation that returns <code>nil</code> data and <code>nil</code> error. Consider the following example:
|
|
|
|
<geshi lang="lua">
|
|
local reader = sock:receiveuntil("\r\n--abcedhb")
|
|
|
|
while true do
|
|
local data, err, partial = reader(4)
|
|
if not data then
|
|
if err then
|
|
ngx.say("failed to read the data stream: ", err)
|
|
break
|
|
end
|
|
|
|
ngx.say("read done")
|
|
break
|
|
end
|
|
ngx.say("read chunk: [", data, "]")
|
|
end
|
|
</geshi>
|
|
|
|
Then for the incoming data stream <code>'hello, world! -agentzh\r\n--abcedhb blah blah'</code>, we shall get the following output from the sample code above:
|
|
|
|
<geshi lang="text">
|
|
read chunk: [hell]
|
|
read chunk: [o, w]
|
|
read chunk: [orld]
|
|
read chunk: [! -a]
|
|
read chunk: [gent]
|
|
read chunk: [zh]
|
|
read done
|
|
</geshi>
|
|
|
|
Note that, the actual data returned ''might'' be a little longer than the size limit specified by the <code>size</code> argument when the boundary pattern has ambiguity for streaming parsing. Near the boundary of the data stream, the data string actually returned could also be shorter than the size limit.
|
|
|
|
Timeout for the iterator function's reading operation is controlled by the [[#lua_socket_read_timeout|lua_socket_read_timeout]] config directive and the [[#tcpsock:settimeout|settimeout]] method. And the latter takes priority. For example:
|
|
|
|
<geshi lang="lua">
|
|
local readline = sock:receiveuntil("\r\n")
|
|
|
|
sock:settimeout(1000) -- one second timeout
|
|
line, err, partial = readline()
|
|
if not line then
|
|
ngx.say("failed to read a line: ", err)
|
|
return
|
|
end
|
|
ngx.say("successfully read a line: ", line)
|
|
</geshi>
|
|
|
|
It is important here to call the [[#tcpsock:settimeout|settimeout]] method ''before'' calling the iterator function (note that the <code>receiveuntil</code> call is irrelevant here).
|
|
|
|
As from the <code>v0.5.1</code> release, this method also takes an optional <code>options</code> table argument to control the behavior. The following options are supported:
|
|
|
|
* <code>inclusive</code>
|
|
|
|
The <code>inclusive</code> takes a boolean value to control whether to include the pattern string in the returned data string. Default to <code>false</code>. For example,
|
|
|
|
<geshi lang="lua">
|
|
local reader = tcpsock:receiveuntil("_END_", { inclusive = true })
|
|
local data = reader()
|
|
ngx.say(data)
|
|
</geshi>
|
|
|
|
Then for the input data stream <code>"hello world _END_ blah blah blah"</code>, then the example above will output <code>hello world _END_</code>, including the pattern string <code>_END_</code> itself.
|
|
|
|
Since the <code>v0.8.8</code> release, this method no longer automatically closes the current connection when the read timeout error happens. For other connection errors, this method always automatically closes the connection.
|
|
|
|
This method was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== tcpsock:close ==
|
|
|
|
'''syntax:''' ''ok, err = tcpsock:close()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Closes the current TCP or stream unix domain socket. It returns the <code>1</code> in case of success and returns <code>nil</code> with a string describing the error otherwise.
|
|
|
|
Note that there is no need to call this method on socket objects that have invoked the [[#tcpsock:setkeepalive|setkeepalive]] method because the socket object is already closed (and the current connection is saved into the built-in connection pool).
|
|
|
|
Socket objects that have not invoked this method (and associated connections) will be closed when the socket object is released by the Lua GC (Garbage Collector) or the current client HTTP request finishes processing.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== tcpsock:settimeout ==
|
|
|
|
'''syntax:''' ''tcpsock:settimeout(time)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Set the timeout value in milliseconds for subsequent socket operations ([[#tcpsock:connect|connect]], [[#tcpsock:receive|receive]], and iterators returned from [[#tcpsock:receiveuntil|receiveuntil]]).
|
|
|
|
Settings done by this method take priority over those specified via config directives (i.e. [[#lua_socket_connect_timeout|lua_socket_connect_timeout]], [[#lua_socket_send_timeout|lua_socket_send_timeout]], and [[#lua_socket_read_timeout|lua_socket_read_timeout]]).
|
|
|
|
Note that this method does ''not'' affect the [[#lua_socket_keepalive_timeout|lua_socket_keepalive_timeout]] setting; the <code>timeout</code> argument to the [[#tcpsock:setkeepalive|setkeepalive]] method should be used for this purpose instead.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== tcpsock:settimeouts ==
|
|
|
|
'''syntax:''' ''tcpsock:settimeouts(connect_timeout, send_timeout, read_timeout)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Respectively sets the connect, send, and read timeout thresholds (in milliseconds) for subsequent socket
|
|
operations ([[#tcpsock:connect|connect]], [[#tcpsock:send|send]], [[#tcpsock:receive|receive]], and iterators returned from [[#tcpsock:receiveuntil|receiveuntil]]).
|
|
|
|
Settings done by this method take priority over those specified via config directives (i.e. [[#lua_socket_connect_timeout|lua_socket_connect_timeout]], [[#lua_socket_send_timeout|lua_socket_send_timeout]], and [[#lua_socket_read_timeout|lua_socket_read_timeout]]).
|
|
|
|
It is recommended to use [[#tcpsock:settimeouts|settimeouts]] instead of [[#tcpsock:settimeout|settimeout]].
|
|
|
|
Note that this method does ''not'' affect the [[#lua_socket_keepalive_timeout|lua_socket_keepalive_timeout]] setting; the <code>timeout</code> argument to the [[#tcpsock:setkeepalive|setkeepalive]] method should be used for this purpose instead.
|
|
|
|
This feature was first introduced in the <code>v0.10.7</code> release.
|
|
|
|
== tcpsock:setoption ==
|
|
|
|
'''syntax:''' ''ok, err = tcpsock:setoption(option, value?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
This function is added for [http://w3.impa.br/~diego/software/luasocket/tcp.html LuaSocket] API compatibility and does nothing for now. Its functionality is implemented <code>v0.10.18</code>.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
In case of success, it returns <code>true</code>. Otherwise, it returns nil and a string describing the error.
|
|
|
|
The <code>option</code> is a string with the option name, and the value depends on the option being set:
|
|
|
|
* <code>keepalive</code>
|
|
|
|
: Setting this option to true enables sending of keep-alive messages on
|
|
: connection-oriented sockets. Make sure the <code>connect</code> function
|
|
: had been called before, for example,
|
|
|
|
<geshi lang="lua">
|
|
local ok, err = tcpsock:setoption("keepalive", true)
|
|
if not ok then
|
|
ngx.say("setoption keepalive failed: ", err)
|
|
end
|
|
</geshi>
|
|
* <code>reuseaddr</code>
|
|
|
|
: Enabling this option indicates that the rules used in validating addresses
|
|
: supplied in a call to bind should allow reuse of local addresses. Make sure
|
|
: the <code>connect</code> function had been called before, for example,
|
|
|
|
<geshi lang="lua">
|
|
local ok, err = tcpsock:setoption("reuseaddr", 0)
|
|
if not ok then
|
|
ngx.say("setoption reuseaddr failed: ", err)
|
|
end
|
|
</geshi>
|
|
* <code>tcp-nodelay</code>
|
|
|
|
: Setting this option to true disables the Nagle's algorithm for the connection.
|
|
: Make sure the <code>connect</code> function had been called before, for example,
|
|
|
|
<geshi lang="lua">
|
|
local ok, err = tcpsock:setoption("tcp-nodelay", true)
|
|
if not ok then
|
|
ngx.say("setoption tcp-nodelay failed: ", err)
|
|
end
|
|
</geshi>
|
|
* <code>sndbuf</code>
|
|
|
|
: Sets the maximum socket send buffer in bytes. The kernel doubles this value
|
|
: (to allow space for bookkeeping overhead) when it is set using setsockopt().
|
|
: Make sure the <code>connect</code> function had been called before, for example,
|
|
|
|
<geshi lang="lua">
|
|
local ok, err = tcpsock:setoption("sndbuf", 1024 * 10)
|
|
if not ok then
|
|
ngx.say("setoption sndbuf failed: ", err)
|
|
end
|
|
</geshi>
|
|
* <code>rcvbuf</code>
|
|
|
|
: Sets the maximum socket receive buffer in bytes. The kernel doubles this value
|
|
: (to allow space for bookkeeping overhead) when it is set using setsockopt. Make
|
|
: sure the <code>connect</code> function had been called before, for example,
|
|
|
|
<geshi lang="lua">
|
|
local ok, err = tcpsock:setoption("rcvbuf", 1024 * 10)
|
|
if not ok then
|
|
ngx.say("setoption rcvbuf failed: ", err)
|
|
end
|
|
</geshi>
|
|
|
|
NOTE: Once the option is set, it will become effective until the connection is closed. If you know the connection is from the connection pool and all the in-pool connections already have called the setoption() method with the desired socket option state, then you can just skip calling setoption() again to avoid the overhead of repeated calls, for example,
|
|
|
|
<geshi lang="lua">
|
|
local count, err = tcpsock:getreusedtimes()
|
|
if not count then
|
|
ngx.say("getreusedtimes failed: ", err)
|
|
return
|
|
end
|
|
|
|
if count == 0 then
|
|
local ok, err = tcpsock:setoption("rcvbuf", 1024 * 10)
|
|
if not ok then
|
|
ngx.say("setoption rcvbuf failed: ", err)
|
|
return
|
|
end
|
|
end
|
|
</geshi>
|
|
|
|
These options described above are supported in <code>v0.10.18</code>, and more options will be implemented in future.
|
|
|
|
== tcpsock:setkeepalive ==
|
|
|
|
'''syntax:''' ''ok, err = tcpsock:setkeepalive(timeout?, size?)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Puts the current socket's connection immediately into the cosocket built-in connection pool and keep it alive until other [[#tcpsock:connect|connect]] method calls request it or the associated maximal idle timeout is expired.
|
|
|
|
The first optional argument, <code>timeout</code>, can be used to specify the maximal idle timeout (in milliseconds) for the current connection. If omitted, the default setting in the [[#lua_socket_keepalive_timeout|lua_socket_keepalive_timeout]] config directive will be used. If the <code>0</code> value is given, then the timeout interval is unlimited.
|
|
|
|
The second optional argument <code>size</code> is considered deprecated since
|
|
the <code>v0.10.14</code> release of this module, in favor of the
|
|
<code>pool_size</code> option of the [[#tcpsock:connect|connect]] method.
|
|
Since the <code>v0.10.14</code> release, this option will only take effect if
|
|
the call to [[#tcpsock:connect|connect]] did not already create a connection
|
|
pool.
|
|
When this option takes effect (no connection pool was previously created by
|
|
[[#tcpsock:connect|connect]]), it will specify the size of the connection pool,
|
|
and create it.
|
|
If omitted (and no pool was previously created), the default size is the value
|
|
of the [[#lua_socket_pool_size|lua_socket_pool_size]] directive.
|
|
The connection pool holds up to <code>size</code> alive connections ready to be
|
|
reused by subsequent calls to [[#tcpsock:connect|connect]], but note that there
|
|
is no upper limit to the total number of opened connections outside of the
|
|
pool.
|
|
When the connection pool would exceed its size limit, the least recently used
|
|
(kept-alive) connection already in the pool will be closed to make room for
|
|
the current connection.
|
|
Note that the cosocket connection pool is per Nginx worker process rather
|
|
than per Nginx server instance, so the size limit specified here also applies
|
|
to every single Nginx worker process. Also note that the size of the connection
|
|
pool cannot be changed once it has been created.
|
|
If you need to restrict the total number of opened connections, specify both
|
|
the <code>pool_size</code> and <code>backlog</code> option in the call to
|
|
[[#tcpsock:connect|connect]].
|
|
|
|
In case of success, this method returns <code>1</code>; otherwise, it returns <code>nil</code> and a string describing the error.
|
|
|
|
When the system receive buffer for the current connection has unread data, then this method will return the "connection in dubious state" error message (as the second return value) because the previous session has unread data left behind for the next session and the connection is not safe to be reused.
|
|
|
|
This method also makes the current cosocket object enter the "closed" state, so there is no need to manually call the [[#tcpsock:close|close]] method on it afterwards.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== tcpsock:getreusedtimes ==
|
|
|
|
'''syntax:''' ''count, err = tcpsock:getreusedtimes()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
This method returns the (successfully) reused times for the current connection. In case of error, it returns <code>nil</code> and a string describing the error.
|
|
|
|
If the current connection does not come from the built-in connection pool, then this method always returns <code>0</code>, that is, the connection has never been reused (yet). If the connection comes from the connection pool, then the return value is always non-zero. So this method can also be used to determine if the current connection comes from the pool.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== ngx.socket.connect ==
|
|
|
|
'''syntax:''' ''tcpsock, err = ngx.socket.connect(host, port)''
|
|
|
|
'''syntax:''' ''tcpsock, err = ngx.socket.connect("unix:/path/to/unix-domain.socket")''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*''
|
|
|
|
This function is a shortcut for combining [[#ngx.socket.tcp|ngx.socket.tcp()]] and the [[#tcpsock:connect|connect()]] method call in a single operation. It is actually implemented like this:
|
|
|
|
<geshi lang="lua">
|
|
local sock = ngx.socket.tcp()
|
|
local ok, err = sock:connect(...)
|
|
if not ok then
|
|
return nil, err
|
|
end
|
|
return sock
|
|
</geshi>
|
|
|
|
There is no way to use the [[#tcpsock:settimeout|settimeout]] method to specify connecting timeout for this method and the [[#lua_socket_connect_timeout|lua_socket_connect_timeout]] directive must be set at configure time instead.
|
|
|
|
This feature was first introduced in the <code>v0.5.0rc1</code> release.
|
|
|
|
== ngx.get_phase ==
|
|
|
|
'''syntax:''' ''str = ngx.get_phase()''
|
|
|
|
'''context:''' ''init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Retrieves the current running phase name. Possible return values are
|
|
|
|
* <code>init</code>
|
|
: for the context of [[#init_by_lua|init_by_lua*]].
|
|
* <code>init_worker</code>
|
|
: for the context of [[#init_worker_by_lua|init_worker_by_lua*]].
|
|
* <code>ssl_cert</code>
|
|
: for the context of [[#ssl_certificate_by_lua_block|ssl_certificate_by_lua*]].
|
|
* <code>ssl_session_fetch</code>
|
|
: for the context of [[#ssl_session_fetch_by_lua_block|ssl_session_fetch_by_lua*]].
|
|
* <code>ssl_session_store</code>
|
|
: for the context of [[#ssl_session_store_by_lua_block|ssl_session_store_by_lua*]].
|
|
* <code>ssl_client_hello</code>
|
|
: for the context of [[#ssl_client_hello_by_lua_block|ssl_client_hello_by_lua*]].
|
|
* <code>set</code>
|
|
: for the context of [[#set_by_lua|set_by_lua*]].
|
|
* <code>rewrite</code>
|
|
: for the context of [[#rewrite_by_lua|rewrite_by_lua*]].
|
|
* <code>balancer</code>
|
|
: for the context of [[#balancer_by_lua_block|balancer_by_lua*]].
|
|
* <code>access</code>
|
|
: for the context of [[#access_by_lua|access_by_lua*]].
|
|
* <code>content</code>
|
|
: for the context of [[#content_by_lua|content_by_lua*]].
|
|
* <code>header_filter</code>
|
|
: for the context of [[#header_filter_by_lua|header_filter_by_lua*]].
|
|
* <code>body_filter</code>
|
|
: for the context of [[#body_filter_by_lua|body_filter_by_lua*]].
|
|
* <code>log</code>
|
|
: for the context of [[#log_by_lua|log_by_lua*]].
|
|
* <code>timer</code>
|
|
: for the context of user callback functions for [[#ngx.timer.at|ngx.timer.*]].
|
|
* <code>exit_worker</code>
|
|
: for the context of [[#exit_worker_by_lua|exit_worker_by_lua*]].
|
|
|
|
This API was first introduced in the <code>v0.5.10</code> release.
|
|
|
|
== ngx.thread.spawn ==
|
|
|
|
'''syntax:''' ''co = ngx.thread.spawn(func, arg1, arg2, ...)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Spawns a new user "light thread" with the Lua function <code>func</code> as well as those optional arguments <code>arg1</code>, <code>arg2</code>, and etc. Returns a Lua thread (or Lua coroutine) object represents this "light thread".
|
|
|
|
"Light threads" are just a special kind of Lua coroutines that are scheduled by the ngx_lua module.
|
|
|
|
Before <code>ngx.thread.spawn</code> returns, the <code>func</code> will be called with those optional arguments until it returns, aborts with an error, or gets yielded due to I/O operations via the [[#Nginx API for Lua|Nginx API for Lua]] (like [[#tcpsock:receive|tcpsock:receive]]).
|
|
|
|
After <code>ngx.thread.spawn</code> returns, the newly-created "light thread" will keep running asynchronously usually at various I/O events.
|
|
|
|
All the Lua code chunks running by [[#rewrite_by_lua|rewrite_by_lua]], [[#access_by_lua|access_by_lua]], and [[#content_by_lua|content_by_lua]] are in a boilerplate "light thread" created automatically by ngx_lua. Such boilerplate "light thread" are also called "entry threads".
|
|
|
|
By default, the corresponding Nginx handler (e.g., [[#rewrite_by_lua|rewrite_by_lua]] handler) will not terminate until
|
|
|
|
# both the "entry thread" and all the user "light threads" terminates,
|
|
# a "light thread" (either the "entry thread" or a user "light thread") aborts by calling [[#ngx.exit|ngx.exit]], [[#ngx.exec|ngx.exec]], [[#ngx.redirect|ngx.redirect]], or [[#ngx.req.set_uri|ngx.req.set_uri(uri, true)]], or
|
|
# the "entry thread" terminates with a Lua error.
|
|
|
|
When the user "light thread" terminates with a Lua error, however, it will not abort other running "light threads" like the "entry thread" does.
|
|
|
|
Due to the limitation in the Nginx subrequest model, it is not allowed to abort a running Nginx subrequest in general. So it is also prohibited to abort a running "light thread" that is pending on one ore more Nginx subrequests. You must call [[#ngx.thread.wait|ngx.thread.wait]] to wait for those "light thread" to terminate before quitting the "world". A notable exception here is that you can abort pending subrequests by calling [[#ngx.exit|ngx.exit]] with and only with the status code <code>ngx.ERROR</code> (-1), <code>408</code>, <code>444</code>, or <code>499</code>.
|
|
|
|
The "light threads" are not scheduled in a pre-emptive way. In other words, no time-slicing is performed automatically. A "light thread" will keep running exclusively on the CPU until
|
|
|
|
# a (nonblocking) I/O operation cannot be completed in a single run,
|
|
# it calls [[#coroutine.yield|coroutine.yield]] to actively give up execution, or
|
|
# it is aborted by a Lua error or an invocation of [[#ngx.exit|ngx.exit]], [[#ngx.exec|ngx.exec]], [[#ngx.redirect|ngx.redirect]], or [[#ngx.req.set_uri|ngx.req.set_uri(uri, true)]].
|
|
|
|
For the first two cases, the "light thread" will usually be resumed later by the ngx_lua scheduler unless a "stop-the-world" event happens.
|
|
|
|
User "light threads" can create "light threads" themselves. And normal user coroutines created by [[#coroutine.create|coroutine.create]] can also create "light threads". The coroutine (be it a normal Lua coroutine or a "light thread") that directly spawns the "light thread" is called the "parent coroutine" for the "light thread" newly spawned.
|
|
|
|
The "parent coroutine" can call [[#ngx.thread.wait|ngx.thread.wait]] to wait on the termination of its child "light thread".
|
|
|
|
You can call coroutine.status() and coroutine.yield() on the "light thread" coroutines.
|
|
|
|
The status of the "light thread" coroutine can be "zombie" if
|
|
|
|
# the current "light thread" already terminates (either successfully or with an error),
|
|
# its parent coroutine is still alive, and
|
|
# its parent coroutine is not waiting on it with [[#ngx.thread.wait|ngx.thread.wait]].
|
|
|
|
The following example demonstrates the use of coroutine.yield() in the "light thread" coroutines
|
|
to do manual time-slicing:
|
|
|
|
<geshi lang="lua">
|
|
local yield = coroutine.yield
|
|
|
|
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")
|
|
</geshi>
|
|
|
|
Then it will generate the output
|
|
|
|
<geshi lang="text">
|
|
0
|
|
1
|
|
f 1
|
|
2
|
|
f 2
|
|
3
|
|
f 3
|
|
4
|
|
</geshi>
|
|
|
|
"Light threads" are mostly useful for making concurrent upstream requests in a single Nginx request handler, much like a generalized version of [[#ngx.location.capture_multi|ngx.location.capture_multi]] that can work with all the [[#Nginx API for Lua|Nginx API for Lua]]. The following example demonstrates parallel requests to MySQL, Memcached, and upstream HTTP services in a single Lua handler, and outputting the results in the order that they actually return (similar to Facebook's BigPipe model):
|
|
|
|
<geshi lang="lua">
|
|
-- query mysql, memcached, and a remote http service at the same time,
|
|
-- output the results in the order that they
|
|
-- actually return the results.
|
|
|
|
local mysql = require "resty.mysql"
|
|
local memcached = require "resty.memcached"
|
|
|
|
local function query_mysql()
|
|
local db = mysql:new()
|
|
db:connect{
|
|
host = "127.0.0.1",
|
|
port = 3306,
|
|
database = "test",
|
|
user = "monty",
|
|
password = "mypass"
|
|
}
|
|
local res, err, errno, sqlstate =
|
|
db:query("select * from cats order by id asc")
|
|
db:set_keepalive(0, 100)
|
|
ngx.say("mysql done: ", cjson.encode(res))
|
|
end
|
|
|
|
local function query_memcached()
|
|
local memc = memcached:new()
|
|
memc:connect("127.0.0.1", 11211)
|
|
local res, err = memc:get("some_key")
|
|
ngx.say("memcached done: ", res)
|
|
end
|
|
|
|
local function query_http()
|
|
local res = ngx.location.capture("/my-http-proxy")
|
|
ngx.say("http done: ", res.body)
|
|
end
|
|
|
|
ngx.thread.spawn(query_mysql) -- create thread 1
|
|
ngx.thread.spawn(query_memcached) -- create thread 2
|
|
ngx.thread.spawn(query_http) -- create thread 3
|
|
</geshi>
|
|
|
|
This API was first enabled in the <code>v0.7.0</code> release.
|
|
|
|
== ngx.thread.wait ==
|
|
|
|
'''syntax:''' ''ok, res1, res2, ... = ngx.thread.wait(thread1, thread2, ...)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Waits on one or more child "light threads" and returns the results of the first "light thread" that terminates (either successfully or with an error).
|
|
|
|
The arguments <code>thread1</code>, <code>thread2</code>, and etc are the Lua thread objects returned by earlier calls of [[#ngx.thread.spawn|ngx.thread.spawn]].
|
|
|
|
The return values have exactly the same meaning as [[#coroutine.resume|coroutine.resume]], that is, the first value returned is a boolean value indicating whether the "light thread" terminates successfully or not, and subsequent values returned are the return values of the user Lua function that was used to spawn the "light thread" (in case of success) or the error object (in case of failure).
|
|
|
|
Only the direct "parent coroutine" can wait on its child "light thread", otherwise a Lua exception will be raised.
|
|
|
|
The following example demonstrates the use of <code>ngx.thread.wait</code> and [[#ngx.location.capture|ngx.location.capture]] to emulate [[#ngx.location.capture_multi|ngx.location.capture_multi]]:
|
|
|
|
<geshi lang="lua">
|
|
local capture = ngx.location.capture
|
|
local spawn = ngx.thread.spawn
|
|
local wait = ngx.thread.wait
|
|
local say = ngx.say
|
|
|
|
local function fetch(uri)
|
|
return capture(uri)
|
|
end
|
|
|
|
local threads = {
|
|
spawn(fetch, "/foo"),
|
|
spawn(fetch, "/bar"),
|
|
spawn(fetch, "/baz")
|
|
}
|
|
|
|
for i = 1, #threads do
|
|
local ok, res = wait(threads[i])
|
|
if not ok then
|
|
say(i, ": failed to run: ", res)
|
|
else
|
|
say(i, ": status: ", res.status)
|
|
say(i, ": body: ", res.body)
|
|
end
|
|
end
|
|
</geshi>
|
|
|
|
Here it essentially implements the "wait all" model.
|
|
|
|
And below is an example demonstrating the "wait any" model:
|
|
|
|
<geshi lang="lua">
|
|
function f()
|
|
ngx.sleep(0.2)
|
|
ngx.say("f: hello")
|
|
return "f done"
|
|
end
|
|
|
|
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))
|
|
|
|
ok, res = ngx.thread.wait(tf, tg)
|
|
if not ok then
|
|
ngx.say("failed to wait: ", res)
|
|
return
|
|
end
|
|
|
|
ngx.say("res: ", res)
|
|
|
|
-- stop the "world", aborting other running threads
|
|
ngx.exit(ngx.OK)
|
|
</geshi>
|
|
|
|
And it will generate the following output:
|
|
|
|
<geshi lang="text">
|
|
f thread created: running
|
|
g thread created: running
|
|
g: hello
|
|
res: g done
|
|
</geshi>
|
|
|
|
This API was first enabled in the <code>v0.7.0</code> release.
|
|
|
|
== ngx.thread.kill ==
|
|
|
|
'''syntax:''' ''ok, err = ngx.thread.kill(thread)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Kills a running "light thread" created by [[#ngx.thread.spawn|ngx.thread.spawn]]. Returns a true value when successful or <code>nil</code> and a string describing the error otherwise.
|
|
|
|
According to the current implementation, only the parent coroutine (or "light thread") can kill a thread. Also, a running "light thread" with pending Nginx subrequests (initiated by [[#ngx.location.capture|ngx.location.capture]] for example) cannot be killed due to a limitation in the Nginx core.
|
|
|
|
This API was first enabled in the <code>v0.9.9</code> release.
|
|
|
|
== ngx.on_abort ==
|
|
|
|
'''syntax:''' ''ok, err = ngx.on_abort(callback)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
Registers a user Lua function as the callback which gets called automatically when the client closes the (downstream) connection prematurely.
|
|
|
|
Returns <code>1</code> if the callback is registered successfully or returns <code>nil</code> and a string describing the error otherwise.
|
|
|
|
All the [[#Nginx API for Lua|Nginx API for Lua]] can be used in the callback function because the function is run in a special "light thread", just as those "light threads" created by [[#ngx.thread.spawn|ngx.thread.spawn]].
|
|
|
|
The callback function can decide what to do with the client abortion event all by itself. For example, it can simply ignore the event by doing nothing and the current Lua request handler will continue executing without interruptions. And the callback function can also decide to terminate everything by calling [[#ngx.exit|ngx.exit]], for example,
|
|
|
|
<geshi lang="lua">
|
|
local function my_cleanup()
|
|
-- custom cleanup work goes here, like cancelling a pending DB transaction
|
|
|
|
-- now abort all the "light threads" running in the current request handler
|
|
ngx.exit(499)
|
|
end
|
|
|
|
local ok, err = ngx.on_abort(my_cleanup)
|
|
if not ok then
|
|
ngx.log(ngx.ERR, "failed to register the on_abort callback: ", err)
|
|
ngx.exit(500)
|
|
end
|
|
</geshi>
|
|
|
|
When [[#lua_check_client_abort|lua_check_client_abort]] is set to <code>off</code> (which is the default), then this function call will always return the error message "lua_check_client_abort is off".
|
|
|
|
According to the current implementation, this function can only be called once in a single request handler; subsequent calls will return the error message "duplicate call".
|
|
|
|
This API was first introduced in the <code>v0.7.4</code> release.
|
|
|
|
See also [[#lua_check_client_abort|lua_check_client_abort]].
|
|
|
|
== ngx.timer.at ==
|
|
|
|
'''syntax:''' ''hdl, err = ngx.timer.at(delay, callback, user_arg1, user_arg2, ...)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Creates an Nginx timer with a user callback function as well as optional user arguments.
|
|
|
|
The first argument, <code>delay</code>, specifies the delay for the timer,
|
|
in seconds. One can specify fractional seconds like <code>0.001</code> to mean 1
|
|
millisecond here. <code>0</code> delay can also be specified, in which case the
|
|
timer will immediately expire when the current handler yields
|
|
execution.
|
|
|
|
The second argument, <code>callback</code>, can
|
|
be any Lua function, which will be invoked later in a background
|
|
"light thread" after the delay specified. The user callback will be
|
|
called automatically by the Nginx core with the arguments <code>premature</code>,
|
|
<code>user_arg1</code>, <code>user_arg2</code>, and etc, where the <code>premature</code>
|
|
argument takes a boolean value indicating whether it is a premature timer
|
|
expiration or not, and <code>user_arg1</code>, <code>user_arg2</code>, and etc, are
|
|
those (extra) user arguments specified when calling <code>ngx.timer.at</code>
|
|
as the remaining arguments.
|
|
|
|
Premature timer expiration happens when the Nginx worker process is
|
|
trying to shut down, as in an Nginx configuration reload triggered by
|
|
the <code>HUP</code> signal or in an Nginx server shutdown. When the Nginx worker
|
|
is trying to shut down, one can no longer call <code>ngx.timer.at</code> to
|
|
create new timers with nonzero delays and in that case <code>ngx.timer.at</code> will return a "conditional false" value and
|
|
a string describing the error, that is, "process exiting".
|
|
|
|
Starting from the <code>v0.9.3</code> release, it is allowed to create zero-delay timers even when the Nginx worker process starts shutting down.
|
|
|
|
When a timer expires, the user Lua code in the timer callback is
|
|
running in a "light thread" detached completely from the original
|
|
request creating the timer. So objects with the same lifetime as the
|
|
request creating them, like [[#ngx.socket.tcp|cosockets]], cannot be shared between the
|
|
original request and the timer user callback function.
|
|
|
|
Here is a simple example:
|
|
|
|
<geshi lang="nginx">
|
|
location / {
|
|
...
|
|
log_by_lua_block {
|
|
local function push_data(premature, uri, args, status)
|
|
-- push the data uri, args, and status to the remote
|
|
-- via ngx.socket.tcp or ngx.socket.udp
|
|
-- (one may want to buffer the data in Lua a bit to
|
|
-- save I/O operations)
|
|
end
|
|
local ok, err = ngx.timer.at(0, push_data,
|
|
ngx.var.uri, ngx.var.args, ngx.header.status)
|
|
if not ok then
|
|
ngx.log(ngx.ERR, "failed to create timer: ", err)
|
|
return
|
|
end
|
|
|
|
-- other job in log_by_lua_block
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
One can also create infinite re-occurring timers, for instance, a timer getting triggered every <code>5</code> seconds, by calling <code>ngx.timer.at</code> recursively in the timer callback function. Here is such an example,
|
|
|
|
<geshi lang="lua">
|
|
local delay = 5
|
|
local handler
|
|
handler = function (premature)
|
|
-- do some routine job in Lua just like a cron job
|
|
if premature then
|
|
return
|
|
end
|
|
local ok, err = ngx.timer.at(delay, handler)
|
|
if not ok then
|
|
ngx.log(ngx.ERR, "failed to create the timer: ", err)
|
|
return
|
|
end
|
|
|
|
-- do something in timer
|
|
end
|
|
|
|
local ok, err = ngx.timer.at(delay, handler)
|
|
if not ok then
|
|
ngx.log(ngx.ERR, "failed to create the timer: ", err)
|
|
return
|
|
end
|
|
|
|
-- do other jobs
|
|
</geshi>
|
|
|
|
It is recommended, however, to use the [[#ngx.timer.every|ngx.timer.every]] API function
|
|
instead for creating recurring timers since it is more robust.
|
|
|
|
Because timer callbacks run in the background and their running time
|
|
will not add to any client request's response time, they can easily
|
|
accumulate in the server and exhaust system resources due to either
|
|
Lua programming mistakes or just too much client traffic. To prevent
|
|
extreme consequences like crashing the Nginx server, there are
|
|
built-in limitations on both the number of "pending timers" and the
|
|
number of "running timers" in an Nginx worker process. The "pending
|
|
timers" here mean timers that have not yet been expired and "running
|
|
timers" are those whose user callbacks are currently running.
|
|
|
|
The maximal number of pending timers allowed in an Nginx
|
|
worker is controlled by the [[#lua_max_pending_timers|lua_max_pending_timers]]
|
|
directive. The maximal number of running timers is controlled by the
|
|
[[#lua_max_running_timers|lua_max_running_timers]] directive.
|
|
|
|
According to the current implementation, each "running timer" will
|
|
take one (fake) connection record from the global connection record
|
|
list configured by the standard [[EventsModule#worker_connections|worker_connections]] directive in
|
|
<code>nginx.conf</code>. So ensure that the
|
|
[[EventsModule#worker_connections|worker_connections]] directive is set to
|
|
a large enough value that takes into account both the real connections
|
|
and fake connections required by timer callbacks (as limited by the
|
|
[[#lua_max_running_timers|lua_max_running_timers]] directive).
|
|
|
|
A lot of the Lua APIs for Nginx are enabled in the context of the timer
|
|
callbacks, like stream/datagram cosockets ([[#ngx.socket.tcp|ngx.socket.tcp]] and [[#ngx.socket.udp|ngx.socket.udp]]), shared
|
|
memory dictionaries ([[#ngx.shared.DICT|ngx.shared.DICT]]), user coroutines ([[#coroutine.create|coroutine.*]]),
|
|
user "light threads" ([[#ngx.thread.spawn|ngx.thread.*]]), [[#ngx.exit|ngx.exit]], [[#ngx.now|ngx.now]]/[[#ngx.time|ngx.time]],
|
|
[[#ngx.md5|ngx.md5]]/[[#ngx.sha1_bin|ngx.sha1_bin]], are all allowed. But the subrequest API (like
|
|
[[#ngx.location.capture|ngx.location.capture]]), the [[#ngx.req.start_time|ngx.req.*]] API, the downstream output API
|
|
(like [[#ngx.say|ngx.say]], [[#ngx.print|ngx.print]], and [[#ngx.flush|ngx.flush]]) are explicitly disabled in
|
|
this context.
|
|
|
|
You must notice that each timer will be based on a fake request (this fake request is also based on a fake connection). Because Nginx's memory release is based on the connection closure, if you run a lot of APIs that apply for memory resources in a timer, such as [[#tcpsock:connect|tcpsock:connect]], will cause the accumulation of memory resources. So it is recommended to create a new timer after running several times to release memory resources.
|
|
|
|
You can pass most of the standard Lua values (nils, booleans, numbers, strings, tables, closures, file handles, and etc) into the timer callback, either explicitly as user arguments or implicitly as upvalues for the callback closure. There are several exceptions, however: you ''cannot'' pass any thread objects returned by [[#coroutine.create|coroutine.create]] and [[#ngx.thread.spawn|ngx.thread.spawn]] or any cosocket objects returned by [[#ngx.socket.tcp|ngx.socket.tcp]], [[#ngx.socket.udp|ngx.socket.udp]], and [[#ngx.req.socket|ngx.req.socket]] because these objects' lifetime is bound to the request context creating them while the timer callback is detached from the creating request's context (by design) and runs in its own (fake) request context. If you try to share the thread or cosocket objects across the boundary of the creating request, then you will get the "no co ctx found" error (for threads) or "bad request" (for cosockets). It is fine, however, to create all these objects inside your timer callback.
|
|
|
|
Please note that the timer Lua handler has its own copy of the `ngx.ctx` magic
|
|
table. It won't share the same `ngx.ctx` with the Lua handler creating the timer.
|
|
If you need to pass data from the timer creator to the timer handler, please
|
|
use the extra parameters of `ngx.timer.at()`.
|
|
|
|
This API was first introduced in the <code>v0.8.0</code> release.
|
|
|
|
== ngx.timer.every ==
|
|
|
|
'''syntax:''' ''hdl, err = ngx.timer.every(delay, callback, user_arg1, user_arg2, ...)''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Similar to the [[#ngx.timer.at|ngx.timer.at]] API function, but
|
|
|
|
# <code>delay</code> ''cannot'' be zero,
|
|
# timer will be created every <code>delay</code> seconds until the current Nginx worker process starts exiting.
|
|
|
|
Like [[#ngx.timer.at|ngx.timer.at]], the <code>callback</code> argument will be called
|
|
automatically with the arguments <code>premature</code>, <code>user_arg1</code>, <code>user_arg2</code>, etc.
|
|
|
|
When success, returns a "conditional true" value (but not a <code>true</code>). Otherwise, returns a "conditional false" value and a string describing the error.
|
|
|
|
This API also respect the [[#lua_max_pending_timers|lua_max_pending_timers]] and [[#lua_max_running_timers|lua_max_running_timers]].
|
|
|
|
This API was first introduced in the <code>v0.10.9</code> release.
|
|
|
|
== ngx.timer.running_count ==
|
|
|
|
'''syntax:''' ''count = ngx.timer.running_count()''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns the number of timers currently running.
|
|
|
|
This directive was first introduced in the <code>v0.9.20</code> release.
|
|
|
|
== ngx.timer.pending_count ==
|
|
|
|
'''syntax:''' ''count = ngx.timer.pending_count()''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Returns the number of pending timers.
|
|
|
|
This directive was first introduced in the <code>v0.9.20</code> release.
|
|
|
|
== ngx.config.subsystem ==
|
|
|
|
'''syntax:''' ''subsystem = ngx.config.subsystem''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_by_lua*, init_worker_by_lua*, exit_worker_by_lua*''
|
|
|
|
This string field indicates the Nginx subsystem the current Lua environment is based on. For this module, this field always takes the string value <code>"http"</code>. For
|
|
[https://github.com/openresty/stream-lua-nginx-module#readme ngx_stream_lua_module], however, this field takes the value <code>"stream"</code>.
|
|
|
|
This field was first introduced in the <code>0.10.1</code>.
|
|
|
|
== ngx.config.debug ==
|
|
|
|
'''syntax:''' ''debug = ngx.config.debug''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_by_lua*, init_worker_by_lua*, exit_worker_by_lua*''
|
|
|
|
This boolean field indicates whether the current Nginx is a debug build, i.e., being built by the <code>./configure</code> option <code>--with-debug</code>.
|
|
|
|
This field was first introduced in the <code>0.8.7</code>.
|
|
|
|
== ngx.config.prefix ==
|
|
|
|
'''syntax:''' ''prefix = ngx.config.prefix()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_by_lua*, init_worker_by_lua*, exit_worker_by_lua*''
|
|
|
|
Returns the Nginx server "prefix" path, as determined by the <code>-p</code> command-line option when running the Nginx executable, or the path specified by the <code>--prefix</code> command-line option when building Nginx with the <code>./configure</code> script.
|
|
|
|
This function was first introduced in the <code>0.9.2</code>.
|
|
|
|
== ngx.config.nginx_version ==
|
|
|
|
'''syntax:''' ''ver = ngx.config.nginx_version''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_by_lua*, init_worker_by_lua*, exit_worker_by_lua*''
|
|
|
|
This field take an integral value indicating the version number of the current Nginx core being used. For example, the version number <code>1.4.3</code> results in the Lua number 1004003.
|
|
|
|
This API was first introduced in the <code>0.9.3</code> release.
|
|
|
|
== ngx.config.nginx_configure ==
|
|
|
|
'''syntax:''' ''str = ngx.config.nginx_configure()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_by_lua*''
|
|
|
|
This function returns a string for the Nginx <code>./configure</code> command's arguments string.
|
|
|
|
This API was first introduced in the <code>0.9.5</code> release.
|
|
|
|
== ngx.config.ngx_lua_version ==
|
|
|
|
'''syntax:''' ''ver = ngx.config.ngx_lua_version''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_by_lua*''
|
|
|
|
This field take an integral value indicating the version number of the current <code>ngx_lua</code> module being used. For example, the version number <code>0.9.3</code> results in the Lua number 9003.
|
|
|
|
This API was first introduced in the <code>0.9.3</code> release.
|
|
|
|
== ngx.worker.exiting ==
|
|
|
|
'''syntax:''' ''exiting = ngx.worker.exiting()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_by_lua*, init_worker_by_lua*, exit_worker_by_lua*''
|
|
|
|
This function returns a boolean value indicating whether the current Nginx worker process already starts exiting. Nginx worker process exiting happens on Nginx server quit or configuration reload (aka HUP reload).
|
|
|
|
This API was first introduced in the <code>0.9.3</code> release.
|
|
|
|
== ngx.worker.pid ==
|
|
|
|
'''syntax:''' ''pid = ngx.worker.pid()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_by_lua*, init_worker_by_lua*, exit_worker_by_lua*''
|
|
|
|
This function returns a Lua number for the process ID (PID) of the current Nginx worker process. This API is more efficient than <code>ngx.var.pid</code> and can be used in contexts where the [[#ngx.var.VARIABLE|ngx.var.VARIABLE]] API cannot be used (like [[#init_worker_by_lua|init_worker_by_lua]]).
|
|
|
|
This API was first introduced in the <code>0.9.5</code> release.
|
|
|
|
== ngx.worker.pids ==
|
|
|
|
'''syntax:''' ''pid = ngx.worker.pids()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, exit_worker_by_lua*''
|
|
|
|
This function returns a Lua table for all Nginx worker process ID (PID). Nginx uses channel to send the current worker PID to another worker in the worker process start or restart. So this API can get all current worker PID.
|
|
== ngx.worker.count ==
|
|
|
|
'''syntax:''' ''count = ngx.worker.count()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_by_lua*, init_worker_by_lua*, exit_worker_by_lua*''
|
|
|
|
Returns the total number of the Nginx worker processes (i.e., the value configured
|
|
by the [https://nginx.org/en/docs/ngx_core_module.html#worker_processes worker_processes]
|
|
directive in <code>nginx.conf</code>).
|
|
|
|
This API was first introduced in the <code>0.9.20</code> release.
|
|
|
|
== ngx.worker.id ==
|
|
|
|
'''syntax:''' ''id = ngx.worker.id()''
|
|
|
|
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, init_worker_by_lua*, exit_worker_by_lua*''
|
|
|
|
Returns the ordinal number of the current Nginx worker processes (starting from number 0).
|
|
|
|
So if the total number of workers is <code>N</code>, then this method may return a number between 0
|
|
and <code>N - 1</code> (inclusive).
|
|
|
|
This function returns meaningful values only for Nginx 1.9.1+. With earlier versions of Nginx, it
|
|
always returns <code>nil</code>.
|
|
|
|
See also [[#ngx.worker.count|ngx.worker.count]].
|
|
|
|
This API was first introduced in the <code>0.9.20</code> release.
|
|
|
|
== ngx.semaphore ==
|
|
|
|
'''syntax:''' ''local semaphore = require "ngx.semaphore"''
|
|
|
|
This is a Lua module that implements a classic-style semaphore API for efficient synchronizations among
|
|
different "light threads". Sharing the same semaphore among different "light threads" created in different (request)
|
|
contexts are also supported as long as the "light threads" reside in the same Nginx worker process
|
|
and the [[#lua_code_cache|lua_code_cache]] directive is turned on (which is the default).
|
|
|
|
This Lua module does not ship with this ngx_lua module itself rather it is shipped with
|
|
the
|
|
[https://github.com/openresty/lua-resty-core lua-resty-core] library.
|
|
|
|
Please refer to the [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/semaphore.md documentation]
|
|
for this <code>ngx.semaphore</code> Lua module in [https://github.com/openresty/lua-resty-core lua-resty-core]
|
|
for more details.
|
|
|
|
This feature requires at least ngx_lua <code>v0.10.0</code>.
|
|
|
|
== ngx.balancer ==
|
|
|
|
'''syntax:''' ''local balancer = require "ngx.balancer"''
|
|
|
|
This is a Lua module that provides a Lua API to allow defining completely dynamic load balancers
|
|
in pure Lua.
|
|
|
|
This Lua module does not ship with this ngx_lua module itself rather it is shipped with
|
|
the
|
|
[https://github.com/openresty/lua-resty-core lua-resty-core] library.
|
|
|
|
Please refer to the [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/balancer.md documentation]
|
|
for this <code>ngx.balancer</code> Lua module in [https://github.com/openresty/lua-resty-core lua-resty-core]
|
|
for more details.
|
|
|
|
This feature requires at least ngx_lua <code>v0.10.0</code>.
|
|
|
|
== ngx.ssl ==
|
|
|
|
'''syntax:''' ''local ssl = require "ngx.ssl"''
|
|
|
|
This Lua module provides API functions to control the SSL handshake process in contexts like
|
|
[ssl_certificate_by_lua*](#ssl_certificate_by_lua_block).
|
|
|
|
This Lua module does not ship with this ngx_lua module itself rather it is shipped with
|
|
the
|
|
[https://github.com/openresty/lua-resty-core lua-resty-core] library.
|
|
|
|
Please refer to the [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md documentation]
|
|
for this <code>ngx.ssl</code> Lua module for more details.
|
|
|
|
This feature requires at least ngx_lua <code>v0.10.0</code>.
|
|
|
|
== ngx.ocsp ==
|
|
|
|
'''syntax:''' ''local ocsp = require "ngx.ocsp"''
|
|
|
|
This Lua module provides API to perform OCSP queries, OCSP response validations, and
|
|
OCSP stapling planting.
|
|
|
|
Usually, this module is used together with the [ngx.ssl](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md)
|
|
module in the
|
|
context of [ssl_certificate_by_lua*](#ssl_certificate_by_lua_block).
|
|
|
|
This Lua module does not ship with this ngx_lua module itself rather it is shipped with
|
|
the
|
|
[https://github.com/openresty/lua-resty-core lua-resty-core] library.
|
|
|
|
Please refer to the [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ocsp.md documentation]
|
|
for this <code>ngx.ocsp</code> Lua module for more details.
|
|
|
|
This feature requires at least ngx_lua <code>v0.10.0</code>.
|
|
|
|
== ndk.set_var.DIRECTIVE ==
|
|
|
|
'''syntax:''' ''res = ndk.set_var.DIRECTIVE_NAME''
|
|
|
|
'''context:''' ''init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
This mechanism allows calling other Nginx C modules' directives that are implemented by [https://github.com/simplresty/ngx_devel_kit Nginx Devel Kit] (NDK)'s set_var submodule's <code>ndk_set_var_value</code>.
|
|
|
|
For example, the following [[HttpSetMiscModule]] directives can be invoked this way:
|
|
|
|
* [[HttpSetMiscModule#set_quote_sql_str|set_quote_sql_str]]
|
|
* [[HttpSetMiscModule#set_quote_pgsql_str|set_quote_pgsql_str]]
|
|
* [[HttpSetMiscModule#set_quote_json_str|set_quote_json_str]]
|
|
* [[HttpSetMiscModule#set_unescape_uri|set_unescape_uri]]
|
|
* [[HttpSetMiscModule#set_escape_uri|set_escape_uri]]
|
|
* [[HttpSetMiscModule#set_encode_base32|set_encode_base32]]
|
|
* [[HttpSetMiscModule#set_decode_base32|set_decode_base32]]
|
|
* [[HttpSetMiscModule#set_encode_base64|set_encode_base64]]
|
|
* [[HttpSetMiscModule#set_decode_base64|set_decode_base64]]
|
|
* [[HttpSetMiscModule#set_encode_base64|set_encode_hex]]
|
|
* [[HttpSetMiscModule#set_decode_base64|set_decode_hex]]
|
|
* [[HttpSetMiscModule#set_encode_base64|set_sha1]]
|
|
* [[HttpSetMiscModule#set_decode_base64|set_md5]]
|
|
|
|
For instance,
|
|
|
|
<geshi lang="lua">
|
|
local res = ndk.set_var.set_escape_uri('a/b')
|
|
-- now res == 'a%2fb'
|
|
</geshi>
|
|
|
|
Similarly, the following directives provided by [[HttpEncryptedSessionModule]] can be invoked from within Lua too:
|
|
|
|
* [[HttpEncryptedSessionModule#set_encrypt_session|set_encrypt_session]]
|
|
* [[HttpEncryptedSessionModule#set_decrypt_session|set_decrypt_session]]
|
|
|
|
This feature requires the [https://github.com/simplresty/ngx_devel_kit ngx_devel_kit] module.
|
|
|
|
== coroutine.create ==
|
|
|
|
'''syntax:''' ''co = coroutine.create(f)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, init_by_lua*, ngx.timer.*, header_filter_by_lua*, body_filter_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Creates a user Lua coroutines with a Lua function, and returns a coroutine object.
|
|
|
|
Similar to the standard Lua [https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.create coroutine.create] API, but works in the context of the Lua coroutines created by ngx_lua.
|
|
|
|
This API was first usable in the context of [[#init_by_lua|init_by_lua*]] since the <code>0.9.2</code>.
|
|
|
|
This API was first introduced in the <code>v0.6.0</code> release.
|
|
|
|
== coroutine.resume ==
|
|
|
|
'''syntax:''' ''ok, ... = coroutine.resume(co, ...)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, init_by_lua*, ngx.timer.*, header_filter_by_lua*, body_filter_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Resumes the execution of a user Lua coroutine object previously yielded or just created.
|
|
|
|
Similar to the standard Lua [https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.resume coroutine.resume] API, but works in the context of the Lua coroutines created by ngx_lua.
|
|
|
|
This API was first usable in the context of [[#init_by_lua|init_by_lua*]] since the <code>0.9.2</code>.
|
|
|
|
This API was first introduced in the <code>v0.6.0</code> release.
|
|
|
|
== coroutine.yield ==
|
|
|
|
'''syntax:''' ''... = coroutine.yield(...)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, init_by_lua*, ngx.timer.*, header_filter_by_lua*, body_filter_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Yields the execution of the current user Lua coroutine.
|
|
|
|
Similar to the standard Lua [https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.yield coroutine.yield] API, but works in the context of the Lua coroutines created by ngx_lua.
|
|
|
|
This API was first usable in the context of [[#init_by_lua|init_by_lua*]] since the <code>0.9.2</code>.
|
|
|
|
This API was first introduced in the <code>v0.6.0</code> release.
|
|
|
|
== coroutine.wrap ==
|
|
|
|
'''syntax:''' ''co = coroutine.wrap(f)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, init_by_lua*, ngx.timer.*, header_filter_by_lua*, body_filter_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Similar to the standard Lua [https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.wrap coroutine.wrap] API, but works in the context of the Lua coroutines created by ngx_lua.
|
|
|
|
This API was first usable in the context of [[#init_by_lua|init_by_lua*]] since the <code>0.9.2</code>.
|
|
|
|
This API was first introduced in the <code>v0.6.0</code> release.
|
|
|
|
== coroutine.running ==
|
|
|
|
'''syntax:''' ''co = coroutine.running()''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, init_by_lua*, ngx.timer.*, header_filter_by_lua*, body_filter_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Identical to the standard Lua [https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.running coroutine.running] API.
|
|
|
|
This API was first usable in the context of [[#init_by_lua|init_by_lua*]] since the <code>0.9.2</code>.
|
|
|
|
This API was first enabled in the <code>v0.6.0</code> release.
|
|
|
|
== coroutine.status ==
|
|
|
|
'''syntax:''' ''status = coroutine.status(co)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, init_by_lua*, ngx.timer.*, header_filter_by_lua*, body_filter_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*''
|
|
|
|
Identical to the standard Lua [https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.status coroutine.status] API.
|
|
|
|
This API was first usable in the context of [[#init_by_lua|init_by_lua*]] since the <code>0.9.2</code>.
|
|
|
|
This API was first enabled in the <code>v0.6.0</code> release.
|
|
|
|
== ngx.run_worker_thread ==
|
|
|
|
'''syntax:''' ''ok, res1, res2, ... = ngx.run_worker_thread(threadpool, module_name, func_name, arg1, arg2, ...)''
|
|
|
|
'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*''
|
|
|
|
'''This API is still experimental and may change in the future without notice.'''
|
|
|
|
'''This API is available only for Linux.'''
|
|
|
|
Wrap the [http://nginx.org/en/docs/dev/development_guide.html#threads nginx worker thread] to execute lua function. The caller coroutine would yield until the function returns.
|
|
|
|
Only the following ngx_lua APIs could be used in `function_name` function of the `module` module:
|
|
|
|
* `ngx.encode_base64`
|
|
* `ngx.decode_base64`
|
|
|
|
* `ngx.hmac_sha1`
|
|
* `ngx.encode_args`
|
|
* `ngx.decode_args`
|
|
* `ngx.quote_sql_str`
|
|
|
|
* `ngx.re.match`
|
|
* `ngx.re.find`
|
|
* `ngx.re.gmatch`
|
|
* `ngx.re.sub`
|
|
* `ngx.re.gsub`
|
|
|
|
* `ngx.crc32_short`
|
|
* `ngx.crc32_long`
|
|
* `ngx.hmac_sha1`
|
|
* `ngx.md5_bin`
|
|
* `ngx.md5`
|
|
|
|
* `ngx.config.subsystem`
|
|
* `ngx.config.debug`
|
|
* `ngx.config.prefix`
|
|
* `ngx.config.nginx_version`
|
|
* `ngx.config.nginx_configure`
|
|
* `ngx.config.ngx_lua_version`
|
|
|
|
|
|
The first argument `threadpool` specifies the Nginx thread pool name defined by [thread_pool](https://nginx.org/en/docs/ngx_core_module.html#thread_pool).
|
|
|
|
The second argument <code>module_name</code> specifies the lua module name to execute in the worker thread, which would return a lua table. The module must be inside the package path, e.g.
|
|
|
|
<geshi lang="nginx">
|
|
lua_package_path '/opt/openresty/?.lua;;';
|
|
</geshi>
|
|
|
|
The third argument <code>func_name</code> specifies the function field in the module table as the second argument.
|
|
|
|
The type of <code>arg</code>s must be one of type below:
|
|
|
|
* boolean
|
|
* number
|
|
* string
|
|
* nil
|
|
* table (the table may be recursive, and contains members of types above.)
|
|
|
|
The <code>ok</code> is in boolean type, which indicate the C land error (failed to get thread from thread pool, pcall the module function failed, .etc). If <code>ok</code> is <code>false</code>, the <code>res1</code> is the error string.
|
|
|
|
The return values (res1, ...) are returned by invocation of the module function. Normally, the <code>res1</code> should be in boolean type, so that the caller could inspect the error.
|
|
|
|
This API is useful when you need to execute the below types of tasks:
|
|
|
|
* CPU bound task, e.g. do md5 calculation
|
|
* File I/O task
|
|
* Call <code>os.execute()</code> or blocking C API via <code>ffi</code>
|
|
* Call external Lua library not based on cosocket or nginx
|
|
|
|
Example1: do md5 calculation.
|
|
|
|
<geshi lang="nginx">
|
|
location /calc_md5 {
|
|
default_type 'text/plain';
|
|
|
|
content_by_lua_block {
|
|
local ok, md5_or_err = ngx.run_worker_thread("testpool", "md5", "md5")
|
|
ngx.say(ok, " : ", md5_or_err)
|
|
}
|
|
}
|
|
|
|
</geshi>
|
|
|
|
<code>md5.lua</code>
|
|
|
|
<geshi lang="lua">
|
|
local function md5()
|
|
return ngx.md5("hello")
|
|
end
|
|
return {md5=md5}
|
|
</geshi>
|
|
|
|
Example2: write logs into the log file.
|
|
|
|
<geshi lang="nginx">
|
|
location /write_log_file {
|
|
default_type 'text/plain';
|
|
|
|
content_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)
|
|
}
|
|
}
|
|
</geshi>
|
|
|
|
<code>write_log_file.lua</code>
|
|
|
|
<geshi lang="lua">
|
|
local function log(str)
|
|
local file, err = io.open("/tmp/tmp.log", "a")
|
|
if not file then
|
|
return false, err
|
|
end
|
|
file:write(str)
|
|
file:flush()
|
|
file:close()
|
|
return true
|
|
end
|
|
return {log=log}
|
|
</geshi>
|
|
|
|
= Obsolete Sections =
|
|
|
|
This section is just holding obsolete documentation sections that have been either renamed or removed so that existing links over the web are still valid.
|
|
|
|
== Special PCRE Sequences ==
|
|
|
|
This section has been renamed to [[#Special Escaping Sequences|Special Escaping Sequences]].
|
|
|
|
== Lua/LuaJIT bytecode support ==
|
|
|
|
This section has been renamed to
|
|
[[#LuaJIT bytecode support|LuaJIT bytecode support]]. As of version
|
|
<code>v0.10.16</code> of this module, the standard Lua interpreter (also known
|
|
as "PUC-Rio Lua") is not supported anymore.
|