#include <icy/http/parser.h>HTTP request/response parser using the llhttp library.
| Return | Name | Description |
|---|---|---|
Parser | Creates a response parser. The response object is populated as data is parsed. | |
Parser | Creates a request parser. The request object is populated as data is parsed. | |
Parser | Creates a parser of the given type without binding a message object. | |
Parser | Deleted constructor. | |
Parser | Deleted constructor. | |
ParseResult | parse | Feeds a buffer of raw HTTP data into the parser. |
void | reset | Reset the internal state (reinitialises llhttp). Safe to call externally, NOT from inside llhttp callbacks. |
void | resetState | Reset internal flags without reinitialising llhttp. Safe to call from inside llhttp callbacks (e.g. on_message_begin). |
bool | complete const | Returns true if parsing is complete, either in success or error. |
bool | upgrade const | Returns true if the connection should be upgraded. |
llhttp_type_t | type const inline | Returns the parser type (HTTP_REQUEST or HTTP_RESPONSE). |
void | setRequest | Binds an HTTP request object to populate during parsing. Must only be called when no message is currently set and type is HTTP_REQUEST. |
void | setResponse | Binds an HTTP response object to populate during parsing. Must only be called when no message is currently set and type is HTTP_RESPONSE. |
void | setObserver | Sets the observer that receives parser events. |
void | clearMessage | Clear request/response pointers so they can be re-set. Used when resetting a pooled connection for reuse. |
http::Message * | message | Returns the currently bound message (request or response), or nullptr. |
ParserObserver * | observer const | Returns the current parser observer, or nullptr if none is set. |
Parser(http::Response * response)Creates a response parser. The response object is populated as data is parsed.
response HTTP response object to populate.Parser(http::Request * request)Creates a request parser. The request object is populated as data is parsed.
request HTTP request object to populate.Parser(llhttp_type_t type)Creates a parser of the given type without binding a message object.
type Either HTTP_REQUEST or HTTP_RESPONSE.Parser(const Parser &) = deleteDeleted constructor.
Parser(Parser &&) = deleteDeleted constructor.
ParseResult parse(const char * data, size_t length)Feeds a buffer of raw HTTP data into the parser.
May be called multiple times for streaming data. The parser state persists between calls. On completion or error, the observer is notified.
data Pointer to the input data buffer.
length Number of bytes in the buffer.
Structured parse result including bytes consumed and terminal state.
void reset()Reset the internal state (reinitialises llhttp). Safe to call externally, NOT from inside llhttp callbacks.
void resetState()Reset internal flags without reinitialising llhttp. Safe to call from inside llhttp callbacks (e.g. on_message_begin).
const
bool complete() constReturns true if parsing is complete, either in success or error.
const
bool upgrade() constReturns true if the connection should be upgraded.
const inline
inline llhttp_type_t type() constReturns the parser type (HTTP_REQUEST or HTTP_RESPONSE).
void setRequest(http::Request * request)Binds an HTTP request object to populate during parsing. Must only be called when no message is currently set and type is HTTP_REQUEST.
request The request object to populate.void setResponse(http::Response * response)Binds an HTTP response object to populate during parsing. Must only be called when no message is currently set and type is HTTP_RESPONSE.
response The response object to populate.void setObserver(ParserObserver * observer)Sets the observer that receives parser events.
observer Observer to notify. May be nullptr to clear.void clearMessage()Clear request/response pointers so they can be re-set. Used when resetting a pooled connection for reuse.
http::Message * message()Returns the currently bound message (request or response), or nullptr.
const
ParserObserver * observer() constReturns the current parser observer, or nullptr if none is set.
| Return | Name | Description |
|---|---|---|
ParserObserver * | _observer | |
http::Request * | _request | |
http::Response * | _response | |
http::Message * | _message | |
llhttp_t | _parser | |
llhttp_settings_t | _settings | |
llhttp_type_t | _type | |
bool | _wasHeaderValue | |
std::string | _lastHeaderField | |
std::string | _lastHeaderValue | |
bool | _complete | |
bool | _upgrade | |
Error | _error | |
ParseResult | _lastResult | |
MessageScratch | _scratch |
ParserObserver * _observerhttp::Request * _requesthttp::Response * _responsehttp::Message * _messagellhttp_t _parserllhttp_settings_t _settingsllhttp_type_t _typebool _wasHeaderValuestd::string _lastHeaderFieldstd::string _lastHeaderValuebool _completebool _upgradeError _errorParseResult _lastResultMessageScratch _scratch| Return | Name | Description |
|---|---|---|
void | init | |
void | clearBoundMessage | |
void | storeHeader | |
void | applyScratchToBoundMessage | |
void | onHeader | Callbacks. |
void | onHeadersEnd | |
void | onBody | |
void | onMessageEnd | |
void | onError |
void init()void clearBoundMessage()void storeHeader(std::string name, std::string value)void applyScratchToBoundMessage()void onHeader(std::string name, std::string value)Callbacks.
void onHeadersEnd()void onBody(const char * buf, size_t len)void onMessageEnd()void onError(llhttp_errno_t errnum, const std::string & message)