http_client Library

A simple HTTP/1 client.

Synopsis

Usage in LUA:

client = http_client()
client:connect("remote.server.com", "80")
status, content = client:get("/")
print(LOG_DEBUG, status, content)
http_client()

Constructor.

Returns:A http_client object
Return type:http_client
connect(host[, port = "80"])

Connect to an endpoint.

Parameters:
  • host (string) – The hostname or ip address to connect to.
  • port (string) – The port to connect to.
connect_timeout(milliseconds)

Set the timeout in milliseconds for a connection attempt. The default is set to 5000.

Parameters:milliseconds (int) – The timeout.
read_timeout(milliseconds)

Set the timeout in milliseconds for a read attempt. The default is set to 5000.

Parameters:milliseconds (int) – The timeout.
get(path)

Send a GET request to a connected remote endpoint and receive the repsonse content.

Parameters:path (string) – The path.
Returns:(int, string) - The status code and the content.
post(path, content)

Send a POST request to a connected remote endpoint and receive the response content.

Parameters:
  • path (string) – The path.
  • content (string) – The content.
Returns:

(int, string) - The status code and the content.

disable_keepalive()

Disable keep-alive. This means the connection gets closed after a request.