Commit 91e9126
committed
TASK-051: per-route hooks via http_resource::add_hook
Add a per-resource scope to the hook bus, restricted to the five
post-route-resolution phases (before_handler, handler_exception,
after_handler, response_sent, request_completed). Other phases throw
std::invalid_argument naming the constraint.
Storage uses a PIMPL (detail::resource_hook_table) reached through a
single std::shared_ptr<> on http_resource (lazily allocated on first
add_hook), so resources that never register a hook pay only the 16-byte
pointer plus a null-check on the dispatch hot path. The sizeof cap on
http_resource is bumped accordingly (vptr + shared_ptr + method_set +
padding); bench_sizeof_http_resource and the in-header static_assert
reflect the new cap.
The per-route chain fires at each of the five applicable phases AFTER
the server-wide chain and BEFORE checking for a server-wide short-circuit
result -- if server-wide short-circuited, the per-route chain is skipped
(response is already fixed). modded_request carries a
weak_ptr<http_resource> populated in finalize_answer once the route
resolves; fire_response_sent_gated and fire_request_completed_gated
lock() it to fire the per-route chain after the server-wide one. If the
resource was unregistered between dispatch and completion, lock()
returns null and the per-route chain is naturally skipped.
hook_handle gains a weak_ptr<detail::resource_hook_table> so per-route
handles drain through the table's writer lock; if the resource is
destroyed before the handle, remove() is a no-op. The handle size cap
is bumped from 32 to 48 in the unit shape test.
Lock order documented in §5.6:
route_table_mutex_ -> resource hook_table_mutex_ -> server-wide
hook_table_mutex_. Exercised by hooks_per_route_concurrent_registration
under TSan.
Carved out of webserver_request.cpp:
- fire_before_handler_gated as a member on webserver_impl (definition
in webserver_finalize.cpp alongside the other gated-fire helpers) so
finalize_answer stays under CCN_MAX after the per-route branch
doubles the local branch count.
Carved out of hook_handle.cpp:
- remove_per_route static helper for the per-route remove() branch so
the host function stays at its pre-task CCN.
Five new integ tests + the unit hook_api_shape pin extension cover:
- invalid-phase rejection
- server-wide-before-per-route ordering on response_sent
- different early-413 size policies on two endpoints
- resource-destroyed-before-handle no-op + no UAF (ASan)
- concurrent registration on resource R from inside a handler on
resource Q (TSan)
Closes TASK-051.1 parent 873359e commit 91e9126
21 files changed
Lines changed: 1954 additions & 153 deletions
File tree
- src
- detail
- httpserver
- detail
- test
- integ
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
379 | 380 | | |
380 | 381 | | |
381 | 382 | | |
382 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
383 | 391 | | |
384 | 392 | | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
393 | 414 | | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
| 415 | + | |
| 416 | + | |
399 | 417 | | |
400 | 418 | | |
401 | 419 | | |
402 | 420 | | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
| 421 | + | |
407 | 422 | | |
408 | 423 | | |
409 | 424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
| 56 | + | |
52 | 57 | | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| 61 | + | |
56 | 62 | | |
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
60 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
61 | 131 | | |
62 | 132 | | |
63 | 133 | | |
| |||
70 | 140 | | |
71 | 141 | | |
72 | 142 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
77 | 152 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
88 | 174 | | |
89 | 175 | | |
90 | 176 | | |
| |||
96 | 182 | | |
97 | 183 | | |
98 | 184 | | |
99 | | - | |
| 185 | + | |
100 | 186 | | |
101 | 187 | | |
102 | | - | |
103 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
104 | 192 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
116 | 202 | | |
117 | 203 | | |
118 | 204 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 205 | + | |
| 206 | + | |
126 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
127 | 214 | | |
128 | 215 | | |
129 | 216 | | |
| |||
139 | 226 | | |
140 | 227 | | |
141 | 228 | | |
142 | | - | |
143 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
144 | 248 | | |
145 | 249 | | |
146 | 250 | | |
| |||
157 | 261 | | |
158 | 262 | | |
159 | 263 | | |
160 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
161 | 272 | | |
162 | 273 | | |
163 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
303 | 304 | | |
304 | 305 | | |
305 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
306 | 318 | | |
307 | 319 | | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
332 | 330 | | |
333 | 331 | | |
334 | 332 | | |
| |||
0 commit comments