Skip to content

Commit 490ed95

Browse files
author
Tuure Vartiainen
committed
Merge branch 'upstream/master' into ssl-psk
2 parents eaf4f01 + 59dff5e commit 490ed95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+759
-158
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ env:
5050
- TEST_NGINX_SLEEP=0.006
5151
matrix:
5252
- NGINX_VERSION=1.11.2
53+
- NGINX_VERSION=1.13.5
5354

5455
services:
5556
- memcache
@@ -59,6 +60,7 @@ services:
5960
before_install:
6061
- '! grep -n -P ''(?<=.{80}).+'' --color `find src -name ''*.c''` `find . -name ''*.h''` || (echo "ERROR: Found C source lines exceeding 80 columns." > /dev/stderr; exit 1)'
6162
- '! grep -n -P ''\t+'' --color `find src -name ''*.c''` `find . -name ''*.h''` || (echo "ERROR: Cannot use tabs." > /dev/stderr; exit 1)'
63+
- sudo cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
6264

6365
install:
6466
- if [ ! -f download-cache/drizzle7-$DRIZZLE_VER.tar.gz ]; then wget -P download-cache http://openresty.org/download/drizzle7-$DRIZZLE_VER.tar.gz; fi
@@ -84,12 +86,14 @@ install:
8486
- git clone https://github.com/openresty/redis2-nginx-module.git ../redis2-nginx-module
8587
- git clone -b ssl-psk https://github.com/vartiait/lua-resty-core.git ../lua-resty-core
8688
- git clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache
89+
- git clone https://github.com/openresty/lua-resty-mysql.git ../lua-resty-mysql
8790
- git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git
8891

8992
before_script:
9093
- mysql -uroot -e 'create database ngx_test; grant all on ngx_test.* to "ngx_test"@"%" identified by "ngx_test"; flush privileges;'
9194

9295
script:
96+
- sudo iptables -I OUTPUT 1 -p udp --dport 10086 -j REJECT
9397
- cd luajit2/
9498
- make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT -msse4.2' > build.log 2>&1 || (cat build.log && exit 1)
9599
- sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1)

README.markdown

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Production ready.
6262
Version
6363
=======
6464

