#include <network_webserver.h>
Easy interface to create and start a web server and handling http requests. The web server starts several threads that handles the requests. So make sure that you keep the handle as long as the server is running.
Public Member Functions | |
MAXON_METHOD Result< void > | Init (Bool useSSL, const NetworkIpAddrPort &serverIpAndPort, const String &serverName) |
MAXON_METHOD Int | GetServerPort () const |
MAXON_METHOD String | GetServerName () const |
MAXON_METHOD Bool | IsUsingSSL () const |
MAXON_METHOD Result< void > | StartServer (Bool waitForListener) |
MAXON_METHOD Result< void > | StopServer () |
MAXON_METHOD Result< void > | RegisterRequest (const String &file, HandleRequestDelegate &&requestDelegate) |
MAXON_OBSERVABLE (Result< void >, ObservableHandleRequest,(const NetworkWebServerRef &server, const NetworkHttpHandlerRef &remoteConnection, const DataDictionary &request), CombinerHttpCodeComponents) | |
Private Member Functions | |
MAXON_INTERFACE (NetworkWebServerInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.networkwebserver") | |
|
private |
MAXON_METHOD Result<void> Init | ( | Bool | useSSL, |
const NetworkIpAddrPort & | serverIpAndPort, | ||
const String & | serverName | ||
) |
Init initializes the web server object and tells which port should be used.
[in] | useSSL | Should the server use SSL/TLS? |
[in] | serverIpAndPort | Server ip and port. If addr is 0.0.0.0 the server will be bound to all interfaces. If serverPort is 0, the system chooses an port. Otherwise the port needs to be in the range 0 < port < 10000. |
[in] | serverName | Name of the server (only 'a..z''A..Z' are valid). |
MAXON_METHOD Int GetServerPort | ( | ) | const |
Returns the server port. If 0 was given at Init() the serverport is only available after starting the server.
MAXON_METHOD String GetServerName | ( | ) | const |
Returns the server name.
MAXON_METHOD Bool IsUsingSSL | ( | ) | const |
Returns whether the server uses the SSL/TLS protocol.
MAXON_METHOD Result<void> StartServer | ( | Bool | waitForListener | ) |
Starts the web server.
[in] | waitForListener | If true the functions waits until the listener is open. Otherwise it returns immediately. |
MAXON_METHOD Result<void> StopServer | ( | ) |
Stops the web server.
MAXON_METHOD Result<void> RegisterRequest | ( | const String & | file, |
HandleRequestDelegate && | requestDelegate | ||
) |
RegisterRequest allows to add callback delegates to handle urls. If the handler returns "HttpCodeError(MAXON_SOURCE_LOCATION, HTTPCODE::CALL_NEXT_HANDLER)" the next handler is called.
[in] | file | Url to catch. if the string ends with a "*" the pattern will be matched. |
[in] | requestDelegate | Delegate to call. |
MAXON_OBSERVABLE | ( | Result< void > | , |
ObservableHandleRequest | , | ||
(const NetworkWebServerRef &server, const NetworkHttpHandlerRef &remoteConnection, const DataDictionary &request) | , | ||
CombinerHttpCodeComponents | |||
) |
ObservableHandleRequest is fired as soon as a client connects to the server. For each connection a new thread is spawned.
[in] | server | Reference to the server object. |
[in] | remoteConnection | Reference to the remote connection. This handle allows to read and write from the ip stream. |
[in] | request | The pre-translated http request from the server. See HTTPREQUEST for details. Predefined values can be found under it's id. All unknown header informations can be found under a string as the key of the dictionary. Try DiagnosticOutput("@", request); to see all members of the dictionary. |