Patch-Source: https://github.com/openresty/lua-nginx-module/commit/0090f3faf66e6870b3974e983ae4b47459c96fa3 -- From 0090f3faf66e6870b3974e983ae4b47459c96fa3 Mon Sep 17 00:00:00 2001 From: Jun Ouyang Date: Thu, 11 May 2023 19:27:13 +0800 Subject: [PATCH] bugfix: disable http2 in body read due to http2 stream processing bug. diff --git a/src/ngx_http_lua_accessby.c b/src/ngx_http_lua_accessby.c index 58c251443e..8814b924bb 100644 --- a/src/ngx_http_lua_accessby.c +++ b/src/ngx_http_lua_accessby.c @@ -136,7 +136,12 @@ ngx_http_lua_access_handler(ngx_http_request_t *r) return NGX_DONE; } +/* http2 read body may break http2 stream process */ +#if (NGX_HTTP_V2) + if (llcf->force_read_body && !ctx->read_body_done && !r->main->stream) { +#else if (llcf->force_read_body && !ctx->read_body_done) { +#endif r->request_body_in_single_buf = 1; r->request_body_in_persistent_file = 1; r->request_body_in_clean_file = 1; diff --git a/src/ngx_http_lua_contentby.c b/src/ngx_http_lua_contentby.c index 76e6a074da..65067cd6a1 100644 --- a/src/ngx_http_lua_contentby.c +++ b/src/ngx_http_lua_contentby.c @@ -195,7 +195,12 @@ ngx_http_lua_content_handler(ngx_http_request_t *r) return rc; } +/* http2 read body may break http2 stream process */ +#if (NGX_HTTP_V2) + if (llcf->force_read_body && !ctx->read_body_done && !r->main->stream) { +#else if (llcf->force_read_body && !ctx->read_body_done) { +#endif r->request_body_in_single_buf = 1; r->request_body_in_persistent_file = 1; r->request_body_in_clean_file = 1; diff --git a/src/ngx_http_lua_req_body.c b/src/ngx_http_lua_req_body.c index 935fafc8a4..3c452b3051 100644 --- a/src/ngx_http_lua_req_body.c +++ b/src/ngx_http_lua_req_body.c @@ -85,6 +85,13 @@ ngx_http_lua_ngx_req_read_body(lua_State *L) return luaL_error(L, "request object not found"); } +/* http2 read body may break http2 stream process */ +#if (NGX_HTTP_V2) + if (r->main->stream) { + return luaL_error(L, "http2 requests are not supported yet"); + } +#endif + r->request_body_in_single_buf = 1; r->request_body_in_persistent_file = 1; r->request_body_in_clean_file = 1; @@ -312,6 +319,13 @@ ngx_http_lua_ngx_req_get_body_file(lua_State *L) return luaL_error(L, "request object not found"); } +/* http2 read body may break http2 stream process */ +#if (NGX_HTTP_V2) + if (r->main->stream) { + return luaL_error(L, "http2 requests are not supported yet"); + } +#endif + ngx_http_lua_check_fake_request(L, r); if (r->request_body == NULL || r->request_body->temp_file == NULL) { diff --git a/src/ngx_http_lua_rewriteby.c b/src/ngx_http_lua_rewriteby.c index d1eabeccdd..2e3065364e 100644 --- a/src/ngx_http_lua_rewriteby.c +++ b/src/ngx_http_lua_rewriteby.c @@ -140,7 +140,12 @@ ngx_http_lua_rewrite_handler(ngx_http_request_t *r) return NGX_DONE; } +/* http2 read body may break http2 stream process */ +#if (NGX_HTTP_V2) + if (llcf->force_read_body && !ctx->read_body_done && !r->main->stream) { +#else if (llcf->force_read_body && !ctx->read_body_done) { +#endif r->request_body_in_single_buf = 1; r->request_body_in_persistent_file = 1; r->request_body_in_clean_file = 1; diff --git a/src/ngx_http_lua_server_rewriteby.c b/src/ngx_http_lua_server_rewriteby.c index 22bb69e8c8..cc6192d925 100644 --- a/src/ngx_http_lua_server_rewriteby.c +++ b/src/ngx_http_lua_server_rewriteby.c @@ -102,8 +102,13 @@ ngx_http_lua_server_rewrite_handler(ngx_http_request_t *r) return NGX_DONE; } - /* TODO: lscf do not have force_read_body */ +/* TODO: lscf do not have force_read_body + * http2 read body may break http2 stream process */ +#if (NGX_HTTP_V2) + if (llcf->force_read_body && !ctx->read_body_done && !r->main->stream) { +#else if (llcf->force_read_body && !ctx->read_body_done) { +#endif r->request_body_in_single_buf = 1; r->request_body_in_persistent_file = 1; r->request_body_in_clean_file = 1;