Set method to POST if we have postdata and no other method is set
[project/luci.git] / libs / httpclient / luasrc / httpclient.lua
index 767a02e..01ef970 100644 (file)
@@ -121,7 +121,6 @@ function request_raw(uri, options)
        options.depth = options.depth or 10
        local headers = options.headers or {}
        local protocol = options.protocol or "HTTP/1.1"
-       local method  = options.method or "GET"
        headers["User-Agent"] = headers["User-Agent"] or "LuCI httpclient 0.1"
        
        if headers.Connection == nil then
@@ -152,16 +151,17 @@ function request_raw(uri, options)
        
        if type(options.body) == "table" then
                options.body = http.urlencode_params(options.body)
-               headers["Content-Type"] = headers["Content-Type"] or 
-                       "application/x-www-form-urlencoded"
        end
 
        if type(options.body) == "string" then
                headers["Content-Length"] = headers["Content-Length"] or #options.body
+               headers["Content-Type"] = headers["Content-Type"] or
+                       "application/x-www-form-urlencoded"
+               options.method = options.method or "POST"
        end
        
        -- Assemble message
-       local message = {method .. " " .. path .. " " .. protocol}
+       local message = {(options.method or "GET") .. " " .. path .. " " .. protocol}
        
        for k, v in pairs(headers) do
                if type(v) == "string" then