Add terse 404 fallback (no route hints, keep obscurity)
This commit is contained in:
+11
-1
@@ -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() {
|
fn main() {
|
||||||
let Some(port) = run_cli() else { return };
|
let Some(port) = run_cli() else { return };
|
||||||
|
|
||||||
@@ -451,6 +461,6 @@ fn main() {
|
|||||||
|
|
||||||
println!("C3 on 0.0.0.0:{port}...");
|
println!("C3 on 0.0.0.0:{port}...");
|
||||||
let cfg = Config::new(format!("0.0.0.0:{port}").parse().unwrap());
|
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();
|
serve_with(cfg, pipeline).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user