-
Notifications
You must be signed in to change notification settings - Fork 0
Implement basic middleware wrappers #80
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
Implement basic middleware wrappers #80
Conversation
Reviewer's GuideThis PR extends the middleware module by turning the empty request/response placeholders into full-featured frame wrappers with constructor, accessor, and mutation helpers, enhances the Next helper for chaining, updates the roadmap to mark these items complete, and adds a unit test that verifies request and response frame modification through a middleware chain. Class diagram for ServiceRequest and ServiceResponse wrappersclassDiagram
class ServiceRequest {
- frame: Vec<u8>
+ new(frame: Vec<u8>)
+ frame() &[u8]
+ frame_mut() &mut Vec<u8>
+ into_inner() Vec<u8>
}
class ServiceResponse {
- frame: Vec<u8>
+ new(frame: Vec<u8>)
+ frame() &[u8]
+ frame_mut() &mut Vec<u8>
+ into_inner() Vec<u8>
}
Class diagram for Next helper for middleware chainingclassDiagram
class Next~'a, S~ {
- service: &'a S
+ new(service: &'a S)
+ call(request: ServiceRequest) -> ServiceResponse
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ModifyMiddleware
participant EchoService
Client->>ModifyMiddleware: Send ServiceRequest(frame)
ModifyMiddleware->>ModifyMiddleware: Append b'!' to frame
ModifyMiddleware->>EchoService: Forward modified ServiceRequest
EchoService->>ModifyMiddleware: Return ServiceResponse(modified frame)
ModifyMiddleware->>ModifyMiddleware: Append b'?' to frame
ModifyMiddleware->>Client: Return ServiceResponse(final frame)
Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Gates Passed
6 Quality Gates Passed
See analysis details in CodeScene
Absence of Expected Change Pattern
- wireframe/src/middleware.rs is usually changed with: wireframe/src/extractor.rs
Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
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.
Hey @leynos - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/middleware.rs:10` </location>
<code_context>
/// Incoming request wrapper passed through middleware.
#[derive(Debug)]
-pub struct ServiceRequest;
+pub struct ServiceRequest {
+ frame: Vec<u8>,
+}
</code_context>
<issue_to_address>
The module is missing a containing item comment (`//!`).
Please add a module-level doc comment at the top of the file using `//!` to describe the purpose of this module.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@coderabbitai review |
✅ Actions performedReview triggered.
|
@sourcery-ai review |
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.
Hey @leynos - I've reviewed your changes - here's some feedback:
- ServiceResponse no longer implements Default, which may break existing code—consider re-deriving Default or providing a default constructor.
- To improve ergonomics, implement From<Vec> for ServiceRequest and Into<Vec> for ServiceResponse so callers can more easily convert to/from raw frames.
- If you want to avoid unnecessary buffer copies in middleware chains, consider using a zero-copy buffer type (e.g. Bytes) instead of Vec as the inner frame.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- ServiceResponse no longer implements Default, which may break existing code—consider re-deriving Default or providing a default constructor.
- To improve ergonomics, implement From<Vec<u8>> for ServiceRequest and Into<Vec<u8>> for ServiceResponse so callers can more easily convert to/from raw frames.
- If you want to avoid unnecessary buffer copies in middleware chains, consider using a zero-copy buffer type (e.g. Bytes) instead of Vec<u8> as the inner frame.
## Individual Comments
### Comment 1
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 2
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 3
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 4
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 5
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 6
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Hey @leynos - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 2
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 3
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 4
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 5
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 6
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 7
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
### Comment 8
<location> `src/middleware.rs:17` </location>
<code_context>
+
+impl ServiceRequest {
+ /// Create a new [`ServiceRequest`] from raw frame bytes.
+ #[must_use]
+ pub fn new(frame: Vec<u8>) -> Self { Self { frame } }
+
</code_context>
<issue_to_address>
Function attribute #[must_use] is placed before the doc comment, but it should come after.
Please move the #[must_use] attribute to after the function's doc comment, as per the review instruction.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
@sourcery-ai resolve |
@sourcery-ai review |
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.
Summary
ServiceRequest
andServiceResponse
wrappers with helpersNext
Testing
cargo clippy --all-targets --all-features -- -D warnings
RUSTFLAGS="-D warnings" cargo test --quiet
https://chatgpt.com/codex/tasks/task_e_68542460db98832293bca00c968731f9
Summary by Sourcery
Implement basic middleware wrappers and chaining for asynchronous services, including typed request/response wrappers with helper methods and a Next helper for composing middleware, and demonstrate usage with a unit test.
New Features:
Enhancements:
Documentation:
Tests:
Summary by CodeRabbit