---
title: roHttpServer
slug: develop/rohttpserver
docTags: 
createdAt: 2025-03-11T07:07:18.732Z
---

This object allows for processing of RESTful HTTP/HTTPS requests from remote URLs to the embedded web server of the BrightSign player. Many of the requests are provided to the script as *roHttpEvent* objects for handling. The JavaScript equivalent is Node.js.

Object Creation: The *roHttpServer* object is created with an *roAssociativeArray*.

```text
CreateObject("roHttpServer", parameters As roAssociativeArray)
```

The associative array can contain the following parameters:

- `port` <font color="#6B21A8">int</font>: The port number of the embedded web server
- `https` <font color="#6B21A8">roAssociativeArray</font>: A set of HTTPS configuration parameters:
  - `key_file` <font color="#6B21A8">string</font>: The name of a file containing the private key in PEM format. If neither the `passphrase` nor `obfuscated_passphrase` are passed, then the key file must be unencrypted.
  - `certificate_file` <font color="#6B21A8">string</font>: The name of a file containing the certificate in PEM format
  - `passphrase` <font color="#6B21A8">string</font>: The passphrase to decrypt the key file
  - `obfuscated_passphrase` <font color="#6B21A8">string</font>: The obfuscated passphrase to decrypt the key file. Contact [support@brightsign.biz](mailto\:support@brightsign.biz) to learn more about generating a key for obfuscation and storing it on the player.
- `bind_to_interface` <font color="#6B21A8">string</font> or <font color="#6B21A8">int</font>: Accept connections on the specified network interface only. Using a string interface name (e.g. “eth0” for Ethernet, “wlan0” for WiFi, “lo” for loopback) is preferred. An integer is supported for backward compatibility with `0` for Ethernet, `1` for WiFi and `32767` for loopback. This is available as of BOS 9.1.92.

:::hint{type="info"}
If the key and certificate are contained in a single file, it may be passed as the `certificate_file` (and the `key_file` can be omitted).
:::

Example

```text
 server = CreateObject("roHttpServer", { port: 443, https: { certificate_file: "cert.pem", passphrase: "sekrit" } })
```

## ifHttpServer

Each “Add” handler method described below takes an associative array as its parameter. Values in the associative array specify how the handler behaves. See the table at the end of this section for common `key:value` pairs.

### GetFailureReason() As String

Yields additional useful information if an *roHttpServer* method fails.

### AddGetFromString(parameters As roAssociativeArray) As Boolean

Causes any HTTP GET requests for the specified URL path to be met directly with the contents of the "body" member of the parameter associative array. The MIME type (and potentially the entire character set) should be specified if the request is expected to come from a web browser. The request is handled entirely within the *roHttpServer* method; no events are sent to the message port.

### AddGetFromFile(parameters As roAssociativeArray) As Boolean

Causes any HTTP GET requests for the specified URL path to be met directly from the specified file. You should always specify the MIME type (and possibly the character set) if you expect the request to come from a web browser. The request is handled entirely within the *roHttpServer* method; no events are sent to the message port.

### AddGetFromFolder(parameters As roAssociativeArray) As Boolean

Constructs a dynamic handler that serves up static files, which will appear as children of the defined storage folder. This method accepts an associative array with the following parameters:

- `folder`: The file path of the folder that will act as the root directory of the server. If this parameter is absent, everything on the storage device will be served.
- `url_prefix`: The URL prefix under which files will be served. If this parameter is absent, the URL will match from root.
- `filters`: An array of filters. Each filter is an associative array with the following parameters. Note that if "re" and "ext" parameters are absent, the filter will match everything:
  - `re`: The regular expression to match against the request URL.
  - `ext`: The extension to match against the leaf file of the request URL.
  - `headers` : An associative array containing arbitrary headers to be included with the automatic response.
  - `content_type` : The contents of the "Content-Type" header included with the automatic response. This cannot be set in the same filter as the headers. The MIME type and character set can be specified together `(e.g. "text/plain; charset=utf-8")` .

You must define all of the folder content types for the folder to be correctly uploaded to the server. For example:

```text
mimeTypes = [{ext: ".html", content_type:"text/html;charset=utf-8"},{ext: ".js", content_type:"text/javascript;charset=utf-8"},{ext: ".css", content_type:"text/css;charset=utf-8"},{ext: ".png", content_type:"image/png"},{ext: ".otf", content_type:"font/otf"}]

server.AddGetFromFolder({ url_prefix: "/GetFolder", folder: "Example", filters: mimeTypes})
```

### AddGetFromEvent(parameters As roAssociativeArray) As Boolean

Requests that an event of type *roHttpEvent* be sent to the configured message port. This occurs when an HTTP GET request is made for the specified URL path.

### AddPostToString(parameters As roAssociativeArray) As Boolean

