This is an automated email from the ASF dual-hosted git repository.

guoqqqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 210943c18d fix: preserve client-control body limit for gRPC upstreams 
(#14036)
210943c18d is described below

commit 210943c18d6e40ea599c7554f12f658bea012d4f
Author: ruanweihong-aaa <[email protected]>
AuthorDate: Fri Oct 23 08:34:05 2026 +0800

    fix: preserve client-control body limit for gRPC upstreams (#14036)
---
 apisix/init.lua                   |   9 ++++
 apisix/plugins/client-control.lua |   1 +
 t/node/grpc-client-control.t      | 108 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+)

diff --git a/apisix/init.lua b/apisix/init.lua
index 45120aac03..4a8b71dc09 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -1068,6 +1068,15 @@ function _M.grpc_access_phase()
     if api_ctx.enable_mirror == true and has_mod then
         apisix_ngx_client.enable_mirror()
     end
+
+    if api_ctx.client_max_body_size then
+        local ok, err = apisix_ngx_client.set_client_max_body_size(
+            api_ctx.client_max_body_size)
+        if not ok then
+            core.log.error("failed to set client max body size: ", err)
+            core.response.exit(503)
+        end
+    end
 end
 
 
diff --git a/apisix/plugins/client-control.lua 
b/apisix/plugins/client-control.lua
index 1975098c83..8838fe791f 100644
--- a/apisix/plugins/client-control.lua
+++ b/apisix/plugins/client-control.lua
@@ -69,6 +69,7 @@ function _M.rewrite(conf, ctx)
             core.log.error("failed to set client max body size: ", err)
             return 503
         end
+        ctx.client_max_body_size = conf.max_body_size
     end
 end
 
diff --git a/t/node/grpc-client-control.t b/t/node/grpc-client-control.t
new file mode 100644
index 0000000000..ae0d642dc8
--- /dev/null
+++ b/t/node/grpc-client-control.t
@@ -0,0 +1,108 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use t::APISIX;
+
+my $nginx_binary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
+my $version = eval { `$nginx_binary -V 2>&1` };
+
+if ($version !~ m/\/apisix-nginx-module/) {
+    plan(skip_all => "apisix-nginx-module not installed");
+} else {
+    plan('no_plan');
+}
+
+no_long_string();
+no_root_location();
+no_shuffle();
+add_block_preprocessor(sub {
+    my ($block) = @_;
+    if (!$block->request) {
+        $block->set_value("request", "GET /t");
+    }
+    if (!$block->no_error_log && !$block->error_log) {
+        $block->set_value("no_error_log", "[error]\n[alert]");
+    }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST: client-control rejects a gRPC request without Content-Length after 
internal redirect
+--- http2
+--- apisix_yaml
+routes:
+  - id: grpc-body-limit
+    uri: /helloworld.Greeter/SayHello
+    plugins:
+      client-control:
+        max_body_size: 1
+    upstream:
+      scheme: grpc
+      nodes:
+        "127.0.0.1:10051": 1
+      type: roundrobin
+#END
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto 
-plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello 
2>&1
+--- response_body_like: 413
+--- error_log
+client intended to send too large chunked body
+
+
+
+=== TEST: client-control zero lets a gRPC body exceed the 30 MiB Nginx limit
+--- http2
+--- apisix_yaml
+routes:
+  - id: grpc-no-body-limit
+    uri: /helloworld.Greeter/SayHello
+    plugins:
+      client-control:
+        max_body_size: 0
+    upstream:
+      scheme: grpc
+      nodes:
+        "127.0.0.1:10051": 1
+      type: roundrobin
+#END
+--- exec
+perl -e 'print "{\"name\":\"", "x" x (31 * 1024 * 1024), "\"}"' | grpcurl 
-import-path ./t/grpc_server_example/proto -proto helloworld.proto -plaintext 
-d @ 127.0.0.1:1984 helloworld.Greeter.SayHello 2>&1
+--- response_body_like: ResourceExhausted
+--- timeout: 60
+
+
+
+=== TEST: client-control raises the gRPC body limit above the 30 MiB Nginx 
limit
+--- http2
+--- apisix_yaml
+routes:
+  - id: grpc-larger-body-limit
+    uri: /helloworld.Greeter/SayHello
+    plugins:
+      client-control:
+        max_body_size: 52428800
+    upstream:
+      scheme: grpc
+      nodes:
+        "127.0.0.1:10051": 1
+      type: roundrobin
+#END
+--- exec
+perl -e 'print "{\"name\":\"", "x" x (31 * 1024 * 1024), "\"}"' | grpcurl 
-import-path ./t/grpc_server_example/proto -proto helloworld.proto -plaintext 
-d @ 127.0.0.1:1984 helloworld.Greeter.SayHello 2>&1
+--- response_body_like: ResourceExhausted
+--- timeout: 60

Reply via email to