From: Miod Vallat Date: Fri, 29 Aug 2025 07:18:18 +0000 (+0200) Subject: Prevent the /* OPTIONS handler to turn every 404 error into 405. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F16059%2Fhead;p=thirdparty%2Fpdns.git Prevent the /* OPTIONS handler to turn every 404 error into 405. Fixes: #14572 Signed-off-by: Miod Vallat --- 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))