Module httoolsp.formdata
Submodule for multipart/form-data
manipulation
Functions
new() | Shortcut for FormData constructor. |
Class FormData
FormData\get_boundary() | Get boundary value. |
FormData\set_boundary(boundary) | Set boundary value. |
FormData\count() | Get the count of form-data parts. |
FormData\get(name, last, as_table) | Get the value of a form-data part with the specified name. |
FormData\get_all(name, as_table) | Get all values of form-data parts with the specified name. |
FormData\set(name, value, content_type, filename) | Add form-data part discarding existing parts with the same name (if any). |
FormData\add(name, value, content_type, filename) | Add form-data part keeping existing parts with the same name. |
FormData\delete(name) | Delete part(s) with the specified name. |
FormData\render() | Render form-data content to string. |
FormData\iterator() | Get iterator function rendering form-data content. |
Functions
Class FormData
A class representing
multipart/form-data
.
- FormData\get_boundary()
-
Get boundary value.
Generates random boundary if not set.
Returns:
-
string
boundary
- FormData\set_boundary(boundary)
-
Set boundary value.
Returns error if boundary is already set.
Parameters:
- boundary string
Returns:
-
bool
true
Or
- bool false
- string error message
- FormData\count()
-
Get the count of form-data parts.
Returns:
-
int
- FormData\get(name, last, as_table)
-
Get the value of a form-data part with the specified name.
Returns the value or the value table depending on
as_table
parameter.Value table is a hash table with the following fields:
name
: part name,string
value
: part value,string
or iteratorfunction
content_type
: part media type,string
ornil
filename
: part filename,string
ornil
If there is more than one part with the specified name, the value of the only first or last part will be returned depending on
last
parameter.Parameters:
- name string part name
- last
optional bool
get the value of the last part instead of the first if
true
(default isfalse
) - as_table
optional bool
return the value as a value table if
true
(default isfalse
)
Returns:
-
string or function
value
Or
-
table
value table
Or
- nil
- string error message
- FormData\get_all(name, as_table)
-
Get all values of form-data parts with the specified name.
Returns an array of values or value tables depending on
as_table
parameter.Parameters:
- name string part name
- as_table
optional bool
return the values as value tables if
true
(default isfalse
)
Returns:
-
table
array of values or value tables
Or
- nil
- string error message
- FormData\set(name, value, content_type, filename)
-
Add form-data part discarding existing parts with the same name (if any).
Parameters:
- name string part name
- value string or function part value
- content_type optional string part media type
- filename optional string part filename
Returns:
-
true
Or
- false
- string error message
- FormData\add(name, value, content_type, filename)
-
Add form-data part keeping existing parts with the same name.
Parameters:
- name string part name
- value string or function part value
- content_type optional string part media type
- filename optional string part filename
Returns:
-
true
Or
- false
- string error message
- FormData\delete(name)
-
Delete part(s) with the specified name.
Parameters:
- name string part name
Returns:
-
int
count of deleted parts, > 0
Or
-
nil
if no part found
Or
- nil
- string error message
- FormData\render()
-
Render form-data content to string.
Returns:
-
string
rendered form-data
Or
- nil
- string error message
- FormData\iterator()
-
Get iterator function rendering form-data content.
Returns:
-
function
iterator
Or
- nil
- string error message