Skip to content

Commit 7786f97

Browse files
committed
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.
1 parent 1a52a58 commit 7786f97

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/ngx_http_lua_req_body.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,20 @@ ngx_http_lua_ngx_req_read_body(lua_State *L)
112112

113113
rc = ngx_http_read_client_request_body(r, ngx_http_lua_req_body_post_read);
114114

115+
#if (nginx_version < 1002006) || \
116+
(nginx_version >= 1003000 && nginx_version < 1003009)
115117
r->main->count--;
118+
#endif
116119

117120
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
118121
return luaL_error(L, "failed to read request body");
119122
}
120123

124+
#if (nginx_version >= 1002006 && nginx_version < 1003000) || \
125+
nginx_version >= 1003009
126+
r->main->count--;
127+
#endif
128+
121129
if (rc == NGX_AGAIN) {
122130
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
123131
"lua read buffered request body requires I/O interruptions");

t/044-req-body.t

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ hello, world
3333
hello, world
3434
--- no_error_log
3535
[error]
36+
[alert]
3637

3738

3839

@@ -1314,3 +1315,30 @@ failed to get req socket: request body already exists
13141315
--- no_error_log
13151316
a client request body is buffered to a temporary file
13161317
1318+
1319+
1320+
=== TEST 41: failed to write 100 continue
1321+
--- config
1322+
location = /test {
1323+
content_by_lua '
1324+
ngx.sleep(0.01)
1325+
ngx.req.read_body()
1326+
ngx.say(ngx.var.request_body)
1327+
';
1328+
}
1329+
--- request
1330+
POST /test
1331+
hello, world
1332+
--- more_headers
1333+
Expect: 100-Continue
1334+
--- abort
1335+
--- timeout: 0.001
1336+
--- wait: 0.1
1337+
--- ignore_response
1338+
hello, world
1339+
--- error_log
1340+
failed to read request body
1341+
--- no_error_log
1342+
[alert]
1343+
http finalize request: 500, "/test?" a:1, c:0
1344+

0 commit comments

Comments
 (0)