Home
HTTP module

ClientConnection

HTTP client connection for managing request/response lifecycle.

ClientConnection

#include <icy/http/client.h>
class ClientConnection

Defined in src/http/include/icy/http/client.h:33

Inherits: Connection

HTTP client connection for managing request/response lifecycle.

List of all members

NameKindOwner
opaquevariableDeclared here
ConnectvariableDeclared here
HeadersvariableDeclared here
PayloadvariableDeclared here
CompletevariableDeclared here
ErrorvariableDeclared here
ClosevariableDeclared here
IncomingProgressvariableDeclared here
ClientConnectionfunctionDeclared here
~ClientConnectionfunctionDeclared here
startfunctionDeclared here
startfunctionDeclared here
sendfunctionDeclared here
setReadStreamfunctionDeclared here
readStreamfunctionDeclared here
_urlvariableDeclared here
_connectvariableDeclared here
_activevariableDeclared here
_completevariableDeclared here
_outgoingBuffervariableDeclared here
_readStreamvariableDeclared here
connectfunctionDeclared here
incomingHeaderfunctionDeclared here
outgoingHeaderfunctionDeclared here
onSocketConnectfunctionDeclared here
PtrtypedefDeclared here
onHeadersfunctionDeclared here
onPayloadfunctionDeclared here
onCompletefunctionDeclared here
onClosefunctionDeclared here
onSocketErrorfunctionDeclared here
ConnectionStreamfriendInherited from Connection
ConnectionAdapterfriendInherited from Connection
ConnectionfunctionInherited from Connection
~ConnectionfunctionInherited from Connection
onHeadersfunctionInherited from Connection
onPayloadfunctionInherited from Connection
onCompletefunctionInherited from Connection
onClosefunctionInherited from Connection
sendfunctionInherited from Connection
sendOwnedfunctionInherited from Connection
sendHeaderfunctionInherited from Connection
closefunctionInherited from Connection
markActivefunctionInherited from Connection
beginStreamingfunctionInherited from Connection
endStreamingfunctionInherited from Connection
closedfunctionInherited from Connection
errorfunctionInherited from Connection
headerAutoSendEnabledfunctionInherited from Connection
setHeaderAutoSendEnabledfunctionInherited from Connection
replaceAdapterfunctionInherited from Connection
replaceAdapterfunctionInherited from Connection
securefunctionInherited from Connection
socketfunctionInherited from Connection
adapterfunctionInherited from Connection
requestfunctionInherited from Connection
responsefunctionInherited from Connection
incomingHeaderfunctionInherited from Connection
outgoingHeaderfunctionInherited from Connection
_socketvariableInherited from Connection
_adaptervariableInherited from Connection
_requestvariableInherited from Connection
_responsevariableInherited from Connection
_errorvariableInherited from Connection
_closedvariableInherited from Connection
_shouldSendHeadervariableInherited from Connection
setErrorfunctionInherited from Connection
onSocketConnectfunctionInherited from Connection
onSocketRecvfunctionInherited from Connection
onSocketErrorfunctionInherited from Connection
onSocketClosefunctionInherited from Connection
PtrtypedefInherited from Connection
priorityvariableInherited from SocketAdapter
SocketAdapterfunctionInherited from SocketAdapter
~SocketAdapterfunctionInherited from SocketAdapter
sendfunctionInherited from SocketAdapter
sendfunctionInherited from SocketAdapter
sendOwnedfunctionInherited from SocketAdapter
sendOwnedfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
setSenderfunctionInherited from SocketAdapter
senderfunctionInherited from SocketAdapter
addReceiverfunctionInherited from SocketAdapter
removeReceiverfunctionInherited from SocketAdapter
hasReceiverfunctionInherited from SocketAdapter
receiversfunctionInherited from SocketAdapter
onSocketConnectfunctionInherited from SocketAdapter
onSocketRecvfunctionInherited from SocketAdapter
onSocketErrorfunctionInherited from SocketAdapter
onSocketClosefunctionInherited from SocketAdapter
_sendervariableInherited from SocketAdapter
_receiversvariableInherited from SocketAdapter
_dirtyvariableInherited from SocketAdapter
cleanupReceiversfunctionInherited from SocketAdapter

Inherited from Connection

