From 54982bcc62d71408441866400ecfd6e7fb583b4d Mon Sep 17 00:00:00 2001 From: Mark Kalsbeek Date: Sun, 9 Aug 2026 07:55:32 +0200 Subject: [PATCH] Add terse 404 fallback (no route hints, keep obscurity) --- src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index cd7979d..d9bcaa5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -438,6 +438,16 @@ fn fetch_asset_handler(c: Conn, _n: Next) -> Conn { } } +/// Fallback for any request the router didn't match. Deliberately terse - +/// no route list, no hint of the `/assets/:package/:version/:filename` +/// shape, nothing to make this service more discoverable to strangers +/// than it already is. Just enough to not look like a hung connection. +fn not_found_handler(c: Conn, _n: Next) -> Conn { + c.put_status(404) + .put_header("content-type", "text/plain") + .put_body("404 not found") +} + fn main() { let Some(port) = run_cli() else { return }; @@ -451,6 +461,6 @@ fn main() { println!("C3 on 0.0.0.0:{port}..."); let cfg = Config::new(format!("0.0.0.0:{port}").parse().unwrap()); - let pipeline = Pipeline::new().plug(router); + let pipeline = Pipeline::new().plug(router).plug(not_found_handler); serve_with(cfg, pipeline).unwrap(); }