Skip to content

Commit 5a4199b

Browse files
committed
bugfix: we might try sending the response header again in ngx.exit() when the header was already sent.
1 parent 20c41e1 commit 5a4199b

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/ngx_http_lua_util.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,21 @@ ngx_http_lua_handle_exit(lua_State *L, ngx_http_request_t *r,
23242324
}
23252325
}
23262326

2327+
#if 1
2328+
if (r->header_sent
2329+
&& ctx->exit_code > NGX_OK
2330+
&& ctx->exit_code != NGX_HTTP_REQUEST_TIME_OUT
2331+
&& ctx->exit_code != NGX_HTTP_CLIENT_CLOSED_REQUEST
2332+
&& ctx->exit_code != NGX_HTTP_CLOSE)
2333+
{
2334+
if (ctx->entered_content_phase) {
2335+
return NGX_OK;
2336+
}
2337+
2338+
return NGX_HTTP_OK;
2339+
}
2340+
#endif
2341+
23272342
return ctx->exit_code;
23282343
}
23292344

t/005-exit.t

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,3 +617,23 @@ GET /lua HTTP/1.0
617617
lua sending HTTP 1.0 response headers
618618
[error]
619619
620+
621+
622+
=== TEST 20: exit(201) with custom response body
623+
--- config
624+
location = /t {
625+
content_by_lua "
626+
ngx.status = 201
627+
ngx.say('ok');
628+
return ngx.exit(201)
629+
";
630+
}
631+
--- request
632+
GET /t
633+
--- ignore_response
634+
--- log_level: debug
635+
--- no_error_log
636+
lua sending HTTP 1.0 response headers
637+
[error]
638+
[alert]
639+

t/023-rewrite/uthread-exit.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ our $StapScript = $t::StapThread::StapScript;
99

1010
repeat_each(2);
1111

12-
plan tests => repeat_each() * (blocks() * 4);
12+
plan tests => repeat_each() * (blocks() * 4 + 1);
1313

1414
$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
1515
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211';
@@ -171,6 +171,7 @@ hello in thread
171171
after
172172
--- no_error_log
173173
[error]
174+
[alert]
174175
175176
176177

0 commit comments

Comments
 (0)