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

Layer 7 (Application) - HTTP routing and request handler implementation. More...

Go to the source code of this file.

Classes

struct  InstanceCtx
 

Functions

const char * status_text (int code)
 Convert an HTTP status code to its standard reason phrase.
 
void fill_route_base (Route *r, const char *path)
 Register a route in the route table.
 
bool req_is_head (uint8_t slot_id)
 True if the request in slot slot_id used the HEAD method (send headers, no body).
 

Variables

SendCtx s_send
 

Detailed Description

Layer 7 (Application) - HTTP routing and request handler implementation.

Dispatch pipeline (called from DetWebServer::handle())

handle()
└─ server_tick() ← drain FreeRTOS event queue
└─ for each slot:
ParseState::PARSE_COMPLETE → match_and_execute()
ParseState::PARSE_ERROR → send(400)
ParseState
States of the HTTP/1.1 request parser.
Definition http_parser.h:53
@ PARSE_ERROR
Unrecoverable parse failure → 400.
@ PARSE_ENTITY_TOO_LARGE
Content-Length > BODY_BUF_SIZE → 413.
@ PARSE_COMPLETE
Full request parsed; ready for dispatch.
@ PARSE_URI_TOO_LONG
Path exceeds MAX_PATH_LEN → 414.
void server_tick(int worker_id)
Drive the session layer for one Arduino loop iteration.
Definition session.cpp:91

Route table Routes are stored in a fixed-size array of Route structs. Both exact and wildcard (suffix *) routes are supported; exact routes always take priority because the loop checks them in insertion order and returns on the first match.

PCB lifecycle / teardown ownership All TCP I/O and teardown go through the transport-layer connection API (det_conn_send / det_conn_flush / det_conn_begin_close / det_conn_close / det_conn_abort_slot), so this layer never calls lwIP or touches the raw tcp_pcb directly. The transport owns the teardown order for every close: it detaches the pcb from its lwIP callbacks and sets the slot ConnState::CONN_FREE (pcb nulled) BEFORE the FIN/RST, on the captured pcb pointer. This means any lwIP error callback that fires mid-teardown sees the slot as already free and takes no action - preventing a double-free. L7 passes only the slot index: det_conn_close(slot) for a graceful local close, det_conn_abort_slot(slot) for a hard RST, det_conn_begin_close(slot) for the drain-then-close dwell.

Definition in file dwserver.cpp.

Function Documentation

◆ status_text()

const char * status_text ( int  code)

Convert an HTTP status code to its standard reason phrase.

Reason phrase for an HTTP status code (e.g. 404 -> "Not Found").

Covers the 18 codes that arise in typical REST micro-server usage. Unknown codes produce "Unknown" so callers never receive a null pointer.

Parameters
codeHTTP status integer.
Returns
Pointer to a string-literal reason phrase; never null.

Definition at line 112 of file dwserver.cpp.

Referenced by DetWebServer::redirect(), DetWebServer::send(), DetWebServer::send_chunked(), DetWebServer::send_empty(), and DetWebServer::send_template().

◆ fill_route_base()

void fill_route_base ( Route r,
const char *  path 
)

Register a route in the route table.

Initialize the common fields (path, flags) of a route-table entry from its pattern.

Paths are stored null-terminated and truncated to MAX_PATH_LEN. The trailing character of the stored path is inspected to detect wildcard routes: any path ending in * is treated as a prefix match.

Registrations beyond MAX_ROUTES are silently ignored - callers should verify return values if overflow is a concern.

Parameters
pathURL path to match, e.g. "/api/*".
methodHTTP method that triggers this route.
callbackHandler invoked with (slot_id, request).

Definition at line 747 of file dwserver.cpp.

References DETIFACE_ANY, Route::iface_filter, Route::is_active, Route::is_param, Route::is_regex, Route::is_wildcard, MAX_PATH_LEN, and Route::path.

Referenced by DetWebServer::on(), DetWebServer::on(), and DetWebServer::on_regex().

◆ req_is_head()

bool req_is_head ( uint8_t  slot_id)

True if the request in slot slot_id used the HEAD method (send headers, no body).

Definition at line 1228 of file dwserver.cpp.

References http_pool.

Referenced by DetWebServer::send(), DetWebServer::send_chunked(), and DetWebServer::send_template().

Variable Documentation

◆ s_send

SendCtx s_send

Definition at line 97 of file dwserver.cpp.

Referenced by DetWebServer::http_poll_slot(), and DetWebServer::send_chunked().