HTTP protocol parser.
More...
#include <wpinet/HttpParser.h>
|
| HttpParser (Type type) |
| Constructor.
|
|
void | Reset (Type type) |
| Reset the parser to initial state.
|
|
void | SetMaxLength (size_t len) |
| Set the maximum accepted length for URLs, field names, and field values.
|
|
std::string_view | Execute (std::string_view in) |
| Executes the parser.
|
|
unsigned int | GetMajor () const |
| Get HTTP major version.
|
|
unsigned int | GetMinor () const |
| Get HTTP minor version.
|
|
unsigned int | GetStatusCode () const |
| Get HTTP status code.
|
|
http_method | GetMethod () const |
| Get HTTP method.
|
|
bool | HasError () const |
| Determine if an error occurred.
|
|
http_errno | GetError () const |
| Get error number.
|
|
void | Abort () |
| Abort the parse.
|
|
bool | IsUpgrade () const |
| Determine if an upgrade header was present and the parser has exited because of that.
|
|
bool | ShouldKeepAlive () const |
| If this returns false in the headersComplete or messageComplete callback, then this should be the last message on the connection.
|
|
void | Pause (bool paused) |
| Pause the parser.
|
|
bool | IsBodyFinal () const |
| Checks if this is the final chunk of the body.
|
|
std::string_view | GetUrl () const |
| Get URL.
|
|
HTTP protocol parser.
Performs incremental parsing with callbacks for each part of the HTTP protocol. As this is incremental, it's suitable for use with event based frameworks that provide arbitrary chunks of data.
◆ Type
Enumerator |
---|
kRequest | |
kResponse | |
kBoth | |
◆ HttpParser()
wpi::HttpParser::HttpParser |
( |
Type | type | ) |
|
|
explicit |
Constructor.
- Parameters
-
type | Type of parser (request or response or both) |
◆ Abort()
void wpi::HttpParser::Abort |
( |
| ) |
|
|
inline |
Abort the parse.
Call this from a callback handler to indicate an error. This will result in GetError() returning one of the callback-related errors (e.g. HPE_CB_message_begin).
◆ Execute()
std::string_view wpi::HttpParser::Execute |
( |
std::string_view | in | ) |
|
|
inline |
Executes the parser.
An empty input is treated as EOF.
- Parameters
-
- Returns
- Trailing input data after the parse.
◆ GetError()
◆ GetMajor()
unsigned int wpi::HttpParser::GetMajor |
( |
| ) |
const |
|
inline |
◆ GetMethod()
Get HTTP method.
Valid only on requests.
◆ GetMinor()
unsigned int wpi::HttpParser::GetMinor |
( |
| ) |
const |
|
inline |
◆ GetParserVersion()
static uint32_t wpi::HttpParser::GetParserVersion |
( |
| ) |
|
|
static |
Returns the library version.
Bits 16-23 contain the major version number, bits 8-15 the minor version number and bits 0-7 the patch level.
◆ GetStatusCode()
unsigned int wpi::HttpParser::GetStatusCode |
( |
| ) |
const |
|
inline |
Get HTTP status code.
Valid only on responses. Valid in and after the OnStatus() callback has been called.
◆ GetUrl()
std::string_view wpi::HttpParser::GetUrl |
( |
| ) |
const |
|
inline |
Get URL.
Valid in and after the url callback has been called.
◆ HasError()
bool wpi::HttpParser::HasError |
( |
| ) |
const |
|
inline |
Determine if an error occurred.
- Returns
- False if no error.
◆ IsBodyFinal()
bool wpi::HttpParser::IsBodyFinal |
( |
| ) |
const |
|
inline |
Checks if this is the final chunk of the body.
◆ IsUpgrade()
bool wpi::HttpParser::IsUpgrade |
( |
| ) |
const |
|
inline |
Determine if an upgrade header was present and the parser has exited because of that.
Should be checked when Execute() returns in addition to checking GetError().
- Returns
- True if upgrade header, false otherwise.
◆ Pause()
void wpi::HttpParser::Pause |
( |
bool | paused | ) |
|
|
inline |
Pause the parser.
- Parameters
-
paused | True to pause, false to unpause. |
◆ Reset()
void wpi::HttpParser::Reset |
( |
Type | type | ) |
|
Reset the parser to initial state.
This allows reusing the same parser object from request to request.
- Parameters
-
type | Type of parser (request or response or both) |
◆ SetMaxLength()
void wpi::HttpParser::SetMaxLength |
( |
size_t | len | ) |
|
|
inline |
Set the maximum accepted length for URLs, field names, and field values.
The default is 1024.
- Parameters
-
◆ ShouldKeepAlive()
bool wpi::HttpParser::ShouldKeepAlive |
( |
| ) |
const |
|
inline |
If this returns false in the headersComplete or messageComplete callback, then this should be the last message on the connection.
If you are the server, respond with the "Connection: close" header. If you are the client, close the connection.
◆ body
sig::Signal<std::string_view, bool> wpi::HttpParser::body |
Body data callback.
The parameters to the callback is the data chunk and whether this is the final chunk of data in the message. Note this callback will be called multiple times arbitrarily (e.g. it's possible that it may be called with just a few characters at a time).
◆ chunkComplete
◆ chunkHeader
Chunk header callback.
The parameter to the callback is the chunk size.
◆ header
sig::Signal<std::string_view, std::string_view> wpi::HttpParser::header |
Header field callback.
The parameters to the callback are the field name and field value.
◆ headersComplete
Headers complete callback.
The parameter to the callback is whether the connection should be kept alive. If this is false, then this should be the last message on the connection. If you are the server, respond with the "Connection: close" header. If you are the client, close the connection.
◆ messageBegin
◆ messageComplete
Headers complete callback.
The parameter to the callback is whether the connection should be kept alive. If this is false, then this should be the last message on the connection. If you are the server, respond with the "Connection: close" header. If you are the client, close the connection.
◆ status
Status callback.
The parameter to the callback is the complete status string. GetStatusCode() can be used to get the numeric status code.
◆ url
URL callback.
The parameter to the callback is the complete URL string.
The documentation for this class was generated from the following file: