Parser
Parser
#include <icy/http/parser.h>class ParserDefined in src/http/include/icy/http/parser.h:55
HTTP request/response parser using the llhttp library.
List of all members
| Name | Kind | Owner |
|---|---|---|
Parser | function | Declared here |
Parser | function | Declared here |
Parser | function | Declared here |
~Parser | function | Declared here |
Parser | function | Declared here |
operator= | function | Declared here |
Parser | function | Declared here |
operator= | function | Declared here |
parse | function | Declared here |
reset | function | Declared here |
resetState | function | Declared here |
complete | function | Declared here |
upgrade | function | Declared here |
type | function | Declared here |
setRequest | function | Declared here |
setResponse | function | Declared here |
setObserver | function | Declared here |
clearMessage | function | Declared here |
message | function | Declared here |
observer | function | Declared here |
_observer | variable | Declared here |
_request | variable | Declared here |
_response | variable | Declared here |
_message | variable | Declared here |
_parser | variable | Declared here |
_settings | variable | Declared here |
_type | variable | Declared here |
_wasHeaderValue | variable | Declared here |
_lastHeaderField | variable | Declared here |
_lastHeaderValue | variable | Declared here |
_complete | variable | Declared here |
_upgrade | variable | Declared here |
_error | variable | Declared here |
_lastResult | variable | Declared here |
_scratch | variable | Declared here |
init | function | Declared here |
clearBoundMessage | function | Declared here |
storeHeader | function | Declared here |
applyScratchToBoundMessage | function | Declared here |
onHeader | function | Declared here |
onHeadersEnd | function | Declared here |
onBody | function | Declared here |
onMessageEnd | function | Declared here |
onError | function | Declared here |
Public Methods
| 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
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
responseHTTP 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
requestHTTP 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
typeEither HTTP_REQUEST or HTTP_RESPONSE.
Parser
Parser(const Parser &) = deleteDefined in src/http/include/icy/http/parser.h:81
Deleted constructor.
Parser
Parser(Parser &&) = deleteDefined 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
dataPointer to the input data buffer.lengthNumber 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() constDefined in src/http/include/icy/http/parser.h:105
Returns true if parsing is complete, either in success or error.
upgrade
const
bool upgrade() constDefined 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() constDefined 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
requestThe 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
responseThe 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
observerObserver 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() constDefined in src/http/include/icy/http/parser.h:135
Returns the current parser observer, or nullptr if none is set.
Protected Attributes
| 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 |
_observer
ParserObserver * _observerDefined in src/http/include/icy/http/parser.h:181
_request
http::Request * _requestDefined in src/http/include/icy/http/parser.h:182
_response
http::Response * _responseDefined in src/http/include/icy/http/parser.h:183
_message
http::Message * _messageDefined in src/http/include/icy/http/parser.h:184
_parser
llhttp_t _parserDefined in src/http/include/icy/http/parser.h:186
_settings
llhttp_settings_t _settingsDefined in src/http/include/icy/http/parser.h:187
_type
llhttp_type_t _typeDefined in src/http/include/icy/http/parser.h:188
_wasHeaderValue
bool _wasHeaderValueDefined in src/http/include/icy/http/parser.h:190
_lastHeaderField
std::string _lastHeaderFieldDefined in src/http/include/icy/http/parser.h:191
_lastHeaderValue
std::string _lastHeaderValueDefined in src/http/include/icy/http/parser.h:192
_complete
bool _completeDefined in src/http/include/icy/http/parser.h:194
_upgrade
bool _upgradeDefined in src/http/include/icy/http/parser.h:195
_error
Error _errorDefined in src/http/include/icy/http/parser.h:197
_lastResult
ParseResult _lastResultDefined in src/http/include/icy/http/parser.h:198
_scratch
MessageScratch _scratchDefined in src/http/include/icy/http/parser.h:199
Protected Methods
| Return | Name | Description |
|---|---|---|
void | init | |
void | clearBoundMessage | |
void | storeHeader | |
void | applyScratchToBoundMessage | |
void | onHeader | Callbacks. |
void | onHeadersEnd | |
void | onBody | |
void | onMessageEnd | |
void | onError |
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 = "")