cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
http2.h
Go to the documentation of this file.
1
6#ifndef __CWIST_HTTP2_H__
7#define __CWIST_HTTP2_H__
8
11
19typedef void (*cwist_http2_request_handler_func)(void *user_ctx, cwist_http_request *req,
21
24
26typedef struct cwist_http2_header {
27 const char *name;
28 const char *value;
30
39 void *(*on_conn_open)(void *user_ctx);
40 void (*on_conn_close)(void *conn_ctx);
44 void *(*on_headers)(void *conn_ctx, cwist_http_request *req, cwist_h2_stream *stream);
47 int (*on_data)(void *conn_ctx, void *stream_ctx, const unsigned char *data, size_t len,
48 int end_stream);
50 void (*on_cancel)(void *conn_ctx, void *stream_ctx);
53 int (*on_poll)(void *conn_ctx, void *stream_ctx);
56 uint64_t (*next_deadline_ms)(void *conn_ctx);
58 void (*on_close)(void *conn_ctx, void *stream_ctx);
60
63 const cwist_http2_stream_hooks *hooks);
64
75
92int cwist_http2_push_resource(cwist_http_request *req, const char *path, const char *content_type,
93 const unsigned char *data, size_t data_len);
94
107 const cwist_http2_header *headers, size_t header_count,
108 int end_stream);
109int cwist_http2_stream_send_data(cwist_h2_stream *stream, const unsigned char *data, size_t len);
111 size_t trailer_count);
112
113/* --- Async defer completion queue (internal; used by net/http/async.c) ---
114 *
115 * A handler on the HTTP/2 path may defer its response with
116 * cwist_async_defer(). The completing worker thread never writes frames
117 * itself (single-threaded HPACK/flow-control invariant); it enqueues the
118 * finished exchange on the per-connection queue and pokes the wake fd, and
119 * the connection thread drains the queue and emits HEADERS/DATA. The queue
120 * is refcounted: cwist_async_defer acquires a reference so a completion that
121 * lands after connection teardown is discarded safely instead of touching
122 * freed connection state. */
124
127int cwist_h2_async_queue_enqueue(cwist_h2_async_queue *q, uint32_t stream_id,
129 cwist_http_response *res, bool send_owned);
130
131#ifdef __cplusplus
132extern "C" {
133#endif
134
138int h2_decode_integer(const unsigned char *buf, size_t len, size_t *pos, uint8_t prefix_bits,
139 uint32_t *value);
140
144char *h2_huffman_decode(const unsigned char *src, size_t src_len, size_t *out_len);
145
149char *h2_decode_string(const unsigned char *buf, size_t len, size_t *pos);
150
158
162const cwist_http2_static_header *h2_static_header(uint32_t index);
163
167size_t h2_encode_integer(unsigned char *dst, size_t dst_cap, uint32_t value, uint8_t prefix_bits);
168
172size_t h2_encode_string(unsigned char *dst, size_t dst_cap, const char *str);
173
174#ifdef __cplusplus
175}
176#endif
177
178#endif
cwist_h2_async_queue * cwist_h2_async_queue_acquire(cwist_h2_async_queue *q)
Take an additional reference on the queue (for an in-flight cwist_async handle).
Definition http2.c:316
int h2_decode_integer(const unsigned char *buf, size_t len, size_t *pos, uint8_t prefix_bits, uint32_t *value)
Decode an HPACK integer.
Definition http2.c:1267
int cwist_http2_stream_send_trailers(cwist_h2_stream *stream, const cwist_http2_header *trailers, size_t trailer_count)
Definition http2.c:2688
int cwist_http2_stream_send_headers(cwist_h2_stream *stream, int status, const cwist_http2_header *headers, size_t header_count, int end_stream)
Definition http2.c:2608
const cwist_http2_static_header * h2_static_header(uint32_t index)
Resolve an HPACK static table index (1-based); NULL when out of range.
Definition http2.c:1570
struct cwist_h2_stream cwist_h2_stream
Definition http2.h:23
size_t h2_encode_string(unsigned char *dst, size_t dst_cap, const char *str)
Encode an HPACK string (literal, non-huffman); 0 when dst is too small.
Definition http2.c:1903
char * h2_decode_string(const unsigned char *buf, size_t len, size_t *pos)
Decode an HPACK string (literal or huffman).
Definition http2.c:1543
cwist_error_t cwist_http2_serve_connection_ex(cwist_https_connection *conn, void *user_ctx, cwist_http2_request_handler_func handler, const cwist_http2_stream_hooks *hooks)
Serve one HTTP/2 connection until it closes. Verifies the preface, sends our SETTINGS,...
Definition http2.c:3573
int cwist_h2_async_queue_enqueue(cwist_h2_async_queue *q, uint32_t stream_id, cwist_http_request *req, cwist_http_response *send, cwist_http_response *res, bool send_owned)
Definition http2.c:339
cwist_error_t cwist_http2_serve_connection(cwist_https_connection *conn, void *user_ctx, cwist_http2_request_handler_func handler)
Starts serving an HTTP/2 connection over an established HTTPS session.
Definition http2.c:3493
void cwist_h2_async_queue_release(cwist_h2_async_queue *q)
Drop a reference on the queue. On the last reference: closes the wake descriptors,...
Definition http2.c:327
struct cwist_h2_async_queue cwist_h2_async_queue
Definition http2.h:123
void(* cwist_http2_request_handler_func)(void *user_ctx, cwist_http_request *req, cwist_http_response *res)
Callback function type for handling HTTP/2 requests.
Definition http2.h:19
int cwist_http2_push_resource(cwist_http_request *req, const char *path, const char *content_type, const unsigned char *data, size_t data_len)
Push a resource to the client over HTTP/2 Server Push.
Definition http2.c:4210
char * h2_huffman_decode(const unsigned char *src, size_t src_len, size_t *out_len)
Decode an HPACK huffman-encoded string.
Definition http2.c:1442
size_t h2_encode_integer(unsigned char *dst, size_t dst_cap, uint32_t value, uint8_t prefix_bits)
Encode an HPACK integer; returns bytes written, 0 when dst is too small.
Definition http2.c:1875
int cwist_http2_stream_send_data(cwist_h2_stream *stream, const unsigned char *data, size_t len)
Send DATA on a hook-taken stream, honoring flow-control credit. Splits data into peer_max_frame_size ...
Definition http2.c:2642
HTTP Protocol Definitions and Helpers.
HTTPS/TLS wrapper interface.
Integrated error structure used throughout the system.
Definition cwist_err.h:72
const char * value
Definition http2.h:28
const char * name
Definition http2.h:27
HPACK static table entry (RFC 7541 Appendix A).
Definition http2.h:154
const char * name
Definition http2.h:155
const char * value
Definition http2.h:156
int(* on_poll)(void *conn_ctx, void *stream_ctx)
Definition http2.h:53
int(* on_data)(void *conn_ctx, void *stream_ctx, const unsigned char *data, size_t len, int end_stream)
Definition http2.h:47
void(* on_close)(void *conn_ctx, void *stream_ctx)
Definition http2.h:58
void(* on_cancel)(void *conn_ctx, void *stream_ctx)
Definition http2.h:50
uint64_t(* next_deadline_ms)(void *conn_ctx)
Definition http2.h:56
void(* on_conn_close)(void *conn_ctx)
Definition http2.h:40
HTTP Response Object. Supports standard string body or Zero-Copy pointer body.
Definition http.h:82