KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
h2_server.h
Go to the documentation of this file.
1
9#ifndef KEEL_H2_SERVER_H
10#define KEEL_H2_SERVER_H
11
12#include <stddef.h>
13#include <stdint.h>
14#include <sys/types.h>
15#include <keel/h2.h>
16#include <keel/request.h>
17#include <keel/response.h>
18#include <keel/body_reader.h>
19#include <keel/router.h>
20
21/* ── Forward declarations ────────────────────────────────────────── */
22
27typedef struct KlConn KlConn;
28
29/* ── KlH2ServerCallbacks — KEEL provides these to the session ────── */
30
32 int (*on_request)(void *ud, uint32_t stream_id,
33 const char *method, size_t method_len,
34 const char *path, size_t path_len,
35 const char *authority, size_t authority_len,
36 const char **hdr_names, const char **hdr_values,
37 const size_t *hdr_name_lens, const size_t *hdr_value_lens,
38 int num_headers);
39 int (*on_data)(void *ud, uint32_t stream_id,
40 const char *data, size_t len);
41 int (*on_stream_end)(void *ud,
42 uint32_t stream_id);
43 void (*on_stream_reset)(void *ud, uint32_t stream_id,
44 uint32_t error_code);
45 ssize_t (*send)(void *ud, const void *data,
46 size_t len);
47};
48
49/* ── KlH2ServerSession — user-provided vtable ───────────────────── */
50
52 ssize_t (*recv)(KlH2ServerSession *self, const void *data,
53 size_t len);
54 int (*submit_response)(KlH2ServerSession *self, uint32_t stream_id,
55 int status, const char **hdr_names,
56 const char **hdr_values, int num_headers,
57 const void *body, size_t body_len);
60 int (*flush)(KlH2ServerSession *self);
62 void (*destroy)(KlH2ServerSession *self);
63};
64
65/* ── Factory ─────────────────────────────────────────────────────── */
66
68typedef KlH2ServerSession *(*KlH2ServerSessionFactory)(KlAllocator *alloc,
69 KlH2ServerCallbacks *callbacks,
70 void *user_data);
71
72/* ── Config ──────────────────────────────────────────────────────── */
73
79
80/* ── Per-stream state ────────────────────────────────────────────── */
81
98
99/* ── Per-connection HTTP/2 state ─────────────────────────────────── */
100
112
113/* ── Internal functions (used by connection.c, server.c) ─────────── */
114
117 const char *leftover, size_t leftover_len);
120 KlH2ServerConfig *cfg,
121 const char *leftover, size_t leftover_len);
130
131#endif
Shared HTTP/2 protocol constants.
KlH2ServerSession *(* KlH2ServerSessionFactory)(KlAllocator *alloc, KlH2ServerCallbacks *callbacks, void *user_data)
Factory for creating server-side HTTP/2 sessions.
Definition h2_server.h:68
void kl_h2_server_drain_shutdown(KlConn *c)
Initiate graceful GOAWAY drain on an HTTP/2 connection.
void kl_h2_server_cleanup(KlConn *c)
Clean up all HTTP/2 state for a connection.
int kl_h2_server_on_writable(KlConn *c)
Handle writable event on an HTTP/2 connection.
int kl_h2_server_on_readable(KlConn *c)
Handle readable event on an HTTP/2 connection.
int kl_h2_server_upgrade(KlConn *c, KlRouter *router, KlH2ServerConfig *cfg, const char *leftover, size_t leftover_len)
Upgrade a connection to HTTP/2 (direct h2c).
int kl_h2_server_upgrade_from_h1(KlConn *c, KlRouter *router, KlH2ServerConfig *cfg, const char *leftover, size_t leftover_len)
Upgrade a connection to HTTP/2 from an HTTP/1.1 Upgrade request.
#define KL_MAX_PARAMS
Maximum number of route parameters.
Definition request.h:22
Bring-your-own allocator vtable.
Definition allocator.h:12
Definition body_reader.h:21
Definition connection.h:34
Definition h2_server.h:31
int(* on_data)(void *ud, uint32_t stream_id, const char *data, size_t len)
Definition h2_server.h:39
void(* on_stream_reset)(void *ud, uint32_t stream_id, uint32_t error_code)
Definition h2_server.h:43
int(* on_request)(void *ud, uint32_t stream_id, const char *method, size_t method_len, const char *path, size_t path_len, const char *authority, size_t authority_len, const char **hdr_names, const char **hdr_values, const size_t *hdr_name_lens, const size_t *hdr_value_lens, int num_headers)
Definition h2_server.h:32
ssize_t(* send)(void *ud, const void *data, size_t len)
Definition h2_server.h:45
int(* on_stream_end)(void *ud, uint32_t stream_id)
Definition h2_server.h:41
Definition h2_server.h:74
int initial_window_size
Definition h2_server.h:77
int max_concurrent_streams
Definition h2_server.h:76
KlH2ServerSessionFactory factory
Definition h2_server.h:75
Definition h2_server.h:101
int goaway_sent
Definition h2_server.h:110
KlH2ServerStream * streams
Definition h2_server.h:107
int num_streams
Definition h2_server.h:108
int max_streams
Definition h2_server.h:109
KlRouter * router
Definition h2_server.h:105
KlConn * conn
Definition h2_server.h:104
KlH2ServerCallbacks callbacks
Definition h2_server.h:103
KlH2ServerSession * session
Definition h2_server.h:102
KlAllocator * alloc
Definition h2_server.h:106
Definition h2_server.h:51
int(* flush)(KlH2ServerSession *self)
Definition h2_server.h:60
int(* want_write)(KlH2ServerSession *self)
Definition h2_server.h:59
int(* shutdown)(KlH2ServerSession *self)
Definition h2_server.h:61
ssize_t(* recv)(KlH2ServerSession *self, const void *data, size_t len)
Definition h2_server.h:52
int(* submit_response)(KlH2ServerSession *self, uint32_t stream_id, int status, const char **hdr_names, const char **hdr_values, int num_headers, const void *body, size_t body_len)
Definition h2_server.h:54
void(* destroy)(KlH2ServerSession *self)
Definition h2_server.h:62
Definition h2_server.h:82
KlRequest req
Definition h2_server.h:84
KlResponse res
Definition h2_server.h:85
size_t hdr_storage_len
Definition h2_server.h:96
KlParam params[KL_MAX_PARAMS]
Definition h2_server.h:88
uint32_t stream_id
Definition h2_server.h:83
int route_result
Definition h2_server.h:90
int body_done
Definition h2_server.h:92
KlRoute * route
Definition h2_server.h:87
int headers_done
Definition h2_server.h:91
KlBodyReader * body_reader
Definition h2_server.h:86
int num_params
Definition h2_server.h:89
char * hdr_storage
Definition h2_server.h:95
int response_submitted
Definition h2_server.h:94
size_t body_received
Definition h2_server.h:93
Definition request.h:14
Definition request.h:26
Definition response.h:21
Definition router.h:22
Definition router.h:42