KindNameDescription
friendConnectionStream
friendConnectionAdapter
functionConnectionCreates a Connection using the given TCP socket.
function~Connection virtual noexcept
functiononHeaders virtualCalled when the incoming HTTP headers have been fully parsed.
functiononPayload virtualCalled for each chunk of incoming body data after headers are complete.
functiononComplete virtualCalled when the incoming HTTP message is fully received.
functiononClose virtualCalled when the connection is closed.
functionsend virtual overrideSend raw data to the peer.
functionsendOwned virtual overrideSend an owned payload buffer to the peer.
functionsendHeader virtualSend the outdoing HTTP header.
functionclose virtualClose the connection and schedule the object for deferred deletion.
functionmarkActive virtual inlineMarks the connection as active. Server connections override this to refresh the idle timer.
functionbeginStreaming virtual inlineExplicitly enter long-lived streaming mode. Base connections ignore this; server connections use it to disable keep-alive idle reaping while a response stream is active.
functionendStreaming virtual inlineExit long-lived streaming mode.
functionclosed constReturn true if the connection is closed.
functionerror constReturn the error object if any.
functionheaderAutoSendEnabled constReturn true if headers should be automatically sent.
functionsetHeaderAutoSendEnabledEnable or disable automatic header emission for the next outgoing send path.
functionreplaceAdapter virtualAssign the new ConnectionAdapter and setup the chain. The flow is: Connection <-> ConnectionAdapter <-> Socket. Takes ownership of the adapter (deferred deletion via uv loop).
functionreplaceAdapter virtualOverload for nullptr (used in destructor to clear adapter).
functionsecure constReturn true if the connection uses TLS/SSL.
functionsocketReturn the underlying socket pointer.
functionadapter constReturn the underlying adapter pointer.
functionrequestThe HTTP request headers.
functionresponseThe HTTP response headers.
functionincomingHeader virtualReturns the incoming HTTP message header (request or response depending on role).
functionoutgoingHeader virtualReturns the outgoing HTTP message header (request or response depending on role).
variable_socket
variable_adapter
variable_request
variable_response
variable_error
variable_closed
variable_shouldSendHeader
functionsetError virtualSet the internal error. Note: Setting the error does not [close()](icy-http-Connection.html#close-27) the connection.
functiononSocketConnect virtual overridenet::SocketAdapter interface
functiononSocketRecv virtual overrideCalled when data is received from the socket. Forwards the event to all registered receivers in priority order.
functiononSocketError virtual overrideCalled when the socket encounters an error. Forwards the event to all registered receivers in priority order.
functiononSocketClose virtual overrideCalled when the socket is closed. Forwards the event to all registered receivers in priority order.
typedefPtr

Inherited from SocketAdapter

KindNameDescription
variablepriorityThe priority of this adapter for STL sort operations.
functionSocketAdapterCreates the SocketAdapter.
function~SocketAdapter virtual noexceptDestroys the SocketAdapter.
functionsend virtualSends the given data buffer to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address.
functionsend virtual
functionsendOwned virtualSends an owned payload buffer to the connected peer.
functionsendOwned virtual
functionsendPacket virtualSends the given packet to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address.
functionsendPacket virtual
functionsendPacket virtualSends the given packet to the connected peer. This method provides delegate compatibility, and unlike other send methods throws an exception if the underlying socket is closed.
functionsetSender virtualSets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default.
functionsenderReturns the output SocketAdapter pointer.
functionaddReceiver virtualSets the pointer to the incoming data adapter. Events proxy data to this adapter by default.
functionremoveReceiver virtualRemove the given receiver.
functionhasReceiver virtualReturns true if the given receiver is connected.
functionreceiversReturns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list.
functiononSocketConnect virtualCalled when the socket establishes a connection. Forwards the event to all registered receivers in priority order. Override to intercept before the application sees the event.
functiononSocketRecv virtualCalled when data is received from the socket. Forwards the event to all registered receivers in priority order.
functiononSocketError virtualCalled when the socket encounters an error. Forwards the event to all registered receivers in priority order.
functiononSocketClose virtualCalled when the socket is closed. Forwards the event to all registered receivers in priority order.
variable_sender
variable_receivers
variable_dirty
functioncleanupReceivers virtual

Public Attributes

ReturnNameDescription
void *opaqueOptional unmanaged client data pointer. Not used by the connection internally.
NullSignalConnectStatus signals.
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.
ProgressSignalIncomingProgressSignals download progress (0-100%)

opaque

void * opaque

Defined in src/http/include/icy/http/client.h:91

Optional unmanaged client data pointer. Not used by the connection internally.


Connect

NullSignal Connect

Defined in src/http/include/icy/http/client.h:110

Status signals.

Signals when the client socket is connected and data can flow


Headers

Signal< void(Response &)> Headers

Defined in src/http/include/icy/http/client.h:111

Signals when the response HTTP header has been received.


Payload

Signal< void(const MutableBuffer &)> Payload

Defined in src/http/include/icy/http/client.h:112

Signals when raw data is received.


Complete

Signal< void(const Response &)> Complete

Defined in src/http/include/icy/http/client.h:113

Signals when the HTTP transaction is complete.


Error

Signal< void(const icy::Error &)> Error

Defined in src/http/include/icy/http/client.h:114

Signals when the underlying transport reports an error.


Close

Signal< void(Connection &)> Close

Defined in src/http/include/icy/http/client.h:115

Signals when the connection is closed.


IncomingProgress

ProgressSignal IncomingProgress

Defined in src/http/include/icy/http/client.h:116

Signals download progress (0-100%)

Public Methods

ReturnNameDescription
ClientConnectionCreates 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.
voidstart virtualStarts the internal HTTP request.
voidstart virtualStarts the given HTTP request, replacing the internal request object.
ssize_tsend virtual overrideSends raw data to the peer, initiating a connection first if needed. Data is buffered internally until the connection is established.
voidsetReadStream virtualSets 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 inlineReturns a reference to the read stream cast to the specified type.

ClientConnection

ClientConnection(const URL & url, const net::TCPSocket::Ptr & socket = std::make_shared< net::TCPSocket >())

Defined in src/http/include/icy/http/client.h:42

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

  • 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.


start

virtual

virtual void start()

Defined in src/http/include/icy/http/client.h:51

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_error if already connecting.

start

virtual

virtual void start(http::Request & req)

Defined in src/http/include/icy/http/client.h:59

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

  • req The HTTP request to send. Replaces the internal request.

Exceptions

  • std::runtime_error if already connecting.

send

virtual override

virtual ssize_t send(const char * data, size_t len, int flags = 0) override

Defined in src/http/include/icy/http/client.h:67

Sends raw data to the peer, initiating a connection first if needed. Data is buffered internally until the connection is established.

Parameters

  • data Pointer to the data buffer.

  • len Number of bytes to send.

  • flags Socket send flags (unused for HTTP).

Returns

Number of bytes sent or buffered.

Reimplements

setReadStream

virtual

virtual void setReadStream(std::ostream * os)

Defined in src/http/include/icy/http/client.h:74

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

  • os Pointer to the output stream. Takes ownership.

Exceptions

  • std::runtime_error if already connecting.

readStream

inline

template<class StreamT> inline StreamT & readStream()

Defined in src/http/include/icy/http/client.h:82

Returns a reference to the read stream cast to the specified type.

Parameters

  • StreamT The concrete stream type to cast to.

Returns

Reference to the stream.

Exceptions

  • std::runtime_error if no read stream has been set.

  • std::bad_cast if the stream is not of type StreamT.

Protected Attributes

ReturnNameDescription
URL_url
bool_connect
bool_active
bool_complete
std::vector< PendingWrite >_outgoingBuffer
std::unique_ptr< std::ostream >_readStream

_url

URL _url

Defined in src/http/include/icy/http/client.h:135


_connect

bool _connect

Defined in src/http/include/icy/http/client.h:136


_active

bool _active

Defined in src/http/include/icy/http/client.h:137


_complete

bool _complete

Defined in src/http/include/icy/http/client.h:138


_outgoingBuffer

std::vector< PendingWrite > _outgoingBuffer

Defined in src/http/include/icy/http/client.h:139


_readStream

std::unique_ptr< std::ostream > _readStream

Defined in src/http/include/icy/http/client.h:140

Protected Methods

ReturnNameDescription
voidconnect virtualConnects to the server endpoint. All sent data is buffered until the connection is made.
http::Message *incomingHeader virtual overrideReturns the incoming HTTP message header (request or response depending on role).
http::Message *outgoingHeader virtual overrideReturns the outgoing HTTP message header (request or response depending on role).
boolonSocketConnect virtual overridenet::SocketAdapter interface

connect

virtual

virtual void connect()

Defined in src/http/include/icy/http/client.h:121

Connects to the server endpoint. All sent data is buffered until the connection is made.


incomingHeader

virtual override

virtual http::Message * incomingHeader() override

Defined in src/http/include/icy/http/client.h:123

Returns the incoming HTTP message header (request or response depending on role).

Reimplements

outgoingHeader

virtual override

virtual http::Message * outgoingHeader() override

Defined in src/http/include/icy/http/client.h:124

Returns the outgoing HTTP message header (request or response depending on role).

Reimplements

onSocketConnect

virtual override

virtual bool onSocketConnect(net::Socket & socket) override

Defined in src/http/include/icy/http/client.h:126

net::SocketAdapter interface

Reimplements

Public Types

NameDescription
Ptr

Ptr

using Ptr = std::shared_ptr< ClientConnection >

Defined in src/http/include/icy/http/client.h:36

Private Methods

ReturnNameDescription
voidonHeaders virtual overrideConnection interface.
voidonPayload virtual overrideCalled for each chunk of incoming response body data.
voidonComplete virtual overrideCalled when the full HTTP response has been received.
voidonClose virtual overrideCalled when the connection is closed.
boolonSocketError virtual overrideCalled when the underlying transport encounters an error.

onHeaders

virtual override

virtual void onHeaders() override

Defined in src/http/include/icy/http/client.h:97

Connection interface.

Called when the response headers have been parsed.

Reimplements

onPayload

virtual override

virtual void onPayload(const MutableBuffer & buffer) override

Defined in src/http/include/icy/http/client.h:99

Called for each chunk of incoming response body data.

Reimplements

onComplete

virtual override

virtual void onComplete() override

Defined in src/http/include/icy/http/client.h:101

Called when the full HTTP response has been received.

Reimplements

onClose

virtual override

virtual void onClose() override

Defined in src/http/include/icy/http/client.h:103

Called when the connection is closed.

Reimplements

onSocketError

virtual override

virtual bool onSocketError(net::Socket & socket, const icy::Error & error) override

Defined in src/http/include/icy/http/client.h:105

Called when the underlying transport encounters an error.

Reimplements