Skip to content

Commit

Permalink
using string.buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Sep 13, 2023
1 parent 7d10bce commit fc6348e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions kong/plugins/grpc-web/deco.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Copyright (c) Kong Inc. 2020

local cjson = require "cjson"
local buffer = require "string.buffer"
local pb = require "pb"
local grpc_tools = require "kong.tools.grpc"
local grpc_frame = grpc_tools.frame
Expand Down Expand Up @@ -139,7 +140,7 @@ function deco:downstream(chunk)
if self.msg_encoding ~= "proto" then
local body = (self.downstream_body or "") .. chunk

local out, n = {}, 1
local out = buffer.new()
local msg, body = grpc_unframe(body)

while msg do
Expand All @@ -148,13 +149,12 @@ function deco:downstream(chunk)
msg = grpc_frame(0x0, msg)
end

out[n] = msg
n = n + 1
out:put(msg)
msg, body = grpc_unframe(body)
end

self.downstream_body = body
chunk = table.concat(out)
chunk = out:get()
end

if self.text_encoding == "base64" then
Expand Down

0 comments on commit fc6348e

Please sign in to comment.