Skip to content

Commit

Permalink
Allow to send chunked request from lua
Browse files Browse the repository at this point in the history
Let assume that we have a lua script which calls `wrk.format` with both
headers and body, with`headers["Transfer-Encoding"] = "chunked"`.

That attempt fails with error like: `unexpected content-length header at`

Closes: wg#503
  • Loading branch information
catap committed Jan 5, 2023
1 parent a211dd5 commit 5230c30
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/wrk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,25 @@ function wrk.format(method, path, headers, body)
headers["Host"] = wrk.headers["Host"]
end

headers["Content-Length"] = body and string.len(body)
if not headers["Transfer-Encoding"] then
headers["Content-Length"] = body and string.len(body)
end

s[1] = string.format("%s %s HTTP/1.1", method, path)
for name, value in pairs(headers) do
s[#s+1] = string.format("%s: %s", name, value)
end

s[#s+1] = ""
s[#s+1] = body or ""
if headers["Transfer-Encoding"] and body then
s[#s+1] = string.format("%x", string.len(body))
s[#s+1] = body
s[#s+1] = "0"
s[#s+1] = ""
s[#s+1] = ""
else
s[#s+1] = body or ""
end

return table.concat(s, "\r\n")
end
Expand Down

0 comments on commit 5230c30

Please sign in to comment.