http_server Module

The module provides the ability to pass data of HTTP requests to Lua scripts and backwards. A Lua plugin can create a named or unnamed HTTP link, bind handlers script to it. When the link is hit via HTTP/HTTPS protocol, all HTTP request's data, will be passed to a handler script. When

A plugin can fill HTTP response body, headers, HTTP status.

require 'http_server'

Overview: API Requests


Creates new plugin's HTTP link object, which can be accessed via HTTP URLs.

Arguments: options: table

Table Field Type Required Description
link_id string - Identifier of a new link. If it's not defined then a new id will be generated.
handler string + Path to a plugin's Lua script file which should be executed when any new data will come ( in HUB:my_plugin/http_receive.lua format )
user_data any - Any data which will be passed to receive_script, send_script and any event. Can be of any valid type: string, number, boolean, array, object. If user_data is null, the value will not be set.
timeout int - Timeout in milliseconds for keeping the connection open. Default value: 30000 milliseconds. Max possible value: 3600000 milliseconds.
answer boolean - Need to wait for an answer from the plugin or the connection can be closed. Default value: false.

Return value: table, link information

Table Field Type Required Description
link_id string + Identifier of a link created.
url string + Full HTTP link for using this link( Like http://192.168.0.125:17001/v1/links/plugins/
secure_url string + Full HTTPS link for using this link( Like https://192.168.0.125:17000/v1/links/plugins/

Lua errors:

Deletes a link object. After the link is deleted its information will be accessible for 1 minute, but no new connections to the link will be allowed.

Arguments:

Parameter Type Required Description
link_id string + Identifier of a target link.

Lua errors:

Get main information about a link object. A plugin can ask only about its own links.

Arguments:

Parameter Type Required Description
link_id string + Identifier of a target link.

Return value: table, link information

Table Field Type Required Description
link_id string + Identifier of a link created.
url string + Full HTTP link for using this link( Like http://192.168.0.125:17001/v1/links/plugins/
secure_url string + Full HTTPS link for using this link( Like https://192.168.0.125:17000/v1/links/plugins/
user_data any - User data that was passed to http_server.create_link_url() call.
connections array of strings - An array of identifiers of "live" connections.

Lua errors:

http_server.close_connection()

Closes an existing connection. A plugin can use its own connections only.

Arguments:

Parameter Type Required Description
id string + Identifier of a connection

Return value: bool

Table Field Type Required Description
link_id string + Identifier of a link created.
url string + Full HTTP link for using this link( Like http://192.168.0.125:17001/v1/links/plugins/
secure_url string + Full HTTPS link for using this link( Like https://192.168.0.125:17000/v1/links/plugins/
user_data any - User data that was passed to http_server.create_link_url() call.
connections array of strings - An array of identifiers of "live" connections.

Lua errors:

http_server.send_data()

Method for sending answer on the request, sends the next portion of data for existing requests. A plugin can use its own connections only.

Arguments: options: table

Table Field Type Required Description
id string + Identifier of a connection
data string + Data to be sent
last boolean - Is it the last portion of data or not. If it is not the last part of data then the http_data_send event will be generated when existing data would be sent. Default value: false.
code int - HTTP status to report. Default value: 200
code_status string - Text description of a HTTP status
headers array of objects - Response headers. Should be added before the first bytes of a response body is printed to an HTTP response.
Headers Type Required Description
string + Name of a header record
string + Value of a header record

Lua errors:

http_server.get_connection_info()

Get main information about the connection. A plugin can ask only about its own connections.

Arguments:

Parameter Type Required Description
id string + Identifier of a connection

Return value: table, information about the connection

Table Field Type Required Description
id string + Identifier of a connection.
link_id string + Identifier of a link
status string + Current status of the connection. Possible values: pending - connection is open and wait for new operations; closed - connection is closed
headers array of objects - HTTP request headers, array of (name, value) objects
params array of objects - HTTP request parameters, array of (name, value) objects
client_ip string + A client's IP address
created int + Connection creation timestamp

Lua errors: