Skip to content

Commit 235875b

Browse files
committed
refactor: removed our own ctx->headers_sent field because we should used r->header_sent instead.
1 parent 95e2931 commit 235875b

File tree

6 files changed

+17
-23
lines changed

6 files changed

+17
-23
lines changed

src/ngx_http_lua_common.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,6 @@ typedef struct ngx_http_lua_ctx_s {
356356

357357
unsigned exited:1;
358358

359-
unsigned headers_sent:1; /* 1: response header has been sent;
360-
0: header not sent yet */
361-
362359
unsigned eof:1; /* 1: last_buf has been sent;
363360
0: last_buf not sent yet */
364361

src/ngx_http_lua_control.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ ngx_http_lua_ngx_exec(lua_State *L)
108108
if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags)
109109
!= NGX_OK)
110110
{
111-
ctx->headers_sent = 1;
112111
return NGX_HTTP_INTERNAL_SERVER_ERROR;
113112
}
114113

@@ -173,7 +172,7 @@ ngx_http_lua_ngx_exec(lua_State *L)
173172
}
174173
}
175174

176-
if (ctx->headers_sent) {
175+
if (r->header_sent) {
177176
return luaL_error(L, "attempt to call ngx.exec after "
178177
"sending out response headers");
179178
}
@@ -237,7 +236,7 @@ ngx_http_lua_ngx_redirect(lua_State *L)
237236

238237
ngx_http_lua_check_if_abortable(L, ctx);
239238

240-
if (ctx->headers_sent) {
239+
if (r->header_sent) {
241240
return luaL_error(L, "attempt to call ngx.redirect after sending out "
242241
"the headers");
243242
}
@@ -319,7 +318,7 @@ ngx_http_lua_ngx_exit(lua_State *L)
319318
return luaL_error(L, "attempt to abort with pending subrequests");
320319
}
321320

322-
if (ctx->headers_sent
321+
if (r->header_sent
323322
&& rc >= NGX_HTTP_SPECIAL_RESPONSE
324323
&& rc != NGX_HTTP_REQUEST_TIME_OUT
325324
&& rc != NGX_HTTP_CLIENT_CLOSED_REQUEST

src/ngx_http_lua_headers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ ngx_http_lua_ngx_header_set(lua_State *L)
452452

453453
ngx_http_lua_check_fake_request2(L, r, ctx);
454454

455-
if (ctx->headers_sent) {
455+
if (r->header_sent) {
456456
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "attempt to "
457457
"set ngx.header.HEADER after sending out "
458458
"response headers");

src/ngx_http_lua_misc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ ngx_http_lua_ngx_get(lua_State *L)
8181

8282
ngx_http_lua_check_fake_request2(L, r, ctx);
8383

84-
dd("headers sent: %d", ctx->headers_sent);
84+
dd("headers sent: %d", r->header_sent);
8585

86-
lua_pushboolean(L, ctx->headers_sent ? 1 : 0);
86+
lua_pushboolean(L, r->header_sent ? 1 : 0);
8787
return 1;
8888
}
8989

@@ -115,7 +115,7 @@ ngx_http_lua_ngx_set(lua_State *L)
115115

116116
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
117117

118-
if (ctx->headers_sent) {
118+
if (r->header_sent) {
119119
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
120120
"attempt to set ngx.status after sending out "
121121
"response headers");

src/ngx_http_lua_output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ ngx_http_lua_ngx_flush(lua_State *L)
515515
}
516516

517517
#if 1
518-
if (!ctx->headers_sent) {
518+
if (!r->header_sent) {
519519
lua_pushnil(L);
520520
lua_pushliteral(L, "nothing to flush");
521521
return 2;
@@ -708,7 +708,7 @@ ngx_http_lua_ngx_send_headers(lua_State *L)
708708
| NGX_HTTP_LUA_CONTEXT_ACCESS
709709
| NGX_HTTP_LUA_CONTEXT_CONTENT);
710710

711-
if (!ctx->headers_sent) {
711+
if (!r->header_sent) {
712712
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
713713
"lua send headers");
714714

src/ngx_http_lua_util.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ ngx_http_lua_send_header_if_needed(ngx_http_request_t *r,
475475
{
476476
ngx_int_t rc;
477477

478-
if (!ctx->headers_sent) {
478+
if (!r->header_sent) {
479479
if (r->headers_out.status == 0) {
480480
r->headers_out.status = NGX_HTTP_OK;
481481
}
@@ -492,7 +492,6 @@ ngx_http_lua_send_header_if_needed(ngx_http_request_t *r,
492492
if (!ctx->buffering) {
493493
dd("sending headers");
494494
rc = ngx_http_send_header(r);
495-
ctx->headers_sent = 1;
496495
return rc;
497496
}
498497
}
@@ -525,7 +524,7 @@ ngx_http_lua_send_chain_link(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
525524

526525
if (llcf->http10_buffering
527526
&& !ctx->buffering
528-
&& !ctx->headers_sent
527+
&& !r->header_sent
529528
&& r->http_version < NGX_HTTP_VERSION_11
530529
&& r->headers_out.content_length_n < 0)
531530
{
@@ -662,7 +661,7 @@ ngx_http_lua_send_http10_headers(ngx_http_request_t *r,
662661
ngx_chain_t *cl;
663662
ngx_int_t rc;
664663

665-
if (ctx->headers_sent) {
664+
if (r->header_sent) {
666665
return NGX_OK;
667666
}
668667

@@ -687,7 +686,6 @@ ngx_http_lua_send_http10_headers(ngx_http_request_t *r,
687686

688687
send:
689688
rc = ngx_http_send_header(r);
690-
ctx->headers_sent = 1;
691689
return rc;
692690
}
693691

@@ -1436,15 +1434,15 @@ ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,
14361434

14371435
ngx_http_lua_request_cleanup(ctx, 0);
14381436

1439-
dd("headers sent? %d", ctx->headers_sent ? 1 : 0);
1437+
dd("headers sent? %d", r->header_sent ? 1 : 0);
14401438

14411439
if (ctx->no_abort) {
14421440
ctx->no_abort = 0;
14431441
return NGX_ERROR;
14441442
}
14451443

1446-
return ctx->headers_sent ? NGX_ERROR :
1447-
NGX_HTTP_INTERNAL_SERVER_ERROR;
1444+
return r->header_sent ? NGX_ERROR :
1445+
NGX_HTTP_INTERNAL_SERVER_ERROR;
14481446
}
14491447

14501448
/* being a user coroutine that has a parent */
@@ -1497,7 +1495,7 @@ ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,
14971495
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "lua handler aborted: "
14981496
"user coroutine has no parent");
14991497

1500-
return ctx->headers_sent ? NGX_ERROR : NGX_HTTP_INTERNAL_SERVER_ERROR;
1498+
return r->header_sent ? NGX_ERROR : NGX_HTTP_INTERNAL_SERVER_ERROR;
15011499

15021500
done:
15031501
if (ctx->entered_content_phase && r->connection->fd != -1) {
@@ -2212,7 +2210,7 @@ ngx_http_lua_handle_exit(lua_State *L, ngx_http_request_t *r,
22122210
ctx->exit_code);
22132211

22142212
#if 1
2215-
if (!ctx->headers_sent
2213+
if (!r->header_sent
22162214
&& r->headers_out.status == 0
22172215
&& ctx->exit_code >= NGX_HTTP_OK)
22182216
{

0 commit comments

Comments
 (0)