DeterministicESPAsyncWebServer 1.2.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
http_parser.cpp File Reference

Standalone HTTP/1.1 request parser — implementation. More...

#include "http_parser.h"

Go to the source code of this file.

Functions

void http_parser_reset (HttpReq *req)
 Reset a parser context to the initial (PARSE_METHOD) state.
 
void http_parser_feed (HttpReq *p, 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.
 

Detailed Description

Standalone HTTP/1.1 request parser — implementation.

No dependency on transport, session, or lwIP. Consumes one byte at a time via http_parser_feed(); the presentation layer is responsible for pulling bytes out of whatever transport buffer it uses.

Definition in file http_parser.cpp.

Function Documentation

◆ http_parser_reset()

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.

Parameters
reqParser 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().

◆ http_parser_feed()

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.

Parameters
reqParser context for this request.
byteNext 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().

◆ http_get_header()

const char * http_get_header ( const HttpReq req,
const char *  key 
)

Look up a header value by name (case-insensitive).

Parameters
reqParsed request.
keyHeader field name (e.g. "Content-Type").
Returns
Pointer to the null-terminated value, or 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().

◆ http_get_query()

const char * http_get_query ( const HttpReq req,
const char *  key 
)

Look up a query parameter value by name (case-sensitive).

Parameters
reqParsed request.
keyParameter name.
Returns
Pointer to the null-terminated value (empty string if 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.

Variable Documentation

◆ http_pool

HttpReq http_pool[MAX_CONNS]

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().