Home
HTTP module

Parser

HTTP request/response parser using the llhttp library.

Parser

#include <icy/http/parser.h>
class Parser

Defined in src/http/include/icy/http/parser.h:55

HTTP request/response parser using the llhttp library.

List of all members

NameKindOwner
ParserfunctionDeclared here
ParserfunctionDeclared here
ParserfunctionDeclared here
~ParserfunctionDeclared here
ParserfunctionDeclared here
operator=functionDeclared here
ParserfunctionDeclared here
operator=functionDeclared here
parsefunctionDeclared here
resetfunctionDeclared here
resetStatefunctionDeclared here
completefunctionDeclared here
upgradefunctionDeclared here
typefunctionDeclared here
setRequestfunctionDeclared here
setResponsefunctionDeclared here
setObserverfunctionDeclared here
clearMessagefunctionDeclared here
messagefunctionDeclared here
observerfunctionDeclared here
_observervariableDeclared here
_requestvariableDeclared here
_responsevariableDeclared here
_messagevariableDeclared here
_parservariableDeclared here
_settingsvariableDeclared here
_typevariableDeclared here
_wasHeaderValuevariableDeclared here
_lastHeaderFieldvariableDeclared here
_lastHeaderValuevariableDeclared here
_completevariableDeclared here
_upgradevariableDeclared here
_errorvariableDeclared here
_lastResultvariableDeclared here
_scratchvariableDeclared here
initfunctionDeclared here
clearBoundMessagefunctionDeclared here
storeHeaderfunctionDeclared here
applyScratchToBoundMessagefunctionDeclared here
onHeaderfunctionDeclared here
onHeadersEndfunctionDeclared here
onBodyfunctionDeclared here
onMessageEndfunctionDeclared here
onErrorfunctionDeclared here

Public Methods

ReturnNameDescription
ParserCreates a response parser. The response object is populated as data is parsed.
ParserCreates a request parser. The request object is populated as data is parsed.
ParserCreates a parser of the given type without binding a message object.
ParserDeleted constructor.
ParserDeleted constructor.
ParseResultparseFeeds a buffer of raw HTTP data into the parser.
voidresetReset the internal state (reinitialises llhttp). Safe to call externally, NOT from inside llhttp callbacks.
voidresetStateReset internal flags without reinitialising llhttp. Safe to call from inside llhttp callbacks (e.g. on_message_begin).
boolcomplete constReturns true if parsing is complete, either in success or error.
boolupgrade constReturns true if the connection should be upgraded.
llhttp_type_ttype const inlineReturns the parser type (HTTP_REQUEST or HTTP_RESPONSE).
voidsetRequestBinds an HTTP request object to populate during parsing. Must only be called when no message is currently set and type is HTTP_REQUEST.
voidsetResponseBinds an HTTP response object to populate during parsing. Must only be called when no message is currently set and type is HTTP_RESPONSE.
voidsetObserverSets the observer that receives parser events.
voidclearMessageClear request/response pointers so they can be re-set. Used when resetting a pooled connection for reuse.
http::Message *messageReturns the currently bound message (request or response), or nullptr.
ParserObserver *observer constReturns the current parser observer, or nullptr if none is set.

Parser

Parser(http::Response * response)

Defined in src/http/include/icy/http/parser.h:70

Creates a response parser. The response object is populated as data is parsed.

Parameters

  • response HTTP response object to populate.

Parser

Parser(http::Request * request)

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

Creates a request parser. The request object is populated as data is parsed.

Parameters

  • request HTTP request object to populate.

Parser

Parser(llhttp_type_t type)

Defined in src/http/include/icy/http/parser.h:78

Creates a parser of the given type without binding a message object.

Parameters

  • type Either HTTP_REQUEST or HTTP_RESPONSE.

Parser

Parser(const Parser &) = delete

Defined in src/http/include/icy/http/parser.h:81

Deleted constructor.


Parser

Parser(Parser &&) = delete

Defined in src/http/include/icy/http/parser.h:83

Deleted constructor.


parse

ParseResult parse(const char * data, size_t length)

Defined in src/http/include/icy/http/parser.h:93

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.

Parameters

  • data Pointer to the input data buffer.

  • length Number of bytes in the buffer.

