-
-
Notifications
You must be signed in to change notification settings - Fork 5
Make use of default router arguments #824
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,11 @@ | |
|
|
||
| #include <sourcemeta/one/http.h> | ||
|
|
||
| #include <cstddef> // std::size_t | ||
| #include <cstdint> // std::uint8_t | ||
| #include <filesystem> // std::filesystem::path | ||
| #include <memory> // std::unique_ptr | ||
| #include <mutex> // std::once_flag | ||
| #include <optional> // std::optional | ||
| #include <span> // std::span | ||
| #include <string_view> // std::string_view | ||
|
|
@@ -64,14 +67,42 @@ class Action { | |
| std::string_view base_path_; | ||
| }; | ||
|
|
||
| auto actions_initialize(const core::URITemplateRouterView &router) -> void; | ||
| class ActionDispatcher { | ||
| public: | ||
| ActionDispatcher(const std::filesystem::path &base, | ||
| const core::URITemplateRouterView &router); | ||
| ~ActionDispatcher() = default; | ||
|
|
||
| // To avoid mistakes | ||
| ActionDispatcher(const ActionDispatcher &) = delete; | ||
| ActionDispatcher(ActionDispatcher &&) = delete; | ||
| auto operator=(const ActionDispatcher &) -> ActionDispatcher & = delete; | ||
| auto operator=(ActionDispatcher &&) -> ActionDispatcher & = delete; | ||
|
|
||
| auto actions_dispatch(const core::URITemplateRouter::Identifier identifier, | ||
| const core::URITemplateRouter::Identifier context, | ||
| const core::URITemplateRouterView &router, | ||
| const std::filesystem::path &base, | ||
| const std::span<std::string_view> matches, | ||
| HTTPRequest &request, HTTPResponse &response) -> void; | ||
| auto dispatch(const core::URITemplateRouter::Identifier identifier, | ||
| const core::URITemplateRouter::Identifier context, | ||
| const std::span<std::string_view> matches, HTTPRequest &request, | ||
| HTTPResponse &response) -> void; | ||
|
|
||
| auto error(const HTTPRequest &request, HTTPResponse &response, | ||
| const char *const code, std::string &&identifier, | ||
| std::string &&message) const -> void; | ||
|
|
||
| private: | ||
| struct Slot { | ||
| std::unique_ptr<Action> instance; | ||
| std::once_flag flag; | ||
| }; | ||
|
|
||
| // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) | ||
| const std::filesystem::path &base_; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) | ||
| const core::URITemplateRouterView &router_; | ||
| // NOLINTNEXTLINE(modernize-avoid-c-arrays) | ||
| std::unique_ptr<Slot[]> slots_; | ||
| std::size_t slots_size_; | ||
| std::string_view default_error_schema_; | ||
| }; | ||
|
|
||
| } // namespace sourcemeta::one | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
error_schema_is a default-initializedstd::string_view, so if the router has noerrorSchemaargument for thisidentifierit stays empty and laterjson_error/servecalls will emit responses without a schema URI. Other locations where this applies: src/actions/dispatch.cc:53, src/actions/dispatch.cc:73.Severity: medium
Other Locations
src/actions/dispatch.cc:53src/actions/dispatch.cc:73🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.