Iray SDK API nvidia_logo_transpbg.gif Up
http.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2025 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
6
7#ifndef MI_NEURAYLIB_HTTP_H
8#define MI_NEURAYLIB_HTTP_H
9
10#include <cstdarg>
11#include <cstdio>
12
14#include <mi/neuraylib/idata.h>
15#include <mi/neuraylib/version.h> // for MI_NEURAYLIB_DEPRECATED_ENUM_VALUE
16
17namespace mi {
18
19namespace http { class IConnection; class IWeb_socket; }
20namespace neuraylib { class IBuffer; }
21
62namespace http {
63
81{
82public:
84 virtual const char* get_request_line() const = 0;
85
87 virtual const char* get_command() const = 0;
88
90 virtual const char* get_protocol() const = 0;
91
95 virtual void set_url( const char* url) = 0;
96
98 virtual const char* get_url() const = 0;
99
104 virtual void set_header( const char* key, const char* value) = 0;
105
109 virtual void remove_header( const char* key) = 0;
110
115 virtual const char* get_header( const char* key) const = 0;
116
128 virtual bool get_header(
129 Size index, const char** key_pointer, const char** value_pointer) const = 0;
130
138 virtual void set_argument( const char* key, const char* value) = 0;
139
146 virtual void add_argument( const char* key, const char* value) = 0;
147
153 virtual void remove_argument(const char* key) = 0;
154
163 virtual const char* get_argument( const char* key) const = 0;
164
176 virtual bool get_argument(
177 Size index, const char** key_pointer, const char** value_pointer) const = 0;
178
182 virtual const char* get_body() const = 0;
183};
184
198{
199public:
204 virtual void set_result_code( Sint32 code, const char* message) = 0;
205
207 virtual Sint32 get_result_code() const = 0;
208
213 virtual void set_header( const char* key, const char* value) = 0;
214
218 virtual void remove_header( const char* key) = 0;
219
224 virtual const char* get_header( const char* key) const = 0;
225
237 virtual bool get_header(
238 Size index, const char** key_pointer, const char** value_pointer) const = 0;
239
241 virtual bool was_sent() const = 0;
242};
243
250class IData_handler : public
251 mi::base::Interface_declare<0x723054d8,0xdfa7,0x4475,0xbc,0xb4,0x44,0x23,0x25,0xea,0x52,0x50>
252{
253public:
261 virtual neuraylib::IBuffer* handle( IConnection* connection, neuraylib::IBuffer* buffer) = 0;
262};
263
278{
279public:
281 virtual const char* get_peer_address() = 0;
282
284 virtual const char* get_local_address() = 0;
285
294 virtual bool print( const char* string) = 0;
295
305 bool printf( const char* string, ...)
306#ifdef MI_COMPILER_GCC
307 __attribute__((format(printf, 2, 3)))
308#endif
309 {
310 va_list args;
311 va_start( args, string);
312 char buffer[16384];
313#ifdef MI_COMPILER_MSC
314 vsnprintf_s( &buffer[0], sizeof( buffer), sizeof( buffer)-1, string, args);
315#else
316 vsnprintf( &buffer[0], sizeof( buffer), string, args);
317#endif
318 bool result = this->print( &buffer[0]);
319 va_end( args);
320 return result;
321 }
322
332 virtual bool enqueue( neuraylib::IBuffer* buffer) = 0;
333
337 virtual Sint32 flush() = 0;
338
342 virtual bool check_error() = 0;
343
345 virtual IRequest* get_request() = 0;
346
348 virtual IResponse* get_response() = 0;
349
356 virtual void add_data_handler( IData_handler* handler) = 0;
357
366 virtual void set_data_attachment( const char* key, IData* value) = 0;
367
376 virtual IData* get_data_attachment( const char* key) = 0;
377
393 template<class T>
394 T* get_data_attachment( const char* key)
395 {
396 IData* ptr = get_data_attachment( key);
397 if( !ptr)
398 return 0;
399 T* ptr_T = static_cast<T*>( ptr->get_interface( typename T::IID()));
400 ptr->release();
401 return ptr_T;
402 }
410 virtual void set_attachment( const char* key, const char* value) = 0;
411
419 virtual const char* get_attachment( const char* key) = 0;
420
426 virtual void remove_attachment( const char* key) = 0;
427
439 virtual Sint32 read_data( Size size, char* buffer) = 0;
440
443 virtual bool is_secure_connection() = 0;
444};
445
453 mi::base::Interface_declare<0x70ad6206,0x38f0,0x4f2a,0xb7,0x5d,0x8f,0x90,0x64,0x3e,0xd0,0x06>
454{
455public:
459 virtual void handle( IWeb_socket* web_socket) = 0;
460};
461
468 mi::base::Interface_declare<0xbe989e2c,0xf1e6,0x492a,0xb6,0x42,0x1f,0xd7,0x30,0x1f,0xa2,0x9f>
469{
470public:
476 virtual void handle( IWeb_socket* web_socket, neuraylib::IBuffer* buffer,
477 bool binary_frame) = 0;
478};
479
493class IWeb_socket : public
494 mi::base::Interface_declare<0x52fd1beb,0x4c6f,0x4456,0x86,0x9c,0xfd,0xf4,0x12,0x52,0x0a,0xae>
495{
496public:
500 virtual const char* get_peer_address() const = 0;
501
505 virtual const char* get_local_address() const = 0;
506
510 virtual const char* get_url_path() const = 0;
511
513 enum State : Uint32 {
527 MI_NEURAYLIB_DEPRECATED_ENUM_VALUE(WS_STATE_FORCE_32_BIT, 0xffffffffU)
528 };
529
533 virtual State get_state() const = 0;
534
547 virtual void set_state_handler( IWeb_socket_state_handler* handler) = 0;
548
558 virtual void set_data_handler( IWeb_socket_data_handler* handler) = 0;
559
573 virtual Difference write( neuraylib::IBuffer* buffer, bool binary_frame = false) = 0;
574
582 virtual bool print( const char* string, bool binary_frame = false) = 0;
583
590 bool printf( const char* string, ...)
591#ifdef MI_COMPILER_GCC
592 __attribute__((format(printf, 2, 3)))
593#endif
594 {
595 va_list args;
596 va_start( args, string);
597 char buffer[16384];
598#ifdef MI_COMPILER_MSC
599 vsnprintf_s( &buffer[0], sizeof( buffer), sizeof( buffer)-1, string, args);
600#else
601 vsnprintf( &buffer[0], sizeof( buffer), string, args);
602#endif
603 bool result = this->print( &buffer[0]);
604 va_end( args);
605 return result;
606 }
607
609 virtual void close() = 0;
610
613
617 virtual void set_max_payload(Uint64 bytes) = 0;
618
622 virtual Uint64 get_max_payload() = 0;
623};
624
634 mi::base::Interface_declare<0xb784d27c,0x3b80,0x432e,0x89,0xa0,0x13,0xe7,0x33,0x04,0x82,0x5c>
635{
636public:
645 virtual bool handle( IWeb_socket* web_socket) = 0;
646};
647
656class IRequest_handler : public
657 mi::base::Interface_declare<0x8747d0dd,0x1e27,0x4413,0xa0,0xd4,0x07,0x60,0x8f,0xed,0xfc,0xf9>
658{
659public:
670 virtual bool handle( IConnection* connection) = 0;
671};
672
686 mi::base::Interface_declare<0xa7fe482e,0x65f8,0x4a4c,0x87,0x21,0xff,0x19,0x21,0x36,0xda,0xe0>
687{
688public:
699 virtual bool handle( IConnection* connection) = 0;
700};
701
710class IResponse_handler : public
711 mi::base::Interface_declare<0xa9386278,0x6938,0x45a7,0xa2,0x3b,0xbb,0x35,0xf7,0xe9,0x28,0x20>
712{
713public:
717 virtual void handle( IConnection* connection) = 0;
718};
719
721class IServer : public
722 mi::base::Interface_declare<0x9923b273,0x082f,0x403a,0x83,0x57,0xcd,0x23,0x9b,0xcf,0x68,0x4c>
723{
724public:
741 virtual Sint32 start( const char* listen_address) = 0;
742
769 const char* listen_address, const char* cert_file,
770 const char* private_key_file, const char* password) = 0;
771
778 virtual void shutdown() = 0;
779
784 virtual Sint32 set_default_mime_type( const char* mime_type) = 0;
785
794 virtual void add_mime_type( const char* extension, const char* mime_type) = 0;
795
800 virtual const char* lookup_mime_type( const char* extension) = 0;
801
805 virtual void install( IRequest_handler* handler) = 0;
806
810 virtual void remove( IRequest_handler* handler) = 0;
811
815 virtual void install( IWeb_socket_handler* handler) = 0;
816
820 virtual void remove( IWeb_socket_handler* handler) = 0;
821
825 virtual void install( ICGIRequest_handler* handler) = 0;
826
830 virtual void remove( ICGIRequest_handler* handler) = 0;
831
835 virtual void install( IResponse_handler* handler) = 0;
836
840 virtual void remove( IResponse_handler* handler) = 0;
841
848 virtual void set_identification( const char* id_string) = 0;
849
851 virtual const char* get_listen_address() = 0;
852
854 virtual const char* get_ssl_listen_address() = 0;
855
860
865
871 virtual void set_keep_alive_timeout( Uint32 nr_of_seconds) = 0;
872
874 virtual Uint32 get_keep_alive_timeout() const = 0;
875
881 virtual void set_send_buffer_size( Uint32 send_buffer_size) = 0;
882
884 virtual Uint32 get_send_buffer_size() const = 0;
885
889 virtual void set_http_post_body_limit( Uint32 http_post_body_limit) = 0;
890
892 virtual Uint32 get_http_post_body_limit() const = 0;
893
902 // try again.
906 virtual void set_concurrent_connection_limit( Uint32 limit ) = 0;
907
910};
911
918class IFactory : public
919 mi::base::Interface_declare<0xddded154,0x4be8,0x42b6,0x81,0x68,0x21,0x16,0xc7,0xbd,0x63,0x40>
920{
921public:
923 virtual IServer* create_server() = 0;
924
940 const char* root_url, const char* root_path, bool is_recursive = true) = 0;
941
950 const char* source_url, const char* target_url) = 0;
951
961 virtual IResponse_handler* create_log_handler( const char* path) = 0;
962
976
991 virtual IWeb_socket* create_client_web_socket( const char* web_socket_address,
992 Float32 connect_timeout) = 0;
993};
994 // end group mi_neuray_http
996
997} // namespace http
998
999} // namespace mi
1000
1001#endif // MI_NEURAYLIB_HTTP_H
This interface is the base interface of all types.
Definition: idata.h:297
Mixin class template for deriving new interface declarations.
Definition: interface_declare.h:43
CGI request handlers are responsible for handling HTTP requests.
Definition: http.h:687
virtual bool handle(IConnection *connection)=0
Handles a request coming in on a connection.
The connection class represents a connection from a client to the server.
Definition: http.h:278
virtual IResponse * get_response()=0
Returns the response associated with the connection.
virtual void set_attachment(const char *key, const char *value)=0
Attaches a string attachment to the connection.
virtual bool print(const char *string)=0
Prints a string to the connection.
virtual void add_data_handler(IData_handler *handler)=0
Adds a data handler to the connection.
virtual IRequest * get_request()=0
Returns the request of the connection.
virtual const char * get_local_address()=0
Returns the address of the local side of the connection.
virtual bool enqueue(neuraylib::IBuffer *buffer)=0
Enqueues a buffer to be sent on the connection.
bool printf(const char *string,...) __attribute__((format(printf
Prints a string to the connection.
virtual Sint32 flush()=0
Waits until all enqueued data has been written.
T * get_data_attachment(const char *key)
Returns an attachment from the connection.
Definition: http.h:394
virtual const char * get_attachment(const char *key)=0
Returns a string attachment from the connection.
virtual bool check_error()=0
Indicates whether an error occurred on the connection.
virtual void set_data_attachment(const char *key, IData *value)=0
Attaches an attachment to the connection.
virtual bool is_secure_connection()=0
Query whether this is a secure (i.e.
virtual void remove_attachment(const char *key)=0
Removes an attachment from the connection.
virtual Sint32 read_data(Size size, char *buffer)=0
Reads incoming CGI data into a supplied buffer.
virtual IData * get_data_attachment(const char *key)=0
Returns an attachment from the connection.
virtual const char * get_peer_address()=0
Returns the address of the peer of the connection.
A data handler may be added to a connection.
Definition: http.h:252
virtual neuraylib::IBuffer * handle(IConnection *connection, neuraylib::IBuffer *buffer)=0
Handles data.
The factory can be used to instantiate the built-in HTTP classes.
Definition: http.h:920
virtual IRequest_handler * create_file_handler(const char *root_url, const char *root_path, bool is_recursive=true)=0
Creates a new file handler for the server.
virtual IResponse_handler * create_log_handler(const char *path)=0
Creates a new log handler.
virtual IResponse_handler * create_chunked_encoding_handler()=0
Creates a new chunked encoding handler.
virtual IServer * create_server()=0
Creates a new HTTP server.
virtual IRequest_handler * create_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.
virtual IWeb_socket * create_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 specifi...
Request handlers are responsible for handling HTTP requests.
Definition: http.h:658
virtual bool handle(IConnection *connection)=0
Handles a request coming in on a connection.
This interface holds all the parameters of a request.
Definition: http.h:81
virtual const char * get_url() const =0
Returns the URL of the request.
virtual const char * get_body() const =0
Returns the body string.
virtual void add_argument(const char *key, const char *value)=0
Adds an argument to the request.
virtual const char * get_protocol() const =0
Returns the protocol of the request.
virtual const char * get_header(const char *key) const =0
Returns a header from the request.
virtual const char * get_command() const =0
Returns the command of the request.
virtual void remove_header(const char *key)=0
Removes a header from the request.
virtual void set_header(const char *key, const char *value)=0
Changes an existing header of the request or adds a new header to the request.
virtual bool get_header(Size index, const char **key_pointer, const char **value_pointer) const =0
Returns the header with the given index.
virtual void set_argument(const char *key, const char *value)=0
Changes an argument of the request or adds an argument to the request.
virtual const char * get_request_line() const =0
Returns the request line of the request.
virtual const char * get_argument(const char *key) const =0
Returns an argument from the request.
virtual bool get_argument(Size index, const char **key_pointer, const char **value_pointer) const =0
Returns the argument with the given index.
virtual void remove_argument(const char *key)=0
Removes an argument from the request.
virtual void set_url(const char *url)=0
Sets the URL of the request.
Response handlers can be used to modify responses generated by request handlers.
Definition: http.h:712
virtual void handle(IConnection *connection)=0
Handles a response on a connection.
This interface holds all the parameters of a response.
Definition: http.h:198
virtual void set_header(const char *key, const char *value)=0
Changes a header of the response or adds a header to the response.
virtual bool was_sent() const =0
Indicates whether the response was already sent.
virtual Sint32 get_result_code() const =0
Returns the result code of the response.
virtual const char * get_header(const char *key) const =0
Returns a header from the response.
virtual void remove_header(const char *key)=0
Removes a header from the response.
virtual bool get_header(Size index, const char **key_pointer, const char **value_pointer) const =0
Returns the header with the given index.
virtual void set_result_code(Sint32 code, const char *message)=0
Sets the result code of the response.
The server builds a framework for the handlers.
Definition: http.h:723
virtual void remove(ICGIRequest_handler *handler)=0
Removes a previously installed CGI request handler from the server.
virtual const char * get_listen_address()=0
Returns the listen address of the server.
virtual Uint32 get_concurrent_connection_limit()=0
Returns the current concurrent connection limit.
virtual const char * get_ssl_listen_address()=0
Returns the SSL listen address of the server.
virtual Sint32 start_ssl(const char *listen_address, const char *cert_file, const char *private_key_file, const char *password)=0
Starts the server in SSL mode listening on the given address.
virtual void shutdown()=0
Shuts down a server that has been previously started.
virtual void install(IResponse_handler *handler)=0
Adds a new response handler to the server.
virtual void remove(IRequest_handler *handler)=0
Removes a previously installed request handler from the server.
virtual void remove(IResponse_handler *handler)=0
Removes a previously installed response handler from the server.
virtual void remove(IWeb_socket_handler *handler)=0
Removes a previously installed WebSocket request handler from the server.
virtual void install(IWeb_socket_handler *handler)=0
Adds a new WebSocket request handler to the server.
virtual Uint32 get_http_post_body_limit() const =0
Returns the size limit for the body of HTTP POST requests.
virtual Sint32 set_default_mime_type(const char *mime_type)=0
Sets the default MIME type to be used when no MIME type was found.
virtual void install(IRequest_handler *handler)=0
Adds a new request handler to the server.
virtual Uint32 get_keep_alive_timeout() const =0
Returns the idle timeout for keep-alive connections.
virtual Sint32 start(const char *listen_address)=0
Starts the server listening on the given address.
virtual void add_mime_type(const char *extension, const char *mime_type)=0
Adds a new MIME type to the server.
virtual Size get_nr_of_connections()=0
Returns the number of existing HTTP connections in this server.
virtual void set_send_buffer_size(Uint32 send_buffer_size)=0
Sets the send buffer size of the socket.
virtual Size get_nr_of_active_connections()=0
Returns the number of HTTP connections in this server which actually handle requests.
virtual void install(ICGIRequest_handler *handler)=0
Adds a new CGI request handler to the server.
virtual void set_concurrent_connection_limit(Uint32 limit)=0
Sets the maximum number of concurrent connections this server will accept.
virtual void set_keep_alive_timeout(Uint32 nr_of_seconds)=0
Sets the idle timeout for keep-alive connections.
virtual void set_http_post_body_limit(Uint32 http_post_body_limit)=0
Sets the size limit for the body of HTTP POST requests.
virtual Uint32 get_send_buffer_size() const =0
Returns the send buffer size of the socket.
virtual void set_identification(const char *id_string)=0
Sets the identification string of the server.
virtual const char * lookup_mime_type(const char *extension)=0
Returns the MIME type registered for a certain extension.
A WebSocket data handler that can be installed to a WebSocket connection to handle data arriving at t...
Definition: http.h:469
virtual void handle(IWeb_socket *web_socket, neuraylib::IBuffer *buffer, bool binary_frame)=0
The handle() function is called when new data is received.
WebSocket handlers are responsible for handling WebSocket requests.
Definition: http.h:635
virtual bool handle(IWeb_socket *web_socket)=0
Handles an incoming WebSocket request.
A WebSocket state handler that can be installed to a WebSocket connection to handle events of the Web...
Definition: http.h:454
virtual void handle(IWeb_socket *web_socket)=0
The handle() function is called when the WebSocket changes its state.
The WebSocket connection class represents a connection that is built on top of an HTTP connection.
Definition: http.h:495
virtual void set_max_payload(Uint64 bytes)=0
Set the maximum payload that web socket messages can have.
virtual bool print(const char *string, bool binary_frame=false)=0
Prints a string to the connection.
virtual void set_state_handler(IWeb_socket_state_handler *handler)=0
Sets a state handler to the WebSocket connection.
virtual State get_state() const =0
Returns the state of the connection.
virtual void close()=0
Closes the connection.
virtual Difference write(neuraylib::IBuffer *buffer, bool binary_frame=false)=0
Writes data from a buffer to the connection.
State
This class represents different states that a WebSocket can be in.
Definition: http.h:513
@ WS_STATE_CLOSED
The closing handshake has been completed or the or the underlying TCP connection has been closed.
Definition: http.h:524
@ WS_STATE_ERROR
An error has occurred.
Definition: http.h:526
@ WS_STATE_CLOSING
The closing handshake has been started.
Definition: http.h:521
@ WS_STATE_CONNECTED
A connection has been established.
Definition: http.h:519
@ WS_STATE_INIT
The initial state.
Definition: http.h:515
@ WS_STATE_CONNECTING
The client has sent a request and awaits a response.
Definition: http.h:517
virtual IConnection * get_http_connection()=0
Returns the HTTP connection associated with this WebSocket connection.
virtual void set_data_handler(IWeb_socket_data_handler *handler)=0
Sets a data handler to the WebSocket connection.
virtual const char * get_peer_address() const =0
Returns the peer's address of the connection.
virtual Uint64 get_max_payload()=0
Get the maximum payload.
bool printf(const char *string,...) __attribute__((format(printf
Prints a string to the connection.
virtual const char * get_url_path() const =0
Returns the URL path that the WebSocket request is sent to.
virtual const char * get_local_address() const =0
Returns the local address of the connection.
Abstract interface for a simple buffer with binary data.
Definition: ibuffer.h:25
virtual const IInterface * get_interface(const Uuid &interface_id) const =0
Acquires a const interface from another.
virtual Uint32 release() const =0
Decrements the reference count.
unsigned long long Uint64
64-bit unsigned integer.
Definition: types.h:62
int Sint32
32-bit signed integer.
Definition: types.h:46
float Float32
32-bit float.
Definition: types.h:51
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
Sint64 Difference
Signed integral type that is large enough to hold the difference of two pointers.
Definition: types.h:122
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
Types.
Mixin class template for deriving new interface declarations.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: neuraylib.h:179
Major and minor version number and an optional qualifier.