#include <icy/http/client.h>Inherits:
Connection
HTTP client connection for managing request/response lifecycle.
| 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%) |
void * opaqueOptional unmanaged client data pointer. Not used by the connection internally.
NullSignal ConnectStatus signals.
Signals when the client socket is connected and data can flow
Signal< void(Response &)> HeadersSignals when the response HTTP header has been received.
Signal< void(const MutableBuffer &)> PayloadSignals when raw data is received.
Signal< void(const Response &)> CompleteSignals when the HTTP transaction is complete.
Signal< void(const icy::Error &)> ErrorSignals when the underlying transport reports an error.
Signal< void(Connection &)> CloseSignals when the connection is closed.
ProgressSignal IncomingProgressSignals download progress (0-100%)
| 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(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.
url Target URL. Scheme, host, port and path are extracted automatically.
socket TCP socket to use. Defaults to a plain TCPSocket; pass an SSLSocket for HTTPS.
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.
std::runtime_error if already connecting.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.
req The HTTP request to send. Replaces the internal request.std::runtime_error if already connecting.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.
data Pointer to the data buffer.
len Number of bytes to send.
flags Socket send flags (unused for HTTP).
Number of bytes sent or buffered.
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().
os Pointer to the output stream. Takes ownership.std::runtime_error if already connecting.inline
template<class StreamT> inline StreamT & readStream()Returns a reference to the read stream cast to the specified type.
StreamT The concrete stream type to cast to.Reference to the stream.
std::runtime_error if no read stream has been set.
std::bad_cast if the stream is not of type StreamT.
| Return | Name | Description |
|---|---|---|
URL | _url | |
bool | _connect | |
bool | _active | |
bool | _complete | |
std::vector< PendingWrite > | _outgoingBuffer | |
std::unique_ptr< std::ostream > | _readStream |
URL _urlbool _connectbool _activebool _completestd::vector< PendingWrite > _outgoingBufferstd::unique_ptr< std::ostream > _readStream| 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 |
virtual
virtual void connect()Connects to the server endpoint. All sent data is buffered until the connection is made.
virtual
virtual http::Message * incomingHeader()Returns the incoming HTTP message header (request or response depending on role).
virtual
virtual http::Message * outgoingHeader()Returns the outgoing HTTP message header (request or response depending on role).
virtual
virtual bool onSocketConnect(net::Socket & socket)net::SocketAdapter interface
| Name | Description |
|---|---|
Ptr |
std::shared_ptr< ClientConnection > Ptr()| 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. |
virtual
virtual void onHeaders()Connection interface.
Called when the response headers have been parsed.
virtual
virtual void onPayload(const MutableBuffer & buffer)Called for each chunk of incoming response body data.
virtual
virtual void onComplete()Called when the full HTTP response has been received.
virtual
virtual void onClose()Called when the connection is closed.
virtual
virtual bool onSocketError(net::Socket & socket, const icy::Error & error)Called when the underlying transport encounters an error.