* luci/libs/http: use a more flexible aproach when storing multi-value fields
This commit is contained in:
parent
1245a9eaa9
commit
079f606bf9
1 changed files with 16 additions and 20 deletions
|
@ -113,32 +113,26 @@ end
|
||||||
|
|
||||||
-- Parameter helper
|
-- Parameter helper
|
||||||
local function __initval( tbl, key )
|
local function __initval( tbl, key )
|
||||||
local multival = ( key:sub( #key - 1, #key ) == "[]" )
|
if tbl[key] == nil then
|
||||||
|
|
||||||
if multival then
|
|
||||||
if type(tbl[key]) == "table" then
|
|
||||||
table.insert( tbl[key], "" )
|
|
||||||
else
|
|
||||||
tbl[key] = { "" }
|
|
||||||
end
|
|
||||||
else
|
|
||||||
tbl[key] = ""
|
tbl[key] = ""
|
||||||
|
elseif type(tbl[key]) == "string" then
|
||||||
|
tbl[key] = { tbl[key], "" }
|
||||||
|
else
|
||||||
|
table.insert( tbl[key], "" )
|
||||||
end
|
end
|
||||||
|
|
||||||
return multival
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function __appendval( tbl, key, multival, chunk )
|
local function __appendval( tbl, key, chunk )
|
||||||
if multival then
|
if type(tbl[key]) == "table" then
|
||||||
tbl[key][#tbl[key]] = tbl[key][#tbl[key]] .. chunk
|
tbl[key][#tbl[key]] = tbl[key][#tbl[key]] .. chunk
|
||||||
else
|
else
|
||||||
tbl[key] = tbl[key] .. chunk
|
tbl[key] = tbl[key] .. chunk
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function __finishval( tbl, key, multival, handler )
|
local function __finishval( tbl, key, handler )
|
||||||
if handler then
|
if handler then
|
||||||
if multival then
|
if type(tbl[key]) == "table" then
|
||||||
tbl[key][#tbl[key]] = handler( tbl[key][#tbl[key]] )
|
tbl[key][#tbl[key]] = handler( tbl[key][#tbl[key]] )
|
||||||
else
|
else
|
||||||
tbl[key] = handler( tbl[key] )
|
tbl[key] = handler( tbl[key] )
|
||||||
|
@ -321,9 +315,10 @@ process_states['mime-headers'] = function( msg, chunk, filecb )
|
||||||
|
|
||||||
-- Treat as form field
|
-- Treat as form field
|
||||||
else
|
else
|
||||||
local mv = __initval( msg.params, field )
|
__initval( msg.params, field )
|
||||||
|
|
||||||
msg._mimecallback = function(chunk,eof)
|
msg._mimecallback = function(chunk,eof)
|
||||||
__appendval( msg.params, field, mv, chunk )
|
__appendval( msg.params, field, chunk )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -475,13 +470,14 @@ process_states['urldecode-key'] = function( msg, chunk, filecb )
|
||||||
filecb( field, chunk, eof )
|
filecb( field, chunk, eof )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local mv = __initval( msg.params, key )
|
__initval( msg.params, key )
|
||||||
|
|
||||||
msg._urldeccallback = function( chunk, eof )
|
msg._urldeccallback = function( chunk, eof )
|
||||||
__appendval( msg.params, key, mv, chunk )
|
__appendval( msg.params, key, chunk )
|
||||||
|
|
||||||
-- FIXME: Use a filter
|
-- FIXME: Use a filter
|
||||||
if eof then
|
if eof then
|
||||||
__finishval( msg.params, key, mv, urldecode )
|
__finishval( msg.params, key, urldecode )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue