Skip to content

Commit 3b2d478

Browse files
committed
bug fix: handle lf linebreak before boundary
1 parent df7efb9 commit 3b2d478

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/resty/upload.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ local function get_boundary()
4545
return match(header, ";%s*boundary=([^\",;]+)")
4646
end
4747

48-
local function read_line_construct(sock, lf_line_break)
48+
local function read_line_construct(sock, boundary, lf_line_break)
4949
local line_end = "\r\n"
5050
if lf_line_break then
5151
line_end = "\n"
5252
end
53-
local read_line, err = sock:receiveuntil(line_end)
53+
local read_line, err = sock:receiveuntil(line_end .. boundary)
5454
if lf_line_break and read_line then
5555
return function (arg)
5656
local ret, err_inner = read_line(arg)
@@ -65,7 +65,7 @@ local function read_line_construct(sock, lf_line_break)
6565
end
6666

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

7070
-- print("boundary: ", boundary)
7171

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

83-
local read2boundary, err = sock:receiveuntil("--" .. boundary)
83+
local read2boundary, err = sock:receiveuntil(boundary)
8484
if not read2boundary then
8585
return nil, err
8686
end
8787

88-
local read_line, err = read_line_construct(sock, lf_line_break)
88+
local read_line, err = read_line_construct(sock, "", lf_line_break)
8989
if not read_line then
9090
return nil, err
9191
end
@@ -273,7 +273,7 @@ local function read_preamble(self)
273273
return nil, nil, err
274274
end
275275

276-
local read2boundary, err = sock:receiveuntil("\r\n--" .. self.boundary)
276+
read2boundary, err = read_line_construct(sock, self.boundary, self.lf_line_break)
277277
if not read2boundary then
278278
return nil, nil, err
279279
end

0 commit comments

Comments
 (0)