The connection class represents a connection from a client to the server.
More...
#include <http.h>
The connection class represents a connection from a client to the server.
An instance of this interface is passed into the various registered callbacks.
- Note
- A pointer to an mi::http::IConnection interface is only valid inside mi::http::IRequest_handler::handle(), mi::http::ICGIRequest_handler::handle(), mi::http::IResponse_handler::handle(), or mi::http::IData_handler::handle().
-
This interface is not derived from mi::base::IInterface. As one consequence, there are no retain() and release() methods, and the interface cannot be used together with the mi::base::Handle class.
◆ add_data_handler()
virtual void mi::http::IConnection::add_data_handler |
( |
IData_handler * |
handler | ) |
|
|
pure virtual |
Adds a data handler to the connection.
The handler is removed when the connection is closed or when the handler's handle()
method returns NULL
.
- Parameters
-
◆ check_error()
virtual bool mi::http::IConnection::check_error |
( |
| ) |
|
|
pure virtual |
Indicates whether an error occurred on the connection.
- Returns
true
, if there was an error, false
otherwise.
◆ enqueue()
virtual bool mi::http::IConnection::enqueue |
( |
neuraylib::IBuffer * |
buffer | ) |
|
|
pure virtual |
Enqueues a buffer to be sent on the connection.
- Note
- The buffer might be modified or discarded by data handlers before being sent. The string might be queued before it is actually sent. See also flush().
- Parameters
-
buffer | The buffer to be written. Ownership of the buffer passes from the caller to the connection. |
- Returns
true
, in case of success, and false
in case of failure.
◆ flush()
virtual Sint32 mi::http::IConnection::flush |
( |
| ) |
|
|
pure virtual |
Waits until all enqueued data has been written.
- Returns
- 0, in case of success, and -1 in case of failure.
◆ get_attachment()
virtual const char * mi::http::IConnection::get_attachment |
( |
const char * |
key | ) |
|
|
pure virtual |
Returns a string attachment from the connection.
Attachments can be used for communication between different handlers. This convenience methods deals with string attachments. Use get_data_attachment() for all other data types.
- Parameters
-
key | The key of the attachment. |
- Returns
- The value of the attachment, or
NULL
if there is no such attachment.
◆ get_data_attachment() [1/2]
template<class T>
T * mi::http::IConnection::get_data_attachment |
( |
const char * |
key | ) |
|
|
inline |
Returns an attachment from the connection.
Attachments can be used for communication between different handlers. This methods deals with arbitrary attachment types. The method get_attachment() is more convenient for string attachments.
This templated member function is a wrapper of the non-template variant for the user's convenience. It eliminates the need to call mi::base::IInterface::get_interface(const Uuid &) on the returned pointer, since the return type already is a pointer to the type T
specified as template parameter.
- Template Parameters
-
T | The interface type of the requested element. |
- Parameters
-
key | The key of the attachment. |
- Returns
- The value of the attachment, or
NULL
if there is no such attachment.
◆ get_data_attachment() [2/2]
virtual IData * mi::http::IConnection::get_data_attachment |
( |
const char * |
key | ) |
|
|
pure virtual |
Returns an attachment from the connection.
Attachments can be used for communication between different handlers. This methods deals with arbitrary attachment types. The method get_attachment() is more convenient for string attachments.
- Parameters
-
key | The key of the attachment. |
- Returns
- The value of the attachment, or
NULL
if there is no such attachment.
◆ get_local_address()
virtual const char * mi::http::IConnection::get_local_address |
( |
| ) |
|
|
pure virtual |
Returns the address of the local side of the connection.
◆ get_peer_address()
virtual const char * mi::http::IConnection::get_peer_address |
( |
| ) |
|
|
pure virtual |
Returns the address of the peer of the connection.
◆ get_request()
virtual IRequest * mi::http::IConnection::get_request |
( |
| ) |
|
|
pure virtual |
Returns the request of the connection.
◆ get_response()
virtual IResponse * mi::http::IConnection::get_response |
( |
| ) |
|
|
pure virtual |
Returns the response associated with the connection.
◆ is_secure_connection()
virtual bool mi::http::IConnection::is_secure_connection |
( |
| ) |
|
|
pure virtual |
Query whether this is a secure (i.e.
HTTPS) connection
- Returns
- A bool indicating whether this is a secure connection
◆ print()
virtual bool mi::http::IConnection::print |
( |
const char * |
string | ) |
|
|
pure virtual |
Prints a string to the connection.
- Note
- The string might be modified or discarded by data handlers before being sent. The string might be queued before it is actually sent. See also flush().
- Parameters
-
string | The string to be written. |
- Returns
true
, in case of success, and false
in case of failure.
◆ printf()
bool mi::http::IConnection::printf |
( |
const char * |
string, |
|
|
|
... |
|
) |
| |
Prints a string to the connection.
- Note
- The string might be modified or discarded by data handlers before being sent. The string might be queued before it is actually sent. See also flush().
- Parameters
-
string | The string to be written using printf()-like format specifiers, followed by matching arguments. The formatted message is limited to 16383 characters. |
- Returns
true
, in case of success, and false
in case of failure.
◆ read_data()
virtual Sint32 mi::http::IConnection::read_data |
( |
Size |
size, |
|
|
char * |
buffer |
|
) |
| |
|
pure virtual |
Reads incoming CGI data into a supplied buffer.
This method can only be called by CGI handlers. The total amount of data is limited by the advised Content-Length header.
- Note
- This method blocks until the given amount of bytes have been read, until the content length is exhausted, or the connection was closed.
- Parameters
-
size | The size of the buffer. |
buffer | The buffer to write the the data into. |
- Returns
- The number of bytes read or 0 if no more data will come.
◆ remove_attachment()
virtual void mi::http::IConnection::remove_attachment |
( |
const char * |
key | ) |
|
|
pure virtual |
Removes an attachment from the connection.
Attachments can be used for communication between different handlers.
- Parameters
-
key | The key of the attachment. |
◆ set_attachment()
virtual void mi::http::IConnection::set_attachment |
( |
const char * |
key, |
|
|
const char * |
value |
|
) |
| |
|
pure virtual |
Attaches a string attachment to the connection.
Attachments can be used for communication between different handlers. This convenience methods deals with string attachments. Use set_data_attachment() for all other data types.
- Parameters
-
key | Key of the attachment. |
value | Value of the attachment. |
◆ set_data_attachment()
virtual void mi::http::IConnection::set_data_attachment |
( |
const char * |
key, |
|
|
IData * |
value |
|
) |
| |
|
pure virtual |
Attaches an attachment to the connection.
Attachments can be used for communication between different handlers. This methods deals with arbitrary attachment types. The method set_attachment() is more convenient for string attachments.
- Parameters
-
key | Key of the attachment. |
value | Value of the attachment. |