This is an automated email from the ASF dual-hosted git repository.
shreemaanabhishek 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 7b665be43 feat: allow grpc web in non prefix based routes (#12830)
7b665be43 is described below
commit 7b665be4399df370660498ca1f7635871aef3f44
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Thu Jan 1 15:45:49 2026 +0545
feat: allow grpc web in non prefix based routes (#12830)
---
apisix/plugins/grpc-web.lua | 18 ++++++------------
docs/en/latest/plugins/grpc-web.md | 8 --------
t/plugin/grpc-web.t | 11 +++++------
3 files changed, 11 insertions(+), 26 deletions(-)
diff --git a/apisix/plugins/grpc-web.lua b/apisix/plugins/grpc-web.lua
index 642a0ab92..da059822e 100644
--- a/apisix/plugins/grpc-web.lua
+++ b/apisix/plugins/grpc-web.lua
@@ -43,7 +43,7 @@ local schema = {
properties = {
cors_allow_headers = {
description =
- "multiple header use ',' to split. default:
content-type,x-grpc-web,x-user-agent.",
+ "multiple header use ',' to split. default:
content-type,x-grpc-web,x-user-agent.",
type = "string",
default = DEFAULT_CORS_ALLOW_HEADERS
}
@@ -134,20 +134,14 @@ function _M.access(conf, ctx)
-- set context variable encoding method
ctx.grpc_web_encoding = encoding
- -- set grpc path
- if not (ctx.curr_req_matched and ctx.curr_req_matched[":ext"]) then
- core.log.error("routing configuration error, grpc-web plugin only
supports ",
- "`prefix matching` pattern routing")
- return exit(ctx, 400)
- end
-
local path = ctx.curr_req_matched[":ext"]
- if path:byte(1) ~= core.string.byte("/") then
- path = "/" .. path
+ if path and path ~= "" then
+ if path:byte(1) ~= core.string.byte("/") then
+ path = "/" .. path
+ end
+ req_set_uri(path)
end
- req_set_uri(path)
-
-- set grpc body
local body, err = core.request.get_body()
if err or not body then
diff --git a/docs/en/latest/plugins/grpc-web.md
b/docs/en/latest/plugins/grpc-web.md
index 87391453a..ea796b513 100644
--- a/docs/en/latest/plugins/grpc-web.md
+++ b/docs/en/latest/plugins/grpc-web.md
@@ -68,14 +68,6 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 -H
"X-API-KEY: $admin_key" -X P
}'
```
-:::info IMPORTANT
-
-While using the `grpc-web` Plugin, always use a prefix matching pattern (`/*`,
`/grpc/example/*`) for matching Routes. This is because the gRPC Web client
passes the package name, the service interface name, the method name and other
information in the proto in the URI. For example,
`/path/a6.RouteService/Insert`.
-
-So, when absolute matching is used, the Plugin would not be hit and the
information from the proto would not be extracted.
-
-:::
-
## Example usage
Refer to [gRPC-Web Client Runtime
Library](https://www.npmjs.com/package/grpc-web) or [Apache APISIX gRPC Web
Test Framework](https://github.com/apache/apisix/tree/master/t/plugin/grpc-web)
to learn how to setup your web client.
diff --git a/t/plugin/grpc-web.t b/t/plugin/grpc-web.t
index 9ba711850..aaf444d96 100644
--- a/t/plugin/grpc-web.t
+++ b/t/plugin/grpc-web.t
@@ -137,7 +137,7 @@ request Content-Type: `application/json` invalid
content_by_lua_block {
local config = {
- uri = "/grpc/web2/a6.RouteService/GetRoute",
+ uri = "/grpc/web/a6.RouteService/GetRoute",
upstream = {
scheme = "grpc",
type = "roundrobin",
@@ -168,15 +168,14 @@ passed
=== TEST 8: test route (absolute match)
--- request
-POST /grpc/web2/a6.RouteService/GetRoute
+POST /grpc/web/a6.RouteService/GetRoute
+hello
--- more_headers
Content-Type: application/grpc-web
---- error_code: 400
+--- error_code: 200
--- response_headers
Access-Control-Allow-Origin: *
-Content-Type: text/html
---- error_log
-routing configuration error, grpc-web plugin only supports `prefix matching`
pattern routing
+Content-Type: application/grpc-web