Returns

Structured parse result including bytes consumed and terminal state.


reset

void reset()

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

Reset the internal state (reinitialises llhttp). Safe to call externally, NOT from inside llhttp callbacks.


resetState

void resetState()

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

Reset internal flags without reinitialising llhttp. Safe to call from inside llhttp callbacks (e.g. on_message_begin).


complete

const

bool complete() const

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

Returns true if parsing is complete, either in success or error.


upgrade

const

bool upgrade() const

Defined in src/http/include/icy/http/parser.h:108

Returns true if the connection should be upgraded.


type

const inline

inline llhttp_type_t type() const

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

Returns the parser type (HTTP_REQUEST or HTTP_RESPONSE).


setRequest

void setRequest(http::Request * request)

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

Binds an HTTP request object to populate during parsing. Must only be called when no message is currently set and type is HTTP_REQUEST.

Parameters

  • request The request object to populate.

setResponse

void setResponse(http::Response * response)

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

Binds an HTTP response object to populate during parsing. Must only be called when no message is currently set and type is HTTP_RESPONSE.

Parameters

  • response The response object to populate.

setObserver

void setObserver(ParserObserver * observer)

Defined in src/http/include/icy/http/parser.h:125

Sets the observer that receives parser events.

Parameters

  • observer Observer to notify. May be nullptr to clear.

clearMessage

void clearMessage()

Defined in src/http/include/icy/http/parser.h:129

Clear request/response pointers so they can be re-set. Used when resetting a pooled connection for reuse.


message

http::Message * message()

Defined in src/http/include/icy/http/parser.h:132

Returns the currently bound message (request or response), or nullptr.


observer

const

ParserObserver * observer() const

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

Returns the current parser observer, or nullptr if none is set.

Protected Attributes

ReturnNameDescription
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

_observer

ParserObserver * _observer

Defined in src/http/include/icy/http/parser.h:181


_request

http::Request * _request

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


_response

http::Response * _response

Defined in src/http/include/icy/http/parser.h:183


_message

http::Message * _message

Defined in src/http/include/icy/http/parser.h:184


_parser

llhttp_t _parser

Defined in src/http/include/icy/http/parser.h:186


_settings

llhttp_settings_t _settings

Defined in src/http/include/icy/http/parser.h:187


_type

llhttp_type_t _type

Defined in src/http/include/icy/http/parser.h:188


_wasHeaderValue

bool _wasHeaderValue

Defined in src/http/include/icy/http/parser.h:190


_lastHeaderField

std::string _lastHeaderField

Defined in src/http/include/icy/http/parser.h:191


_lastHeaderValue

std::string _lastHeaderValue

Defined in src/http/include/icy/http/parser.h:192


_complete

bool _complete

Defined in src/http/include/icy/http/parser.h:194


_upgrade

bool _upgrade

Defined in src/http/include/icy/http/parser.h:195


_error

Error _error

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


_lastResult

ParseResult _lastResult

Defined in src/http/include/icy/http/parser.h:198


_scratch

MessageScratch _scratch

Defined in src/http/include/icy/http/parser.h:199

Protected Methods

ReturnNameDescription
voidinit
voidclearBoundMessage
voidstoreHeader
voidapplyScratchToBoundMessage
voidonHeaderCallbacks.
voidonHeadersEnd
voidonBody
voidonMessageEnd
voidonError

init

void init()

Defined in src/http/include/icy/http/parser.h:158


clearBoundMessage

void clearBoundMessage()

Defined in src/http/include/icy/http/parser.h:159


storeHeader

void storeHeader(std::string name, std::string value)

Defined in src/http/include/icy/http/parser.h:160


applyScratchToBoundMessage

void applyScratchToBoundMessage()

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


onHeader

void onHeader(std::string name, std::string value)

Defined in src/http/include/icy/http/parser.h:164

Callbacks.


onHeadersEnd

void onHeadersEnd()

Defined in src/http/include/icy/http/parser.h:165


onBody

void onBody(const char * buf, size_t len)

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


onMessageEnd

void onMessageEnd()

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


onError

void onError(llhttp_errno_t errnum, const std::string & message = "")

Defined in src/http/include/icy/http/parser.h:168