|
| 1 | +## 3) System Overview |
| 2 | + |
| 3 | +### 3.1 High-level shape |
| 4 | + |
| 5 | +``` |
| 6 | +┌──────────────────────────────────────────────────────────────────────┐ |
| 7 | +│ Consumer translation unit │ |
| 8 | +│ #include <httpserver.hpp> │ |
| 9 | +│ │ |
| 10 | +│ webserver ──→ http_request ──→ http_resource / lambda handler │ |
| 11 | +│ │ ↓ │ |
| 12 | +│ ↓ http_response │ |
| 13 | +│ (PIMPL) (value type, SBO body) │ |
| 14 | +└──────────┬───────────────────────────────────────────────────────────┘ |
| 15 | + │ (no backend types crossed) |
| 16 | + │ |
| 17 | +┌──────────┴───────────────────────────────────────────────────────────┐ |
| 18 | +│ libhttpserver.so internals │ |
| 19 | +│ │ |
| 20 | +│ webserver::impl (MHD_Daemon, route table, mutex, bans set) │ |
| 21 | +│ ├── route table: { exact: hash, param/prefix: radix, regex: chain} │ |
| 22 | +│ ├── per-connection arena (std::pmr::monotonic_buffer_resource) │ |
| 23 | +│ └── http_request::impl (allocated from connection's arena) │ |
| 24 | +│ │ |
| 25 | +│ detail::body (polymorphic; subclasses string/file/iovec/pipe/ │ |
| 26 | +│ deferred/empty live in details/body.hpp) │ |
| 27 | +└──────────┬───────────────────────────────────────────────────────────┘ |
| 28 | + │ |
| 29 | +┌──────────┴───────────────────────────────────────────────────────────┐ |
| 30 | +│ libmicrohttpd (C backend) │ |
| 31 | +│ MHD_Daemon, MHD_Connection, MHD_Response │ |
| 32 | +└────────────────────────────────────────────────────────────────────────┘ |
| 33 | +``` |
| 34 | + |
| 35 | +### 3.2 Component summary |
| 36 | + |
| 37 | +| Component | Responsibility | Implementation | |
| 38 | +|---|---|---| |
| 39 | +| `webserver` | Lifecycle, route registration, IP block list, MHD daemon ownership | PIMPL via `std::unique_ptr<webserver_impl>` | |
| 40 | +| `http_request` | Per-request inputs (path, method, headers, args, body, TLS metadata) | PIMPL via `std::unique_ptr<http_request_impl>`; impl allocated from per-connection arena | |
| 41 | +| `http_response` | Response value: status, headers, footers, cookies, body | Non-PIMPL value type; polymorphic body in 64-byte SBO buffer with heap fallback | |
| 42 | +| `http_resource` | Class-form handler (state shared across HTTP methods of one resource) | Public abstract base; allow-mask held as `method_set` (`uint32_t` bitmask) | |
| 43 | +| `websocket_handler` | Per-endpoint WebSocket protocol handler | Public abstract base; registered via `unique_ptr` / `shared_ptr` overloads | |
| 44 | +| `detail::body` | Polymorphic body kinds (string / file / iovec / pipe / deferred / empty) | Internal hierarchy in `src/httpserver/details/body.hpp` | |
| 45 | +| Route table | Path → (method_set, handler) lookup | `unordered_map` (exact) + radix tree (parameterized + prefix) + regex chain (fallback) | |
| 46 | + |
| 47 | +--- |
0 commit comments