http.protocol: Support filehandlers for unhandled encodings
The setfilehandler() functions used for mime and url encoded message bodies all operate with a signature of fh(meta, chunk, eof), but for unhandled encodings, the callback was directly assigned to the sink function, which has a signature of snk(chunk). Insert a wrapper to properly generate the EOF flag, and include a stub "meta" block providing a virtual "name" and also the original client provided Content-Type header, to possibly help with taking alternative actions in the file handler. The sink function created for raw content decoding also used the wrong signature for the sink function. Signed-off-by: Karl Palsson <karlp@remake.is>
This commit is contained in:
parent
c42bd54abb
commit
2a77918b02
1 changed files with 12 additions and 3 deletions
|
@ -559,14 +559,23 @@ function parse_message_body( src, msg, filecb )
|
||||||
|
|
||||||
-- If we have a file callback then feed it
|
-- If we have a file callback then feed it
|
||||||
if type(filecb) == "function" then
|
if type(filecb) == "function" then
|
||||||
sink = filecb
|
local meta = {
|
||||||
|
name = "raw",
|
||||||
|
encoding = msg.env.CONTENT_TYPE
|
||||||
|
}
|
||||||
|
sink = function( chunk )
|
||||||
|
if chunk then
|
||||||
|
return filecb(meta, chunk, false)
|
||||||
|
else
|
||||||
|
return filecb(meta, nil, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
-- ... else append to .content
|
-- ... else append to .content
|
||||||
else
|
else
|
||||||
msg.content = ""
|
msg.content = ""
|
||||||
msg.content_length = 0
|
msg.content_length = 0
|
||||||
|
|
||||||
sink = function( chunk, err )
|
sink = function( chunk )
|
||||||
if chunk then
|
if chunk then
|
||||||
if ( msg.content_length + #chunk ) <= HTTP_MAX_CONTENT then
|
if ( msg.content_length + #chunk ) <= HTTP_MAX_CONTENT then
|
||||||
msg.content = msg.content .. chunk
|
msg.content = msg.content .. chunk
|
||||||
|
|
Loading…
Reference in a new issue