ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
h2_server.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file protocore_h2_server.h
6 * @brief Bridge between the HTTP/2 engine (protocore_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 protocore_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 PARSE_COMPLETE so the existing route dispatcher serves it. Responses from
12 * the handlers route back here (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" // the entry point: the enable gate below, and the widths
26
27#if PROTOCORE_ENABLE_HTTP2 && PROTOCORE_ENABLE_TLS
28
30
31/** @brief RFC 9113 sec 8.3: what one HEADERS + DATA response carries. */
32typedef struct
33{
34 int code; ///< the status a response carries
35 const char *content_type; ///< its media type
36 const char *body; ///< its body bytes
37 size_t len; ///< how many
38} H2RespArgs;
39
40/**
41 * @brief The HTTP/2 engine (RFC 9113): one connection per transport slot.
42 *
43 * A caller sets the members a call takes, invokes it through ::H2Server, and reads the outcome off
44 * the same handle.
45 *
46 * @var H2ServerNs::slot the connection a call acts on
47 * @var H2ServerNs::resp what a serialized response carries
48 * @var H2ServerNs::ok a call's true/false outcome
49 * @var H2ServerNs::open start the engine after ALPN "h2"; sends our initial SETTINGS
50 * @var H2ServerNs::data feed the slot's decrypted inbound bytes in; drives requests via HttpReq
51 * @var H2ServerNs::respond serialize a response for the slot's current stream (HEADERS + DATA),
52 * then ready the slot's HttpReq for the next stream; the connection stays
53 * open
54 * @var H2ServerNs::close release per-slot state on connection close
55 *
56 * Every entry takes the module's borrow. How those bytes are carved is h2_server.c's and is
57 * never named here. ::protocore_h2_server_span is where a caller gets one.
58 */
59typedef struct
60{
61 uint8_t slot; ///< the connection a call acts on
62
63 H2RespArgs resp; ///< what a serialized response carries
64
65 proto_bool ok;
66
67 void (*const open)(uint8_t *work);
68 void (*const data)(uint8_t *work);
69 void (*const respond)(uint8_t *work);
70 void (*const close)(uint8_t *work);
71
72} H2ServerNs;
73
74/** @brief The one symbol this module exports. */
75extern H2ServerNs H2Server;
76
77/** @brief Not an entry: an entry takes a borrow and this is where that borrow comes from. */
78uint8_t *protocore_h2_server_span(void);
79
80/**
81 * @brief The response sink the presentation layer installs at ALPN.
82 *
83 * Its shape is the seam's (::protocore_resp_sink_fn), not this module's, so it stays a plain
84 * function and carries its arguments onto the handle before the call that does the work.
85 */
86proto_bool protocore_h2_server_respond(uint8_t slot, int code, const char *content_type, const char *body, size_t len);
87
88#endif // PROTOCORE_ENABLE_HTTP2 && PROTOCORE_ENABLE_TLS
89
91
92#endif // PROTOCORE_H2_SERVER_H
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97