|
DeterministicESPAsyncWebServer 1.2.0
Zero-allocation, bounded-execution async HTTP server for ESP32
|
Standalone HTTP/1.1 request parser — no transport dependency. More...
Go to the source code of this file.
Classes | |
| struct | Header |
| A single HTTP header field (key: value). More... | |
| struct | QueryParam |
| A single parsed query-string parameter. More... | |
| struct | HttpReq |
| Fully-parsed HTTP/1.1 request. More... | |
Enumerations | |
| enum | ParseState { PARSE_METHOD , PARSE_PATH , PARSE_QUERY , PARSE_VERSION , PARSE_HEADER_KEY , PARSE_HEADER_VAL , PARSE_EXPECT_LF , PARSE_EXPECT_BODY_LF , PARSE_BODY , PARSE_COMPLETE , PARSE_ERROR , PARSE_ENTITY_TOO_LARGE , PARSE_URI_TOO_LONG } |
| States of the HTTP/1.1 request parser. More... | |
| enum | HttpVersion { HTTP_UNKNOWN = 0 , HTTP_10 , HTTP_11 } |
| Parsed HTTP protocol version. More... | |
Functions | |
| void | http_parser_reset (HttpReq *req) |
| Reset a parser context to the initial (PARSE_METHOD) state. | |
| void | http_parser_feed (HttpReq *req, uint8_t byte) |
| Feed one byte to the parser state machine. | |
| const char * | http_get_header (const HttpReq *req, const char *key) |
| Look up a header value by name (case-insensitive). | |
| const char * | http_get_query (const HttpReq *req, const char *key) |
| Look up a query parameter value by name (case-sensitive). | |
Variables | |
| HttpReq | http_pool [MAX_CONNS] |
| Pool of parser contexts, one per transport slot. | |
Standalone HTTP/1.1 request parser — no transport dependency.
The parser is a pure byte-stream state machine. It has no knowledge of ring buffers, TCP PCBs, or FreeRTOS. Feed it bytes one at a time via http_parser_feed() and inspect HttpReq::parse_state to know when the request is ready.
State machine
Definition in file http_parser.h.
| enum ParseState |
States of the HTTP/1.1 request parser.
Advance via http_parser_feed(). The application layer inspects this after each feed call or after draining a complete chunk.
Definition at line 52 of file http_parser.h.
| enum HttpVersion |
Parsed HTTP protocol version.
Populated from the request line (HTTP/1.0 or HTTP/1.1) using an FNV-1a hash accumulated during PARSE_VERSION. The application layer may use this to drive keep-alive semantics: HTTP/1.1 defaults to persistent connections; HTTP/1.0 defaults to close.
| Enumerator | |
|---|---|
| HTTP_UNKNOWN | Version string did not match any known token. |
| HTTP_10 | HTTP/1.0 — close semantics by default. |
| HTTP_11 | HTTP/1.1 — persistent connection by default. |
Definition at line 77 of file http_parser.h.
| void http_parser_reset | ( | HttpReq * | req | ) |
Reset a parser context to the initial (PARSE_METHOD) state.
Zeroes all fields and sets parse_state = PARSE_METHOD. Call before the first use, after each completed or failed request, and on connection events.
| req | Parser context to reset. Must not be null. |
Definition at line 150 of file http_parser.cpp.
References HttpReq::_version_hash, PARSE_METHOD, HttpReq::parse_state, and HttpReq::slot_id.
Referenced by http_reset().
| void http_parser_feed | ( | HttpReq * | req, |
| uint8_t | byte | ||
| ) |
Feed one byte to the parser state machine.
Returns immediately without modifying state when parse_state is already PARSE_COMPLETE, PARSE_ERROR, PARSE_ENTITY_TOO_LARGE, or PARSE_URI_TOO_LONG.
| req | Parser context for this request. |
| byte | Next byte from the HTTP stream. |
Definition at line 159 of file http_parser.cpp.
References HttpReq::_version_hash, HttpReq::body, BODY_BUF_SIZE, HttpReq::body_bytes_read, HttpReq::body_len, HttpReq::content_length, HttpReq::current_token_idx, HttpReq::header_count, HttpReq::headers, HTTP_10, HTTP_11, HTTP_UNKNOWN, Header::key, MAX_HEADERS, MAX_KEY_LEN, MAX_PATH_LEN, MAX_QUERY_LEN, MAX_VAL_LEN, HttpReq::method, PARSE_BODY, PARSE_COMPLETE, PARSE_ENTITY_TOO_LARGE, PARSE_ERROR, PARSE_EXPECT_BODY_LF, PARSE_EXPECT_LF, PARSE_HEADER_KEY, PARSE_HEADER_VAL, PARSE_METHOD, PARSE_PATH, PARSE_QUERY, HttpReq::parse_state, PARSE_URI_TOO_LONG, PARSE_VERSION, HttpReq::path, HttpReq::path_idx, HttpReq::query, HttpReq::query_idx, Header::val, and HttpReq::version.
Referenced by http_parse().
| const char * http_get_header | ( | const HttpReq * | req, |
| const char * | key | ||
| ) |
Look up a header value by name (case-insensitive).
| req | Parsed request. |
| key | Header field name (e.g. "Content-Type"). |
nullptr if not found. Definition at line 389 of file http_parser.cpp.
References HttpReq::header_count, HttpReq::headers, Header::key, and Header::val.
Referenced by multipart_parse().
| const char * http_get_query | ( | const HttpReq * | req, |
| const char * | key | ||
| ) |
Look up a query parameter value by name (case-sensitive).
| req | Parsed request. |
| key | Parameter name. |
key= with no value), or nullptr if the key is absent. Definition at line 399 of file http_parser.cpp.
References QueryParam::key, HttpReq::query_count, HttpReq::query_params, and QueryParam::val.
Pool of parser contexts, one per transport slot.
Definition at line 15 of file http_parser.cpp.
Referenced by DetWebServer::handle(), http_parse(), and http_reset().