Module cURL

Provide same functions as `lcurl` module with some additions.

Here are the only functions that have been added or changed.

Functions

form (form) Create HTTP multipart/formdata object.

Tables

FORM_DESCRIPTION Form description table.
form_stream Table describe stream part in form.
form_file Table describe file part in form.
form_buffer Table describe buffer part in form.
form_content Table describe content part in form.

Class httpform

httpform:add (form) Add new part to form.

Class easy

easy:perfom ([options]) Perform a file transfer
easy.data User data.

Class multi

multi:iperform () Iterator that returns the next data, type and corresponding easy handle.
multi.data User data.


Functions

form (form)
Create HTTP multipart/formdata object.

Parameters:

  • form FORM_DESCRIPTION description

Returns:

    Form new curl HTTP Post object context

See also:

Tables

FORM_DESCRIPTION
Form description table.

Fields:

Usage:

     post_form = cURL.form{
    
       -- file form filesystem
       name01 = {
         file = "post_form.lua",
         type = "text/plain",
         name = "post.lua",
       },
    
       -- file form string
       name02 = {
         data = "<html><bold>bold</bold></html>",
         name = "dummy.html",
         type = "text/html",
       },
    
       -- file form stream object
       name03 = {
         stream  = Stream:new('8', 25),
         name    = "stream1.txt",
         type    = "text/plain",
         headers = {
           "X-Test-Char : 8",
           "X-Test-length : 25",
         }
       },
    
       -- file form stream function
       name04 = {
         stream  = stream,
         length  = length,
         name    = "stream2.txt",
         type    = "text/plain",
       },
    
       -- content form string
       name05 = 'value05',
    
       -- content form string
       name06 = { 'value06', -- or content = 'value05'
         type    = "text/plain",
       },
    
     }
form_stream
Table describe stream part in form.

Fields:

  • stream function, table or userdata stream function is same as in readfunction. Also stream object may provide `length` method.
  • length number (default stream:length())
  • name string file name
  • type string mime type (e.g. 'text/plain')
  • headers table array of headers
form_file
Table describe file part in form.

Fields:

  • file string path to file in local FS (e.g. 'path/to/some/file.txt')
  • name string file name (default basename(file))
  • type string mime type (e.g. 'text/plain')
  • headers table array of headers
form_buffer
Table describe buffer part in form.

Fields:

  • data string file content
  • name string file name
  • type string mime type (e.g. 'text/plain')
  • headers table array of headers
form_content
Table describe content part in form.

Fields:

  • content string value (or first field in table)
  • type string mime type (e.g. 'text/plain')
  • headers table array of headers

Class httpform

httpform:add (form)
Add new part to form.

Parameters:

  • form FORM_DESCRIPTION description

Returns:

    httpform self

See also:

Class easy

easy:perfom ([options])
Perform a file transfer

Parameters:

Returns:

    easy self

Usage:

    e:perfom{writefunction = assert(io.open("fname.txt", "w+b"))}
easy.data
User data.

Please use this field to associate any data with curl handle.

  • data

Usage:

     f = io.open("lua.org.download", "w+")
     e = curl.easy{url = "http://lua.org", writefunction = f}
     e.data = f

Class multi

multi:iperform ()
Iterator that returns the next data, type and corresponding easy handle.
Returned data types: `response`, `header`, `data`, `error`, `done`.
Note. response data may appeare several times (e.g. if you proceed http request with digest auth you should get 401 and 200 responses).
Easy handle is removed at the end of the operation (when get `done` or `error` row).

Returns:

    Iterator iterator for generic for

Usage:

    for data, type, easy in m:iperform() do ... end
multi.data
User data.

Please use this field to associate any data with curl handle.

  • data
generated by LDoc 1.4.0