Requests that an event of type *roHttpEvent* be sent to the configured message port. This occurs when an HTTP POST request is made for the specified URL path. Use the *roHttpEvent.GetRequestBodyString()* method to retrieve the posted body.

### AddPostToFile(parameters As roAssociativeArray) As Boolean

Requests that, when an HTTP POST request is made to the specified URL path, the request body be stored in a temporary file according to the `parameters["destination_directory"]` value in the associative array. When this request is complete, an *roHttpEvent* event is sent to the configured message port. Use the *roHttpEvent.GetRequestBodyFile()* method to retrieve the name of the temporary file. If the file still exists at the time the response is sent, it will be automatically deleted. However, if the player reboots or loses power during the POST process, the file will not be deleted. For this reason, we recommend using a dedicated subdirectory as the `"destination_directory"` and wiping this subdirectory during startup (using `DeleteDirectory()`) before adding handlers that refer to it.

### AddPostToFormData(parameters As roAssociativeArray) As Boolean

Requests that, when an HTTP POST request is made to the specified URL path, an attempt be made to store form data (passed as `application/x-www-form-urlencoded` or `multipart/form-data`) in an associative array that can be retrieved by calling the *roHttpEvent.GetFormData()* method.

### AddMethodFromEvent(parameters As roAssociativeArray) As Boolean

Requests that an event of type *roHttpEvent* be sent to the configured message port. Unlike `AddGetFromEvent()`, this method can support arbitrary HTTP methods. The HTTP method is specified using the method member in the associative array.

### AddMethodToFile(parameters As roAssociativeArray) As Boolean

Requests that, when an arbitrary HTTP request is made to the specified URL path, the request body be stored in a temporary file according to the `parameters["destination_directory"]` value in the associative array. The HTTP method is specified using the `method` member in the associative array. When the request is complete, an *roHttpEvent* event is sent to the configured message port. Use the *roHttpEvent.GetRequestBodyFile()* method to retrieve the name of the temporary file. If the file still exists at the time the response is sent, it will be automatically deleted.

### AddMethodToString(parameters As roAssociativeArray) As Boolean

Attempts to support an arbitrary HTTP method. The request body is placed in a string and an event is raised. This makes the request body available via the *roHttpEvent.GetRequestBodyString()* method. A response can be sent in the same manner as the `AddGetToEvent()` method.

### SetupDWSLink(title As String) As Boolean

Generates a tab in the [Diagnostic Web Server (DWS)](docId\:qXt4YHey7IEj_M9dH73wM) that links directly to the base \<ip\_address\:port> of the *roHttpServer* instance. The passed string specifies the title of the tab.

Example

```text
server1.SetupDWSLink("My AWS Link")
server2.SetupDWSLink("My Other AWS Link")
```

### Parameters for "Add" Handler Methods 

The following table describes common key\:value pairs for "Add" handler methods:

| **Name**               | **Applies to**                                                                               | **Value**                                                                                                                                                                                                                                        |
| ---------------------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| url\_path              | All                                                                                          | The path for which the handler method will be used                                                                                                                                                                                               |
| user\_data             | AddGetFromEvent()<br /><br />AddPostToString()<br />AddPostToFile()<br />AddMethodToString() | A user-defined value that can be retrieved by calling *roHttpEvent.GetUserData()*                                                                                                                                                                |
| method                 | AddMethodFromEvent()<br />AddMethodToFile()                                                  | The HTTP method associated with the generated *roHttpEvent*. The method type can then be retrieved using *roHttpEvent.GetMethod()*.                                                                                                              |
| passwords              | All                                                                                          | An associative array that contains a mapping between usernames and passwords                                                                                                                                                                     |
| auth                   | All                                                                                          | The authentication type to use when passwords are set. This value can be either "basic" or "digest". The value defaults to “digest” if not specified.                                                                                            |
| realm                  | All                                                                                          | The authentication realm, which will be displayed by web browsers when prompting for a username and password                                                                                                                                     |
| headers                | AddGetFromFile()                                                                             | An associative array that contains arbitrary headers to be included with the automated response                                                                                                                                                  |
| content\_type          | AddGetFromFile()                                                                             | The contents of the "Content-Type" header that is included with the automated response. This may not be set at the same time as the headers member. You can set both the MIME type and character set together (e.g. "text/plain; charset=utf-8") |
| body                   | AddGetFromString()                                                                           | The response body                                                                                                                                                                                                                                |
| filename               | AddGetFromFile()                                                                             | The path to the file used for the response body.                                                                                                                                                                                                 |
| destination\_directory | AddPostToFile()                                                                              | The path to the directory used for the temporary file containing the request body. A random filename will be generated automatically.                                                                                                            |

## ifMessagePort

### SetPort(port As roMessagePort)

Posts messages of type *roHttpEvent*  to the attached message port.
