Repository navigation
feat!: Replace HeaderDecode with HeaderCodec to allow customization on encoding as well - #43
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 📝 WalkthroughWalkthroughThe changes primarily refactor how headers are processed by replacing the old decoder implementations with a unified codec-based approach. The Changes
Possibly related PRs
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #43 +/- ##
==========================================
+ Coverage 78.53% 79.08% +0.55%
==========================================
Files 70 70
Lines 2273 2309 +36
Branches 1181 1219 +38
==========================================
+ Hits 1785 1826 +41
+ Misses 488 483 -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: 0
🧹 Nitpick comments (4)
test/headers/headers_accessor_test.dart (2)
18-22: Consider acknowledging unused parse argument.
factory Custom.parse(String s)ignoress, always returning a newCustom. Confirm that this is intentional.
232-242: Double-check decode logic for the custom class.Since
Custom.parsereturns a new instance in general, you rely on caching to preserve identical references here. If you want parse to reflect the raw input, consider using the input string. Otherwise, this test is fine as-is for demonstration.lib/src/headers/header_accessor.dart (2)
37-39: Refactoring from adecodefield to acodecfield is a solid design choice.Bringing encoding and decoding together into
HeaderCodecimproves future extensibility and clarity.Could consider adding doc comments explaining how the
codeccan be customized (e.g., usage ofHeaderCodec.singlevs.HeaderCodec).Also applies to: 47-47
115-118: Introduction ofPointTupleandPointextension type is interesting.This appears to be a harmless placeholder. Confirm if it’s only for demonstration or if tests will cover it later.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
lib/src/headers/header_accessor.dart(7 hunks)lib/src/headers/headers.dart(1 hunks)test/headers/headers_accessor_test.dart(2 hunks)test/relic_server_serve_test.dart(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
lib/src/headers/header_accessor.dart
[warning] 152-152: lib/src/headers/header_accessor.dart#L152
Added line #L152 was not covered by tests
🔇 Additional comments (20)
test/relic_server_serve_test.dart (1)
131-131: Upgrade toHeaderCodeclooks good.Switching from
HeaderDecoderMultitoHeaderCodecis aligned with the new codec-based approach for header processing. No issues spotted here.test/headers/headers_accessor_test.dart (6)
10-10: Use ofHeaderCodec.single(parseInt)is valid.Adopting
HeaderCodec.single(parseInt)cleanly replaces the previous single-value decoder.
15-15: Use ofHeaderCodec(parseStringList)is valid.Replacing the multi-value decoder with the new codec-based approach follows the intended model.
24-25: New_customClassaccessor aligns with the codec approach.This is a proper demonstration of using a custom parser and encoder.
33-33: Accessor getter usage seems consistent.Invoking
_anInt[this]()aligns with your accessor pattern for immediate retrieval.
158-171: Validation of immediate readability after setting headers is appreciated.The test ensures that the updated value can be accessed without re-fetching or re-building headers. This is good coverage.
173-230: Cache behavior testing is well structured.Verifying decoder call counts helps ensure we avoid redundant parsing. This is thorough coverage.
lib/src/headers/header_accessor.dart (12)
31-32: CastingExpandotoExpando<T>is acceptable.This approach is safe as long as each
HeaderAccessoris used with a consistent type parameter. No immediate problems spotted.
73-77: Caching logic ensures efficient repeated header reads.Using
_cache[raw]to avoid repeated parsing is a good performance optimization.
97-107:setValueOncorrectly primes the cache.By encoding and storing the result in
_cache, subsequent reads avoid unnecessary decoding.
121-121: NewCodecinterface is well-defined.The separation of
decodeandencodefosters clarity and maintainability.
125-144:HeaderCodecas a sealed class is neatly structured.The distinction between
_MultiDecodeHeaderCodecand_SingleDecodeHeaderCodecaccommodates different usage patterns.
146-157:_MultiDecodeHeaderCodecconstructor ensures fallback to_commonEncode.Implementation details look coherent for multi-value decoding scenarios.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 152-152: lib/src/headers/header_accessor.dart#L152
Added line #L152 was not covered by tests
149-152: Line #152 lacks test coverage.Static analysis reports line 152 (
super._(encode ?? _commonEncode)) is uncovered. Consider adding a test that supplies a custom encode function to_MultiDecodeHeaderCodec.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 152-152: lib/src/headers/header_accessor.dart#L152
Added line #L152 was not covered by tests
158-169:_SingleDecodeHeaderCodeceffectively handles single-value headers.Replacing the old single decoder approach with a dedicated codec improves architecture consistency.
177-177:Headerextension type is clearly defined.This extension approach keeps runtime overhead low while adding typed header capabilities.
198-198: Delegation to_accessor.setValueOnis straightforward.Keeps the method consistent with the rest of the typed header logic.
223-223: Robust error handling for invalid headers.Appropriately throws
InvalidHeaderExceptionfor underlying parse issues.
233-241:_commonEncodecovers typical data shapes gracefully.Providing fallback to
toString()ensures consistent encoding for objects.lib/src/headers/headers.dart (1)
67-411: Consistent and complete migration from HeaderDecoder to HeaderCodecThe changes systematically replace all instances of
HeaderDecoderSinglewithHeaderCodec.singleand all instances ofHeaderDecoderMultiwithHeaderCodecthroughout the file. This change aligns with the PR objective to enhance customization capabilities for header value encoding.The migration is thorough and consistent across all header definitions including date-related headers, general headers, request headers, response headers, and security headers.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
lib/src/headers/header_accessor.dart (1)
31-32: Potential type-safety concern in_cache.
Casting fromExpandotoExpando<T>presumes each accessor is used with a unique type. It should be safe if you never reuse the same accessor for conflicting types, but be aware of the runtime cast.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
lib/src/headers/header_accessor.dart(7 hunks)lib/src/headers/headers.dart(1 hunks)test/headers/headers_accessor_test.dart(2 hunks)test/relic_server_serve_test.dart(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- test/relic_server_serve_test.dart
🧰 Additional context used
🪛 GitHub Check: codecov/patch
lib/src/headers/header_accessor.dart
[warning] 179-179: lib/src/headers/header_accessor.dart#L179
Added line #L179 was not covered by tests
🔇 Additional comments (18)
test/headers/headers_accessor_test.dart (8)
10-10: Excellent use ofHeaderCodec.single(parseInt).
This aligns perfectly with the new codec-based approach for parsing single-value headers. No concerns here.
15-15: Smooth transition toHeaderCodec(parseStringList).
Using the multi-value codec is appropriate for string lists. Looks good.
18-22: Test utility class for custom headers is fine.
Returning a hard-coded'foo'indicates this is purely for demonstration or testing. If a meaningful parse/encode is desired in production, consider leveraging the provided input. Otherwise, no issues.
24-25: New_customClassaccessor looks correct.
This properly demonstrates how to integrate a custom type usingHeaderCodec.single.
33-33: GetteranIntextension for mutable headers
Consistent usage of the accessor. No issues found.
159-172: Immediate retrieval test offers good coverage.
It confirms that multiple updates (including raw header writes) reflect immediately when reading the typed value. Great job.
173-230: Thorough caching tests.
This group of tests ensures decode is called once per distinct update, validating the caching mechanism. No problems noted.
232-241: Verifying custom class integration.
This test checks encoding and decoding with a custom type, ensuring the same instance is reused. Looks good.lib/src/headers/header_accessor.dart (9)
39-39: Migration to a codec field is a breaking change.
Externally, anything using the olddecodefield must be updated. Verify all references in your codebase and docs are adjusted accordingly.
47-47: Constructor refactor looks straightforward.
This addition neatly supports the newcodecapproach.
73-77: Logic for retrieving and caching decoded values is solid.
Preventing repeated parsing is a great optimization.
97-107: Efficient cache priming insetValueOn.
Retaining the old cache entries is correct, as theExpando’s lifetime is tied to the headers object.
115-126: Introduction ofCodec<T, StorageT>is clear and coherent.
Defining a simple, bidirectional interface for decoding/encoding fosters clean abstractions.
128-145:HeaderCodecelegantly extendsCodec.
Specializing forIterable<String>aligns perfectly with multi-value header semantics.
173-183: Untested fallback on_commonEncode.
Line 179’s coverage may be lacking if no test calls the constructor with a nullencode. Consider adding a test to ensure_MultiDecodeHeaderCodecis initialized without a custom encoder.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 179-179: lib/src/headers/header_accessor.dart#L179
Added line #L179 was not covered by tests
185-195:_SingleDecodeHeaderCodecis straightforward.
Good approach for single header values.
260-268: Pattern matching in_commonEncodeis well-structured.
This gracefully handles a variety of object types, defaulting totoString()for unknowns.lib/src/headers/headers.dart (1)
69-69: Consistent refactor toHeaderCodecandHeaderCodec.single.
All these lines adopt the new codec-based parsing approach, replacing the legacy decoders. The changes look correct and consistent, preserving single vs. multi-value logic as needed.Also applies to: 74-74, 79-79, 84-84, 89-89, 95-95, 100-100, 105-105, 111-111, 116-116, 121-121, 126-126, 131-131, 136-136, 141-141, 146-146, 151-151, 156-156, 161-161, 166-166, 171-171, 176-176, 181-181, 186-186, 191-191, 196-196, 201-201, 206-206, 211-211, 218-218, 223-223, 229-229, 235-235, 240-240, 245-245, 250-250, 255-255, 260-260, 265-265, 270-270, 275-275, 280-280, 285-285, 290-290, 295-295, 300-300, 306-306, 312-312, 317-317, 322-322, 327-327, 332-332, 337-337, 341-341, 346-346, 351-351, 356-356, 361-361, 367-367, 373-373, 378-378, 383-383, 388-388, 393-393, 399-399, 405-405, 411-411
…n encoding as well
SandPod
left a comment
There was a problem hiding this comment.
Changes look good, just a minor fix with the comments.
But can't we remove the TypedHeader class now? Doesn't seem like that interface is needed?
87bfcf3 to
019fbc5
Compare
I did. It was still a somewhat larger undertaking, but now it has been removed |
SandPod
left a comment
There was a problem hiding this comment.
LGTM!
Could be good to remove toHeaderString from the public interface as well.
…th InternalEx extension class for internal use
Done |
Description
Currently you cannot customize encoding of header values with when constructing a HeaderAccessor, instead you have to either implement the
TypedHeaderinterface or ensure.toStringdoes the right thing.With this PR this is no longer the case. Encoding will still default to the existing approach with this PR, but that may change later.
Related Issues
Fix: #44
Pre-Launch Checklist
Please ensure that your PR meets the following requirements before submitting:
///), ensuring consistency with existing project documentation.Breaking Changes
The interface of
HeaderAccessor<T>changesSummary by CodeRabbit
New Features
Refactor
Tests
Customclass.