Skip to content

Commit

Permalink
fix(grpc): empty message cannot be unframed
Browse files Browse the repository at this point in the history
Fix FTI-5054

Update CHANGELOG.md
  • Loading branch information
StarlightIbuki committed May 12, 2023
1 parent b2d2938 commit 804fb15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

## Unreleased

### Fixes

#### Plugins

- **grpc-gateway**: Fixed an issue that empty (all default value) messages cannot be unframed correctly.
[#10836](https://github.com/Kong/kong/pull/10836)

### Dependencies

- Bumped lua-resty-openssl from 0.8.20 to 0.8.22
Expand Down
6 changes: 5 additions & 1 deletion kong/tools/grpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ end

--- wraps a binary payload into a grpc stream frame.
function _M.frame(ftype, msg)
-- byte 0: frame type
-- byte 1-4: frame size in big endian (could be zero)
-- byte 5-: frame content
return bpack("C>I", ftype, #msg) .. msg
end

Expand All @@ -149,7 +152,8 @@ end
--- If heading frame isn't complete, returns `nil, body`,
--- try again with more data.
function _M.unframe(body)
if not body or #body <= 5 then
-- must be at least 5 bytes(frame header)
if not body or #body < 5 then
return nil, body
end

Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/28-grpc-gateway/01-proxy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ for _, strategy in helpers.each_strategy() do
end)

-- Bug found when test FTI-5002's fix. It will be fixed in another PR.
pending("empty message #10802", function()
test("empty message #10802", function()
local req_body = { array = {}, nullable = "" }
local res, _ = proxy_client:post("/v1/echo", {
headers = { ["Content-Type"] = "application/json" },
Expand Down

0 comments on commit 804fb15

Please sign in to comment.