Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions luncheon/http_message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,20 @@ function HttpMessage:body_type()

enc = headers:get_all("transfer_encoding")
local ty = "close"
if not enc then
return {
type = ty,
}
end
for _, v in ipairs(enc) do
if HttpMessage.includes_chunk_encoding(v) then
ty = "chunked"
break
if enc then
for _, v in ipairs(enc) do
if HttpMessage.includes_chunk_encoding(v) then
ty = "chunked"
break
end
end
end

-- Check for protocol violation: close-delimited responses in HTTP/1.1 must have Connection: close
if ty == "close" and self.http_version and self.http_version >= 1.1 and self:get_connection() ~= "close" then
return nil, "Protocol violation: close-delimited response without Connection: close in HTTP/1.1"
end

local trailers = false
if ty == "chunked" then
local trailer = headers:get_all("trailer")
Expand Down Expand Up @@ -521,6 +524,17 @@ function HttpMessage:get_headers()
return self.headers
end

---@return string|nil
---@return nil|string
function HttpMessage:get_connection()
local headers, err = self:get_headers()
if not headers then
return nil, err
end
local connection = headers:get_one("connection")
return connection and string.lower(connection)
end

--- Serailize the provide Request or Response into a string with new lines
---@return string|nil result The serialized string if nil an error occured
---@return nil|string err If not nil the error
Expand Down