Table of Contents
List of Examples
http_timeout
parameterhttp_timeout_connect
parameterhttp_timeout_read
parameterhttp_timeout_write
parameterhttp_tlsmode
parameterhttp_reuse
parameterhttp_retry
parameterhttp_logtype
parameterhttp_debug
parameterruxc_http_get()
usageruxc_http_post()
usageruxc_http_delete()
usageTable of Contents
The module exports utility functions based on libruxc.
Among them are function to perform HTTP GET and POST queries.
The ruxc project is available at: https://github.com/miconda/ruxc.
The following modules must be installed (but not loaded) to use this module:
none.
The interval in milliseconds after which the HTTP GET or POST query times out. It is the overall timeout, including DNS resolution, connecting time, redirects, and reading the response body. Slow DNS resolution may cause a request to exceed the timeout, because the DNS request cannot be interrupted with the available APIs. It takes precedence over http_timeout_read() and http_timeout_write(), but not http_timeout_connect. See also the comments in 'https://github.com/algesten/ureq/blob/main/src/agent.rs'.
Use 0 to disable setting it in the library.
Default value is 5000 (5 secs).
The interval in milliseconds after which to give up on connecting to the HTTP/S server. If http_timeout is set, this one takes precedence. The library beneath has a default 30 seconds connect timeout.
Use 0 to disable setting it in the library.
Default value is 5000 (5 secs).
Example 1.2. Set http_timeout_connect
parameter
... modparam("ruxc", "http_timeout_connect", 2000) ...
The interval in milliseconds after which the read on HTTP/S connection socket timeouts. If http_timeout is set, it takes precedence.
Use 0 to disable setting it in the library.
Default value is 5000 (5 secs).
The interval in milliseconds after which the write on HTTP/S connection socket timeouts. If http_timeout is set, it takes precedence.
Use 0 to disable setting it in the library.
Default value is 5000 (5 secs).
The mode to connect over TLS to HTTPS sites: 0 accept all certificates; 1 - accept trusted certificates.
Default value is 0 (accept all certificates).
Set to 1 in order to reuse the connection for all requests (each Kamailio process has its own connection). Useful to avoid TCP connect (and TLS handshake) when all requests are performed against the same HTTP/S server.
Set to 2 in order to keep connections per base URL (scheme://host:port) indexed in a hash map. Useful when doing HTTP/S requests to many servers.
Default value is 0 (new connection for each request).
How many times to retry if the HTTP request does not get a 200 OK response.
Default value is 0 (no retry).
Set the log type for libruxc http functions: 0 - stdout; 1 - syslog.
Default value is 0.
Perform a HTTP GET request to "url", storing the response body in the "respv" variable. The "hdrs" can be empty string to skip setting them. The first two parameters can contain variables that are evaluated at runtime. The "respv" has to be the name of a writable variable.
The function returns response code of HTTP reply or negative value if something went wrong.
This function can be used from ANY_ROUTE.
Example 1.10. ruxc_http_get()
usage
... ruxc_http_get("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(fu{s.escape.param})", "", "X-Token: abc", "$var(result)"); switch ($rc) { ... } ...
Perform a HTTP POST request to "url", storing the response body in the "respv" variable. The "body" and "hdrs" can be empty strings to skip setting them. The first three parameters can contain variables that are evaluated at runtime. The "respv" has to be the name of a writable variable.
The function returns response code of HTTP reply or negative value if something went wrong.
This function can be used from ANY_ROUTE.
Example 1.11. ruxc_http_post()
usage
... ruxc_http_post("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(fu{s.escape.param})", "", "X-Token: abc", "$var(result)"); switch ($rc) { ... } ...
Perform a HTTP DELETE request to "url", storing the response body in the "respv" variable. The "body" and "hdrs" can be empty strings to skip setting them. The first three parameters can contain variables that are evaluated at runtime. The "respv" has to be the name of a writable variable.
The function returns response code of HTTP reply or negative value if something went wrong.
This function can be used from ANY_ROUTE.
Example 1.12. ruxc_http_delete()
usage
... ruxc_http_delete("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(fu{s.escape.param})", "", "X-Token: abc", "$var(result)"); switch ($rc) { ... } ...
The module needs "libruxc" library, which is provided by "ruxc" project from https://github.com/miconda/ruxc/. The library is implemented in Rust language, with generated C API and library. Until the libruxc is going to be packaged in OS distributions, the ruxc module can be compiled by copying ruxc.h and libruxc.a files in the folder of the module.
To generate the libruxc.a file, it requires to have Rust language installed and its environment configured, then run the following commands:
Example 1.13. Libruxc Usage
... git clone https://github.com/miconda/ruxc cd ruxc cargo build --release cp include/ruxc.h target/release/libruxc.a \ /path/to/kamailio/src/modules/ruxc/ cd /path/to/kamailio/ make include_modules="ruxc ..." cfg make all make install ## or compiling individual module for use inside source tree # make modules modules=src/modules/ruxc ...
For more details about compilation and installation of libruxc, see: https://github.com/miconda/ruxc.