ClientConnection
ClientConnection
#include <icy/http/client.h>Inherits:
Connection
HTTP client connection for managing request/response lifecycle.
Public Attributes
| Return | Name | Description |
|---|---|---|
void * | opaque | Optional unmanaged client data pointer. Not used by the connection internally. |
NullSignal | Connect | Status signals. |
Signal< void(Response &)> | Headers | Signals when the response HTTP header has been received. |
Signal< void(const MutableBuffer &)> | Payload | Signals when raw data is received. |
Signal< void(const Response &)> | Complete | Signals when the HTTP transaction is complete. |
Signal< void(const icy::Error &)> | Error | Signals when the underlying transport reports an error. |
Signal< void(Connection &)> | Close | Signals when the connection is closed. |
ProgressSignal | IncomingProgress | Signals download progress (0-100%) |
opaque
void * opaqueOptional unmanaged client data pointer. Not used by the connection internally.
Connect
NullSignal ConnectStatus signals.
Signals when the client socket is connected and data can flow
Headers
Signal< void(Response &)> HeadersSignals when the response HTTP header has been received.
Payload
Signal< void(const MutableBuffer &)> PayloadSignals when raw data is received.
Complete
Signal< void(const Response &)> CompleteSignals when the HTTP transaction is complete.
Error
Signal< void(const icy::Error &)> ErrorSignals when the underlying transport reports an error.
Close
Signal< void(Connection &)> CloseSignals when the connection is closed.
IncomingProgress
ProgressSignal IncomingProgressSignals download progress (0-100%)
Public Methods
| Return | Name | Description |
|---|---|---|
ClientConnection | Creates a ClientConnection to the given URL, pre-populating the request URI and Host header. The response status is initialised to 502 Bad Gateway until a real response is received. | |
void | start virtual | Starts the internal HTTP request. |
void | start virtual | Starts the given HTTP request, replacing the internal request object. |
ssize_t | send virtual | Sends raw data to the peer, initiating a connection first if needed. Data is buffered internally until the connection is established. |
void | setReadStream virtual | Sets the output stream to which incoming response body data is written. The stream pointer is owned by the connection and freed with it. Must be called before start(). |
StreamT & | readStream inline | Returns a reference to the read stream cast to the specified type. |
ClientConnection
ClientConnection(const URL & url, const net::TCPSocket::Ptr & socket)Creates a ClientConnection to the given URL, pre-populating the request URI and Host header. The response status is initialised to 502 Bad Gateway until a real response is received.
Parameters
urlTarget URL. Scheme, host, port and path are extracted automatically.socketTCP socket to use. Defaults to a plain TCPSocket; pass an SSLSocket for HTTPS.
start
virtual
virtual void start()Starts the internal HTTP request.
Calls connect() internally if the socket is not already connecting or connected. The actual request will be sent when the socket is connected.
Exceptions
std::runtime_errorif already connecting.
start
virtual
virtual void start(http::Request & req)Starts the given HTTP request, replacing the internal request object.
Calls connect() internally if the socket is not already connecting or connected. The actual request will be sent when the socket is connected.
Parameters
reqThe HTTP request to send. Replaces the internal request.
Exceptions
std::runtime_errorif already connecting.
send
virtual
virtual ssize_t send(const char * data, size_t len, int flags)Sends raw data to the peer, initiating a connection first if needed. Data is buffered internally until the connection is established.
Parameters
dataPointer to the data buffer.lenNumber of bytes to send.flagsSocket send flags (unused for HTTP).
Returns
Number of bytes sent or buffered.
setReadStream
virtual
virtual void setReadStream(std::ostream * os)Sets the output stream to which incoming response body data is written. The stream pointer is owned by the connection and freed with it. Must be called before start().
Parameters
osPointer to the output stream. Takes ownership.
Exceptions
std::runtime_errorif already connecting.
readStream
inline
template<class StreamT> inline StreamT & readStream()Returns a reference to the read stream cast to the specified type.
Parameters
StreamTThe concrete stream type to cast to.
Returns
Reference to the stream.
Exceptions
std::runtime_errorif no read stream has been set.std::bad_castif the stream is not of type StreamT.
Protected Attributes
| Return | Name | Description |
|---|---|---|
URL | _url | |
bool | _connect | |
bool | _active | |
bool | _complete | |
std::vector< PendingWrite > | _outgoingBuffer | |
std::unique_ptr< std::ostream > | _readStream |
_url
URL _url_connect
bool _connect_active
bool _active_complete
bool _complete_outgoingBuffer
std::vector< PendingWrite > _outgoingBuffer_readStream
std::unique_ptr< std::ostream > _readStreamProtected Methods
| Return | Name | Description |
|---|---|---|
void | connect virtual | Connects to the server endpoint. All sent data is buffered until the connection is made. |
http::Message * | incomingHeader virtual | Returns the incoming HTTP message header (request or response depending on role). |
http::Message * | outgoingHeader virtual | Returns the outgoing HTTP message header (request or response depending on role). |
bool | onSocketConnect virtual | net::SocketAdapter interface |
connect
virtual
virtual void connect()Connects to the server endpoint. All sent data is buffered until the connection is made.
incomingHeader
virtual
virtual http::Message * incomingHeader()Returns the incoming HTTP message header (request or response depending on role).
outgoingHeader
virtual
virtual http::Message * outgoingHeader()Returns the outgoing HTTP message header (request or response depending on role).
onSocketConnect
virtual
virtual bool onSocketConnect(net::Socket & socket)net::SocketAdapter interface
Public Types
| Name | Description |
|---|---|
Ptr |
Ptr
std::shared_ptr< ClientConnection > Ptr()Private Methods
| Return | Name | Description |
|---|---|---|
void | onHeaders virtual | Connection interface. |
void | onPayload virtual | Called for each chunk of incoming response body data. |
void | onComplete virtual | Called when the full HTTP response has been received. |
void | onClose virtual | Called when the connection is closed. |
bool | onSocketError virtual | Called when the underlying transport encounters an error. |
onHeaders
virtual
virtual void onHeaders()Connection interface.
Called when the response headers have been parsed.
onPayload
virtual
virtual void onPayload(const MutableBuffer & buffer)Called for each chunk of incoming response body data.
onComplete
virtual
virtual void onComplete()Called when the full HTTP response has been received.
onClose
virtual
virtual void onClose()Called when the connection is closed.
onSocketError
virtual
virtual bool onSocketError(net::Socket & socket, const icy::Error & error)Called when the underlying transport encounters an error.
