diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2016-01-15 15:20:41 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2016-01-15 15:20:41 +0100 |
commit | ad064f0b039839dd333bfe8e9631cbc5218410b0 (patch) | |
tree | c13911127dbab695710aa784b54b22e794f1a43c /modules/luci-base/luasrc/http/protocol.lua | |
parent | 1a7b0b22a85d8294d7a2c196b708266c872dd054 (diff) | |
parent | b130ca554f13e17c787a1c6fd09e67dd7727a4d3 (diff) |
Merge pull request #563 from cshore/pull-request-app-uhttpd
Pull request app uhttpd
Diffstat (limited to 'modules/luci-base/luasrc/http/protocol.lua')
-rw-r--r-- | modules/luci-base/luasrc/http/protocol.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/luci-base/luasrc/http/protocol.lua b/modules/luci-base/luasrc/http/protocol.lua index 0cb62aeec9..061c6ad544 100644 --- a/modules/luci-base/luasrc/http/protocol.lua +++ b/modules/luci-base/luasrc/http/protocol.lua @@ -114,6 +114,16 @@ local function __initval( tbl, key ) end -- (Internal function) +-- Initialize given file parameter. +local function __initfileval( tbl, key, filename, fd ) + if tbl[key] == nil then + tbl[key] = { file=filename, fd=fd, name=key, "" } + else + table.insert( tbl[key], "" ) + end +end + +-- (Internal function) -- Append given data to given parameter, either by extending the string value -- or by appending it to the last string in the parameter's value table. local function __appendval( tbl, key, chunk ) @@ -313,6 +323,22 @@ function mimedecode_message_body( src, msg, filecb ) __appendval( msg.params, field.name, field.file ) store = filecb + elseif field.name and field.file then + local nxf = require "nixio" + local fd = nxf.mkstemp(field.name) + __initfileval ( msg.params, field.name, field.file, fd ) + if fd then + store = function(hdr, buf, eof) + fd:write(buf) + if (eof) then + fd:seek(0, "set") + end + end + else + store = function( hdr, buf, eof ) + __appendval( msg.params, field.name, buf ) + end + end elseif field.name then __initval( msg.params, field.name ) |