net.httpserver

This API has was deprecated and removed in Prosody 0.9.0. See the new HTTP server API

This module is for starting a HTTP server. Multiple plugins can share the same port, as long as they use different base paths.

Functions

new_from_config(config, handler, default_options)

This sets up a new HTTP handler listening on the ports/paths specified in the 'config' parameter table. This table should be fetched from the config file with e.g. configmanager.get() or module:get_option(). It has the same standard format as that used by BOSH.

The 'handler' parameter should be a function that receives incoming HTTP requests. It is described below.

Finally, the 'default_options' parameter must be a table, and can contain any of the following fields:

  • base - The base path to listen on, e.g. "pastebin". Required.
  • port - The default port to listen on. Defaults to 5280.
  • interface - The default interface to listen on. Defaults to "*" (all).
  • ssl - A standard SSL options table with 'key' and 'certificate' fields. Defaults to no SSL.

Request handler

The request handler takes 3 parameters: (method, body, request).

The method is a string, e.g. "GET" or "POST". If the method is one that allows including a body, then 'body' will be the data sent in the request (e.g. a form, file, etc.). Otherwise, body is nil.

The 'request' parameter is the request object, and contains various advanced details such as the request headers, client connection object. Many of the fields of this object are shared with client request objects.

The request handler should return a string of data to be sent to the client or a response object if more advanced control is required over the response.