Repository navigation
feat(Handler)!: Signature changed - #76
Conversation
|
Important Review skippedAuto 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 📝 WalkthroughWalkthroughThis update refactors context handling and handler signatures throughout the codebase. It introduces a sealed Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant Middleware
participant Handler
Client->>Server: Sends HTTP Request
Server->>Middleware: Wraps request in NewContext
Middleware->>Handler: Passes NewContext
Handler-->>Middleware: Returns HandledContext
Middleware-->>Server: Returns HandledContext
Server-->>Client: Sends HTTP Response
Possibly related PRs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #76 +/- ##
==========================================
+ Coverage 82.42% 82.59% +0.17%
==========================================
Files 80 80
Lines 2429 2425 -4
Branches 1362 1356 -6
==========================================
+ Hits 2002 2003 +1
+ Misses 427 422 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
example/example.dart (1)
29-35:⚠️ Potential issueUpdate handler function signature and context types
Since theHandlertypedef now takes aNewContextand must return aHandledContext, the example’shello(final RequestContext ctx)should be updated to something like:HandledContext hello(final NewContext ctx) { … }Also, adjust the cast to use the new context hierarchy (e.g.
ctx as RespondableContextmay no longer be needed or should target the new sealed subtypes).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (93)
CHANGELOG.md(1 hunks)example/example.dart(1 hunks)example/multi_isolate.dart(1 hunks)lib/io_adapter.dart(1 hunks)lib/relic.dart(2 hunks)lib/src/adapter/context.dart(2 hunks)lib/src/adapter/io/http_response_extension.dart(0 hunks)lib/src/adapter/io/io_serve.dart(1 hunks)lib/src/handler/handler.dart(2 hunks)lib/src/middleware/middleware.dart(1 hunks)lib/src/middleware/middleware_logger.dart(1 hunks)lib/src/relic_server.dart(2 hunks)test/handler/pipeline_test.dart(1 hunks)test/headers/basic/access_control_allow_credentials_header_test.dart(0 hunks)test/headers/basic/access_control_max_age_header_test.dart(0 hunks)test/headers/basic/access_control_request_headers_heder_test.dart(0 hunks)test/headers/basic/age_header_test.dart(0 hunks)test/headers/basic/allow_header_test.dart(0 hunks)test/headers/basic/content_location_header_test.dart(0 hunks)test/headers/basic/date_header_test.dart(0 hunks)test/headers/basic/expires_header_test.dart(0 hunks)test/headers/basic/host_header_test.dart(0 hunks)test/headers/basic/if_modified_since_header_test.dart(0 hunks)test/headers/basic/if_unmodified_since_header_test.dart(0 hunks)test/headers/basic/last_modified_header.dart(0 hunks)test/headers/basic/location_header_test.dart(0 hunks)test/headers/basic/max_forwards_header_test.dart(0 hunks)test/headers/basic/origin_header_test.dart(0 hunks)test/headers/basic/referer_header_test.dart(0 hunks)test/headers/basic/server_header_test.dart(0 hunks)test/headers/basic/trailer_header_test.dart(0 hunks)test/headers/basic/user_agent_header_test.dart(0 hunks)test/headers/basic/via_header_test.dart(0 hunks)test/headers/basic/x_powered_by_header_test.dart(0 hunks)test/headers/header_test.dart(0 hunks)test/headers/typed_headers/accept_encoding_header_test.dart(0 hunks)test/headers/typed_headers/accept_header_test.dart(0 hunks)test/headers/typed_headers/accept_language_test.dart(0 hunks)test/headers/typed_headers/accept_ranges_header_test.dart(0 hunks)test/headers/typed_headers/access_control_allow_headers_header_test.dart(0 hunks)test/headers/typed_headers/access_control_allow_methods_header_test.dart(0 hunks)test/headers/typed_headers/access_control_allow_origin_header_test.dart(0 hunks)test/headers/typed_headers/access_control_expose_headers_header_test.dart(0 hunks)test/headers/typed_headers/access_control_request_method_header_test.dart(0 hunks)test/headers/typed_headers/authorization_header_test.dart(0 hunks)test/headers/typed_headers/cache_control_header_test.dart(0 hunks)test/headers/typed_headers/clear_site_data_header_test.dart(0 hunks)test/headers/typed_headers/connection_header_test.dart(0 hunks)test/headers/typed_headers/content_disposition_header_test.dart(0 hunks)test/headers/typed_headers/content_encoding_header_test.dart(0 hunks)test/headers/typed_headers/content_language_header_test.dart(0 hunks)test/headers/typed_headers/content_range_header_test.dart(0 hunks)test/headers/typed_headers/content_security_policy_header_test.dart(0 hunks)test/headers/typed_headers/cookie_header_test.dart(0 hunks)test/headers/typed_headers/cross_origin_embedder_policy_header_test.dart(0 hunks)test/headers/typed_headers/cross_origin_opener_policy_header_test.dart(0 hunks)test/headers/typed_headers/cross_origin_resource_policy_header_test.dart(0 hunks)test/headers/typed_headers/etag_header_test.dart(0 hunks)test/headers/typed_headers/expect_header_test.dart(0 hunks)test/headers/typed_headers/from_header_test.dart(0 hunks)test/headers/typed_headers/if_match_header_test.dart(0 hunks)test/headers/typed_headers/if_none_match_header_test.dart(0 hunks)test/headers/typed_headers/if_range_header_test.dart(0 hunks)test/headers/typed_headers/permissions_policy_header_test.dart(0 hunks)test/headers/typed_headers/proxy_authenticate_header_test.dart(0 hunks)test/headers/typed_headers/proxy_authorization_header_test.dart(0 hunks)test/headers/typed_headers/range_header_test.dart(0 hunks)test/headers/typed_headers/referrer_policy_header_test.dart(0 hunks)test/headers/typed_headers/retry_after_header_test.dart(0 hunks)test/headers/typed_headers/sec_fetch_dest_header_test.dart(0 hunks)test/headers/typed_headers/sec_fetch_mode_header_test.dart(0 hunks)test/headers/typed_headers/sec_fetch_site_header_test.dart(0 hunks)test/headers/typed_headers/set_cookie_header_test.dart(0 hunks)test/headers/typed_headers/strict_transport_security_header_test.dart(0 hunks)test/headers/typed_headers/te_header_test.dart(0 hunks)test/headers/typed_headers/transfer_encoding_header_test.dart(0 hunks)test/headers/typed_headers/upgrade_header_test.dart(0 hunks)test/headers/typed_headers/vary_header_test.dart(0 hunks)test/headers/typed_headers/www_authenticate_header_test.dart(0 hunks)test/hijack/relic_hijack_test.dart(0 hunks)test/message/apply_headers_test.dart(0 hunks)test/message/message_test.dart(0 hunks)test/message/request_test.dart(0 hunks)test/message/response_test.dart(0 hunks)test/middleware/create_middleware_test.dart(0 hunks)test/middleware/routing_middleware_test.dart(1 hunks)test/relic_server_serve_test.dart(0 hunks)test/static/basic_file_test.dart(0 hunks)test/static/create_file_handler_test.dart(0 hunks)test/static/default_document_test.dart(0 hunks)test/static/directory_listing_test.dart(0 hunks)test/static/test_util.dart(0 hunks)test/util/test_util.dart(1 hunks)
💤 Files with no reviewable changes (79)
- test/headers/basic/date_header_test.dart
- test/headers/typed_headers/expect_header_test.dart
- test/headers/basic/last_modified_header.dart
- test/headers/typed_headers/cross_origin_resource_policy_header_test.dart
- test/headers/basic/origin_header_test.dart
- test/headers/basic/allow_header_test.dart
- test/headers/basic/age_header_test.dart
- test/headers/typed_headers/access_control_expose_headers_header_test.dart
- test/message/apply_headers_test.dart
- test/headers/typed_headers/accept_header_test.dart
- test/headers/basic/user_agent_header_test.dart
- test/headers/typed_headers/accept_ranges_header_test.dart
- test/headers/typed_headers/transfer_encoding_header_test.dart
- test/headers/typed_headers/sec_fetch_dest_header_test.dart
- test/headers/basic/access_control_max_age_header_test.dart
- test/headers/typed_headers/content_language_header_test.dart
- test/headers/typed_headers/sec_fetch_mode_header_test.dart
- test/headers/typed_headers/access_control_allow_headers_header_test.dart
- test/headers/typed_headers/content_encoding_header_test.dart
- test/headers/basic/access_control_allow_credentials_header_test.dart
- test/headers/typed_headers/access_control_allow_origin_header_test.dart
- test/headers/typed_headers/set_cookie_header_test.dart
- test/headers/typed_headers/content_disposition_header_test.dart
- test/headers/typed_headers/accept_encoding_header_test.dart
- test/headers/typed_headers/sec_fetch_site_header_test.dart
- lib/src/adapter/io/http_response_extension.dart
- test/headers/basic/expires_header_test.dart
- test/headers/typed_headers/proxy_authenticate_header_test.dart
- test/headers/typed_headers/connection_header_test.dart
- test/headers/typed_headers/content_security_policy_header_test.dart
- test/headers/basic/max_forwards_header_test.dart
- test/static/basic_file_test.dart
- test/headers/typed_headers/cookie_header_test.dart
- test/headers/typed_headers/etag_header_test.dart
- test/headers/typed_headers/cross_origin_embedder_policy_header_test.dart
- test/static/default_document_test.dart
- test/headers/basic/if_modified_since_header_test.dart
- test/middleware/create_middleware_test.dart
- test/headers/typed_headers/access_control_allow_methods_header_test.dart
- test/headers/typed_headers/permissions_policy_header_test.dart
- test/headers/typed_headers/if_none_match_header_test.dart
- test/headers/typed_headers/cache_control_header_test.dart
- test/headers/basic/location_header_test.dart
- test/headers/typed_headers/authorization_header_test.dart
- test/headers/basic/trailer_header_test.dart
- test/headers/typed_headers/accept_language_test.dart
- test/headers/typed_headers/range_header_test.dart
- test/headers/typed_headers/from_header_test.dart
- test/headers/basic/host_header_test.dart
- test/headers/basic/content_location_header_test.dart
- test/headers/typed_headers/strict_transport_security_header_test.dart
- test/headers/typed_headers/retry_after_header_test.dart
- test/headers/typed_headers/vary_header_test.dart
- test/headers/typed_headers/te_header_test.dart
- test/headers/basic/via_header_test.dart
- test/headers/typed_headers/www_authenticate_header_test.dart
- test/message/response_test.dart
- test/headers/typed_headers/content_range_header_test.dart
- test/static/test_util.dart
- test/headers/basic/server_header_test.dart
- test/headers/basic/if_unmodified_since_header_test.dart
- test/headers/typed_headers/if_match_header_test.dart
- test/headers/typed_headers/clear_site_data_header_test.dart
- test/headers/typed_headers/access_control_request_method_header_test.dart
- test/headers/typed_headers/upgrade_header_test.dart
- test/message/message_test.dart
- test/headers/basic/referer_header_test.dart
- test/headers/typed_headers/referrer_policy_header_test.dart
- test/headers/typed_headers/if_range_header_test.dart
- test/message/request_test.dart
- test/headers/typed_headers/proxy_authorization_header_test.dart
- test/static/create_file_handler_test.dart
- test/relic_server_serve_test.dart
- test/static/directory_listing_test.dart
- test/headers/basic/access_control_request_headers_heder_test.dart
- test/headers/typed_headers/cross_origin_opener_policy_header_test.dart
- test/headers/header_test.dart
- test/headers/basic/x_powered_by_header_test.dart
- test/hijack/relic_hijack_test.dart
🔇 Additional comments (26)
example/example.dart (1)
3-3: Import ofio_adapter.dartis correct
Switching topackage:relic/io_adapter.dartaligns with the new public I/O adapter entry point.example/multi_isolate.dart (1)
5-6: Import consolidation is correct
Addingpackage:relic/io_adapter.dartand keepingpackage:relic/relic.dartensures thatserveand related I/O functions resolve through the new public API.lib/src/adapter/io/io_serve.dart (1)
4-8: Relative imports adjusted properly
Changing toimport '../../handler/handler.dart';andimport '../../relic_server.dart';correctly targets the project’slib/srclayout. No functional changes or regressions appear.lib/io_adapter.dart (1)
1-3: Newio_adapter.dartexports look good
Consolidating exports ofsrc/adapter/io/io_adapter.dartandsrc/adapter/io/io_serve.dartunder a single public library simplifies imports for consumers.test/handler/pipeline_test.dart (1)
31-31: Signature updated to align with new Handler typedefThe function signature has been correctly updated to use
NewContextandHandledContexttypes, which aligns with the refactoredHandlertypedef in the core library.test/middleware/routing_middleware_test.dart (1)
351-351: Explicitly specified generic type parameter for RouterThe Router instantiation now correctly includes the explicit
<Handler>type parameter, ensuring type safety and consistency with the updated Handler typedef.lib/src/middleware/middleware.dart (2)
54-55: Parameter name change improves clarityChanged parameter name from
requestCtxtoctxfor better clarity, consistent with the broader refactoring in the codebase.
59-59: Updated innerHandler invocationUpdated to use the new parameter name
ctxinstead ofrequestCtx, ensuring consistency with the parameter name change.lib/relic.dart (3)
4-4: Added export for context typesAdded export for
src/adapter/context.dart, making the refactored context types available in the public API. This is essential for the breaking change in the handler signature.
15-15: Added export for standard headers extensionsAdded export for
src/headers/standard_headers_extensions.dart, centralizing access to standard header extensions in the public API.
24-24: Added export for routing middlewareAdded export for
src/middleware/routing_middleware.dart, making routing functionality available in the public API. This aligns with the reorganization of the package's public API surface.lib/src/middleware/middleware_logger.dart (4)
20-20: Improved parameter naming for clarityThe parameter name change from
requesttoctxbetter reflects that this is a context object containing the request, not just the request itself.
25-26: Renamed variable improves code clarityRenaming
newCtxtohandledCtxbetter reflects the nature of the variable as the result of handling a request context. This aligns with the newHandledContexttype in the updated architecture.
30-32: Simplified logging call with improved context handlingThe updated code properly uses the renamed variables and accesses request data through the context hierarchy, which is more consistent with the new context model where
HandledContextis a sealed class.
35-35: Improved error logging with proper context accessError logging now correctly uses
ctx.requestinstead of a potentially redundantrequest.request, making the code more maintainable and consistent with the context architecture changes.lib/src/relic_server.dart (3)
117-118: Improved parameter naming for clarityThe parameter name change from
requesttoctxbetter reflects that this is a context object containing the request, not just the request itself. This is consistent with the naming conventions in other parts of the codebase.
119-132: Refined context handling with sealed classThe variable rename from
newCtxtohandledCtxand the updated switch expression make the code more readable and correctly handle the sealedHandledContextclass hierarchy. The use of wildcard pattern_on line 131 is a clean simplification since you're just returning the context without modification.
136-142: Improved error handling with simplified context responseError handling now correctly uses
ctx.requestfor logging andctx.withResponse()to create a response context, which is more direct and consistent with the new context model. This approach removes unnecessary type checking while maintaining type safety through the sealed class hierarchy.lib/src/handler/handler.dart (1)
61-61: Removed unnecessary type checkingThe
respondWithfunction now directly callsctx.withResponsewithout runtime type checking. This simplification is made possible by the new context type hierarchy where the input context is expected to be aNewContextwhich guarantees the availability of thewithResponsemethod.test/util/test_util.dart (4)
6-6: Updated import to use public adapter APIThe import has been changed from an internal implementation file to the new public
io_adapter.dart. This is in line with the PR's goal of ensuring that code dependent onHttpServerfromdart:iois only imported when explicitly requested by the user.
14-14: Updated SyncHandler typedef to match new Handler signatureThe SyncHandler typedef has been updated to reflect the new Handler signature, accepting a
NewContextand returning aHandledContext. This ensures consistency between the test utilities and the main codebase.
20-32: Simplified handler creation with direct context responseThe createSyncHandler function has been updated to work with the new context types. It now directly calls
ctx.withResponse()without type checking, which is more concise and aligns with the sealed class hierarchy whereNewContextguarantees the availability of this method.
38-38: Updated asyncHandler signature for type consistencyThe asyncHandler function has been updated to accept a
NewContextand return aFuture<HandledContext>, maintaining consistency with the synchronous handler and the updated Handler typedef.lib/src/adapter/context.dart (3)
61-66: LGTM: Clean introduction of sealed classHandledContextThe addition of the sealed class
HandledContextcreates a clear type hierarchy for handled requests. This matches the PR's objective of restructuring theRequestContextclass hierarchy.
68-69: LGTM: UpdatedResponseContextinheritanceChanged
ResponseContextto extendHandledContextrather than implementing it as an interface, consistent with the new type hierarchy. The class still correctly implementsRespondableContextto maintain its interface contract.
79-79: LGTM: UpdatedHijackContextinheritanceThe
HijackContextis now a proper subclass ofHandledContext, completing the context hierarchy refactoring described in the PR objectives.
82d9a81 to
4ac1893
Compare
Also move io_serve.dart under adapter/io/, but export from lib/io_adapter.dart Changes are related to serverpod integration.
…text Function(NewContext)`
.. and example.dart
4ac1893 to
b253b4f
Compare
SandPod
left a comment
There was a problem hiding this comment.
Should maybe add a check for dart fix && dart apply to the CI pipe?
LGMT! 👍
Description
This PR address issues discovered while integrating relic into serverpod
Handler Signature Refactor
Handlertypedef has been changed fromFutureOr<RequestContext> Function(RequestContext ctx)toFutureOr<HandledContext> Function(NewContext ctx).RequestContexthierarchy has been modified:HandledContextis now asealedclass thatextends RequestContext.ResponseContextandHijackContextnow extendHandledContext.HandledContext.Exports Changed
lib/io_adapter.dartintroduced. Code dependend onHttpServerfromdart:iowill only be imported to your project if you import this file.Related Issues
Pre-Launch Checklist
Please ensure that your PR meets the following requirements before submitting:
///), ensuring consistency with existing project documentation.Breaking Changes
Handlersignature has changedSummary by CodeRabbit
New Features
Refactor
Chores
Tests