36#ifndef DETERMINISTICESPASYNCWEBSERVER_HTTP_PARSER_H
37#define DETERMINISTICESPASYNCWEBSERVER_HTTP_PARSER_H
129#if DETWS_CAPTURE_AUTH_HEADER
153#if DETWS_ENABLE_STREAM_BODY
161#if DETWS_ENABLE_STREAM_BODY
175typedef bool (*HttpStreamBeginCb)(
HttpReq *req);
177typedef void (*HttpStreamDataCb)(
HttpReq *req,
const uint8_t *data,
size_t len);
183typedef void (*HttpStreamAbortCb)(
HttpReq *req);
186void http_parser_set_stream_hooks(HttpStreamBeginCb begin, HttpStreamDataCb data, HttpStreamAbortCb abort =
nullptr);
User-facing configuration for DeterministicESPAsyncWebServer.
#define MAX_VAL_LEN
Maximum header field-value length.
#define MAX_QUERY_PARAMS
Maximum number of parsed query-string parameters.
#define MAX_QUERY_LEN
Maximum raw query-string length (everything after ?).
#define DETWS_METHOD_BUF_SIZE
HTTP method-token buffer size (bytes, including the NUL).
#define QUERY_VAL_LEN
Maximum query-parameter value length.
#define BODY_BUF_SIZE
Maximum request body bytes stored in HttpReq::body.
#define MAX_HEADERS
Maximum HTTP headers stored per request.
#define MAX_PATH_LEN
Maximum URL path length (including leading /).
#define QUERY_KEY_LEN
Maximum query-parameter key length.
#define MAX_KEY_LEN
Maximum header field-name length (e.g. "Content-Type").
#define MAX_PATH_PARAMS
Maximum number of :name path parameters captured per route match.
#define DETWS_AUTH_HDR_CAP
const char * http_get_param(const HttpReq *req, const char *key)
Look up a captured path parameter by name (case-sensitive).
ParseState
States of the HTTP/1.1 request parser.
@ PARSE_QUERY
Reading the raw query string (after ?).
@ PARSE_METHOD
Reading the HTTP method (GET, POST, …).
@ PARSE_ERROR
Unrecoverable parse failure → 400.
@ PARSE_ENTITY_TOO_LARGE
Content-Length > BODY_BUF_SIZE → 413.
@ PARSE_BODY
Reading the request body.
@ PARSE_COMPLETE
Full request parsed; ready for dispatch.
@ PARSE_HEADER_VAL
Reading a header field value.
@ PARSE_VERSION
Accumulating HTTP/1.x - hashed for validation.
@ PARSE_EXPECT_BODY_LF
Consuming the LF of the blank-line CRLF.
@ PARSE_HEADER_KEY
Reading a header field name.
@ PARSE_PATH
Reading the URL path component.
@ PARSE_URI_TOO_LONG
Path exceeds MAX_PATH_LEN → 414.
@ PARSE_EXPECT_LF
Consuming the LF of a header-line CRLF pair.
void http_parser_reset(HttpReq *req)
Reset a parser context to the initial (ParseState::PARSE_METHOD) state.
const char * http_get_header(const HttpReq *req, const char *key)
Look up a header value by name (case-insensitive).
void http_parser_feed(HttpReq *req, uint8_t byte)
Feed one byte to the parser state machine.
HttpReq http_pool[CONN_POOL_SLOTS]
Pool of parser contexts, one per connection-pool slot (incl. reserved dispatch slots).
HttpVersion
Parsed HTTP protocol version.
@ HTTP_10
HTTP/1.0 - close semantics by default.
@ HTTP_11
HTTP/1.1 - persistent connection by default.
@ HTTP_UNKNOWN
Version string did not match any known token.
bool http_get_cookie(const HttpReq *req, const char *name, char *out, size_t out_size)
Read a named cookie from the request Cookie header (RFC 6265 4.2.1).
bool http_forwarded_client(const HttpReq *req, char *ip_out, size_t ip_cap, bool *is_https)
Recover the original client from a reverse-proxy Forwarded (RFC 7239) or de-facto X-Forwarded-For / X...
bool http_get_form(const HttpReq *req, const char *key, char *out, size_t out_size)
Look up an application/x-www-form-urlencoded body field by name.
const char * http_get_query(const HttpReq *req, const char *key)
Look up a query parameter value by name (case-sensitive).
Fully-parsed HTTP/1.1 request.
QueryParam query_params[MAX_QUERY_PARAMS]
Parsed key=value pairs.
Header headers[MAX_HEADERS]
Captured header fields.
char query[MAX_QUERY_LEN]
Raw query string (after ?).
char method[DETWS_METHOD_BUF_SIZE]
HTTP method, null-terminated (OPTIONS, or WebDAV methods when enabled).
uint32_t _version_hash
FNV-1a accumulator for version validation (internal).
uint8_t body[BODY_BUF_SIZE+1]
Stored body bytes, always null-terminated.
QueryParam path_params[MAX_PATH_PARAMS]
:name captures from the matched route.
uint8_t header_count
Valid entries in headers[].
size_t current_token_idx
Write cursor shared by key/value sub-states.
ParseState parse_state
Current parser state.
size_t path_idx
Write cursor into path[].
size_t content_length
Value of Content-Length header (0 if absent).
char cur_key[MAX_KEY_LEN]
Field-name of the in-progress header.
uint8_t path_param_count
Valid entries in path_params[].
uint8_t slot_id
Transport slot index (set by presentation layer).
uint8_t content_length_count
Number of Content-Length fields seen (RFC 7230 §3.3.2).
size_t body_len
Bytes stored in body[] (≤ BODY_BUF_SIZE).
HttpVersion version
Protocol version parsed from the request line.
uint8_t host_count
Number of Host fields seen (RFC 7230 §5.4).
char cur_val[MAX_VAL_LEN]
Field-value of the in-progress header.
char path[MAX_PATH_LEN]
URL path, null-terminated; no query string.
uint8_t query_count
Valid entries in query_params[].
size_t body_bytes_read
Body bytes received (may exceed BODY_BUF_SIZE).
size_t query_idx
Write cursor into query[].
A single parsed query-string parameter.
char val[QUERY_VAL_LEN]
Parameter value (empty string if absent).
char key[QUERY_KEY_LEN]
Parameter name, null-terminated.