-
Notifications
You must be signed in to change notification settings - Fork 741
pandaproxy: fix unmatched-route 404 body shape #30417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright 2026 Redpanda Data, Inc. | ||
| * | ||
| * Use of this software is governed by the Business Source License | ||
| * included in the file licenses/BSL.md | ||
| * | ||
| * As of the Change Date specified in that file, in accordance with | ||
| * the Business Source License, use of this software will be governed | ||
| * by the Apache License, Version 2.0 | ||
| */ | ||
|
|
||
| #include "pandaproxy/default_404_handler.h" | ||
|
|
||
| #include "pandaproxy/error.h" | ||
| #include "pandaproxy/json/requests/error_reply.h" | ||
| #include "pandaproxy/json/rjson_util.h" | ||
|
|
||
| #include <seastar/core/future.hh> | ||
| #include <seastar/http/reply.hh> | ||
| #include <seastar/http/request.hh> | ||
|
|
||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| namespace pandaproxy { | ||
|
|
||
| ss::future<std::unique_ptr<ss::http::reply>> default_404_handler::handle( | ||
| const ss::sstring&, | ||
| std::unique_ptr<ss::http::request>, | ||
| std::unique_ptr<ss::http::reply> rep) { | ||
| auto ec = make_error_condition(reply_error_code::not_found); | ||
| json::error_body body{.ec = ec, .message = ss::sstring{ec.message()}}; | ||
| rep->set_status(ss::http::reply::status_type::not_found); | ||
| rep->write_body( | ||
| _mime_type, pandaproxy::json::rjson_serialize_str(std::move(body))); | ||
| return ss::make_ready_future<std::unique_ptr<ss::http::reply>>( | ||
| std::move(rep)); | ||
| } | ||
|
|
||
| } // namespace pandaproxy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright 2026 Redpanda Data, Inc. | ||
| * | ||
| * Use of this software is governed by the Business Source License | ||
| * included in the file licenses/BSL.md | ||
| * | ||
| * As of the Change Date specified in that file, in accordance with | ||
| * the Business Source License, use of this software will be governed | ||
| * by the Apache License, Version 2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "base/seastarx.h" | ||
|
|
||
| #include <seastar/core/future.hh> | ||
| #include <seastar/core/sstring.hh> | ||
| #include <seastar/http/handlers.hh> | ||
| #include <seastar/http/reply.hh> | ||
| #include <seastar/http/request.hh> | ||
|
|
||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| namespace pandaproxy { | ||
|
|
||
| /// \brief Default handler for unmatched (method, path) combinations on a | ||
| /// pandaproxy::server. Emits the schema-registry/REST-proxy error body | ||
| /// {"error_code": 404, "message": "HTTP 404 Not Found"} (with error_code | ||
| /// instead of Seastar's fallback code field) so clients parsing this | ||
| /// envelope get the shape they expect. | ||
| class default_404_handler : public ss::httpd::handler_base { | ||
| public: | ||
| explicit default_404_handler(ss::sstring mime_type) | ||
| : _mime_type(std::move(mime_type)) {} | ||
|
|
||
| ss::future<std::unique_ptr<ss::http::reply>> handle( | ||
| const ss::sstring&, | ||
| std::unique_ptr<ss::http::request>, | ||
| std::unique_ptr<ss::http::reply> rep) final; | ||
|
|
||
| private: | ||
| ss::sstring _mime_type; | ||
| }; | ||
|
|
||
| } // namespace pandaproxy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright 2026 Redpanda Data, Inc. | ||
| * | ||
| * Use of this software is governed by the Business Source License | ||
| * included in the file licenses/BSL.md | ||
| * | ||
| * As of the Change Date specified in that file, in accordance with | ||
| * the Business Source License, use of this software will be governed | ||
| * by the Apache License, Version 2.0 | ||
| */ | ||
|
|
||
| #include "pandaproxy/default_404_handler.h" | ||
|
|
||
| #include "json/document.h" | ||
|
|
||
| #include <seastar/http/reply.hh> | ||
| #include <seastar/http/request.hh> | ||
| #include <seastar/testing/thread_test_case.hh> | ||
|
|
||
| #include <boost/test/tools/old/interface.hpp> | ||
| #include <boost/test/unit_test.hpp> | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| namespace pp = pandaproxy; | ||
|
|
||
| SEASTAR_THREAD_TEST_CASE(default_404_handler_emits_error_code_envelope) { | ||
| pp::default_404_handler handler{ | ||
| ss::sstring{"application/vnd.schemaregistry.v1+json"}}; | ||
|
|
||
| auto rep = handler | ||
| .handle( | ||
| ss::sstring{}, | ||
| std::make_unique<ss::http::request>(), | ||
| std::make_unique<ss::http::reply>()) | ||
| .get(); | ||
|
|
||
| BOOST_REQUIRE(rep != nullptr); | ||
| BOOST_REQUIRE_EQUAL( | ||
| static_cast<int>(rep->_status), | ||
| static_cast<int>(ss::http::reply::status_type::not_found)); | ||
|
|
||
| json::Document doc; | ||
| doc.Parse(rep->_content.c_str(), rep->_content.size()); | ||
| BOOST_REQUIRE(!doc.HasParseError()); | ||
| BOOST_REQUIRE(doc.IsObject()); | ||
|
|
||
| BOOST_REQUIRE(doc.HasMember("error_code")); | ||
| BOOST_REQUIRE(doc["error_code"].IsInt()); | ||
| BOOST_REQUIRE_EQUAL(doc["error_code"].GetInt(), 404); | ||
|
|
||
| BOOST_REQUIRE(doc.HasMember("message")); | ||
| BOOST_REQUIRE(doc["message"].IsString()); | ||
| BOOST_REQUIRE_EQUAL( | ||
| std::string(doc["message"].GetString()), | ||
| std::string("HTTP 404 Not Found")); | ||
|
|
||
| auto content_type_it = rep->_headers.find("Content-Type"); | ||
| BOOST_REQUIRE(content_type_it != rep->_headers.end()); | ||
| BOOST_REQUIRE_EQUAL( | ||
| content_type_it->second, | ||
| ss::sstring("application/vnd.schemaregistry.v1+json")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to reset the
_default_handlerpointer duringstop()? Doesschema_registry::api::restart()work with this?I think the answer is yes to both, but just double-checking.