65-
This document describes ngx_lua [v0.10.8](https://github.com/openresty/lua-nginx-module/tags) released on 8 April 2017.
65+
This document describes ngx_lua [v0.10.10](https://github.com/openresty/lua-nginx-module/tags) released on 8 August 2017.
6666

6767
Synopsis
6868
========
@@ -990,7 +990,7 @@ Copyright and License
990990

991991
This module is licensed under the BSD license.
992992

993-
Copyright (C) 2009-2016, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
993+
Copyright (C) 2009-2017, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
994994

995995
Copyright (C) 2009-2017, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>, OpenResty Inc.
996996

@@ -1335,16 +1335,19 @@ Runs the Lua code specified by the argument `<lua-script-str>` on the global Lua
13351335

13361336
When Nginx receives the `HUP` signal and starts reloading the config file, the Lua VM will also be re-created and `init_by_lua` 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 `init_by_lua` handler will run upon every request because in this special mode a standalone Lua VM is always created for each request.
13371337

1338-
Usually you can register (true) Lua global variables or pre-load Lua modules at server start-up by means of this hook. Here is an example for pre-loading Lua modules:
1338+
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:
13391339

13401340
```nginx
13411341
1342-
init_by_lua 'cjson = require "cjson"';
1342+
# this runs before forking out nginx worker processes:
1343+
init_by_lua_block { require "cjson" }
13431344
13441345
server {
13451346
location = /api {
13461347
content_by_lua_block {
1347-
ngx.say(cjson.encode({dog = 5, cat = 6}))
1348+
-- the following require() will just return
1349+
-- the alrady loaded module from package.loaded:
1350+
ngx.say(require "cjson".encode{dog = 5, cat = 6})
13481351
}
13491352
}
13501353
}
@@ -1356,10 +1359,10 @@ You can also initialize the [lua_shared_dict](#lua_shared_dict) shm storage at t
13561359
13571360
lua_shared_dict dogs 1m;
13581361
1359-
init_by_lua '
1362+
init_by_lua_block {
13601363
local dogs = ngx.shared.dogs;
13611364
dogs:set("Tom", 56)
1362-
';
1365+
}
13631366
13641367
server {
13651368
location = /api {
@@ -2691,7 +2694,7 @@ ssl_session_store_by_lua_file
26912694

26922695
**context:** *http*
26932696

2694-
**phase:** *right-before-SSL-handshake*
2697+
**phase:** *right-after-SSL-handshake*
26952698

26962699
Equivalent to [ssl_session_store_by_lua_block](#ssl_session_store_by_lua_block), except that the file specified by `<path-to-lua-script-file>` contains the Lua code, or rather, the [Lua/LuaJIT bytecode](#lualuajit-bytecode-support) to be executed.
26972700

@@ -3188,6 +3191,8 @@ Nginx API for Lua
31883191
* [ngx.shared.DICT.lpop](#ngxshareddictlpop)
31893192
* [ngx.shared.DICT.rpop](#ngxshareddictrpop)
31903193
* [ngx.shared.DICT.llen](#ngxshareddictllen)
3194+
* [ngx.shared.DICT.ttl](#ngxshareddictttl)
3195+
* [ngx.shared.DICT.expire](#ngxshareddictexpire)
31913196
* [ngx.shared.DICT.flush_all](#ngxshareddictflush_all)
31923197
* [ngx.shared.DICT.flush_expired](#ngxshareddictflush_expired)
31933198
* [ngx.shared.DICT.get_keys](#ngxshareddictget_keys)
@@ -6195,6 +6200,8 @@ The resulting object `dict` has the following methods:
61956200
* [lpop](#ngxshareddictlpop)
61966201
* [rpop](#ngxshareddictrpop)
61976202
* [llen](#ngxshareddictllen)
6203+
* [ttl](#ngxshareddictttl)
6204+
* [expire](#ngxshareddictexpire)
61986205
* [flush_all](#ngxshareddictflush_all)
61996206
* [flush_expired](#ngxshareddictflush_expired)
62006207
* [get_keys](#ngxshareddictget_keys)
@@ -6540,6 +6547,82 @@ See also [ngx.shared.DICT](#ngxshareddict).
65406547

65416548
[Back to TOC](#nginx-api-for-lua)
65426549

6550+
ngx.shared.DICT.ttl
6551+
-------------------
6552+
**syntax:** *ttl, err = ngx.shared.DICT:ttl(key)*
6553+
6554+
**context:** *init_by_lua&#42;, set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;*
6555+
6556+
**requires:** `resty.core.shdict` or `resty.core`
6557+
6558+
Retrieves the remaining TTL (time-to-live in seconds) of a key-value pair in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict). Returns the TTL as a number if the operation is successfully completed or `nil` and an error message otherwise.
6559+
6560+
If the key does not exist (or has already expired), this method will return `nil` and the error string `"not found"`.
6561+
6562+
The TTL is originally determined by the `exptime` argument of the [set](#ngxshareddictset), [add](#ngxshareddictadd), [replace](#ngxshareddictreplace) (and the likes) methods. It has a time resolution of `0.001` seconds. A value of `0` means that the item will never expire.
6563+
6564+
Example:
6565+
6566+
```lua
6567+
6568+
require "resty.core"
6569+
6570+
local cats = ngx.shared.cats
6571+
local succ, err = cats:set("Marry", "a nice cat", 0.5)
6572+
6573+
ngx.sleep(0.2)
6574+
6575+
local ttl, err = cats:ttl("Marry")
6576+
ngx.say(ttl) -- 0.3
6577+
```
6578+
6579+
This feature was first introduced in the `v0.10.11` release.
6580+
6581+
**Note:** This method requires the `resty.core.shdict` or `resty.core` modules from the [lua-resty-core](https://github.com/openresty/lua-resty-core) library.
6582+
6583+
See also [ngx.shared.DICT](#ngxshareddict).
6584+
6585+
[Back to TOC](#nginx-api-for-lua)
6586+
6587+
ngx.shared.DICT.expire
6588+
----------------------
6589+
**syntax:** *success, err = ngx.shared.DICT:expire(key, exptime)*
6590+
6591+
**context:** *init_by_lua&#42;, set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;*
6592+
6593+
**requires:** `resty.core.shdict` or `resty.core`
6594+
6595+
Updates the `exptime` (in second) of a key-value pair in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict). Returns a boolean indicating success if the operation completes or `nil` and an error message otherwise.
6596+
6597+
If the key does not exist, this method will return `nil` and the error string `"not found"`.
6598+
6599+
The `exptime` argument has a resolution of `0.001` seconds. If `exptime` is `0`, then the item will never expire.
6600+
6601+
Example:
6602+
6603+
```lua
6604+
6605+
require "resty.core"
6606+
6607+
local cats = ngx.shared.cats
6608+
local succ, err = cats:set("Marry", "a nice cat", 0.1)
6609+
6610+
succ, err = cats:expire("Marry", 0.5)
6611+
6612+
ngx.sleep(0.2)
6613+
6614+
local val, err = cats:get("Marry")
6615+
ngx.say(val) -- "a nice cat"
6616+
```
6617+
6618+
This feature was first introduced in the `v0.10.11` release.
6619+
6620+
**Note:** This method requires the `resty.core.shdict` or `resty.core` modules from the [lua-resty-core](https://github.com/openresty/lua-resty-core) library.
6621+
6622+
See also [ngx.shared.DICT](#ngxshareddict).
6623+
6624+
[Back to TOC](#nginx-api-for-lua)
6625+
65436626
ngx.shared.DICT.flush_all
65446627
-------------------------
65456628
**syntax:** *ngx.shared.DICT:flush_all()*

doc/HttpLuaModule.wiki

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Production ready.
1010

1111
= Version =
1212

13-
This document describes ngx_lua [https://github.com/openresty/lua-nginx-module/tags v0.10.8] released on 8 April 2017.
13+
This document describes ngx_lua [https://github.com/openresty/lua-nginx-module/tags v0.10.10] released on 8 August 2017.
1414

1515
= Synopsis =
1616
<geshi lang="nginx">
@@ -812,7 +812,7 @@ There are also various testing modes based on mockeagain, valgrind, and etc. Ref
812812
813813
This module is licensed under the BSD license.
814814
815-
Copyright (C) 2009-2016, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
815+
Copyright (C) 2009-2017, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
816816
817817
Copyright (C) 2009-2017, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>, OpenResty Inc.
818818
@@ -1057,15 +1057,18 @@ Runs the Lua code specified by the argument <code><lua-script-str></code> on the
10571057
10581058
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</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</code> handler will run upon every request because in this special mode a standalone Lua VM is always created for each request.
10591059
1060-
Usually you can register (true) Lua global variables or pre-load Lua modules at server start-up by means of this hook. Here is an example for pre-loading Lua modules:
1060+
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:
10611061
10621062
<geshi lang="nginx">
1063-
init_by_lua 'cjson = require "cjson"';
1063+
# this runs before forking out nginx worker processes:
1064+
init_by_lua_block { require "cjson" }
10641065
10651066
server {
10661067
location = /api {
10671068
content_by_lua_block {
1068-
ngx.say(cjson.encode({dog = 5, cat = 6}))
1069+
-- the following require() will just return
1070+
-- the alrady loaded module from package.loaded:
1071+
ngx.say(require "cjson".encode{dog = 5, cat = 6})
10691072
}
10701073
}
10711074
}
@@ -1076,10 +1079,10 @@ You can also initialize the [[#lua_shared_dict|lua_shared_dict]] shm storage at
10761079
<geshi lang="nginx">
10771080
lua_shared_dict dogs 1m;
10781081
1079-
init_by_lua '
1082+
init_by_lua_block {
10801083
local dogs = ngx.shared.dogs;
10811084
dogs:set("Tom", 56)
1082-
';
1085+
}
10831086
10841087
server {
10851088
location = /api {
@@ -2368,7 +2371,7 @@ Note that: this directive is only allowed to used in '''http context''' from the
23682371
23692372
'''context:''' ''http''
23702373
2371-
'''phase:''' ''right-before-SSL-handshake''
2374+
'''phase:''' ''right-after-SSL-handshake''
23722375
23732376
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 [[#Lua/LuaJIT bytecode support|Lua/LuaJIT bytecode]] to be executed.
23742377
@@ -5309,6 +5312,8 @@ The resulting object <code>dict</code> has the following methods:
53095312
* [[#ngx.shared.DICT.lpop|lpop]]
53105313
* [[#ngx.shared.DICT.rpop|rpop]]
53115314
* [[#ngx.shared.DICT.llen|llen]]
5315+
* [[#ngx.shared.DICT.ttl|ttl]]
5316+
* [[#ngx.shared.DICT.expire|expire]]
53125317
* [[#ngx.shared.DICT.flush_all|flush_all]]
53135318
* [[#ngx.shared.DICT.flush_expired|flush_expired]]
53145319
* [[#ngx.shared.DICT.get_keys|get_keys]]
@@ -5604,6 +5609,74 @@ This feature was first introduced in the <code>v0.10.6</code> release.
56045609
56055610
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
56065611
5612+
== ngx.shared.DICT.ttl ==
5613+
'''syntax:''' ''ttl, err = ngx.shared.DICT:ttl(key)''
5614+
5615+
'''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*''
5616+
5617+
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
5618+
5619+
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.
5620+
5621+
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>.
5622+
5623+
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.
5624+
5625+
Example:
5626+
5627+
<geshi lang="lua">
5628+
require "resty.core"
5629+
5630+
local cats = ngx.shared.cats
5631+
local succ, err = cats:set("Marry", "a nice cat", 0.5)
5632+
5633+
ngx.sleep(0.2)
5634+
5635+
local ttl, err = cats:ttl("Marry")
5636+
ngx.say(ttl) -- 0.3
5637+
</geshi>
5638+
5639+
This feature was first introduced in the <code>v0.10.11</code> release.
5640+
5641+
'''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.
5642+
5643+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5644+
5645+
== ngx.shared.DICT.expire ==
5646+
'''syntax:''' ''success, err = ngx.shared.DICT:expire(key, exptime)''
5647+
5648+
'''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*''
5649+
5650+
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
5651+
5652+
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.
5653+
5654+
If the key does not exist, this method will return <code>nil</code> and the error string <code>"not found"</code>.
5655+
5656+
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.
5657+
5658+
Example:
5659+
5660+
<geshi lang="lua">
5661+
require "resty.core"
5662+
5663+
local cats = ngx.shared.cats
5664+
local succ, err = cats:set("Marry", "a nice cat", 0.1)
5665+
5666+
succ, err = cats:expire("Marry", 0.5)
5667+
5668+
ngx.sleep(0.2)
5669+
5670+
local val, err = cats:get("Marry")
5671+
ngx.say(val) -- "a nice cat"
5672+
</geshi>
5673+
5674+
This feature was first introduced in the <code>v0.10.11</code> release.
5675+
5676+
'''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.
5677+
5678+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5679+
56075680
== ngx.shared.DICT.flush_all ==
56085681
'''syntax:''' ''ngx.shared.DICT:flush_all()''
56095682

src/api/ngx_http_lua_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/* Public API for other Nginx modules */
2020

2121

22-
#define ngx_http_lua_version 10009
22+
#define ngx_http_lua_version 10011
2323

2424

2525
typedef struct {

src/ngx_http_lua_accessby.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ ngx_http_lua_access_by_chunk(lua_State *L, ngx_http_request_t *r)
238238
{
239239
int co_ref;
240240
ngx_int_t rc;
241+
ngx_uint_t nreqs;
241242
lua_State *co;
242243
ngx_event_t *rev;
243244
ngx_connection_t *c;
@@ -329,6 +330,9 @@ ngx_http_lua_access_by_chunk(lua_State *L, ngx_http_request_t *r)
329330
r->read_event_handler = ngx_http_block_reading;
330331
}
331332

333+
c = r->connection;
334+
nreqs = c->requests;
335+
332336
rc = ngx_http_lua_run_thread(L, r, ctx, 0);
333337

334338
dd("returned %d", (int) rc);
@@ -337,10 +341,8 @@ ngx_http_lua_access_by_chunk(lua_State *L, ngx_http_request_t *r)
337341
return rc;
338342
}
339343

340-
c = r->connection;
341-
342344
if (rc == NGX_AGAIN) {
343-
rc = ngx_http_lua_run_posted_threads(c, L, r, ctx);
345+
rc = ngx_http_lua_run_posted_threads(c, L, r, ctx, nreqs);
344346

345347
if (rc == NGX_ERROR || rc == NGX_DONE || rc > NGX_OK) {
346348
return rc;
@@ -353,7 +355,7 @@ ngx_http_lua_access_by_chunk(lua_State *L, ngx_http_request_t *r)
353355
} else if (rc == NGX_DONE) {
354356
ngx_http_lua_finalize_request(r, NGX_DONE);
355357

356-
rc = ngx_http_lua_run_posted_threads(c, L, r, ctx);
358+
rc = ngx_http_lua_run_posted_threads(c, L, r, ctx, nreqs);
357359

358360
if (rc == NGX_ERROR || rc == NGX_DONE || rc > NGX_OK) {
359361
return rc;

src/ngx_http_lua_directive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ ngx_http_lua_conf_read_lua_token(ngx_conf_t *cf,
15421542

15431543
#if nginx_version >= 1009002
15441544
if (dump) {
1545-
dump->last = ngx_cpymem(dump->last, b->pos, size);
1545+
dump->last = ngx_cpymem(dump->last, b->start + len, size);
15461546
}
15471547
#endif
15481548
}

0 commit comments

Comments
 (0)