HTTP module

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 and per-request ServerResponder objects.
ServerResponderBase responder interface for handling one HTTP request on a server connection. Derived classes typically override 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.
StaticFileInfoMetadata needed to serve a static file with HTTP validators.

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

Defined in src/http/include/icy/http/response.h:25

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

Defined in src/http/include/icy/http/server.h:39

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

Defined in src/http/include/icy/http/server.h:52

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

using ClientConnectionPtrVec = std::vector< ClientConnection::Ptr >

Type: std::vector< ClientConnection::Ptr >

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

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").
boolstatStaticFileRead static-file metadata from disk.
boolprepareStaticFileResponseApply static-file headers and request conditionals to the response.
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)

Defined in src/http/include/icy/http/authenticator.h:162

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

Parameters

ParameterTypeDescription
headerstd::string_viewValue of the Authorization or WWW-Authenticate header.

isDigestCredentials

bool isDigestCredentials(std::string_view header)

Defined in src/http/include/icy/http/authenticator.h:166

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

Parameters

ParameterTypeDescription
headerstd::string_viewValue of the Authorization or WWW-Authenticate header.

hasBasicCredentials

bool hasBasicCredentials(const http::Request & request)

Defined in src/http/include/icy/http/authenticator.h:170

Returns true if the request contains a Basic Authorization header.

Parameters

ParameterTypeDescription
requestconst http::Request &HTTP request to inspect.

hasDigestCredentials

bool hasDigestCredentials(const http::Request & request)

Defined in src/http/include/icy/http/authenticator.h:174

Returns true if the request contains a Digest Authorization header.

Parameters

ParameterTypeDescription
requestconst http::Request &HTTP request to inspect.

hasProxyBasicCredentials

bool hasProxyBasicCredentials(const http::Request & request)

Defined in src/http/include/icy/http/authenticator.h:178

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

Parameters

ParameterTypeDescription
requestconst http::Request &HTTP request to inspect.

hasProxyDigestCredentials

bool hasProxyDigestCredentials(const http::Request & request)

Defined in src/http/include/icy/http/authenticator.h:182

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

Parameters

ParameterTypeDescription
requestconst http::Request &HTTP request to inspect.

extractCredentials

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

Defined in src/http/include/icy/http/authenticator.h:189

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

ParameterTypeDescription
userInfostd::string_viewInput string in the form "user:password".
usernamestd::string &Receives the extracted username.
passwordstd::string &Receives the extracted password.

extractCredentials

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

Defined in src/http/include/icy/http/authenticator.h:197

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

Parameters

ParameterTypeDescription
uriconst http::URL &URL to extract credentials from.
usernamestd::string &Receives the extracted username.
passwordstd::string &Receives the extracted password.

createConnectionT

inline

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

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

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

Returns

Shared pointer to the created connection.

Parameters

ParameterTypeDescription
urlconst URL &Target URL. Must have a recognised scheme.
loopuv::Loop *Event loop to use. Defaults to the default libuv loop.

Exceptions

ExceptionDescription
std::runtime_errorif the URL scheme is not recognised.

createConnection

inline

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

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

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

Returns

Shared pointer to the created connection.

Parameters

ParameterTypeDescription
urlconst URL &Target URL. The scheme determines the socket and adapter type.
clienthttp::Client *Optional Client instance to register the connection with.
loopuv::Loop *Event loop to use. Defaults to the default libuv loop.

getStatusCodeReason

const char * getStatusCodeReason(StatusCode status)

Defined in src/http/include/icy/http/response.h:161

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

Returns

Null-terminated reason phrase string.

Parameters

ParameterTypeDescription
statusStatusCodeHTTP status code.

getStatusCodeString

const char * getStatusCodeString(StatusCode status)

Defined in src/http/include/icy/http/response.h:167

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

Returns

Null-terminated status code string.

Parameters

ParameterTypeDescription
statusStatusCodeHTTP status code.

statStaticFile

bool statStaticFile(std::string_view path, StaticFileInfo & info)

Defined in src/http/include/icy/http/server.h:273

Read static-file metadata from disk.

Returns

True if the path exists and is a regular file.

Parameters

ParameterTypeDescription
pathstd::string_viewFile path on disk.
infoStaticFileInfo &Receives the file size, weak ETag, and HTTP-normalized last-modified time.

prepareStaticFileResponse

bool prepareStaticFileResponse(const Request & request, Response & response, const StaticFileInfo & info)

Defined in src/http/include/icy/http/server.h:284

Apply static-file headers and request conditionals to the response.

Sets Content-Length, ETag, and Last-Modified from info, then evaluates If-None-Match and If-Modified-Since for the current request.

Returns

True if the response should not send a body (304 or 412).

Parameters

ParameterTypeDescription
requestconst Request &Incoming HTTP request.
responseResponse &Outgoing HTTP response to update.
infoconst StaticFileInfo &Precomputed static-file metadata.

parseURI

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

Defined in src/http/include/icy/http/util.h:26

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

Returns

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

Parameters

ParameterTypeDescription
requeststd::string_viewRaw HTTP request line (e.g. "GET /path?q=1 HTTP/1.1").

matchURL

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

Defined in src/http/include/icy/http/util.h:32

Tests whether a URI matches a glob-style expression.

Returns

true if the URI matches the expression.

Parameters

ParameterTypeDescription
uristd::string_viewThe URI to test.
expressionstd::string_viewPattern to match against. '*' matches any sequence of characters.

parseCookieItem

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

Defined in src/http/include/icy/http/util.h:38

Extracts a named attribute from a Cookie header value.

Returns

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

Parameters

ParameterTypeDescription
cookiestd::string_viewFull Cookie header value (e.g. "name=value; Path=/; HttpOnly").
itemstd::string_viewAttribute name to find (e.g. "Path").

splitURIParameters

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

Defined in src/http/include/icy/http/util.h:45

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

Returns

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

Parameters

ParameterTypeDescription
uristd::string_viewURI string optionally containing a '?' query component.
outNVCollection &Collection to populate with parsed parameters.

splitParameters

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

Defined in src/http/include/icy/http/util.h:56

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

ParameterTypeDescription
sconst std::string &Input string to split.
valuestd::string &Receives the primary value before the first ';'.
parametersNVCollection &Receives the parsed attribute key-value pairs.

splitParameters

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

Defined in src/http/include/icy/http/util.h:64

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

Parameters

ParameterTypeDescription
beginconst std::string::const_iterator &Iterator to the start of the string to parse.
endconst std::string::const_iterator &Iterator past the end of the string to parse.
parametersNVCollection &Receives the parsed attribute key-value pairs.