-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(resources-introspection): initial support for route and HTTP method introspection #3594
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
base: master
Are you sure you want to change the base?
Conversation
…oval and fix test failures
…nto introspection
…nto introspection
…nto introspection
Hi, @robjtede Here's a limited-scope approach for listing routes and methods from the Please review and let me know your thoughts! |
… usage - Added `GuardDetail` enum to encapsulate various introspection details of a guard. - Refactored `HttpMethodsExtractor` implementation to use `GuardDetail` instead of `downcast_ref`.
… usage - Added `GuardDetail` enum to encapsulate various introspection details of a guard. - Refactored `HttpMethodsExtractor` implementation to use `GuardDetail` instead of `downcast_ref`.
…nto introspection
@@ -128,6 +128,9 @@ compat = [ | |||
# Opt-out forwards-compatibility for handler visibility inheritance fix. | |||
compat-routing-macros-force-pub = ["actix-web-codegen?/compat-routing-macros-force-pub"] | |||
|
|||
# Enabling the retrieval of metadata for initialized resources, including path and HTTP method. | |||
resources-introspection = [] |
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.
Can you suggest a better name for the feature flag? Another option could be experimental-introspection
to better reflect its current state of development. Open to other naming suggestions that capture the intent of the feature.
@@ -105,6 +126,11 @@ where | |||
let rmap = Rc::new(rmap); | |||
ResourceMap::finish(&rmap); | |||
|
|||
#[cfg(feature = "resources-introspection")] | |||
{ | |||
crate::introspection::process_introspection(Rc::clone(&rmap), rdef_methods); |
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.
Surely there is a better place to make the call to introspection::process_introspection
. This observation applies to all locations where I am currently making this call, including scope.rs
, route.rs
, resource.rs
, and app_service.rs
. Given some time, I can improve this implementation, always aiming to minimize breaking changes. Any ideas?
PR Type
Feature
PR Checklist
Overview
Hello, this is my first contribution to the project. This PR introduces a new resource introspection feature for actix-web that allows retrieving all configured route paths along with their associated HTTP methods after the server has started. Currently, it supports only basic
Guards
that determine HTTP methods. The feature is activated using theresources-introspection
feature flag.The main method is
actix_web::introspection::get_registered_resources()
, which returns a vector ofResourceIntrospection
objects. This method can be executed in an async task alongside the actix-web server or on a separate thread.I developed this feature because it's extremely useful for auditing services with many route paths that change constantly. I hope it proves valuable for others as well, and I welcome any feedback or suggestions for improvement.
Closes #1462
Closes #2677