Skip to content

Commit ac8ed38

Browse files
committed
ci: update ci test
1 parent 8e0e8b2 commit ac8ed38

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

README.markdown

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,8 @@ Directives
11321132
* [content_by_lua](#content_by_lua)
11331133
* [content_by_lua_block](#content_by_lua_block)
11341134
* [content_by_lua_file](#content_by_lua_file)
1135+
* [server_rewrite_by_lua_block](#server_rewrite_by_lua_block)
1136+
* [server_rewrite_by_lua_file](#server_rewrite_by_lua_file)
11351137
* [rewrite_by_lua](#rewrite_by_lua)
11361138
* [rewrite_by_lua_block](#rewrite_by_lua_block)
11371139
* [rewrite_by_lua_file](#rewrite_by_lua_file)
@@ -1910,6 +1912,97 @@ But be very careful about malicious user inputs and always carefully validate or
19101912

19111913
[Back to TOC](#directives)
19121914

1915+
server_rewrite_by_lua_block
1916+
---------------------------
1917+
1918+
**syntax:** *server_rewrite_by_lua_block { lua-script }*
1919+
1920+
**context:** *http, server*
1921+
1922+
**phase:** *server rewrite*
1923+
1924+
Acts as a server rewrite phase handler and executes Lua code string specified in `{ lua-script }` for every request.
1925+
The Lua code may make [API calls](#nginx-api-for-lua) and is executed as a new spawned coroutine in an independent global environment (i.e. a sandbox).
1926+
1927+
```nginx
1928+
1929+
server {
1930+
...
1931+
1932+
server_rewrite_by_lua_block {
1933+
ngx.ctx.a = "server_rewrite_by_lua_block in http"
1934+
}
1935+
1936+
location /lua {
1937+
content_by_lua_block {
1938+
ngx.say(ngx.ctx.a)
1939+
ngx.log(ngx.INFO, ngx.ctx.a)
1940+
}
1941+
}
1942+
}
1943+
```
1944+
1945+
Just as any other rewrite phase handlers, [server_rewrite_by_lua_block](#server_rewrite_by_lua_block) also runs in subrequests.
1946+
1947+
```nginx
1948+
1949+
server {
1950+
server_rewrite_by_lua_block {
1951+
ngx.log(ngx.INFO, "is_subrequest:", ngx.is_subrequest)
1952+
}
1953+
1954+
location /lua {
1955+
content_by_lua_block {
1956+
local res = ngx.location.capture("/sub")
1957+
ngx.print(res.body)
1958+
}
1959+
}
1960+
1961+
location /sub {
1962+
content_by_lua_block {
1963+
ngx.say("OK")
1964+
}
1965+
}
1966+
}
1967+
```
1968+
1969+
Note that when calling `ngx.exit(ngx.OK)` 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](#ngxexit) with status >= 200 (`ngx.HTTP_OK`) and status < 300 (`ngx.HTTP_SPECIAL_RESPONSE`) for successful quits and `ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)` (or its friends) for failures.
1970+
1971+
1972+
```nginx
1973+
1974+
server_rewrite_by_lua_block {
1975+
ngx.exit(503)
1976+
}
1977+
1978+
location /bar {
1979+
...
1980+
# never exec
1981+
}
1982+
```
1983+
1984+
1985+
[Back to TOC](#directives)
1986+
1987+
server_rewrite_by_lua_file
1988+
--------------------------
1989+
1990+
**syntax:** *server_rewrite_by_lua_file &lt;path-to-lua-script-file&gt;*
1991+
1992+
**context:** *http, server*
1993+
1994+
**phase:** *server rewrite*
1995+
1996+
Equivalent to [server_rewrite_by_lua_block](#server_rewrite_by_lua_block), except that the file specified by `<path-to-lua-script-file>` contains the Lua code, or, as from the `v0.10.22` release, the [LuaJIT bytecode](#luajit-bytecode-support) to be executed.
1997+
1998+
Nginx variables can be used in the `<path-to-lua-script-file>` string to provide flexibility. This however carries some risks and is not ordinarily recommended.
1999+
2000+
When a relative path like `foo/bar.lua` is given, they will be turned into the absolute path relative to the `server prefix` path determined by the `-p PATH` command-line option while starting the Nginx server.
2001+
2002+
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) `off` in `nginx.conf` to avoid reloading Nginx.
2003+
2004+
[Back to TOC](#directives)
2005+
19132006
rewrite_by_lua
19142007
--------------
19152008

t/167-server-rewite.t renamed to t/167-server-rewrite.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ our $StapScript = $t::StapThread::StapScript;
1919
2020
repeat_each(2);
2121
22-
plan tests => repeat_each() * (blocks() * 4 - 10);
22+
plan tests => repeat_each() * (blocks() * 3 + 10);
2323

2424
#log_level("info");
2525
#no_long_string();
@@ -463,7 +463,7 @@ rewrite_by_lua_file in server
463463
GET /lua
464464
--- ignore_response
465465
--- error_log
466-
failed to load inlined Lua code: server_rewrite_by_lua(nginx.conf:27):2: unexpected symbol near ''for end''
466+
failed to load inlined Lua code: server_rewrite_by_lua(nginx.conf:25):2: unexpected symbol near ''for end''
467467
--- no_error_log
468468
no_such_error
469469
@@ -483,6 +483,6 @@ no_such_error
483483
GET /lua
484484
--- ignore_response
485485
--- error_log
486-
failed to load inlined Lua code: server_rewrite_by_lua(nginx.conf:41):2: unexpected symbol near ''for end''
486+
failed to load inlined Lua code: server_rewrite_by_lua(nginx.conf:39):2: unexpected symbol near ''for end''
487487
--- no_error_log
488488
no_such_error

0 commit comments

Comments
 (0)