Commit 022bbbf
feat(TASK-026): GREEN route() / route(method_set) registration entry points
Adds two public lambda-registration entry points to webserver:
void route(http_method m,
const std::string& path,
std::function<http_response(const http_request&)> handler);
void route(method_set methods,
const std::string& path,
std::function<http_response(const http_request&)> handler);
route() is the table-driven escape hatch for registering a handler
when the HTTP method is a runtime value (config-driven route tables,
programmatic registration loops). The on_* family is preferred when
the method is known statically. Both forms tunnel into the same
internal registration helper, now generalized:
- Renames the private webserver::on_method_(http_method, path, h)
helper to webserver::on_methods_(method_set, path, h) so the
atomic all-or-nothing multi-method registration semantics live in
one place. The seven public on_* forwarders each wrap their
http_method in method_set{}.set(m) before forwarding; route(http_method,
...) does the same after rejecting the http_method::count_ sentinel.
- on_methods_ pre-validates that EVERY requested slot is empty before
mutating ANY of them. If any one would conflict (slot already taken
on the existing lambda shim, or a class-based resource owns the path),
no slot mutation happens and std::invalid_argument is thrown. This
is what makes route(method_set{get, post}, "/p", ...) safe when GET
is already taken on /p: the call throws AND POST stays unregistered.
The dispatch path (finalize_answer / lambda_resource shim) is unchanged.
Doc updates:
- New Doxygen block on the two route() declarations explicitly states
the escape-hatch convention (per OQ-003 resolution).
- on_method_ -> on_methods_ rename ripples through three legacy comments
in src/httpserver/detail/lambda_resource.hpp.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 336f1a9 commit 022bbbf
3 files changed
Lines changed: 155 additions & 49 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
230 | 283 | | |
231 | 284 | | |
232 | 285 | | |
| |||
433 | 486 | | |
434 | 487 | | |
435 | 488 | | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
448 | 506 | | |
449 | 507 | | |
450 | 508 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
| 309 | + | |
310 | 310 | | |
311 | | - | |
312 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
313 | 315 | | |
314 | 316 | | |
315 | | - | |
316 | | - | |
317 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
318 | 320 | | |
319 | 321 | | |
320 | 322 | | |
321 | 323 | | |
322 | | - | |
| 324 | + | |
| 325 | + | |
323 | 326 | | |
324 | 327 | | |
325 | 328 | | |
326 | 329 | | |
327 | 330 | | |
328 | 331 | | |
329 | | - | |
330 | | - | |
331 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
332 | 339 | | |
333 | 340 | | |
334 | | - | |
| 341 | + | |
335 | 342 | | |
336 | 343 | | |
337 | 344 | | |
338 | | - | |
| 345 | + | |
| 346 | + | |
339 | 347 | | |
340 | 348 | | |
341 | | - | |
342 | | - | |
| 349 | + | |
| 350 | + | |
343 | 351 | | |
344 | 352 | | |
345 | 353 | | |
| |||
360 | 368 | | |
361 | 369 | | |
362 | 370 | | |
363 | | - | |
| 371 | + | |
364 | 372 | | |
365 | 373 | | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
370 | 387 | | |
371 | 388 | | |
372 | 389 | | |
373 | 390 | | |
374 | 391 | | |
375 | 392 | | |
376 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
377 | 403 | | |
378 | 404 | | |
379 | 405 | | |
| |||
392 | 418 | | |
393 | 419 | | |
394 | 420 | | |
395 | | - | |
| 421 | + | |
396 | 422 | | |
397 | 423 | | |
398 | 424 | | |
399 | 425 | | |
400 | | - | |
| 426 | + | |
401 | 427 | | |
402 | 428 | | |
403 | 429 | | |
404 | 430 | | |
405 | | - | |
| 431 | + | |
406 | 432 | | |
407 | 433 | | |
408 | 434 | | |
409 | 435 | | |
410 | | - | |
| 436 | + | |
411 | 437 | | |
412 | 438 | | |
413 | 439 | | |
414 | 440 | | |
415 | | - | |
| 441 | + | |
416 | 442 | | |
417 | 443 | | |
418 | 444 | | |
419 | 445 | | |
420 | | - | |
| 446 | + | |
421 | 447 | | |
422 | 448 | | |
423 | 449 | | |
424 | 450 | | |
425 | | - | |
| 451 | + | |
426 | 452 | | |
427 | 453 | | |
428 | 454 | | |
429 | 455 | | |
430 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
431 | 479 | | |
432 | 480 | | |
433 | 481 | | |
| |||
0 commit comments