diff --git a/doc/ftp.html b/doc/ftp.html index 3f23a4a..3866942 100644 --- a/doc/ftp.html +++ b/doc/ftp.html @@ -95,7 +95,7 @@ the FTP module:

-ftp.get(url)
+ftp.get(url [, create])
ftp.get{
  host = string,
  sink = LTN12 sink,
@@ -114,7 +114,10 @@ ftp.get{
The get function has two forms. The simple form has fixed functionality: it downloads the contents of a URL and returns it as a string. The generic form allows a lot more control, as explained -below. +below. The create parameter is only used in the string form, +and will be used as alternative for socket.tcp +if it is provided. In the advanced form create has to be specified +in the arguments table.

@@ -180,7 +183,7 @@ end

-ftp.put(url, content)
+ftp.put(url, content [, create])
ftp.put{
  host = string,
  source = LTN12 sink,
@@ -198,7 +201,11 @@ ftp.put{

The put function has two forms. The simple form has fixed functionality: it uploads a string of content into a URL. The generic form -allows a lot more control, as explained below. +allows a lot more control, as explained below. The create +parameter is only used in the string form, and will be used as alternative +for socket.tcp if it is provided. +In the advanced form create has to be specified in the arguments +table.

diff --git a/doc/http.html b/doc/http.html index cd41c0d..96a937b 100644 --- a/doc/http.html +++ b/doc/http.html @@ -122,7 +122,7 @@ the HTTP module:

-http.request(url [, body])
+http.request(url [, body [, create]])
http.request{
  url = string,
  [sink = LTN12 sink,]
@@ -148,7 +148,9 @@ If the first argument of the request function is a string, it should be an url. In that case, if a body is provided as a string, the function will perform a POST method in the url. Otherwise, it performs a GET in the -url +url. The create parameter is only used in the string form, +and will be used as alternative for socket.tcp +if it is provided.

diff --git a/src/ftp.lua b/src/ftp.lua index ea1145b..1ffbbe4 100644 --- a/src/ftp.lua +++ b/src/ftp.lua @@ -232,14 +232,15 @@ local function parse(u) return t end -local function sput(u, body) +local function sput(u, body, create) local putt = parse(u) putt.source = ltn12.source.string(body) + putt.create = create return tput(putt) end -_M.put = socket.protect(function(putt, body) - if base.type(putt) == "string" then return sput(putt, body) +_M.put = socket.protect(function(putt, body, create) + if base.type(putt) == "string" then return sput(putt, body, create) else return tput(putt) end end) @@ -256,10 +257,11 @@ local function tget(gett) return f:close() end -local function sget(u) +local function sget(u, create) local gett = parse(u) local t = {} gett.sink = ltn12.sink.table(t) + gett.create = create tget(gett) return table.concat(t) end @@ -277,8 +279,8 @@ _M.command = socket.protect(function(cmdt) return f:close() end) -_M.get = socket.protect(function(gett) - if base.type(gett) == "string" then return sget(gett) +_M.get = socket.protect(function(gett, create) + if base.type(gett) == "string" then return sget(gett, create) else return tget(gett) end end) diff --git a/src/http.lua b/src/http.lua index d5457f6..49261d3 100644 --- a/src/http.lua +++ b/src/http.lua @@ -329,11 +329,12 @@ end return 1, code, headers, status end -local function srequest(u, b) +local function srequest(u, b, create) local t = {} local reqt = { url = u, - sink = ltn12.sink.table(t) + sink = ltn12.sink.table(t), + create = create, } if b then reqt.source = ltn12.source.string(b) @@ -347,8 +348,8 @@ local function srequest(u, b) return table.concat(t), code, headers, status end -_M.request = socket.protect(function(reqt, body) - if base.type(reqt) == "string" then return srequest(reqt, body) +_M.request = socket.protect(function(reqt, body, create) + if base.type(reqt) == "string" then return srequest(reqt, body, create) else return trequest(reqt) end end)