neuray API Programmer's Manual

mi::http::IFactory Class Reference

[HTTP server]

Description

The factory can be used to instantiate the built-in HTTP classes. In addition to the HTTP server it can create a number of built-in request and response handlers. Those handlers need to be installed with one or more servers using the server's install() methods. Unless indicated otherwise a handler obtained from the factory function can be installed to multiple HTTP servers.

Public Member Functions

virtual IResponse_handlercreate_chunked_encoding_handler() =0
Creates a new chunked encoding handler. More...
virtual IWeb_socketcreate_client_web_socket( const char* web_socket_address, Float32 connect_timeout) =0
Creates a client-side WebSocket connection that will attempt to establish a connection to the specified server's address and will send WebSocket requests to the specified URL. More...
virtual IRequest_handlercreate_file_handler( const char* root_url, const char* root_path, bool is_recursive = true) =0
Creates a new file handler for the server. More...
virtual IResponse_handlercreate_log_handler( const char* path) =0
Creates a new log handler. More...
virtual IRequest_handlercreate_redirect_handler( const char* source_url, const char* target_url) =0
Creates a new redirect handler which will redirect requests to a certain URL to a new URL. More...
virtual IServercreate_server() =0
Creates a new HTTP server.

Member Functions

virtual IResponse_handler* mi::​http::​IFactory::create_chunked_encoding_handler() [pure virtual]

Creates a new chunked encoding handler. If installed on a server it will allow to keep connections alive even if the size of the generated content is not know in advance. This is done by installing a data handler on a connection if the response does not contain the data size when it is sent. The response handler will modify the response and then modify all data passed to the client to be sent in chunks. This handler needs to be installed as the last response handler to work correctly. Exempt from this are response handlers which do not change the data on the way to its clients, e.g., the log handler.

The handler needs to be installed with the desired server using mi::http::IServer::install( IResponse_handler*).

virtual IWeb_socket* mi::​http::​IFactory::create_client_web_socket( const char* web_socket_address, Float32 connect_timeout) [pure virtual]

Creates a client-side WebSocket connection that will attempt to establish a connection to the specified server's address and will send WebSocket requests to the specified URL.

Note:
The WebSocket address must have one of the following two formats:
  • "ws://host_address[:host_port]/url" for insecure connections, or

  • "wss://host_address[:host_port]/url" for secure connections.

Parameters

web_socket_address
The address to be connected to.
connect_timeout
The timeout interval in seconds when attempting to connect to a server.

Returns

A valid WebSocket if a connection can be established to the server, or NULL in case of failures.

virtual IRequest_handler* mi::​http::​IFactory::create_file_handler( const char* root_url, const char* root_path, bool is_recursive = true) [pure virtual]

Creates a new file handler for the server. The handler will map a given file or directory into the URL namespace at the root_url.

The handler needs to be installed with the desired server using mi::http::IServer::install( IRequest_handler*).

Parameters

root_url
The URL needs to start with this prefix to be served by the handler.
root_path
When a matching URL is found root_url is replaced by this argument to get the path of a file to be served. If this file can be opened for reading, it will be sent to the client.
is_recursive
Indicates whether handler serves only a single file or a directory tree.

Returns

The new request handler.

virtual IResponse_handler* mi::​http::​IFactory::create_log_handler( const char* path) [pure virtual]

Creates a new log handler. This handler will write a request log to a file with a given path. The file format of the log file is the so called 'Combined log format' used by various HTTP servers.

The handler needs to be installed with the desired server using mi::http::IServer::install( IResponse_handler*).

Parameters

path
Path of the log file to be written.
virtual IRequest_handler* mi::​http::​IFactory::create_redirect_handler( const char* source_url, const char* target_url) [pure virtual]

Creates a new redirect handler which will redirect requests to a certain URL to a new URL. The handler needs to be installed with the desired server using mi::http::IServer::install( IRequest_handler*).

Parameters

source_url
If this URL is found it is redirected to the target_url.
target_url
Target of the redirection.
virtual IServer* mi::​http::​IFactory::create_server() [pure virtual]

Creates a new HTTP server.