Module ctr.httpc
The httpc module.
Usage:
local httpc = require("ctr.httpc")
-
context ()
-
Create a HTTP Context.
Returns:
context
a new http context
-
:open (url[, method="GET"])
-
Open an url in the context.
Parameters:
- url
string
the url to open
- method
string
method to use; can be
"GET"
, "POST"
, "HEAD"
, "PUT"
or "DELETE"
(default "GET")
Returns:
boolean
true
if everything went fine
Or
-
boolean
false
in case of error
-
integer
error code
-
:addRequestHeaderField (name, value)
-
Add a field in the request header.
Parameters:
- name
string
Name of the field
- value
string
Value of the field
Returns:
boolean
true
if everything went fine
Or
-
boolean
false
in case of error
-
integer
error code
-
:beginRequest ()
-
Begin a request to get the content at the URL.
Returns:
boolean
true
if everything went fine
Or
-
boolean
false
in case of error
-
integer
error code
-
:getStatusCode ()
-
Return the status code returned by the request.
Returns:
integer
the status code
Or
-
nil
in case of error
-
integer
error code
-
:getDownloadSize ()
-
Return the amount of data to download.
Returns:
number
size in (bytes)
-
:downloadData ()
-
Download and return the data of the context.
Returns:
string
data
Or
-
nil
in case of error
-
integer
error code
-
:close ()
-
Close the context.
-
:addPostData (name, value)
-
Add a POST form field to a HTTP context.
Parameters:
- name
string
name of the field
- value
string
value of the field
-
:getResponseHeader (name[, maximum=2048])
-
Get a header field from a response.
Parameters:
- name
string
name of the header field to get
- maximum
number
size of the value to get
(default 2048)
Returns:
string
field value
-
:addTrustedRootCA (DER)
-
Add a trusted RootCA cert to a context.
Parameters:
Returns:
boolean
true
if everything went fine
Or
-
boolean
false
in case of error
-
integer
error code
-
:setSSLOptions (disableVerify[, tlsv10=false])
-
Set SSL options for a context.
Parameters:
- disableVerify
boolean
disable server certificate verification if
true
- tlsv10
boolean
use TLS v1.0 if
true
(default false)
-
addDefaultCert ()
-
Add all the default certificates to the context.