Revised sysupgrade part 1
[project/luci.git] / libs / http / luasrc / http / protocol.lua
index 6e2ae29..6873d24 100644 (file)
@@ -421,7 +421,7 @@ function mimedecode_message_body( src, msg, filecb )
                                        end
 
                                        if store then
-                                               store( field.headers, predata, true )
+                                               store( field, predata, true )
                                        end
 
 
@@ -439,7 +439,7 @@ function mimedecode_message_body( src, msg, filecb )
                                        data   = data:sub( 1, #data - 78 )
 
                                        if store then
-                                               store( field.headers, data, false )
+                                               store( field, data, false )
                                        else
                                                return nil, "Invalid MIME section header"
                                        end
@@ -451,7 +451,7 @@ function mimedecode_message_body( src, msg, filecb )
                                        lchunk, eof = parse_headers( data, field )
                                        inhdr = not eof
                                else
-                                       store( field.headers, lchunk, false )
+                                       store( field, lchunk, false )
                                        lchunk, chunk = chunk, nil
                                end
                        end
@@ -500,7 +500,7 @@ function urldecode_message_body( src, msg )
                                if spos then
                                        local pair = data:sub( spos, epos - 1 )
                                        local key  = pair:match("^(.-)=")
-                                       local val  = pair:match("=(.*)$")
+                                       local val  = pair:match("=([^%s]*)%s*$")
 
                                        if key and #key > 0 then
                                                __initval( msg.params, key )
@@ -638,16 +638,17 @@ function parse_message_body( src, msg, filecb )
                        msg.content = ""
                        msg.content_length = 0
 
-                       sink = function( chunk )
-                               if ( msg.content_length + #chunk ) <= HTTP_MAX_CONTENT then
-
-                                       msg.content        = msg.content        .. chunk
-                                       msg.content_length = msg.content_length + #chunk
-
-                                       return true
-                               else
-                                       return nil, "POST data exceeds maximum allowed length"
+                       sink = function( chunk, err )
+                               if chunk then
+                                       if ( msg.content_length + #chunk ) <= HTTP_MAX_CONTENT then
+                                               msg.content        = msg.content        .. chunk
+                                               msg.content_length = msg.content_length + #chunk
+                                               return true
+                                       else
+                                               return nil, "POST data exceeds maximum allowed length"
+                                       end
                                end
+                               return true
                        end
                end
 
@@ -671,6 +672,7 @@ end
 statusmsg = {
        [200] = "OK",
        [301] = "Moved Permanently",
+       [302] = "Found",
        [304] = "Not Modified",
        [400] = "Bad Request",
        [403] = "Forbidden",