NetworkWebServerInterface Class Reference

#include <network_webserver.h>

Inheritance diagram for NetworkWebServerInterface:

Detailed Description

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")
 

Member Function Documentation

◆ MAXON_INTERFACE()

MAXON_INTERFACE ( NetworkWebServerInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.networkwebserver"   
)
private

◆ Init()

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.

Parameters
[in]useSSLShould the server use SSL/TLS?
[in]serverIpAndPortServer 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]serverNameName of the server (only 'a..z''A..Z' are valid).
Returns
OK on success.

◆ GetServerPort()

MAXON_METHOD Int GetServerPort ( ) const

Returns the server port. If 0 was given at Init() the serverport is only available after starting the server.

◆ GetServerName()

MAXON_METHOD String GetServerName ( ) const

Returns the server name.

◆ IsUsingSSL()

MAXON_METHOD Bool IsUsingSSL ( ) const

Returns whether the server uses the SSL/TLS protocol.

◆ StartServer()

MAXON_METHOD Result<void> StartServer ( Bool  waitForListener)

Starts the web server.

Parameters
[in]waitForListenerIf true the functions waits until the listener is open. Otherwise it returns immediately.
Returns
True if the functions was successful.

◆ StopServer()

MAXON_METHOD Result<void> StopServer ( )

Stops the web server.

Returns
True if the functions was successful.

◆ RegisterRequest()

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.

Parameters
[in]fileUrl to catch. if the string ends with a "*" the pattern will be matched.
[in]requestDelegateDelegate to call.
Returns
OK on success.

◆ MAXON_OBSERVABLE()

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.

Parameters
[in]serverReference to the server object.
[in]remoteConnectionReference to the remote connection. This handle allows to read and write from the ip stream.
[in]requestThe 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.
Returns
Return HTTPCODE::FINISHED if the request has been successfully replied. Return HTTPCODE::CALL_NEXT_HANDLER to call the next handler in the queue. Return a error code to respond with the error code.