Skip to content

Commit

Permalink
refactor(pdk): output content with string.buffer (#11937)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored Nov 7, 2023
1 parent c74cbc7 commit ae5d5ea
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions kong/pdk/service/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-- @module kong.service.request

local cjson = require "cjson.safe"
local buffer = require "string.buffer"
local checks = require "kong.pdk.private.checks"
local phase_checker = require "kong.pdk.private.phases"

Expand Down Expand Up @@ -541,26 +542,23 @@ local function new(self)

table_sort(keys)

local out = {}
local i = 1
local out = buffer.new()

for _, k in ipairs(keys) do
out[i] = "--"
out[i + 1] = boundary
out[i + 2] = "\r\n"
out[i + 3] = 'Content-Disposition: form-data; name="'
out[i + 4] = k
out[i + 5] = '"\r\n\r\n'
local v = args[k]
out[i + 6] = v
out[i + 7] = "\r\n"
i = i + 8
out:put("--")
:put(boundary)
:put("\r\n")
:put('Content-Disposition: form-data; name="')
:put(k)
:put('"\r\n\r\n')
:put(args[k])
:put("\r\n")
end
out[i] = "--"
out[i + 1] = boundary
out[i + 2] = "--\r\n"
out:put("--")
:put(boundary)
:put("--\r\n")

local output = table.concat(out)
local output = out:get()

return output, CONTENT_TYPE_FORM_DATA .. "; boundary=" .. boundary
end,
Expand Down

1 comment on commit ae5d5ea

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:ae5d5ea87f608bf80b1efe7a1aa3a2062fd6b873
Artifacts available https://github.com/Kong/kong/actions/runs/6784831130

Please sign in to comment.