Skip to content

Commit

Permalink
fix(grpc-gateway) clear up output buffer when getting partial response (
Browse files Browse the repository at this point in the history
#12)

Fix #9
  • Loading branch information
fffonion authored and gszr committed Jun 17, 2021
1 parent 70d3587 commit 5f936ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions kong/plugins/grpc-gateway/deco.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,9 @@ function deco:downstream(chunk)
return chunk
end

function deco:get_raw_downstream_body()
return self.downstream_body
end


return deco
10 changes: 7 additions & 3 deletions kong/plugins/grpc-gateway/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ function grpc_gateway:body_filter(conf)
end

local ret = dec:downstream(ngx_arg[1])
-- fall through if we can't decode response
-- or it's empty
if not ret or #ret == 0 then
return
if ngx_arg[2] then
-- it's eof and we still cannot decode, fall through
ret = deco:get_raw_downstream_body()
else
-- clear output if we cannot decode, it could be body is not complete yet
ret = nil
end
end
ngx_arg[1] = ret
end
Expand Down

0 comments on commit 5f936ba

Please sign in to comment.