ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
h2_server.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file pc_h2_server.h
6 * @brief Bridge between the HTTP/2 engine (pc_h2_conn) and the server's request pipeline.
7 *
8 * When a TLS connection negotiates ALPN "h2", the session layer hands its decrypted bytes to
9 * this module instead of the HTTP/1.1 parser. It runs one pc_h2_conn per connection slot, maps each
10 * decoded request's pseudo-headers (:method / :path / :authority) and headers into the slot's
11 * HttpReq, and marks it ParseState::PARSE_COMPLETE so the existing route dispatcher serves it. Responses from
12 * the handlers route back here (PC::send branches on the slot's h2 flag) and are
13 * serialized as HEADERS + DATA frames, leaving the connection open for the next stream.
14 *
15 * The per-slot engines are large (a whole frame is buffered), so their pool lives in PSRAM where
16 * available; HTTP/2 is therefore practical on PSRAM boards (ESP32-S3/-P4, WROVER).
17 *
18 * @author Douglas Quigg (dstroy0)
19 * @date 2026
20 */
21
22#ifndef PROTOCORE_H2_SERVER_H
23#define PROTOCORE_H2_SERVER_H
24
25#include "protocore_config.h"
26
27#if PC_ENABLE_HTTP2 && PC_ENABLE_TLS
28
29#include <stddef.h>
30#include <stdint.h>
31
32/** @brief Start the HTTP/2 engine for @p slot after ALPN "h2" (sends our initial SETTINGS). */
33void pc_h2_server_open(uint8_t slot);
34
35/** @brief Feed the slot's decrypted inbound bytes into the engine; drives requests via HttpReq. */
36void pc_h2_server_data(uint8_t slot);
37
38/**
39 * @brief Serialize a handler's response for the slot's current stream (HEADERS + DATA), then ready
40 * the slot's HttpReq for the next stream (the connection stays open). @return false on error.
41 */
42bool pc_h2_server_respond(uint8_t slot, int code, const char *content_type, const char *body, size_t len);
43
44/** @brief Release per-slot HTTP/2 state on connection close. */
45void pc_h2_server_close(uint8_t slot);
46
47#endif // PC_ENABLE_HTTP2 && PC_ENABLE_TLS
48#endif // PROTOCORE_H2_SERVER_H
User-facing configuration for ProtoCore.