HTTP module

http

HTTP request/response types, parsers, and server/client helpers.

http

HTTP request/response types, parsers, and server/client helpers.

Classes

NameDescription
AuthenticatorMaintains HTTP Basic or Digest authentication state for outbound requests.
BasicAuthenticatorEncodes and decodes HTTP Basic authentication credentials.
ChunkedAdapterHTTP chunked transfer encoding adapter for streaming responses.
ClientHTTP client for creating and managing outgoing connections.
ClientConnectionHTTP client connection for managing request/response lifecycle.
ConnectionBase HTTP connection managing socket I/O and message lifecycle
ConnectionAdapterDefault HTTP socket adapter for reading and writing HTTP messages
ConnectionPoolLIFO connection pool for reusing ServerConnection objects. Avoids per-request heap allocation by resetting and reusing connections instead of destroying and recreating them.
ConnectionStreamPacket stream wrapper for an HTTP connection.
CookieHTTP cookie value plus its response/header attributes.
FilePartForm part backed by a file on disk.
FormPartAn implementation of FormPart.
FormWriterFormWriter is an HTTP client connection adapter for writing HTML forms.
MessageThe base class for Request and Response.
MultipartAdapterHTTP multipart encoding adapter for multipart/x-mixed-replace streaming.
ParserHTTP request/response parser using the llhttp library.
ParserObserverAbstract observer interface for HTTP parser events.
ProgressSignalHTTP progress signal for upload and download progress notifications.
RequestHTTP request message with method, URI, headers, and optional body.
ResponseHTTP response message with status, reason phrase, headers, and body metadata.
ServerHTTP server implementation.
ServerConnectionHTTP server connection.
ServerConnectionFactoryFactory for creating per-socket [ServerConnection](icy-http-ServerConnection.html#serverconnection) and per-request [ServerResponder](icy-http-ServerResponder.html#serverresponder) objects.
ServerResponderBase responder interface for handling one HTTP request on a server connection. Derived classes typically override [onRequest()](icy-http-ServerResponder.html#onrequest) and optionally the streaming hooks.
StringPartForm part backed by an in-memory string payload.
URLAn RFC 3986 based URL parser. Constructors and assignment operators will throw a SyntaxException if the URL is invalid.
DateCacheCaches the formatted Date header, updated once per second. Avoids per-request time formatting and string allocation.
MethodHTTP request methods.

Enumerations

NameDescription
StatusCodeHTTP Response Status Codes.
ServerConnectionStateHTTP server-side lifecycle phases used by the keep-alive state machine.
ServerConnectionModeTransport mode for server connections before and after protocol upgrade.

StatusCode

enum StatusCode

HTTP Response Status Codes.

ValueDescription
Continue
SwitchingProtocols
OK
Created
Accepted
NonAuthoritative
NoContent
ResetContent
PartialContent
MultipleChoices
MovedPermanently
Found
SeeOther
NotModified
UseProxy
TemporaryRedirect
BadRequest
Unauthorized
PaymentRequired
Forbidden
NotFound
MethodNotAllowed
NotAcceptable
ProxyAuthRequired
RequestTimeout
Conflict
Gone
LengthRequired
PreconditionFailed
EntityTooLarge
UriTooLong
UnsupportedMediaType
RangeNotSatisfiable
ExpectationFailed
UnprocessableEntity
UpgradeRequired
InternalServerError
NotImplemented
BadGateway
Unavailable
GatewayTimeout
VersionNotSupported

ServerConnectionState

enum ServerConnectionState

HTTP server-side lifecycle phases used by the keep-alive state machine.

ValueDescription
ReceivingHeadersParsing request headers.
ReceivingBodyReceiving request body bytes.
DispatchingOrSendingDispatching the responder or sending a normal response.
StreamingSending a long-lived streaming response.
UpgradedUpgraded to a non-HTTP protocol such as WebSocket.
ClosingClose has been requested and teardown is in progress.
ClosedConnection has fully closed.

ServerConnectionMode

enum ServerConnectionMode

Transport mode for server connections before and after protocol upgrade.

ValueDescription
HttpStandard HTTP request/response mode.
UpgradedUpgraded transport mode owned by another protocol adapter.

Typedefs

ReturnNameDescription
std::vector< ClientConnection::Ptr >ClientConnectionPtrVecList of owned client connections tracked by an HTTP client.

ClientConnectionPtrVec

std::vector< ClientConnection::Ptr > ClientConnectionPtrVec()

List of owned client connections tracked by an HTTP client.

Functions

ReturnNameDescription
boolisBasicCredentialsReturns true if the given Authorization header value uses HTTP Basic authentication.
boolisDigestCredentialsReturns true if the given Authorization header value uses HTTP Digest authentication.
boolhasBasicCredentialsReturns true if the request contains a Basic Authorization header.
boolhasDigestCredentialsReturns true if the request contains a Digest Authorization header.
boolhasProxyBasicCredentialsReturns true if the request contains a Basic Proxy-Authorization header.
boolhasProxyDigestCredentialsReturns true if the request contains a Digest Proxy-Authorization header.
voidextractCredentialsSplits a "user:password" user-info string into separate username and password strings. If no ':' is present, the entire string is treated as the username and password is empty.
voidextractCredentialsExtracts username and password from the user-info component of a URL. Does nothing if the URL has no user-info part.
ClientConnection::PtrcreateConnectionT inlineCreates a ClientConnection (or subtype) for the given URL without registering it with a Client instance. The socket and adapter are chosen based on the URL scheme:
ClientConnection::PtrcreateConnection inlineCreates a ClientConnection for the given URL and optionally registers it with a Client. Equivalent to calling Client::createConnection() when client is non-null.
const char *getStatusCodeReasonReturns the standard reason phrase for the given HTTP status code (e.g. "OK" for StatusCode::OK, "Not Found" for StatusCode::NotFound).
const char *getStatusCodeStringReturns a combined "NNN Reason" string for the given HTTP status code (e.g. "200 OK").
std::stringparseURIExtracts the URI (path and query) from a raw HTTP request line.
boolmatchURLTests whether a URI matches a glob-style expression.
std::stringparseCookieItemExtracts a named attribute from a Cookie header value.
boolsplitURIParametersParses URL query parameters from a URI into key-value pairs. Handles percent-decoding of names and values.
voidsplitParametersSplits a header-style parameter string into a primary value and named attributes. Attributes are separated by ';'. Enclosing quotes are stripped from values.
voidsplitParametersSplits a substring (defined by iterators) into named attributes. Attributes are separated by ';'. Enclosing quotes are stripped from values.

isBasicCredentials

bool isBasicCredentials(std::string_view header)

Returns true if the given Authorization header value uses HTTP Basic authentication.

Parameters

  • header Value of the Authorization or WWW-Authenticate header.

isDigestCredentials

bool isDigestCredentials(std::string_view header)

Returns true if the given Authorization header value uses HTTP Digest authentication.

Parameters

  • header Value of the Authorization or WWW-Authenticate header.

hasBasicCredentials

bool hasBasicCredentials(const http::Request & request)

Returns true if the request contains a Basic Authorization header.

Parameters

  • request HTTP request to inspect.

hasDigestCredentials

bool hasDigestCredentials(const http::Request & request)

Returns true if the request contains a Digest Authorization header.

Parameters

  • request HTTP request to inspect.

hasProxyBasicCredentials

bool hasProxyBasicCredentials(const http::Request & request)

Returns true if the request contains a Basic Proxy-Authorization header.

Parameters

  • request HTTP request to inspect.

hasProxyDigestCredentials

bool hasProxyDigestCredentials(const http::Request & request)

Returns true if the request contains a Digest Proxy-Authorization header.

Parameters

  • request HTTP request to inspect.

extractCredentials

void extractCredentials(std::string_view userInfo, std::string & username, std::string & password)

Splits a "user:password" user-info string into separate username and password strings. If no ':' is present, the entire string is treated as the username and password is empty.

Parameters

  • userInfo Input string in the form "user:password".

  • username Receives the extracted username.

  • password Receives the extracted password.


extractCredentials

void extractCredentials(const http::URL & uri, std::string & username, std::string & password)

Extracts username and password from the user-info component of a URL. Does nothing if the URL has no user-info part.

Parameters

  • uri URL to extract credentials from.

  • username Receives the extracted username.

  • password Receives the extracted password.


createConnectionT

inline

template<class ConnectionT> inline ClientConnection::Ptr createConnectionT(const URL & url, uv::Loop * loop)

Creates a ClientConnection (or subtype) for the given URL without registering it with a Client instance. The socket and adapter are chosen based on the URL scheme:

  • "http" -> TCPSocket

  • "https" -> SSLSocket

  • "ws" -> TCPSocket + WebSocket adapter

  • "wss" -> SSLSocket + WebSocket adapter

Parameters

Parameters

  • url Target URL. Must have a recognised scheme.

  • loop Event loop to use. Defaults to the default libuv loop.

Returns

Shared pointer to the created connection.

Exceptions

  • std::runtime_error if the URL scheme is not recognised.

createConnection

inline

inline ClientConnection::Ptr createConnection(const URL & url, http::Client * client, uv::Loop * loop)

Creates a ClientConnection for the given URL and optionally registers it with a Client. Equivalent to calling Client::createConnection() when client is non-null.

Parameters

  • url Target URL. The scheme determines the socket and adapter type.

  • client Optional Client instance to register the connection with.

  • loop Event loop to use. Defaults to the default libuv loop.

Returns

Shared pointer to the created connection.


getStatusCodeReason

const char * getStatusCodeReason(StatusCode status)

Returns the standard reason phrase for the given HTTP status code (e.g. "OK" for StatusCode::OK, "Not Found" for StatusCode::NotFound).

Parameters

  • status HTTP status code.

Returns

Null-terminated reason phrase string.


getStatusCodeString

const char * getStatusCodeString(StatusCode status)

Returns a combined "NNN Reason" string for the given HTTP status code (e.g. "200 OK").

Parameters

  • status HTTP status code.

Returns

Null-terminated status code string.


parseURI

std::string parseURI(std::string_view request)

Extracts the URI (path and query) from a raw HTTP request line.

Parameters

  • request Raw HTTP request line (e.g. "GET /path?q=1 HTTP/1.1").

Returns

The URI portion (e.g. "/path?q=1").


matchURL

bool matchURL(std::string_view uri, std::string_view expression)

Tests whether a URI matches a glob-style expression.

Parameters

  • uri The URI to test.

  • expression Pattern to match against. '*' matches any sequence of characters.

Returns

true if the URI matches the expression.


parseCookieItem

std::string parseCookieItem(std::string_view cookie, std::string_view item)

Extracts a named attribute from a Cookie header value.

Parameters

  • cookie Full Cookie header value (e.g. "name=value; Path=/; HttpOnly").

  • item Attribute name to find (e.g. "Path").

Returns

The value of the named attribute, or an empty string if not found.


splitURIParameters

bool splitURIParameters(std::string_view uri, NVCollection & out)

Parses URL query parameters from a URI into key-value pairs. Handles percent-decoding of names and values.

Parameters

  • uri URI string optionally containing a '?' query component.

  • out Collection to populate with parsed parameters.

Returns

true if at least one parameter was parsed; false otherwise.


splitParameters

void splitParameters(const std::string & s, std::string & value, NVCollection & parameters)

Splits a header-style parameter string into a primary value and named attributes. Attributes are separated by ';'. Enclosing quotes are stripped from values.

Example input: "multipart/mixed; boundary="boundary-01234567"" Output value: "multipart/mixed", parameters: { "boundary" -> "boundary-01234567" }

Parameters

  • s Input string to split.

  • value Receives the primary value before the first ';'.

  • parameters Receives the parsed attribute key-value pairs.


splitParameters

void splitParameters(const std::string::const_iterator & begin, const std::string::const_iterator & end, NVCollection & parameters)

Splits a substring (defined by iterators) into named attributes. Attributes are separated by ';'. Enclosing quotes are stripped from values.

Parameters

  • begin Iterator to the start of the string to parse.

  • end Iterator past the end of the string to parse.

  • parameters Receives the parsed attribute key-value pairs.