From 8d6161dbd93d932b55f7e5232f93c389d78d8206 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Fri, 29 Aug 2025 09:18:18 +0200 Subject: [PATCH] Prevent the /* OPTIONS handler to turn every 404 error into 405. Fixes: #14572 Signed-off-by: Miod Vallat --- ext/yahttp/yahttp/router.cpp | 8 +++++++- regression-tests.api/test_Basics.py | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/yahttp/yahttp/router.cpp b/ext/yahttp/yahttp/router.cpp index 5f6885a88..312cb5aa0 100644 --- a/ext/yahttp/yahttp/router.cpp +++ b/ext/yahttp/yahttp/router.cpp @@ -101,7 +101,13 @@ namespace YaHTTP { if (matched && !method.empty() && req->method != method) { // method did not match, record it though so we can return correct result matched = false; - seen = true; + // The OPTIONS handler registered in pdns/webserver.cc matches every + // url, and would cause "not found" errors to always be superseded + // with "found, but wrong method" errors, so don't pretend there has + // been a match in this case. + if (method != "OPTIONS") { + seen = true; + } continue; } if (matched) { diff --git a/regression-tests.api/test_Basics.py b/regression-tests.api/test_Basics.py index 6acf9a803..329fbd959 100644 --- a/regression-tests.api/test_Basics.py +++ b/regression-tests.api/test_Basics.py @@ -61,4 +61,13 @@ class TestBasics(ApiTestCase): r = self.session.options(self.url("/api/v1/servers/localhost/invalid")) self.assertEqual(r.status_code, requests.codes.not_found) + r = self.session.options(self.url("/api/v1/servers/remotehost")) + self.assertEqual(r.status_code, requests.codes.not_found) + + r = self.session.get(self.url("/api/v1/servers/remotehost")) + if is_auth(): + self.assertEqual(r.status_code, requests.codes.not_found) + else: + self.assertEqual(r.status_code, requests.codes.unauthorized) + print("response", repr(r.headers)) -- 2.47.3