luci-base: handle bodies of non-POST requests as well
Decode the HTTP message bodies of any request carrying a Content-Length header, not just those in POST requests. This allows handling parameters in other methods, OPTIONS in particular. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
e56d9f4686
commit
7d13ec6010
1 changed files with 14 additions and 16 deletions
|
@ -486,26 +486,22 @@ end
|
||||||
-- handled then the whole message body will be stored unaltered as "content"
|
-- handled then the whole message body will be stored unaltered as "content"
|
||||||
-- property within the given message object.
|
-- property within the given message object.
|
||||||
function parse_message_body(src, msg, filecb)
|
function parse_message_body(src, msg, filecb)
|
||||||
local ctype = lhttp.header_attribute(msg.env.CONTENT_TYPE, nil)
|
if msg.env.CONTENT_LENGTH or msg.env.REQUEST_METHOD == "POST" then
|
||||||
|
local ctype = lhttp.header_attribute(msg.env.CONTENT_TYPE, nil)
|
||||||
|
|
||||||
-- Is it multipart/mime ?
|
-- Is it multipart/mime ?
|
||||||
if msg.env.REQUEST_METHOD == "POST" and
|
if ctype == "multipart/form-data" then
|
||||||
ctype == "multipart/form-data"
|
return mimedecode_message_body(src, msg, filecb)
|
||||||
then
|
|
||||||
return mimedecode_message_body(src, msg, filecb)
|
|
||||||
|
|
||||||
-- Is it application/x-www-form-urlencoded ?
|
-- Is it application/x-www-form-urlencoded ?
|
||||||
elseif msg.env.REQUEST_METHOD == "POST" and
|
elseif ctype == "application/x-www-form-urlencoded" then
|
||||||
ctype == "application/x-www-form-urlencoded"
|
return urldecode_message_body(src, msg)
|
||||||
then
|
|
||||||
return urldecode_message_body(src, msg)
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
-- Unhandled encoding
|
-- Unhandled encoding
|
||||||
-- If a file callback is given then feed it chunk by chunk, else
|
-- If a file callback is given then feed it chunk by chunk, else
|
||||||
-- store whole buffer in message.content
|
-- store whole buffer in message.content
|
||||||
else
|
|
||||||
|
|
||||||
local sink
|
local sink
|
||||||
|
|
||||||
-- If we have a file callback then feed it
|
-- If we have a file callback then feed it
|
||||||
|
@ -553,4 +549,6 @@ function parse_message_body(src, msg, filecb)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue