You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.markdown
+44-10Lines changed: 44 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ This module is under active development and is production ready.
13
13
Version
14
14
=======
15
15
16
-
This document describes ngx_lua [v0.5.0rc17](https://github.com/chaoslawful/lua-nginx-module/tags) released on 6 March 2012.
16
+
This document describes ngx_lua [v0.5.0rc19](https://github.com/chaoslawful/lua-nginx-module/tags) released on 15 March 2012.
17
17
18
18
Synopsis
19
19
========
@@ -786,6 +786,25 @@ The `<time>` argument can be an integer, with an optional time unit, like `s` (s
786
786
787
787
This directive was first introduced in the `v0.5.0rc1` release.
788
788
789
+
lua_http10_buffering
790
+
--------------------
791
+
792
+
**syntax:***lua_http10_buffering on|off*
793
+
794
+
**default:***lua_http10_buffering on*
795
+
796
+
**context:***http, server, location, location-if*
797
+
798
+
Enables or disables the automatic response caching for HTTP 1.0 (or older) requests. This buffering mechanism is mainly used for HTTP 1.0 keep-alive which replies on a proper `Content-Length` response header.
799
+
800
+
If the Lua code explicitly sets a `Content-Length` response header before sending the headers (either explicity via [ngx.send_headers](http://wiki.nginx.org/HttpLuaModule#ngx.send_headers) or implicitly via the first [ngx.say](http://wiki.nginx.org/HttpLuaModule#ngx.say) or [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print) call).
801
+
802
+
If you want to output huge response data in a streaming fashion (via the [ngx.flush](http://wiki.nginx.org/HttpLuaModule#ngx.flush) call, for example), then you MUST turn off this directive to prevent memory footprint boost.
803
+
804
+
This directive is turned `on` by default.
805
+
806
+
THis directive was first introduced in the `v0.5.0rc19` release.
807
+
789
808
Nginx API for Lua
790
809
=================
791
810
Introduction
@@ -900,16 +919,19 @@ Core constants
900
919
ngx.ERROR (-1)
901
920
ngx.AGAIN (-2)
902
921
ngx.DONE (-4)
922
+
ngx.DECLINED (-5)
903
923
904
924
905
-
Note that only two of these constants are utilized by the [Nginx API for Lua](http://wiki.nginx.org/HttpLuaModule#Nginx_API_for_Lua) (i.e., [ngx.exit](http://wiki.nginx.org/HttpLuaModule#ngx.exit) accepts `NGX_OK`and `NGX_ERROR` as input).
925
+
Note that only three of these constants are utilized by the [Nginx API for Lua](http://wiki.nginx.org/HttpLuaModule#Nginx_API_for_Lua) (i.e., [ngx.exit](http://wiki.nginx.org/HttpLuaModule#ngx.exit) accepts `NGX_OK`, `NGX_ERROR`, and `NGX_DECLINED` as input).
906
926
907
927
908
928
ngx.null
909
929
910
930
911
931
The `ngx.null` constant is a `NULL` light userdata which is usually used to represent nil values in Lua tables and etc. It is identical with the [lua-cjson](http://www.kyne.com.au/~mark/software/lua-cjson.php) library's `cjson.null` constant. This constant was first introduced in the `v0.5.0rc5` release.
912
932
933
+
The `ngx.DECLINED` constant was first introduced in the `v0.5.0rc19` release.
@@ -1623,6 +1645,14 @@ or a Lua table holding the query arguments' key-value pairs, as in
1623
1645
1624
1646
where in the latter case, this method will automatically escape argument keys and values according to the URI escaping rule.
1625
1647
1648
+
Multi-value arguments are also supported:
1649
+
1650
+
1651
+
ngx.req.set_uri_args({ a = 3, b = {5, 6} })
1652
+
1653
+
1654
+
which will result in a querystring like `a=3&b=5&b=6`.
1655
+
1626
1656
This interface was first introduced in the `v0.3.1rc13` release.
1627
1657
1628
1658
See also [ngx.req.set_uri](http://wiki.nginx.org/HttpLuaModule#ngx.req.set_uri).
@@ -3425,13 +3455,17 @@ HTTP 1.0 support
3425
3455
================
3426
3456
3427
3457
The HTTP 1.0 protocol does not support chunked outputs and always requires an
3428
-
explicit `Content-Length` header when the response body is non-empty. So when
3429
-
an HTTP 1.0 request is present, This module will automatically buffer all the
3458
+
explicit `Content-Length` header when the response body is non-empty in order to support the HTTP 1.0 keep-alive (as required by the ApacheBench (ab) tool). So when
3459
+
an HTTP 1.0 request is present and the [lua_http10_buffering](http://wiki.nginx.org/HttpLuaModule#lua_http10_buffering) directive is turned `on`, this module will automatically buffer all the
3430
3460
outputs of user calls of [ngx.say](http://wiki.nginx.org/HttpLuaModule#ngx.say) and [ngx.print](http://wiki.nginx.org/HttpLuaModule#ngx.print) and
3431
3461
postpone sending response headers until it sees all the outputs in the response
3432
3462
body, and at that time ngx_lua can calculate the total length of the body and
3433
3463
construct a proper `Content-Length` header for the HTTP 1.0 client.
3434
3464
3465
+
If the user Lua code sets the `Content-Length` response header itself, then the automatic buffering will be disabled even if the [lua_http10_buffering](http://wiki.nginx.org/HttpLuaModule#lua_http10_buffering) directive is turned `on`.
3466
+
3467
+
For big responses' streaming outputs, it's important to disable the [lua_http10_buffering](http://wiki.nginx.org/HttpLuaModule#lua_http10_buffering) directive, otherwise the memory usage will grow very quickly.
3468
+
3435
3469
Note that, common HTTP benchmark tools like `ab` and `http_load` always issue
3436
3470
HTTP 1.0 requests by default. To force `curl` to send HTTP 1.0 requests, use
3437
3471
the `-0` option.
@@ -3718,16 +3752,16 @@ TODO
3718
3752
3719
3753
Short Term
3720
3754
----------
3721
-
* implement the `ngx.sleep(time)` Lua API.
3722
-
* implement the `ngx.worker.get_pid()` Lua API.
3755
+
* implement the `ngx.sleep(time)` Lua API. (For now, use [ngx.location.capture](http://wiki.nginx.org/HttpLuaModule#ngx.location.capture) with [HttpEchoModule](http://wiki.nginx.org/HttpEchoModule)'s [echo_sleep](http://wiki.nginx.org/HttpEchoModule#echo_sleep) config directive instead.)
3756
+
* implement the `ngx.worker.get_pid()` Lua API. (For now, use `ngx.var.pid` directly.)
3723
3757
* implement [LuaSocket UDP API](http://w3.impa.br/~diego/software/luasocket/udp.html) in our cosocket API.
3758
+
* implement the SSL cosocket API.
3724
3759
* implement the `ngx.re.split` method.
3725
3760
* use `ngx_hash_t` to optimize the built-in header look-up process for [ngx.req.set_header](http://wiki.nginx.org/HttpLuaModule#ngx.req.set_header), [ngx.header.HEADER](http://wiki.nginx.org/HttpLuaModule#ngx.header.HEADER), and etc.
3726
3761
* fix HTTP 1.0 support: we should by default close the current HTTP 1.0 connection right away if no `Content-Length` response header is set. the current automatic full buffering bahvior is way too expensive.
3727
3762
* add configure options for different strategies of handling the cosocket connection exceeding in the pools.
3728
3763
* add directives to run Lua codes when nginx stops/reloads.
3729
3764
* deal with TCP 3-second delay problem under great connection harness.
3730
-
* add support for multi-value arguments to [ngx.req.set_uri_args](http://wiki.nginx.org/HttpLuaModule#ngx.req.set_uri_args) if its `args` argument is a Lua table.
3731
3765
* add APIs to access cookies as key/value pairs.
3732
3766
* add `ignore_resp_headers`, `ignore_resp_body`, and `ignore_resp` options to [ngx.location.capture](http://wiki.nginx.org/HttpLuaModule#ngx.location.capture) and [ngx.location.capture_multi](http://wiki.nginx.org/HttpLuaModule#ngx.location.capture_multi) methods, to allow micro performance tuning on the user side.
Enables or disables the automatic response caching for HTTP 1.0 (or older) requests. This buffering mechanism is mainly used for HTTP 1.0 keep-alive which replies on a proper <code>Content-Length</code> response header.
769
+
770
+
If the Lua code explicitly sets a <code>Content-Length</code> response header before sending the headers (either explicity via [[#ngx.send_headers|ngx.send_headers]] or implicitly via the first [[#ngx.say|ngx.say]] or [[#ngx.print|ngx.print]] call).
771
+
772
+
If you want to output huge response data in a streaming fashion (via the [[#ngx.flush|ngx.flush]] call, for example), then you MUST turn off this directive to prevent memory footprint boost.
773
+
774
+
This directive is turned <code>on</code> by default.
775
+
776
+
THis directive was first introduced in the <code>v0.5.0rc19</code> release.
777
+
760
778
= Nginx API for Lua =
761
779
== Introduction ==
762
780
The various <code>*_by_lua</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.
@@ -866,16 +884,19 @@ Setting <code>ngx.var.Foo</code> to a <code>nil</code> value will unset the <cod
866
884
ngx.ERROR (-1)
867
885
ngx.AGAIN (-2)
868
886
ngx.DONE (-4)
887
+
ngx.DECLINED (-5)
869
888
</geshi>
870
889
871
-
Note that only two 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>and <code>NGX_ERROR</code> as input).
890
+
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).
872
891
873
892
<geshi lang="lua">
874
893
ngx.null
875
894
</geshi>
876
895
877
896
The <code>ngx.null</code> constant is a <code>NULL</code> light userdata which is usually used to represent nil values in Lua tables and etc. It is identical with 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.
878
897
898
+
The <code>ngx.DECLINED</code> constant was first introduced in the <code>v0.5.0rc19</code> release.
@@ -1578,6 +1599,14 @@ or a Lua table holding the query arguments' key-value pairs, as in
1578
1599
1579
1600
where in the latter case, this method will automatically escape argument keys and values according to the URI escaping rule.
1580
1601
1602
+
Multi-value arguments are also supported:
1603
+
1604
+
<geshi lang="lua">
1605
+
ngx.req.set_uri_args({ a = 3, b = {5, 6} })
1606
+
</geshi>
1607
+
1608
+
which will result in a querystring like <code>a=3&b=5&b=6</code>.
1609
+
1581
1610
This interface was first introduced in the <code>v0.3.1rc13</code> release.
1582
1611
1583
1612
See also [[#ngx.req.set_uri|ngx.req.set_uri]].
@@ -3312,13 +3341,17 @@ This feature requires the [https://github.com/simpl/ngx_devel_kit ngx_devel_kit]
3312
3341
= HTTP 1.0 support =
3313
3342
3314
3343
The HTTP 1.0 protocol does not support chunked outputs and always requires an
3315
-
explicit <code>Content-Length</code> header when the response body is non-empty. So when
3316
-
an HTTP 1.0 request is present, This module will automatically buffer all the
3344
+
explicit <code>Content-Length</code> header when the response body is non-empty in order to support the HTTP 1.0 keep-alive (as required by the ApacheBench (ab) tool). So when
3345
+
an HTTP 1.0 request is present and the [[#lua_http10_buffering|lua_http10_buffering]] directive is turned <code>on</code>, this module will automatically buffer all the
3317
3346
outputs of user calls of [[#ngx.say|ngx.say]] and [[#ngx.print|ngx.print]] and
3318
3347
postpone sending response headers until it sees all the outputs in the response
3319
3348
body, and at that time ngx_lua can calculate the total length of the body and
3320
3349
construct a proper <code>Content-Length</code> header for the HTTP 1.0 client.
3321
3350
3351
+
If the user Lua code sets the <code>Content-Length</code> response header itself, then the automatic buffering will be disabled even if the [[#lua_http10_buffering|lua_http10_buffering]] directive is turned <code>on</code>.
3352
+
3353
+
For big responses' streaming outputs, it's important to disable the [[#lua_http10_buffering|lua_http10_buffering]] directive, otherwise the memory usage will grow very quickly.
3354
+
3322
3355
Note that, common HTTP benchmark tools like <code>ab</code> and <code>http_load</code> always issue
3323
3356
HTTP 1.0 requests by default. To force <code>curl</code> to send HTTP 1.0 requests, use
* implement the <code>ngx.sleep(time)</code> Lua API.
3596
-
* implement the <code>ngx.worker.get_pid()</code> Lua API.
3628
+
* implement the <code>ngx.sleep(time)</code> Lua API. (For now, use [[#ngx.location.capture|ngx.location.capture]] with [[HttpEchoModule]]'s [[HttpEchoModule#echo_sleep|echo_sleep]] config directive instead.)
3629
+
* implement the <code>ngx.worker.get_pid()</code> Lua API. (For now, use <code>ngx.var.pid</code> directly.)
3597
3630
* implement [http://w3.impa.br/~diego/software/luasocket/udp.html LuaSocket UDP API] in our cosocket API.
3631
+
* implement the SSL cosocket API.
3598
3632
* implement the <code>ngx.re.split</code> method.
3599
3633
* use <code>ngx_hash_t</code> to optimize the built-in header look-up process for [[#ngx.req.set_header|ngx.req.set_header]], [[#ngx.header.HEADER|ngx.header.HEADER]], and etc.
3600
3634
* fix HTTP 1.0 support: we should by default close the current HTTP 1.0 connection right away if no <code>Content-Length</code> response header is set. the current automatic full buffering bahvior is way too expensive.
3601
3635
* add configure options for different strategies of handling the cosocket connection exceeding in the pools.
3602
3636
* add directives to run Lua codes when nginx stops/reloads.
3603
3637
* deal with TCP 3-second delay problem under great connection harness.
3604
-
* add support for multi-value arguments to [[#ngx.req.set_uri_args|ngx.req.set_uri_args]] if its <code>args</code> argument is a Lua table.
3605
3638
* add APIs to access cookies as key/value pairs.
3606
3639
* 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.
3607
3640
@@ -3782,7 +3815,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
0 commit comments