Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apisix/plugins/grpc-transcode/proto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ local function create_proto_obj(proto_id)
end

local content
-- `id_schema` accepts a string or an integer, and the two are never equal
-- in Lua, so compare them in the same form.
proto_id = tostring(proto_id)
for _, proto in config_util.iterate_values(protos.values) do
if proto_id == proto.value.id then
if proto_id == tostring(proto.value.id) then
content = proto.value.content
break
end
Expand Down
52 changes: 52 additions & 0 deletions t/plugin/grpc-transcode.t
Original file line number Diff line number Diff line change
Expand Up @@ -837,3 +837,55 @@ POST /grpctest
Content-Type: application/json
--- response_body eval
qr/"items":\[\]/



=== TEST 32: set route with proto_id as an integer
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test

local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["POST"],
"uri": "/grpctest",
"plugins": {
"grpc-transcode": {
"proto_id": 1,
"service": "helloworld.Greeter",
"method": "SayHello"
}
},
"upstream": {
"scheme": "grpc",
"type": "roundrobin",
"nodes": {
"127.0.0.1:10051": 1
}
}
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed



=== TEST 33: hit route, an integer proto_id resolves the same proto
--- request
POST /grpctest
{"name":"world"}
--- more_headers
Content-Type: application/json
--- response_body eval
qr/"message":"Hello world"/
Loading