Milo release is composed by a header file milo.h and static library libmilo.a
The exact command to build milo is dependent on your compiler. For instance, for clang the command is the following:
clang++ -std=c++11 -I $MILO_DIR -o output main.cc $MILO_DIR/libmilo.awhere $MILO_DIR is the directory containing the milo.h and libmilo.a files.
When downloading Milo, you can choose between debug or release version:
All callbacks in Milo have the following signature (Callback):
void(*)(milo_parser::Parser*, uintptr_t, uintptr_t)where the parameters have the following meaning:
- The current parser.
- The payload offset. Can be
0. - The data length. Can be
0.
If length is 0, it means the callback has no payload associated.
Callbacks are dispatched only when the corresponding CALLBACK_ACTIVE_* flag is set in the parser active_callbacks field.
Callbacks are disabled by default.
The file milo.h defines several constants (* is used to denote a family prefix):
MILO_VERSION: The current Milo complete version as a string.MILO_VERSION_MAJOR: The current Milo major version.MILO_VERSION_MINOR: The current Milo minor version.MILO_VERSION_PATCHThe current Milo patch version.ERROR_*: An error code.METHOD_*: An HTTP request method.CALLBACK_*: A parser callback.CALLBACK_ACTIVE_*: A callback activation flag.STATE_*: A parser state.
Internal generated lookup tables used by the parser are not exported in milo.h.
A struct representing a string containing the following fields:
ptr(const unsigned char *): The string data pointer.len(uintptr_t): The string length.
A struct representing the callbacks for a parser. Here's the list of supported callbacks:
on_state_change: Invoked after the parser changes its state. Only invoked in debug mode.on_error: Invoked after the parsing fails.on_finish: Invoked after the parser is marked as finished.on_message_start: Invoked after a new message starts.on_message_complete: Invoked after a message finishes.on_request: Invoked after the message is identified as a request.on_response: Invoked after the message is identified as a response.on_reset: Invoked after the parser is reset (either manually or after parsing a new message except the first one).on_method: Invoked after the HTTP method has been parsed.on_url: Invoked after the request URL has been parsed.on_protocol: Invoked after the request or response protocol has been parsed.on_version: Invoked after the request or response version has been parsed.on_status: Invoked after the response status has been parsed.on_reason: Invoked after the response status reason has been parsed.on_header_name: Invoked after a new header name has been parsed.on_header_value: Invoked after a new header value has been parsed.on_headers: Invoked after headers are completed.on_connect: Invoked inCONNECTrequests after headers have been completed.on_upgrade: Invoked after a request or response enters tunnel mode viaUpgradeandConnection: upgrade.on_chunk_length: Invoked after a new chunk length has been parsed.on_chunk_extension_name: Invoked after a new chunk extension name has been parsed.on_chunk_extension_value: Invoked after a new chunk extension value has been parsed.on_chunk: Invoked after new chunk data is received.on_data: Invoked after new body data is received (either chunked or not).on_body: Invoked after the body has been parsed. Note that this has no data attached soon_datamust be used to save the body.on_trailer_name: Invoked after a new trailer name has been parsed.on_trailer_value: Invoked after a new trailer value has been parsed.on_trailers: Invoked after trailers are completed.
If you want to remove a previously set callback, you can use milo_parser::milo_noop.
A struct representing a parser. It has the following fields:
autodetect(bool): If the parser should autodetect requests and responses. Enabled by default.is_request(bool): The configured or detected message type. Set this whenautodetectisfalse.paused(bool): If the parser is paused.manage_unconsumed(bool): If the parser should automatically copy and prepend unconsumed data.continue_without_data(bool): If the next execution of the parse loop should execute even if there is no more data.is_connect(bool): If the current request usedCONNECTmethod.skip_body(bool): If the parser should skip the body.max_start_line_length(uintptr_t): Maximum allowed request/status line length. By default is8192.max_header_length(uintptr_t): Maximum allowed header length. By default is8192.context(void*): The context of this parser. Use is reserved to the developer.state(uint8_t): The current parser state.position(uintptr_t): The current parser position in the slice in the current execution ofmilo_parse.parsed(uint64_t): The total bytes consumed from this parser.error_code(uint8_t): The parser error. By default isERROR_NONE.method(uint8_t): The current request method.status(uint32_t): The current response status.version_major(uint8_t): The current message HTTP version major version.version_minor(uint8_t): The current message HTTP version minor version.content_length(uint64_t): The value of theContent-Lengthheader.chunk_size(uint64_t): The expected length of the next chunk.remaining_content_length(uint64_t): The missing data length of the body according to thecontent_lengthfield.remaining_chunk_size(uint64_t): The missing data length of the next chunk according to thechunk_sizefield.has_content_length(bool): If the current message has aContent-Lengthheader.has_transfer_encoding(bool): If the current message has aTransfer-Encodingheader.has_chunked_transfer_encoding(bool): If the current message is using chunked encoding.has_connection_close(bool): If the current message has aConnection: closetoken.has_connection_upgrade(bool): If the current message has aConnection: upgradetoken.has_upgrade(bool): If the current message has anUpgradeheader.has_trailers(bool): If the current message has aTrailerheader.active_callbacks(uint64_t): Active callback bitmask. Set to one or moreCALLBACK_ACTIVE_*values.callbacks(ParserCallbacks): The callbacks for the current parser.error_description(const unsigned char*): The parser error description.error_description_len(uint16_t): The parser error description length.unconsumed(const unsigned char*): The unconsumed data from the previous execution ofparsewhenmanage_unconsumedistrue.unconsumed_len(uintptr_t): The unconsumed data length from the previous execution ofparsewhenmanage_unconsumedistrue.
All the fields MUST be considered readonly, with the following exceptions:
autodetectis_requestmanage_unconsumedcontinue_without_datais_connectskip_bodymax_start_line_lengthmax_header_lengthcontextactive_callbackscallbacks
An enum listing all possible parser errors.
An enum listing all possible HTTP methods recognized by Milo.
An enum listing all possible parser callbacks.
An enum listing all possible parser states.
Returns true if debug informations are available in this build.
A callback that does nothing.
Use this callback as pointer when you want to remove a callback from the parser.
Release memory from a string previously obtained from other APIs.
By convention, all milo's C++ function which ends in _string MUST have their value freed up with this function when done.
Creates a new parser.
The returned value MUST be destroyed later using milo_destroy.
Destroys a parser.
Parses data up to limit characters.
It returns the number of consumed characters.
Resets a parser. The second parameters specifies if to also reset the parsed counter.
The following fields are not modified:
positioncontextautodetectis_requestmanage_unconsumedcontinue_without_datamax_start_line_lengthmax_header_lengthcontextactive_callbackscallbacks
Clears all values about the message in the parser.
The autodetect and is_request fields are not cleared.
Pauses the parser. The parser will have to be resumed via milo_parser::milo_resume.
Resumes the parser.
Marks the parser as finished. Any new invocation of milo_parser::milo_parse will put the parser in the error state.
Marks the parsing a failed, setting a error code and and error message.
Returns the current parser's state as string.
The returned value MUST be freed using milo_parser::milo_free_string.
Returns the current parser's error state as string.
The returned value MUST be freed using milo_parser::milo_free_string.
Returns the current parser's error description.
The returned value MUST be freed using milo_parser::milo_free_string.