Send HTTP requests from HSL asynchronously as it suspends the current exeuction thread until done.
Follow the instructions in our manual to add our package repository and then run the below command.
apt-get install halon-extras-http-background
yum install halon-extras-http-background
For the configuration schema, see http-background.schema.json. Below is a sample configuration.
plugins:
- id: http-background
config:
threads:
- id: default
max_total: 100
max_host: 20
These functions needs to be imported from the extras://http-background
module path.
Params
- id
string
(required) - url
string
(required) - options
array
- tls_verify_peer
boolean
(defaulttrue
) - tls_verify_host
boolean
(defaulttrue
) - tls_client_cert
array
present a client certificate- x509
X509Resource
- privatekey
PrivateKeyResource
- chain
array
ofX509Resource
- x509
- timeout
number
in seconds (default no timeout) - connect_timeout
number
in seconds (default300
) - max_file_size
number
maxmium file size to retrieve (default no limit) - method
string
the request method (default depending on payload) - proxy
string
custom proxy server - encoder
string
encoder of the POST data (supported: base64) - headers (
array
ofstring
) additional headers, default empty array - sourceip
string
the sourceip (ipv4 or ipv6) - username
string
a username - password
string
a password - aws_sigv4
string
aws_sigv4 option (see CURLOPT_AWS_SIGV4), for exampleaws:amz:us-east-1:s3
. Use this option together withusername
andpassword
.
- tls_verify_peer
- post
File
,array
orstring
Type default POST Content-Type header is based on the POST data type
File
:application/octet-stream
array
:multipart/form-data
string
:application/x-www-form-urlencoded
If post is an array
the format should be associative array
where the key (string
) is the field name
- data
File
orstring
content of the field - type
string
content-type of the field - filename
string
filename of the field - encoder
string
encoder of the field (see curl_mime_encoder)
Returns
An associative array with a status
and content
key (if the HTTP request was submitted with a response code) or a error
key (if an error occurred).
Example
import { http_background } from "extras://http-background";
echo http_background(
"default",
"https://httpbin.org/get?a=b"
);
echo http_background(
"default",
"https://httpbin.org/post?a=b",
[],
["field1" => ["data" => "test"]]
);