Skip to content

Commit

Permalink
bug fix: handle lf linebreak before boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
suikabreaker committed Jan 25, 2022
1 parent df7efb9 commit 3b2d478
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/resty/upload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ local function get_boundary()
return match(header, ";%s*boundary=([^\",;]+)")
end

local function read_line_construct(sock, lf_line_break)
local function read_line_construct(sock, boundary, lf_line_break)
local line_end = "\r\n"
if lf_line_break then
line_end = "\n"
end
local read_line, err = sock:receiveuntil(line_end)
local read_line, err = sock:receiveuntil(line_end .. boundary)
if lf_line_break and read_line then
return function (arg)
local ret, err_inner = read_line(arg)
Expand All @@ -65,7 +65,7 @@ local function read_line_construct(sock, lf_line_break)
end

function _M.new(self, chunk_size, max_line_size, lf_line_break)
local boundary = get_boundary()
local boundary = "--" .. get_boundary()

-- print("boundary: ", boundary)

Expand All @@ -80,12 +80,12 @@ function _M.new(self, chunk_size, max_line_size, lf_line_break)
return nil, err
end

local read2boundary, err = sock:receiveuntil("--" .. boundary)
local read2boundary, err = sock:receiveuntil(boundary)
if not read2boundary then
return nil, err
end

local read_line, err = read_line_construct(sock, lf_line_break)
local read_line, err = read_line_construct(sock, "", lf_line_break)
if not read_line then
return nil, err
end
Expand Down Expand Up @@ -273,7 +273,7 @@ local function read_preamble(self)
return nil, nil, err
end

local read2boundary, err = sock:receiveuntil("\r\n--" .. self.boundary)
read2boundary, err = read_line_construct(sock, self.boundary, self.lf_line_break)
if not read2boundary then
return nil, nil, err
end
Expand Down

0 comments on commit 3b2d478

Please sign in to comment.