From 940ee5193da8148c00ecc42998c8fd7b43de2960 Mon Sep 17 00:00:00 2001 From: Antoine Romero-Romero <45259848+AntoineRR@users.noreply.github.com> Date: Mon, 30 Jan 2023 19:32:48 +0000 Subject: [PATCH] fix: return 404 status code when route isn't found (#380) --- integration_tests/test_status_code.py | 6 ++++++ src/server.rs | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/integration_tests/test_status_code.py b/integration_tests/test_status_code.py index 6a865b3e0..fdb9cf327 100644 --- a/integration_tests/test_status_code.py +++ b/integration_tests/test_status_code.py @@ -13,6 +13,12 @@ def test_404_post_request_status_code(session): assert r.status_code == 404 +def test_404_not_found(session): + r = requests.get(f"{BASE_URL}/actually_not_found_route") + assert r.status_code == 404 + assert r.text == "Not found" + + def test_307_get_request(session): r = requests.get(f"{BASE_URL}/redirect") assert r.text == "This is the redirected route" diff --git a/src/server.rs b/src/server.rs index e60b53cc6..8b4bd394f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -385,7 +385,8 @@ async fn index( } } } else { - response_builder.finish() + response_builder.status(StatusCode::NOT_FOUND); + response_builder.body("Not found") }; apply_middleware(