HTTP module

ConnectionAdapter

Default HTTP socket adapter for reading and writing HTTP messages

ConnectionAdapter

#include <icy/http/connection.h>

Inherits: ParserObserver, SocketAdapter

Default HTTP socket adapter for reading and writing HTTP messages

Public Methods

ReturnNameDescription
ConnectionAdapterCreates a ConnectionAdapter for the given connection.
ssize_tsend virtualSends data to the peer, flushing the outgoing HTTP header first if needed.
ssize_tsendOwned virtualSends an owned payload buffer to the connected peer.
voidremoveReceiverRemove the given receiver.
Parser &parserReturns the HTTP parser instance.
Connection *connectionReturns the owning Connection pointer, or nullptr if detached.
voidresetResets the adapter for reuse with a new socket and request. Clears the parser state and re-wires the sender without reallocating. Used by the connection pool to avoid destroying/recreating adapters.

ConnectionAdapter

ConnectionAdapter(Connection * connection, llhttp_type_t type)

Creates a ConnectionAdapter for the given connection.

Parameters

  • connection Owning HTTP connection.

  • type Parser type: HTTP_REQUEST for server side, HTTP_RESPONSE for client side.


send

virtual

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

Sends data to the peer, flushing the outgoing HTTP header first if needed.

Parameters

  • data Pointer to the data buffer.

  • len Number of bytes to send.

  • flags Send flags (unused for HTTP, used for WebSocket frame type).

Returns

Number of bytes sent, or -1 on error.


sendOwned

virtual

virtual ssize_t sendOwned(Buffer && buffer, int flags)

Sends an owned payload buffer to the connected peer.

The buffer is moved through the adapter chain and retained by the transport layer until async write completion.


removeReceiver

void removeReceiver(SocketAdapter * adapter)

Remove the given receiver.

By default this function does nothing unless the given receiver matches the current receiver.


parser

Parser & parser()

Returns the HTTP parser instance.


connection

Connection * connection()

Returns the owning Connection pointer, or nullptr if detached.


reset

void reset(net::SocketAdapter * sender, http::Request * request)

Resets the adapter for reuse with a new socket and request. Clears the parser state and re-wires the sender without reallocating. Used by the connection pool to avoid destroying/recreating adapters.

Parameters

  • sender New socket adapter to send data through.

  • request New HTTP request object for the parser to populate.

Protected Attributes

ReturnNameDescription
Connection *_connection
Parser_parser

_connection

Connection * _connection

_parser

Parser _parser

Protected Methods

ReturnNameDescription
boolonSocketRecv virtualSocketAdapter interface.
voidonParserHeader virtualHTTP Parser interface.
voidonParserHeadersEnd virtualCalled when all HTTP headers have been parsed.
voidonParserChunk virtualCalled for each chunk of body data received.
voidonParserError virtualCalled when a parse error occurs.
voidonParserEnd virtualCalled when the HTTP message is fully parsed.

onSocketRecv

virtual

virtual bool onSocketRecv(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress)

SocketAdapter interface.


onParserHeader

virtual

virtual void onParserHeader(const std::string & name, const std::string & value)

HTTP Parser interface.


onParserHeadersEnd

virtual

virtual void onParserHeadersEnd(bool upgrade)

Called when all HTTP headers have been parsed.

Parameters

  • upgrade True if the connection should be upgraded (e.g. to WebSocket).

onParserChunk

virtual

virtual void onParserChunk(const char * data, size_t len)

Called for each chunk of body data received.

Parameters

  • data Pointer to the body data chunk.

  • len Length of the chunk in bytes.


onParserError

virtual

virtual void onParserError(const icy::Error & err)

Called when a parse error occurs.

Parameters

  • err Error details from llhttp.

onParserEnd

virtual

virtual void onParserEnd()

Called when the HTTP message is fully parsed.