Skip to content

Commit e699fcc

Browse files
author
aviram
committed
2 parents d4d2988 + cd669b5 commit e699fcc

14 files changed

+285
-27
lines changed

README

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Status
88
This module is under active development and is production ready.
99

1010
Version
11-
This document describes ngx_lua v0.8.10
12-
(<https://github.com/chaoslawful/lua-nginx-module/tags>) released on 22
11+
This document describes ngx_lua v0.9.0
12+
(<https://github.com/chaoslawful/lua-nginx-module/tags>) released on 29
1313
September 2013.
1414

1515
Synopsis
@@ -6289,9 +6289,16 @@ See Also
62896289
* lua-resty-dns (<http://github.com/agentzh/lua-resty-dns>) library
62906290
based on ngx_lua cosocket.
62916291

6292+
* lua-resty-websocket
6293+
(<http://github.com/agentzh/lua-resty-websocket>) library for both
6294+
WebSocket server and client, based on ngx_lua cosocket.
6295+
62926296
* lua-resty-string (<http://github.com/agentzh/lua-resty-string>)
62936297
library based on LuaJIT FFI (<http://luajit.org/ext_ffi.html>).
62946298

6299+
* lua-resty-lock (<http://github.com/agentzh/lua-resty-lock>) library
6300+
for a nonblocking simple lock API.
6301+
62956302
* Routing requests to different MySQL queries based on URI arguments
62966303
(<http://openresty.org/#RoutingMySQLQueriesBasedOnURIArgs>)
62976304

README.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This module is under active development and is production ready.
1818
Version
1919
=======
2020

21-
This document describes ngx_lua [v0.8.10](https://github.com/chaoslawful/lua-nginx-module/tags) released on 22 September 2013.
21+
This document describes ngx_lua [v0.9.0](https://github.com/chaoslawful/lua-nginx-module/tags) released on 29 September 2013.
2222

2323
Synopsis
2424
========
@@ -5509,7 +5509,9 @@ See Also
55095509
* [lua-resty-mysql](http://github.com/agentzh/lua-resty-mysql) library based on ngx_lua cosocket.
55105510
* [lua-resty-upload](http://github.com/agentzh/lua-resty-upload) library based on ngx_lua cosocket.
55115511
* [lua-resty-dns](http://github.com/agentzh/lua-resty-dns) library based on ngx_lua cosocket.
5512+
* [lua-resty-websocket](http://github.com/agentzh/lua-resty-websocket) library for both WebSocket server and client, based on ngx_lua cosocket.
55125513
* [lua-resty-string](http://github.com/agentzh/lua-resty-string) library based on [LuaJIT FFI](http://luajit.org/ext_ffi.html).
5514+
* [lua-resty-lock](http://github.com/agentzh/lua-resty-lock) library for a nonblocking simple lock API.
55135515
* [Routing requests to different MySQL queries based on URI arguments](http://openresty.org/#RoutingMySQLQueriesBasedOnURIArgs)
55145516
* [Dynamic Routing Based on Redis and Lua](http://openresty.org/#DynamicRoutingBasedOnRedis)
55155517
* [Using LuaRocks with ngx_lua](http://openresty.org/#UsingLuaRocks)

doc/HttpLuaModule.wiki

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This module is under active development and is production ready.
1010

1111
= Version =
1212

13-
This document describes ngx_lua [https://github.com/chaoslawful/lua-nginx-module/tags v0.8.10] released on 22 September 2013.
13+
This document describes ngx_lua [https://github.com/chaoslawful/lua-nginx-module/tags v0.9.0] released on 29 September 2013.
1414

1515
= Synopsis =
1616
<geshi lang="nginx">
@@ -5317,7 +5317,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
53175317
* [http://github.com/agentzh/lua-resty-mysql lua-resty-mysql] library based on ngx_lua cosocket.
53185318
* [http://github.com/agentzh/lua-resty-upload lua-resty-upload] library based on ngx_lua cosocket.
53195319
* [http://github.com/agentzh/lua-resty-dns lua-resty-dns] library based on ngx_lua cosocket.
5320+
* [http://github.com/agentzh/lua-resty-websocket lua-resty-websocket] library for both WebSocket server and client, based on ngx_lua cosocket.
53205321
* [http://github.com/agentzh/lua-resty-string lua-resty-string] library based on [http://luajit.org/ext_ffi.html LuaJIT FFI].
5322+
* [http://github.com/agentzh/lua-resty-lock lua-resty-lock] library for a nonblocking simple lock API.
53215323
* [http://openresty.org/#RoutingMySQLQueriesBasedOnURIArgs Routing requests to different MySQL queries based on URI arguments]
53225324
* [http://openresty.org/#DynamicRoutingBasedOnRedis Dynamic Routing Based on Redis and Lua]
53235325
* [http://openresty.org/#UsingLuaRocks Using LuaRocks with ngx_lua]

src/ngx_http_lua_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ typedef struct {
201201
ngx_flag_t transform_underscores_in_resp_headers;
202202
ngx_flag_t log_socket_errors;
203203
ngx_flag_t check_client_abort;
204+
ngx_flag_t use_default_type;
204205
} ngx_http_lua_loc_conf_t;
205206

206207

src/ngx_http_lua_headers.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,20 @@ ngx_http_lua_ngx_req_get_headers(lua_State *L)
322322

323323
ngx_http_lua_check_fake_request(L, r);
324324

325-
lua_createtable(L, 0, 4);
325+
part = &r->headers_in.headers.part;
326+
count = part->nelts;
327+
while (part->next) {
328+
part = part->next;
329+
count += part->nelts;
330+
}
331+
332+
if (max > 0 && count > max) {
333+
count = max;
334+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
335+
"lua exceeding request header limit %d", max);
336+
}
337+
338+
lua_createtable(L, 0, count);
326339

327340
if (!raw) {
328341
lua_pushlightuserdata(L, &ngx_http_lua_req_get_headers_metatable_key);
@@ -366,10 +379,7 @@ ngx_http_lua_ngx_req_get_headers(lua_State *L)
366379
"lua request header: \"%V: %V\"",
367380
&header[i].key, &header[i].value);
368381

369-
if (max > 0 && ++count == max) {
370-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
371-
"lua hit request header limit %d", max);
372-
382+
if (--count == 0) {
373383
return 1;
374384
}
375385
}
@@ -486,7 +496,7 @@ ngx_http_lua_ngx_header_set(lua_State *L)
486496
}
487497

488498
if (!ctx->headers_set) {
489-
rc = ngx_http_set_content_type(r);
499+
rc = ngx_http_lua_set_content_type(r);
490500
if (rc != NGX_OK) {
491501
return luaL_error(L,
492502
"failed to set default content type: %d",

src/ngx_http_lua_module.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ static ngx_command_t ngx_http_lua_cmds[] = {
343343
offsetof(ngx_http_lua_loc_conf_t, check_client_abort),
344344
NULL },
345345

346+
{ ngx_string("lua_use_default_type"),
347+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
348+
|NGX_CONF_FLAG,
349+
ngx_conf_set_flag_slot,
350+
NGX_HTTP_LOC_CONF_OFFSET,
351+
offsetof(ngx_http_lua_loc_conf_t, use_default_type),
352+
NULL },
353+
346354
ngx_null_command
347355
};
348356

@@ -616,6 +624,7 @@ ngx_http_lua_create_loc_conf(ngx_conf_t *cf)
616624
conf->enable_code_cache = NGX_CONF_UNSET;
617625
conf->http10_buffering = NGX_CONF_UNSET;
618626
conf->check_client_abort = NGX_CONF_UNSET;
627+
conf->use_default_type = NGX_CONF_UNSET;
619628

620629
conf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
621630
conf->connect_timeout = NGX_CONF_UNSET_MSEC;
@@ -679,6 +688,7 @@ ngx_http_lua_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
679688
ngx_conf_merge_value(conf->enable_code_cache, prev->enable_code_cache, 1);
680689
ngx_conf_merge_value(conf->http10_buffering, prev->http10_buffering, 1);
681690
ngx_conf_merge_value(conf->check_client_abort, prev->check_client_abort, 0);
691+
ngx_conf_merge_value(conf->use_default_type, prev->use_default_type, 1);
682692

683693
ngx_conf_merge_msec_value(conf->keepalive_timeout,
684694
prev->keepalive_timeout, 60000);

src/ngx_http_lua_socket_tcp.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,10 +3149,20 @@ ngx_http_lua_req_socket(lua_State *L)
31493149
lua_pushliteral(L, "nginx version too old");
31503150
return 2;
31513151
#else
3152-
if (!r->request_body) {
3153-
lua_pushnil(L);
3154-
lua_pushliteral(L, "requesty body not read yet");
3155-
return 2;
3152+
if (r->request_body) {
3153+
if (r->request_body->rest > 0) {
3154+
lua_pushnil(L);
3155+
lua_pushliteral(L, "pending request body reading in some "
3156+
"other thread");
3157+
return 2;
3158+
}
3159+
3160+
} else {
3161+
rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
3162+
if (rb == NULL) {
3163+
return luaL_error(L, "out of memory");
3164+
}
3165+
r->request_body = rb;
31563166
}
31573167

31583168
if (c->buffered) {

src/ngx_http_lua_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ ngx_http_lua_send_header_if_needed(ngx_http_request_t *r,
484484
r->headers_out.status = NGX_HTTP_OK;
485485
}
486486

487-
if (!ctx->headers_set && ngx_http_set_content_type(r) != NGX_OK) {
487+
if (!ctx->headers_set && ngx_http_lua_set_content_type(r) != NGX_OK) {
488488
return NGX_ERROR;
489489
}
490490

src/ngx_http_lua_util.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ ngx_http_lua_hash_str(u_char *src, size_t n)
249249
}
250250

251251

252+
static ngx_inline ngx_int_t
253+
ngx_http_lua_set_content_type(ngx_http_request_t *r)
254+
{
255+
ngx_http_lua_loc_conf_t *llcf;
256+
257+
llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
258+
if (llcf->use_default_type) {
259+
return ngx_http_set_content_type(r);
260+
}
261+
262+
return NGX_OK;
263+
}
264+
265+
252266
extern ngx_uint_t ngx_http_lua_location_hash;
253267
extern ngx_uint_t ngx_http_lua_content_length_hash;
254268

t/024-access/client-abort.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ delete thread 2
734734
lua req cleanup
735735
736736
--- shutdown: 1
737+
--- wait: 0.1
737738
--- ignore_response
738739
--- no_error_log
739740
[error]

t/025-codecache.t

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
118118

119119

120120

121-
122121
=== TEST 4: code cache explicitly off (server level)
123122
--- config
124123
lua_code_cache off;
@@ -154,7 +153,6 @@ qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
154153

155154

156155

157-
158156
=== TEST 5: code cache explicitly off (server level) but be overridden in the location
159157
--- config
160158
lua_code_cache off;
@@ -441,7 +439,6 @@ qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
441439

442440

443441

444-
445442
=== TEST 13: no clear builtin lib "string"
446443
--- config
447444
location /lua {
@@ -467,7 +464,6 @@ qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
467464

468465

469466

470-
471467
=== TEST 14: no clear builtin lib "string"
472468
--- http_config eval
473469
"lua_package_path '$::HtmlDir/?.lua;./?.lua';"
@@ -504,7 +500,6 @@ qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
504500

505501

506502

507-
508503
=== TEST 15: skip luarocks
509504
--- http_config eval
510505
"lua_package_path '$::HtmlDir/?.lua;./?.lua';
@@ -555,7 +550,6 @@ qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
555550

556551

557552

558-
559553
=== TEST 16: skip luarocks*
560554
--- http_config eval
561555
"lua_package_path '$::HtmlDir/?.lua;./?.lua';
@@ -606,7 +600,6 @@ qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
606600

607601

608602

609-
610603
=== TEST 17: clear _G table
611604
--- http_config eval
612605
"lua_package_path '$::HtmlDir/?.lua;./?.lua';"
@@ -631,7 +624,6 @@ qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/
631624

632625

633626

634-
635627
=== TEST 18: github #257: globals cleared when code cache off
636628
--- http_config
637629
lua_code_cache off;

t/028-req-header.t

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use t::TestNginxLua;
99

1010
repeat_each(2);
1111

12-
plan tests => repeat_each() * (2 * blocks() + 18);
12+
plan tests => repeat_each() * (2 * blocks() + 19);
1313

1414
#no_diff();
1515
#no_long_string();
@@ -34,6 +34,9 @@ Bar: baz
3434
--- response_body
3535
Foo: bar
3636
Bar: baz
37+
--- log_level: debug
38+
--- no_error_log
39+
lua exceeding request header limit
3740
3841
3942
@@ -427,7 +430,7 @@ for my $k (@k) {
427430
CORE::join("", @k);
428431
--- timeout: 4
429432
--- error_log
430-
lua hit request header limit 100
433+
lua exceeding request header limit 100
431434
432435
433436
@@ -475,7 +478,7 @@ for my $k (@k) {
475478
CORE::join("", @k);
476479
--- timeout: 4
477480
--- error_log
478-
lua hit request header limit 102
481+
lua exceeding request header limit 102
479482
480483
481484

0 commit comments

Comments
 (0)