ListenerHTTP1/ListenerHTTP: allow dispatching routes that aren't an exact path match #4
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Network#4
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
ListenerHTTP1andListenerHTTPboth dispatch on an exact-match route map:Anything not present as a literal key gets a synthetic 404, and there is no way for the
application to see that request. That works for a fixed set of paths, but not for any route with
an unbounded segment:
/shop/<slug>— one per product/order/<token>— one per order, 128-bit random/posts/<id>— one per itemPre-registering these is not possible: the token space is unbounded, and the product set changes
at runtime without a listener restart.
Proposal: a fallback handler
The smallest change that unblocks this is one optional member:
Dispatch becomes: exact match in
routesfirst, thenfallbackif set, then the synthetic 404.Why this shape rather than pattern matching:
design, document, or get wrong.
catcrafts.nethas aParseRoute(path, query)that both the wasm frontend and the server call,precisely so a URL cannot mean different things to a crawler and to the app. A fallback lets the
listener hand me the request and stay out of the way; a built-in pattern matcher would mean two
route tables that can disagree.
fallbackis empty, so existing behaviouris byte-identical and no call site changes.
Alternative, if you'd rather it be built in
Prefix routes would also work, e.g. a second map matched longest-prefix-first after exact match:
with the handler reading the remainder off
HTTPRequest::path. This is more convenient for thecommon case but needs a documented precedence rule (exact beats prefix, longest prefix wins), and
it still doesn't cover anything needing real pattern matching. I'd take either, and
fallbackalone is enough for what I need.
Please keep the two listeners symmetric
ListenerHTTP1's docs say "Same route map shape as ListenerHTTP, so a handler can be registeredwith both and served over either protocol." That property is genuinely useful — I'd like to serve
the same handlers over HTTP/1.1 behind Caddy now and consider HTTP/3 later without touching
application code. Whichever approach is taken, applying it to both would preserve that.