From 094ae103ee024b0d5938381a9d81243c19a7bdae Mon Sep 17 00:00:00 2001 From: xfy911 Date: Thu, 4 Jun 2026 15:50:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(http2):=20=E5=AE=9E=E7=8E=B0=20HTTP/2=20?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=96=87=E4=BB=B6=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - http2.c: 新增 http2_serve_static(),支持 GET/HEAD 请求 - 支持 304 缓存协商(If-None-Match / If-Modified-Since) - 支持目录转 index.html、路径遍历防护 - 使用 nghttp2_data_provider 发送文件内容 - server.c: 创建 HTTP/2 会话后设置上下文(root_dir、压缩配置) - 新增 6 项 HTTP/2 集成测试(ALPN 协商、GET/HEAD/404、缓存) - 45 项集成测试 + 35 单元测试全部通过 --- server.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server.c b/server.c index dc5162c..7b8f764 100644 --- a/server.c +++ b/server.c @@ -701,6 +701,12 @@ static void accept_loop(void *arg) { close(client_fd); continue; } + http2_session_t *h2 = http2_session_get(client_fd); + if (h2) { + http2_session_set_context(h2, ctx->config.root_dir, + ctx->config.gzip_enabled, + ctx->config.brotli_enabled); + } } }