Skip to content

codetail-tech/http2fork

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TinyHTTPD with HTTP/2 Support

基于 Tinyhttpd 的教学项目,新增了 HTTP/2 协议支持。用 C 语言实现,适合学习 HTTP/2 协议原理和网络编程。

A learning-oriented HTTP server based on Tinyhttpd, extended with HTTP/2 protocol support. Written in C, great for understanding HTTP/2 internals and network programming.

Features / 功能特性

  • HTTP/2 binary framing (二进制分帧)
  • HPACK header compression with Huffman encoding (HPACK 头部压缩)
  • Stream multiplexing (流多路复用)
  • Flow control (流量控制)
  • HTTP/2 direct connection and h2c upgrade (直连和 h2c 升级)
  • Backward compatible with HTTP/1.0 (向后兼容 HTTP/1.0)
  • Static file serving and CGI support (静态文件和 CGI)

Build / 编译

make httpd

Run / 运行

./httpd 4000

The server listens on the specified port (e.g. 4000).

Test / 测试

# Run all tests (unit + property-based)
make test

# Run only property-based tests
make test-pbt

# Manual HTTP/2 test with curl
curl --http2-prior-knowledge http://localhost:4000/index.html

# HTTP/1.0 backward compatibility
curl --http1.0 http://localhost:4000/index.html

# Multiplexed requests
curl --http2-prior-knowledge http://localhost:4000/index.html http://localhost:4000/README

Project Structure / 项目结构

File Description
httpd.c Main server, protocol detection, HTTP/1.0 handler
http2_connection.c/h HTTP/2 connection lifecycle and frame dispatch
http2_frame.c/h Frame parsing and serialization (RFC 7540)
hpack.c/h HPACK header compression (RFC 7541)
http2_stream.c/h Stream management and state machine
http2_flow.c/h Flow control
http2_settings.c/h SETTINGS frame handling
http2_types.h Shared types, constants, error codes
test_*.c Unit tests and property-based tests

Architecture / 架构

Client Request
      │
      ▼
Protocol Detector ──→ HTTP/1.0 Handler (original logic)
      │
      ▼
HTTP/2 Connection Handler
      ├── Frame Parser / Serializer
      ├── HPACK Encoder / Decoder
      ├── Stream Manager
      ├── Flow Controller
      └── Settings Handler

Property-Based Tests / 属性测试

The project uses property-based testing to verify correctness properties derived from RFC 7540 and RFC 7541:

Property Description
1 Frame parse/serialize roundtrip (帧解析序列化往返一致性)
2 HPACK encode/decode roundtrip (HPACK 编解码往返一致性)
3 Huffman encode/decode roundtrip (Huffman 编解码往返一致性)
4 Stream ID validation (流 ID 验证规则)
5 Stream state transitions (流状态转换正确性)
6 Concurrent stream limits (并发流数量限制)
7 Flow control window invariants (流量控制窗口不变量)
8 Flow control blocking behavior (流量控制阻塞行为)
9 SETTINGS parameter validation (SETTINGS 参数验证)
10 GOAWAY frame correctness (GOAWAY 帧正确性)
11 PING response correctness (PING 响应正确性)
12 Protocol upgrade response format (协议升级响应格式)
13 Connection preface validation (连接前言验证)

Prerequisites / 依赖

  • GCC with C99 support
  • pthreads
  • Perl + perl-CGI (for CGI scripts)

Credits

Original Tinyhttpd by J. David Blackstone (1999), licensed under GPL. HTTP/2 support added as a learning exercise following RFC 7540 and RFC 7541.

About

add http2 support to a classic http program with ai coding

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages