Repository navigation
feat!: Support typed access to custom headers - #38
Conversation
📝 WalkthroughWalkthroughThis pull request refactors how HTTP headers are handled in Relic. Changes include updating export and exception handling in header-related files, refactoring header parsing and typed header implementations to use more generic iterable collections instead of lists, and introducing new constructs such as a header accessor with caching. The custom headers implementation has been removed in favor of consolidated exception handling and an extensible typed header design. In addition, both internal logic and tests have been adjusted (e.g., using a new Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant S as RelicServer
participant H as Headers Builder
participant A as HeaderAccessor
participant E as Exception Handler
C->>S: Send HTTP request with headers
S->>H: Build/Parse headers (using Headers.fromMap/empty/build)
H->>A: Retrieve typed header value (iterable-based parsing, caching via Expando)
A->>S: Return parsed header value or error
alt Header valid
S->>S: Process request with header data
else Header invalid
A->>E: Throw HeaderException
E-->>S: Error response generation
end
S-->>C: Respond with HTTP response (headers transformed via extension methods)
Assessment against linked issues
🪧 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 (
|
54ec86c to
febe642
Compare
febe642 to
7b59f10
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #38 +/- ##
==========================================
- Coverage 81.30% 78.43% -2.88%
==========================================
Files 70 70
Lines 2621 2272 -349
Branches 1119 1181 +62
==========================================
- Hits 2131 1782 -349
Misses 490 490 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
077f136 to
16d04be
Compare
This commit introduces a flyweight pattern to efficiently handle typed headers. The implementation includes: - HeaderFlyweight class to manage shared, immutable header representations - Lazy header value parsing with caching to improve performance - Type-safe header access through extension types - Reduced memory footprint by reusing header definitions This change significantly improves both memory usage and performance when dealing with multiple headers across different requests/responses.
This commit changes the Headers class to function as a read-only map of string keys to iterable string values rather than a map to list values. The implementation now uses a backing store with a CaseInsensitiveMap for proper header name handling. This makes Headers more efficient by avoiding unnecessary list copying operations. Key changes: - Changed List<String> to Iterable<String> in method signatures - Added proper Headers factory methods - Implemented modify() method for controlled mutations - Added a MutableHeaders implementation (partial file) - Fixed extensions to work with Iterables instead of Lists
7902ecd to
aaf51e2
Compare
This commit marks many strict mode-related tests as skipped with clear "todo" comments. Header validation is being refactored to use typed headers with more consistent validation behavior, rather than the previous strict/non-strict mode. The updates primarily affect header validation tests across the codebase, preparing for upcoming change where strict headers are handled via middleware.
… mutation This commit introduces a new method setValueOn to HeaderFlyweight that allows for type-safe mutation of headers. The implementation supports various value types including String, DateTime, TypedHeader, and Iterable<String>. Additionally, this refactors the codebase to: - Support a new HeadersBase class that both Headers and MutableHeaders extend - Add a removeFrom method to HeaderFlyweight - Update standard extensions to work with the new typing system
This method enables transforming a Headers instance by applying a function that modifies a MutableHeaders instance. The new name better reflects that we're creating a transformed copy rather than modifying the original. Also updated usage throughout codebase, including: - All method references in Headers class - All test cases using this method
…to typed headers This is a work-around for how Dart extension properties are resolved. By adding these getters, we ensure MutableHeaders instances can access typed header properties in the same way as regular Headers, improving API consistency and usability.
This change restructures header property access by moving getter properties from HeadersBase to Headers extension. Since we were already duplicating these properties on MutableHeaders, this makes the code organization more consistent by following the same pattern for both Headers types. The underlying accessor methods (_) remain on HeadersBase for code reuse.
This commit removes the failedHeadersToParse Map from Headers class. All associated test cases are also removed.
…d a test that we handle Set-Cookie (and similar split-always headers) correct
2507e1f to
2da9997
Compare
SandPod
left a comment
There was a problem hiding this comment.
LGTM! 🚀
Given that the "invalid" and named arguments for SingleTest are removed :)
a8da619 to
1f3cbca
Compare
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
1 similar comment
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (9)
test/headers/mutable_headers_test.dart (2)
31-33: Add a descriptive test name.This test is missing a proper description. Adding a clear name would improve readability and make the purpose of the test explicit.
- test('', () { + test('when accessing keys then all keys are returned', () { expect(mutable.keys, ['1', '2', '3']); });
14-15: Consider more precise terminology in test descriptions.The current description uses "disappear" when describing the removal of values. Using more precise terminology like "removed" or "no longer present" would better match the technical operation being performed.
- 'when assigning null to a key ' - 'then the value disappear', () { + 'when assigning null to a key ' + 'then the value is removed', () {- 'when removing a key ' - 'then the value disappear', () { + 'when removing a key ' + 'then the value is no longer present', () {Also applies to: 23-24
test/headers/headers_accessor_test.dart (1)
134-147: Good test for immutability protection, but consider compile-time checks.The test correctly verifies that attempting to set a header on an immutable collection fails at runtime. The TODO comment about compile-time prevention is a good consideration for future improvement.
Consider investigating if you can leverage Dart's type system to make this a compile-time error instead of a runtime error. This might involve using separate interfaces for read-only vs. mutable header accessors.
test/headers/basic/access_control_max_age_header_test.dart (1)
49-53: Consider simplifying the async pattern.The nested async function can be simplified since you're already using async/await in the outer test.
- () async => await getServerRequestHeaders( + getServerRequestHeaders( server: server, headers: {'access-control-max-age': 'invalid'}, touchHeaders: (h) => h.accessControlMaxAge, - ), + ),test/headers/header_test.dart (2)
18-21: UseHeaders.buildfor consistency (optional suggestion).
WhileHeaders.fromMapis valid for quick instantiations, consider usingHeaders.buildfor a cohesive creation pattern across all tests. This is a minor consistency suggestion only.- var headers = Headers.fromMap({ + var headers = Headers.build((mh) { + mh['X-Custom-Header'] = ['value']; + });
156-182: Selectively excluding headers from invalid test.
The TODO comment indicates further scrutiny is needed for each excluded header. This is fine for now, but make sure to revisit for correctness.Do you want me to open an issue or propose a test expansion that covers these excluded headers once they are clarified?
lib/src/headers/headers.dart (2)
2-2: Correct the incomplete TODO comment.There's a missing part of the word “dependency” in the comment. Also, consider linking an issue to track this removal if it's going to remain.
-import 'dart:io' as io; // TODO: Get rid of this dependen +import 'dart:io' as io; // TODO: Get rid of this dependency
54-54: Replace or clarify the "TODO: Should die".This comment is ambiguous. It’s better to use a more descriptive TODO or reference an issue to keep it actionable and clear.
lib/src/headers/header_accessor.dart (1)
14-16: Document potential memory usage of_caches.Since
_cachesis a static container, consider clarifying its lifecycle and concurrency implications. Even thoughExpandodoesn't strongly reference objects, adding comments or safeguards can help prevent misunderstanding or misuse.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (107)
lib/relic.dart(1 hunks)lib/src/extensions/http_response_extension.dart(2 hunks)lib/src/handler/pipeline.dart(1 hunks)lib/src/headers/custom/custom_headers.dart(0 hunks)lib/src/headers/exception/header_exception.dart(1 hunks)lib/src/headers/exception/invalid_header_exception.dart(0 hunks)lib/src/headers/extension/string_list_extensions.dart(3 hunks)lib/src/headers/header_accessor.dart(1 hunks)lib/src/headers/headers.dart(3 hunks)lib/src/headers/mutable_headers.dart(1 hunks)lib/src/headers/parser/common_types_parser.dart(3 hunks)lib/src/headers/parser/headers_parser.dart(1 hunks)lib/src/headers/standard_headers_extensions.dart(1 hunks)lib/src/headers/typed/headers/accept_encoding_header.dart(1 hunks)lib/src/headers/typed/headers/accept_header.dart(2 hunks)lib/src/headers/typed/headers/accept_language_header.dart(1 hunks)lib/src/headers/typed/headers/access_control_allow_headers_header.dart(2 hunks)lib/src/headers/typed/headers/access_control_allow_methods_header.dart(1 hunks)lib/src/headers/typed/headers/access_control_expose_headers_header.dart(2 hunks)lib/src/headers/typed/headers/cache_control_header.dart(2 hunks)lib/src/headers/typed/headers/clear_site_data_header.dart(1 hunks)lib/src/headers/typed/headers/connection_header.dart(1 hunks)lib/src/headers/typed/headers/content_encoding_header.dart(1 hunks)lib/src/headers/typed/headers/content_language_header.dart(1 hunks)lib/src/headers/typed/headers/content_security_policy_header.dart(1 hunks)lib/src/headers/typed/headers/etag_condition_header.dart(2 hunks)lib/src/headers/typed/headers/from_header.dart(1 hunks)lib/src/headers/typed/headers/permission_policy_header.dart(1 hunks)lib/src/headers/typed/headers/te_header.dart(1 hunks)lib/src/headers/typed/headers/transfer_encoding_header.dart(1 hunks)lib/src/headers/typed/headers/upgrade_header.dart(1 hunks)lib/src/headers/typed/headers/vary_header.dart(2 hunks)lib/src/headers/typed/typed_header_interface.dart(0 hunks)lib/src/message/request.dart(1 hunks)lib/src/message/response.dart(12 hunks)lib/src/relic_server.dart(4 hunks)lib/src/static/static_handler.dart(4 hunks)pubspec.yaml(1 hunks)test/exception/relic_exceptions_test.dart(1 hunks)test/handler/cascade_test.dart(4 hunks)test/headers/basic/access_control_allow_credentials_header_test.dart(3 hunks)test/headers/basic/access_control_max_age_header_test.dart(1 hunks)test/headers/basic/access_control_request_headers_heder_test.dart(2 hunks)test/headers/basic/age_header_test.dart(1 hunks)test/headers/basic/allow_header_test.dart(1 hunks)test/headers/basic/content_location_header_test.dart(1 hunks)test/headers/basic/date_header_test.dart(1 hunks)test/headers/basic/expires_header_test.dart(1 hunks)test/headers/basic/host_header_test.dart(2 hunks)test/headers/basic/if_modified_since_header_test.dart(9 hunks)test/headers/basic/if_unmodified_since_header_test.dart(1 hunks)test/headers/basic/last_modified_header.dart(9 hunks)test/headers/basic/location_header_test.dart(1 hunks)test/headers/basic/max_forwards_header_test.dart(1 hunks)test/headers/basic/origin_header_test.dart(1 hunks)test/headers/basic/referer_header_test.dart(1 hunks)test/headers/basic/server_header_test.dart(1 hunks)test/headers/basic/trailer_header_test.dart(8 hunks)test/headers/basic/user_agent_header_test.dart(6 hunks)test/headers/basic/via_header_test.dart(8 hunks)test/headers/basic/x_powered_by_header_test.dart(2 hunks)test/headers/custom/custom_headers_test.dart(0 hunks)test/headers/header_test.dart(1 hunks)test/headers/headers_accessor_test.dart(1 hunks)test/headers/headers_test_utils.dart(3 hunks)test/headers/mutable_headers_test.dart(1 hunks)test/headers/typed_headers/accept_encoding_header_test.dart(20 hunks)test/headers/typed_headers/accept_header_test.dart(13 hunks)test/headers/typed_headers/accept_language_test.dart(1 hunks)test/headers/typed_headers/accept_ranges_header_test.dart(7 hunks)test/headers/typed_headers/access_control_allow_headers_header_test.dart(8 hunks)test/headers/typed_headers/access_control_allow_methods_header_test.dart(9 hunks)test/headers/typed_headers/access_control_allow_origin_header_test.dart(11 hunks)test/headers/typed_headers/access_control_expose_headers_header_test.dart(10 hunks)test/headers/typed_headers/access_control_request_method_header_test.dart(8 hunks)test/headers/typed_headers/authorization_header_test.dart(23 hunks)test/headers/typed_headers/cache_control_header_test.dart(22 hunks)test/headers/typed_headers/clear_site_data_header_test.dart(9 hunks)test/headers/typed_headers/connection_header_test.dart(9 hunks)test/headers/typed_headers/content_disposition_header_test.dart(8 hunks)test/headers/typed_headers/content_encoding_header_test.dart(10 hunks)test/headers/typed_headers/content_language_header_test.dart(9 hunks)test/headers/typed_headers/content_range_header_test.dart(11 hunks)test/headers/typed_headers/content_security_policy_header_test.dart(7 hunks)test/headers/typed_headers/cookie_header_test.dart(12 hunks)test/headers/typed_headers/cross_origin_embedder_policy_header_test.dart(1 hunks)test/headers/typed_headers/cross_origin_opener_policy_header_test.dart(7 hunks)test/headers/typed_headers/cross_origin_resource_policy_header_test.dart(1 hunks)test/headers/typed_headers/etag_header_test.dart(8 hunks)test/headers/typed_headers/expect_header_test.dart(6 hunks)test/headers/typed_headers/from_header_test.dart(12 hunks)test/headers/typed_headers/if_match_header_test.dart(13 hunks)test/headers/typed_headers/if_none_match_header_test.dart(13 hunks)test/headers/typed_headers/if_range_header_test.dart(9 hunks)test/headers/typed_headers/permissions_policy_header_test.dart(7 hunks)test/headers/typed_headers/proxy_authenticate_header_test.dart(11 hunks)test/headers/typed_headers/proxy_authorization_header_test.dart(23 hunks)test/headers/typed_headers/range_header_test.dart(12 hunks)test/headers/typed_headers/referrer_policy_header_test.dart(7 hunks)test/headers/typed_headers/retry_after_header_test.dart(11 hunks)test/headers/typed_headers/sec_fetch_dest_header_test.dart(7 hunks)test/headers/typed_headers/sec_fetch_mode_header_test.dart(7 hunks)test/headers/typed_headers/sec_fetch_site_header_test.dart(7 hunks)test/headers/typed_headers/set_cookie_header_test.dart(13 hunks)test/headers/typed_headers/strict_transport_security_header_test.dart(2 hunks)test/headers/typed_headers/te_header_test.dart(14 hunks)test/headers/typed_headers/transfer_encoding_header_test.dart(1 hunks)
⛔ Files not processed due to max files limit (20)
- test/headers/typed_headers/upgrade_header_test.dart
- test/headers/typed_headers/vary_header_test.dart
- test/headers/typed_headers/www_authenticate_header_test.dart
- test/hijack/hijack_test.dart
- test/hijack/relic_hijack_test.dart
- test/message/apply_headers_test.dart
- test/message/message_test.dart
- test/message/request_test.dart
- test/message/response_test.dart
- test/middleware/create_middleware_test.dart
- test/relic_server_serve_test.dart
- test/relic_server_test.dart
- test/static/alternative_root_test.dart
- test/static/basic_file_test.dart
- test/static/create_file_handler_test.dart
- test/static/default_document_test.dart
- test/static/directory_listing_test.dart
- test/static/get_handler_test.dart
- test/static/symbolic_link_test.dart
- test/util/test_util.dart
💤 Files with no reviewable changes (4)
- lib/src/headers/typed/typed_header_interface.dart
- lib/src/headers/exception/invalid_header_exception.dart
- test/headers/custom/custom_headers_test.dart
- lib/src/headers/custom/custom_headers.dart
🧰 Additional context used
🪛 GitHub Check: codecov/patch
lib/src/headers/exception/header_exception.dart
[warning] 67-67: lib/src/headers/exception/header_exception.dart#L67
Added line #L67 was not covered by tests
[warning] 71-71: lib/src/headers/exception/header_exception.dart#L71
Added line #L71 was not covered by tests
lib/src/message/response.dart
[warning] 141-141: lib/src/message/response.dart#L141
Added line #L141 was not covered by tests
[warning] 272-272: lib/src/message/response.dart#L272
Added line #L272 was not covered by tests
lib/src/headers/headers.dart
[warning] 23-23: lib/src/headers/headers.dart#L23
Added line #L23 was not covered by tests
🔇 Additional comments (507)
test/headers/typed_headers/from_header_test.dart (4)
3-3: Standard headers extensions import addedThis new import provides access to the standard headers extensions that support the typed header access implementation. This is a good addition as it aligns with the PR's goal of supporting typed access to custom headers.
28-28: AddedtouchHeadersparameter to header testsThe addition of the
touchHeadersparameter is a key part of the header optimization implementation. This parameter allows the tests to explicitly access specific headers, which supports the PR's goal of reducing memory overhead by only processing headers when they're accessed.In test cases expecting exceptions,
touchHeadersis set to access the specific header (e.g.,(h) => h.from), while in cases not expecting exceptions, it's set to a no-op function ((_) {}).Also applies to: 50-51, 71-72, 84-85, 97-98, 111-112, 127-128, 144-145, 165-166, 188-189, 212-213
69-69: ChangedHeaders headerstovar headersThe change from explicit type declaration to using
varsimplifies the code while maintaining type safety through type inference. This is part of the broader refactoring to support the new typed header access mechanism.Also applies to: 82-82, 95-95, 109-109, 125-125, 142-142, 186-186, 210-210
216-217: Updated header access patternThis change implements the new typed header access mechanism. The code now uses an indexer pattern (
Headers.from[headers]) to access the header value, and properly tests that attempting to access an invalid header throws an exception.test/headers/typed_headers/cross_origin_opener_policy_header_test.dart (3)
3-3: Standard headers extensions import addedThis new import provides access to the standard headers extensions that support the typed header access implementation. This is a good addition as it aligns with the PR's goal of supporting typed access to custom headers.
28-28: AddedtouchHeadersparameter to header testsThe addition of the
touchHeadersparameter is a key part of the header optimization implementation. This parameter allows the tests to explicitly access specific headers, which supports the PR's goal of reducing memory overhead by only processing headers when they're accessed.In test cases expecting exceptions,
touchHeadersis set to access the specific header (e.g.,(h) => h.crossOriginOpenerPolicy), while in cases not expecting exceptions, it's set to a no-op function ((_) {}).Also applies to: 47-48, 66-67, 78-79, 91-92, 116-117
64-64: ChangedHeaders headerstovar headersThe change from explicit type declaration to using
varsimplifies the code while maintaining type safety through type inference. This is part of the broader refactoring to support the new typed header access mechanism.Also applies to: 76-76, 89-89, 114-114
pubspec.yaml (1)
32-32: Added meta package dependencyThe addition of the
metapackage (^1.9.1) as a dev dependency is appropriate for supporting the new header accessor implementation. This package provides annotations and utilities that can help with static analysis and type safety, which are valuable for the typed header access feature being implemented.test/exception/relic_exceptions_test.dart (1)
1-1: Import reordering for consistencyMoving the
package:relic/relic.dartimport to the top of the import list improves code organization and follows the common Dart style convention of putting package imports before relative imports. This is a small but good improvement for code readability and maintainability.lib/src/headers/typed/headers/clear_site_data_header.dart (1)
27-27: Improved flexibility by accepting Iterable instead of ListThe parameter type change from
List<String>toIterable<String>is a good improvement that makes the API more flexible. This allows consumers to pass any iterable collection of strings rather than specifically requiring a List.lib/src/handler/pipeline.dart (1)
40-40: Good optimization with const constructorAdding the
constkeyword to the_Pipelineconstructor is a positive change that allows instances to be created as compile-time constants. This can improve performance and memory usage in Dart applications.lib/src/headers/parser/headers_parser.dart (1)
2-2: Improved exception handling structureUpdating the import to use
header_exception.dartinstead of the previous import aligns with the broader consolidation of exception handling in the PR. This suggests thatInvalidHeaderExceptionis now part of a hierarchy underHeaderException, which improves organization and clarity in error handling.lib/src/headers/typed/headers/te_header.dart (1)
19-19: Improved flexibility by accepting Iterable instead of ListThe parameter type change from
List<String>toIterable<String>is a good improvement that makes the API more flexible. This change is consistent with similar updates across other headers in the codebase, creating a uniform interface for header parsing.lib/src/headers/typed/headers/upgrade_header.dart (1)
18-18: Parameter type generalization looks good.Changing from
List<String>toIterable<String>provides greater flexibility when parsing headers, allowing any iterable collection of strings to be accepted rather than only lists. This modification aligns with the PR's objective to enhance header handling and works well with the existing implementation.lib/src/headers/typed/headers/access_control_allow_methods_header.dart (1)
27-27: Parameter type generalization is appropriate.Updating the parameter type from
List<String>toIterable<String>improves API flexibility while maintaining compatibility with the existing implementation. The change is consistent with the PR's objective to enhance header handling.lib/src/headers/typed/headers/accept_encoding_header.dart (1)
24-24: Parameter type broadening looks good.The change from
List<String>toIterable<String>is well-implemented and maintains compatibility with the existing code logic. This modification provides greater flexibility in how header values can be passed to the parsing method.lib/src/headers/typed/headers/connection_header.dart (1)
21-21: Parameter type generalization is appropriate.Changing from
List<String>toIterable<String>enhances API flexibility while maintaining compatibility with the existing implementation. This change is consistent with the modifications in other header classes and supports the PR's objective of improving header handling.test/headers/mutable_headers_test.dart (1)
42-49: LGTM! Good test for Headers.build.The test properly verifies that values assigned during
Headers.buildexecution are present in the returned headers collection.lib/src/headers/typed/headers/content_encoding_header.dart (1)
23-23: Good API flexibility improvement.Changing the parameter type from
List<String>toIterable<String>improves API flexibility, allowing for more types of collections to be passed as arguments while maintaining backward compatibility.lib/src/headers/typed/headers/transfer_encoding_header.dart (1)
21-21: Good API flexibility improvement.Changing the parameter type from
List<String>toIterable<String>improves API flexibility, allowing for more types of collections to be passed as arguments while maintaining backward compatibility. This change is consistent with similar changes in other header classes.lib/src/headers/typed/headers/accept_language_header.dart (1)
24-24: Good API flexibility improvement.Changing the parameter type from
List<String>toIterable<String>improves API flexibility, allowing for more types of collections to be passed as arguments while maintaining backward compatibility. This change is consistent with similar changes in other header classes.lib/src/headers/typed/headers/content_security_policy_header.dart (1)
61-61: Good shift from List to Iterable for flexibilityChanging from
List<String>toIterable<String>makes the code more flexible by accepting a wider range of collection types. This is consistent with the PR's goal of enhancing typed access to headers and reducing memory overhead. The implementation still works correctly as thejoin()method on line 72 is available in both types.test/headers/typed_headers/access_control_allow_headers_header_test.dart (2)
30-30: LGTM: Header access control is improved with touchHeadersThe addition of the
touchHeadersparameter is consistent with the PR's goal of enhancing typed access to headers. This allows fine-grained control over which headers are accessed during testing, which is particularly useful for verifying that validation only occurs on accessed headers.Also applies to: 50-50, 69-70, 82-83, 102-103, 115-116, 139-140
67-67: LGTM: Using type inference improves readabilitySwitching from explicit
Headerstype declarations tovarleverages Dart's type inference, which makes the code more concise while maintaining type safety.Also applies to: 80-80, 100-100, 113-113, 137-137
test/handler/cascade_test.dart (2)
12-12: Simplification of header access is welcomeChanging from
request.headers.custom['header']to directly accessingrequest.headers['header']simplifies the header access pattern. This aligns with the PR's goal of eliminating the distinction between standard and custom headers.Also applies to: 18-18, 24-24
47-47: Header construction is now more straightforwardUsing
Headers.buildwith direct assignments to the map is a cleaner approach than the previous implementation usingHeaders.responsewith aCustomHeadersobject. This change supports the consolidation of header handling in the codebase.Also applies to: 61-64, 79-83
lib/src/extensions/http_response_extension.dart (2)
4-4: LGTM: Import added for standard headers extensionsThe addition of this import provides access to the new header extension functionality, which is necessary for the refactored header handling approach.
17-18: Simplified header application improves code qualityThe change from creating a mapped version of headers and checking for non-null values to directly iterating over
headers.entriessimplifies the code and reduces unnecessary operations. This is a performance improvement and makes the code more maintainable.test/headers/basic/if_modified_since_header_test.dart (5)
4-4: Import of standard headers extensions now explicitly included.This import provides access to header extension methods which is necessary for the refactored header access pattern.
29-29: Added touchHeaders parameter to trigger typed header access.The
touchHeadersparameter specifies which header should be processed during testing. This change supports the new typed header access pattern implemented in this PR, allowing tests to specifically trigger the accessor forifModifiedSince.Also applies to: 51-51, 86-86, 102-102, 118-118
69-71: Simplified type declaration and added no-op header access.The type was changed from explicit
Headerstovarfor better flexibility, and a no-op function was added fortouchHeaders. This tests that invalid headers don't cause issues when they're not actually accessed.
145-146: Updated header access pattern to use the new accessor API.The test now properly checks two aspects of header validation:
- Access via the accessor's
valueOrNullIfInvalidproperty returns null for invalid headers- Direct property access throws an
InvalidHeaderexceptionThis matches the PR's goal of supporting typed access to headers while maintaining validation.
161-162: Consistent usage of the new header accessor API.Similar to the previous test case, this validates both the null value for invalid headers and the expected exception behavior.
lib/src/headers/typed/headers/permission_policy_header.dart (1)
68-68: Changed values field type from List to Iterable.This change increases flexibility by allowing any iterable collection of strings to be used instead of requiring specifically a List. The implementation in
toHeaderString()already treats the values as an iterable, making this a safe and beneficial change.Since the constructor still accepts any
Iterable<String>, this is a non-breaking change that improves API flexibility.test/headers/typed_headers/sec_fetch_site_header_test.dart (4)
1-1: Updated imports to support the new header access pattern.The import statements have been updated to include
standard_headers_extensions.dartwhich provides the extension methods needed for the new typed header access.Also applies to: 3-3
27-27: Added touchHeaders parameter to trigger typed header access.The
touchHeadersparameter specifies which header should be processed during testing, in this case accessingsecFetchSite. This change supports the PR's goal of providing a consistent typed access pattern for all headers.Also applies to: 46-46, 77-77, 90-90
63-65: Added no-op header access to test that invalid headers don't cause issues when not accessed.This test confirms that even with an invalid header value, no exception is thrown if the header is not actually accessed. This is an important part of the memory optimization aspect of the PR, where header parsing is lazy.
112-115: Changed variable type and added touchHeaders parameter.The type declaration is simplified from explicit
Headerstovar, and a no-op function is added fortouchHeaders. This maintains consistency with the header access pattern implemented throughout the tests.lib/src/headers/typed/headers/from_header.dart (2)
11-11: Changed emails field type from List to Iterable.This change improves flexibility by allowing any iterable collection of strings (not just Lists). The implementation in
toHeaderString()and other methods already treats emails as an iterable, making this a safe enhancement.
17-17: Updated parse factory method to accept Iterable instead of List.This change aligns with the updated field type and follows the PR's pattern of using more flexible
Iterable<String>parameters throughout the codebase. This makes the API more flexible without changing core functionality.Note that since the implementation already uses methods compatible with
Iterable(splitTrimAndFilterUnique(),length,first, etc.), this change maintains backward compatibility while increasing flexibility.test/headers/typed_headers/accept_encoding_header_test.dart (5)
1-2: Improve import organization for better maintainability.The imports have been reorganized with the standard library imports first, followed by the package imports. This is a good practice for code organization and readability.
6-6: Import ordering is correct.The relative imports are placed after package imports, which follows Dart style guidelines.
28-28: NewtouchHeadersparameter ensures header validation is properly triggered.The addition of the
touchHeadersparameter specifying(h) => h.acceptEncodingensures that the header is accessed during the test, which is necessary for validating the header's behavior. This change aligns with the new header accessor pattern introduced in this PR.Also applies to: 50-50, 72-72, 94-94, 114-114, 128-128, 145-145, 162-162, 179-179, 196-196, 211-211, 231-231, 252-252, 268-268, 284-284, 301-301, 317-317
112-117: LGTM: Test correctly checks that invalid headers are ignored if not accessed.This test verifies that invalid headers don't cause issues if they aren't actively accessed, which is important behavior for the new header accessor pattern.
348-349: Updated API for accessing invalid headers.The test now uses
Headers.acceptEncoding[headers].valueOrNullIfInvalidto check that invalid headers return null, followed by verifying thatheaders.acceptEncodingthrows an exception. This reflects the new header accessor API which properly differentiates between accessing a non-existent header and accessing an invalid one.test/headers/headers_accessor_test.dart (7)
1-7: LGTM: Imports are properly organized.The imports follow good organization practices with package imports first, followed by relative imports, and are all relevant to the test file's functionality.
8-16: Good implementation of the header accessors with appropriate decoders.The code defines two constant header accessors with different types:
_anIntfor single integer values usingHeaderDecoderSingle_someStringsfor lists of strings usingHeaderDecoderMultiThis demonstrates the type-safety capabilities of the new
HeaderAccessorclass.
18-25: Clean extension methods for typed header access.The extensions on
HeadersandMutableHeadersprovide a clean API for getting and setting typed header values. This pattern enhances type safety while keeping the API ergonomic.
27-43: Tests correctly verify basic parsing functionality.These tests verify that:
- Single values are correctly parsed to their expected type (int)
- Multi values are correctly parsed to their expected type (List)
The assertions are clear and test both the type and value.
44-66: Comprehensive testing of empty header behavior.The tests thoroughly verify the behavior of headers when the collection is empty:
- Testing both accessor methods (
isSetIn/isSetandisValidIn/isValid)- Verifying raw value access returns null
- Ensuring
valuethrows an appropriate exception- Checking null-safe accessors return null
This provides good coverage of the API's behavior with empty collections.
68-92: Good testing of invalid header behavior.The tests for invalid headers verify:
- The header is correctly identified as set but invalid
- Attempting to access the value throws the expected exceptions
valueOrNullIfInvalidsafely returns nullThis ensures robust error handling for malformed headers.
94-132: Thorough tests for header modification operations.The tests verify:
- Setting headers in mutable collections works correctly
- Removing headers by setting to null works correctly
- Removing headers using the explicit
removeFrommethod works correctly- Original headers remain unchanged after transformations
These tests ensure that header modification operations work as expected while maintaining immutability of the original collections.
test/headers/typed_headers/access_control_allow_methods_header_test.dart (5)
1-4: Import reorganization improves code organization.The imports have been reorganized with the standard library first, followed by package imports. The explicit import of
standard_headers_extensions.dartmakes dependencies clearer.
29-29: AddedtouchHeadersparameter ensures proper header validation.The addition of the
touchHeadersparameter ensures that the header is accessed during tests, which is necessary for testing the validation behavior. This is consistent with the new header accessor pattern.Also applies to: 50-50, 69-70, 82-83, 101-102, 119-120, 132-133, 158-159
67-74: Test correctly verifies that invalid headers don't cause issues when not accessed.This test confirms that even with an invalid header value (
CUSTOM), no exception is thrown as long as the header is not directly accessed through the accessor. This is important for the lazy validation approach.
80-92: Tests for valid header parsing maintain coverage while using the new accessor pattern.These tests verify that:
- Valid headers are correctly parsed
- Duplicate methods are properly handled
- Wildcard headers are correctly identified
- Missing headers return null
The test expectations remain unchanged while adapting to the new accessor pattern.
Also applies to: 99-111, 117-124, 130-137
156-162: Test for header behavior in non-strict mode is correctly maintained.This test verifies that when strict validation is disabled, accessing a missing header returns null, maintaining backward compatibility with existing behavior.
test/headers/typed_headers/permissions_policy_header_test.dart (5)
1-4: Import reorganization follows consistent pattern.The imports follow the same organization pattern as other files, with standard library imports first, followed by package imports, and explicit import of extensions.
27-27: AddedtouchHeadersparameter maintains consistent pattern across tests.The addition of the
touchHeadersparameter follows the same pattern as the other header test files, ensuring consistency in how headers are accessed and validated during tests.Also applies to: 46-47, 59-60, 81-82, 99-100, 122-123
44-51: Test correctly verifies that invalid headers don't cause issues when not accessed.This test properly validates that even with an empty header value, no exception is thrown as long as the header is not directly accessed through the accessor.
57-69: Tests for policy parsing maintain coverage with new accessor pattern.These tests verify that permissions policies are correctly parsed under various conditions:
- Single policies with simple values
- Multiple policies with complex values
- Missing headers return null
The test expectations remain unchanged while adapting to the new accessor pattern.
Also applies to: 75-90, 96-103
126-128: Updated API for handling invalid headers is consistent with other tests.The test now uses
Headers.permissionsPolicy[headers].valueOrNullIfInvalidto check that invalid headers return null, followed by verifying thatheaders.permissionsPolicythrows an exception. This is consistent with the pattern used in other header tests.test/headers/typed_headers/sec_fetch_mode_header_test.dart (7)
1-3: Import structure updated to support new header handling approach.The imports now include both the main Relic package and the standard headers extensions, aligning with the PR's goal of enhancing typed access to headers.
27-28: Added touchHeaders parameter to explicitly access the secFetchMode header.This change explicitly specifies that the test is accessing the
secFetchModeheader, which is part of the new approach to handle headers in a more type-safe manner.
46-47: Consistent use of touchHeaders parameter for explicit header access.The explicit access to
secFetchModethrough the touchHeaders parameter ensures the header is processed during testing, triggering appropriate validation.
63-66: Type simplification and explicit header non-interaction.The change from
Headers headerstovar headerssimplifies the type declaration. The touchHeaders parameter with an empty function ensures the header isn't actually used, which is important for this particular test case that verifies no error is thrown when invalid headers aren't accessed.
75-78: Consistent header access pattern application.The pattern of using
varfor type declaration and explicitly touching the header is applied consistently throughout the test file.
88-91: Consistent application of the touchHeaders pattern.The pattern is applied properly to test the scenario where no header is passed.
112-115: Consistently applying touchHeaders parameter with no-op function.This change ensures the header isn't processed in the test, which aligns with testing that empty headers don't cause issues when not explicitly accessed.
test/headers/basic/last_modified_header.dart (9)
2-4: Import structure updated to support new header handling approach.The imports now properly include both the main Relic package and the standard headers extensions module.
29-30: Added touchHeaders parameter to test empty header validation.The touchHeaders parameter explicitly specifies that the test is accessing the
lastModifiedheader, ensuring proper validation is triggered.
51-52: Consistent use of touchHeaders parameter for invalid date format test.This change ensures the test explicitly accesses the header to trigger validation of the date format.
69-73: Simplified type declaration and explicit header non-interaction.The type simplification and the use of a no-op function ensure the invalid header isn't processed during this test, validating that no error is thrown when invalid headers aren't accessed.
83-87: Consistent header access pattern with explicit header touching.The pattern is applied properly to ensure the valid header is processed and its value can be properly tested.
99-103: Applied header access pattern for whitespace handling test.The touchHeaders pattern is consistently applied to test proper whitespace handling.
115-119: Applied header access pattern for null return test.The touchHeaders parameter is properly configured to test the scenario where no header is passed.
139-147: Updated test for empty headers with non-strict validation.The test has been updated to use a no-op touchHeaders function and check that the header value is properly handled as invalid.
155-163: Updated invalid header test to use new validation approach.The test now properly uses:
- A no-op touchHeaders function to avoid triggering validation during header retrieval
- The new
Headers.lastModified[headers].valueOrNullIfInvalidsyntax to check the raw value- An expectation that accessing
headers.lastModifiedthrows an InvalidHeader exceptionThis aligns with the PR's goal of improving header validation.
test/headers/typed_headers/sec_fetch_dest_header_test.dart (7)
1-3: Import structure updated to support new header handling approach.The imports now include both the main Relic package and the standard headers extensions, which is necessary for the new typed header access approach.
27-28: Added touchHeaders parameter to explicitly access the secFetchDest header.This change explicitly triggers validation of the Sec-Fetch-Dest header value, aligning with the new approach to header handling.
46-47: Consistent use of touchHeaders parameter for explicit header access.The header is explicitly accessed to test validation of invalid values.
63-66: Type simplification and explicit header non-interaction.The use of
varinstead ofHeaderssimplifies the type declaration without changing functionality. The no-op touchHeaders function ensures the invalid header isn't accessed, validating that no error is thrown in this scenario.
75-78: Consistent header access pattern application.The pattern is properly applied to test valid header parsing.
88-91: Consistent application of touchHeaders pattern.The pattern is applied consistently for the test case where no header is passed.
112-115: Consistently applying touchHeaders parameter with no-op function.This ensures the header isn't processed in the test case where an empty header is passed with non-strict validation.
test/headers/typed_headers/connection_header_test.dart (9)
1-2: Import structure updated to support new header handling approach.The imports have been updated to include both the main Relic package and the standard headers extensions module, supporting the new unified header handling approach.
28-29: Added touchHeaders parameter to test empty header validation.The touchHeaders parameter ensures the Connection header is explicitly accessed during the test, triggering validation.
50-51: Consistent use of touchHeaders parameter for invalid value validation.This change ensures the test explicitly accesses the header to trigger validation of the header value.
69-73: Type simplification and explicit header non-interaction.The type simplification to
varand the use of a no-op touchHeaders function ensure the invalid header isn't processed during this test, which is essential for verifying that no error occurs when invalid headers aren't accessed.
82-85: Consistent header access pattern with explicit header touching.The pattern is applied properly to ensure the header with directives is processed correctly.
99-102: Applied header access pattern for duplicate directives test.The touchHeaders pattern is consistently applied to test proper handling of duplicate directives.
115-118: Applied header access pattern for keep-alive test.The touchHeaders parameter is properly configured to test the keep-alive directive.
128-131: Applied header access pattern for close directive test.The touchHeaders parameter is consistently applied to test the close directive.
154-162: Updated invalid header test to use new validation approach.The test now properly:
- Uses a no-op touchHeaders function to avoid triggering validation during header retrieval
- Checks the raw value using
Headers.connection[headers].valueOrNullIfInvalid- Expects that accessing
headers.connectionthrows an InvalidHeader exceptionThis aligns with the PR's approach to improved header validation and typed access.
test/headers/basic/age_header_test.dart (9)
1-2: Updates to imports are aligned with header handling changes.The import modifications correctly reflect the restructured header handling mechanism, importing both
relic.dartand the specificstandard_headers_extensions.dartfile.Also applies to: 6-6
11-21: Test group structure improved for better readability.The test group structure has been refined with proper indentation and more descriptive formatting, improving code readability.
22-41: Successfully implemented touchHeaders parameter for empty Age header test.The addition of the
touchHeadersparameter to access the header's age property ensures that the header is properly validated during the test, aligning with the new typed header access approach.
43-83: Properly implemented touchHeaders for validation tests.The touchHeaders parameter has been correctly added to all Age header validation tests (invalid, negative, non-integer), ensuring each test properly accesses the typed header value before validation occurs.
106-119: Valid header test implementation looks good.The test for valid Age headers now includes the touchHeaders parameter while maintaining the original functionality, ensuring that the age is parsed correctly.
134-148: Whitespace handling test properly updated.The test for Age headers with extra whitespace has been properly updated with the touchHeaders parameter and maintains the same validation functionality.
148-159: Null handling test correctly modified.The test checking for null return when no Age header is present has been properly updated with the touchHeaders parameter while preserving the test's original purpose.
172-184: Non-strict mode test correctly updated.The test for empty Age headers with strict flag set to false has been updated correctly to use the touchHeaders parameter, while maintaining the appropriate assertions for valueOrNullIfInvalid and exception throwing.
188-202: Invalid header test correctly updated for non-strict mode.The test for invalid Age headers with strict flag set to false has been properly updated with touchHeaders, while maintaining the same validation behavior checking valueOrNullIfInvalid and exception throwing.
test/headers/basic/trailer_header_test.dart (8)
1-2: Imports correctly updated for header handling changes.The import modifications reflect the restructured header handling mechanism, importing both
relic.dartandstandard_headers_extensions.dart.Also applies to: 6-6
20-37: Empty trailer header test properly updated.The test for empty Trailer headers has been correctly enhanced with the touchHeaders parameter to ensure proper validation during access of the header's trailer property.
39-52: Non-used header test updated correctly.The test for unused headers has been properly updated to use the touchHeaders parameter with an empty callback, verifying that invalid headers don't cause errors when not accessed.
54-68: Valid trailer header test successfully updated.The test for valid Trailer headers now includes the touchHeaders parameter, ensuring the header is properly accessed and validated during the test.
70-84: Whitespace handling test properly modified.The test for Trailer headers with whitespace has been correctly updated with the touchHeaders parameter while maintaining the same validation functionality.
86-100: Custom values test properly updated.The test for Trailer headers with custom values has been correctly modified to include the touchHeaders parameter, ensuring proper validation during access.
102-113: Null check test updated with a different header property.The test for null return when no Trailer header is passed now uses the touchHeaders parameter to access the lastModified property instead. This demonstrates that accessing one property doesn't affect others.
125-136: Non-strict mode test correctly updated.The test for custom Trailer headers with strict flag set to false has been properly updated with the touchHeaders parameter, ensuring proper header handling in non-strict mode.
lib/src/message/request.dart (1)
137-137:Details
✅ Verification successful
Changed default headers initialization to Headers.empty().
This is a deliberate breaking change that aligns with the PR objective of enhancing header handling. The change from
Headers.request()toHeaders.empty()eliminates the distinction between standard and custom headers and reduces memory overhead by not initializing unnecessary header data.
🏁 Script executed:
#!/bin/bash # Verify that Headers.empty() exists and is used correctly # Look for the definition of Headers.empty() rg "factory Headers.empty" --type dartLength of output: 113
Default Headers Initialization Change Verified
The change to initialize default headers using
Headers.empty()is correct. The shell script output confirms thatHeaders.empty()is defined as intended inlib/src/headers/headers.dart(line containingfactory Headers.empty() => _emptyHeaders;). This change, designed to eliminate unnecessary overhead and the distinction between standard and custom headers, is verified and aligns with the PR objective.
- File Verified:
lib/src/headers/headers.dartcontains the proper definition forHeaders.empty().- Affected File:
lib/src/message/request.dartat line 137 whereheaders ?? Headers.empty(),is used.test/headers/typed_headers/etag_header_test.dart (8)
1-3: Imports updated for the new header handling mechanism.The import changes correctly reflect the restructured header handling, adding the specific import for standard_headers_extensions.dart.
20-40: Empty ETag header test properly updated.The test for empty ETag headers now includes the touchHeaders parameter to properly access and validate the header's etag property during the test.
42-61: Invalid ETag test correctly updated.The test for invalid ETag headers has been properly updated with the touchHeaders parameter, ensuring proper validation occurs during header access.
63-76: Unused invalid header test properly updated.The test for unused invalid headers has been correctly updated to use touchHeaders with an empty callback, verifying that invalid headers don't cause errors when not accessed.
78-90: Strong ETag validation test successfully updated.The test for valid strong ETag headers now includes the touchHeaders parameter, ensuring proper access and validation of the etag property and its isWeak flag.
92-104: Weak ETag validation test properly updated.The test for valid weak ETag headers has been correctly updated with the touchHeaders parameter, maintaining the same validation of both the etag value and isWeak flag.
106-117: Null check test correctly modified.The test for null return when no ETag header is passed has been properly updated with the touchHeaders parameter while preserving its original validation purpose.
129-143: Non-strict mode test updated with new validation approach.The test for invalid ETag headers in non-strict mode now:
- Uses touchHeaders with an empty callback
- Validates using
Headers.etag[headers].valueOrNullIfInvalidinstead of checking failedHeadersToParse- Correctly verifies that accessing headers.etag throws an invalid header exception
This aligns with the PR's goal of consolidating header access and validation.
test/headers/typed_headers/access_control_expose_headers_header_test.dart (3)
30-30: Consistent implementation of touchHeaders parameter across test casesThe addition of the
touchHeadersparameter in allgetServerRequestHeaderscalls enhances test precision by explicitly specifying when theAccess-Control-Expose-Headersheader should be accessed. This change aligns with the PR objective of supporting typed access to all headers and ensures that headers are only processed when needed.Also applies to: 53-53, 74-74, 88-88, 104-104, 118-118, 132-132, 151-151, 184-184
72-72: Improved type flexibility with 'var' instead of explicit 'Headers'Changing from explicit
Headerstype tovarsimplifies the code while maintaining type safety through inference. This change aligns with modern Dart practices and the PR's goal of enhancing header handling.Also applies to: 86-86, 102-102, 116-116, 130-130, 149-149, 182-182
189-191: Clear exception-based invalid header handlingThe updated assertions properly test both the low-level accessor behavior (
valueOrNullIfInvalid) and the high-level extension property behavior (throwingInvalidHeaderexception). This ensures proper validation throughout the header access chain.lib/src/headers/typed/headers/vary_header.dart (3)
12-12: Enhanced flexibility with Iterable type for fields propertyChanging
fieldsfromList<String>?toIterable<String>?increases flexibility by allowing any iterable collection of strings to be used, not just Lists. This change aligns with the broader objective of improving the header handling system.
28-28: Broadened input parameter type for VaryHeader.parse methodUpdating the
parsemethod to acceptIterable<String>instead ofList<String>maintains consistency with thefieldsproperty and provides more flexibility in how header values can be provided to the parser.
29-54: LGTM - Implementation adapts well to the new Iterable typeThe implementation correctly handles the
Iterabletype throughout the class. The parsing logic, wildcard handling, and string conversion all work properly with the more generic collection type.test/headers/typed_headers/content_encoding_header_test.dart (3)
28-28: Consistent implementation of touchHeaders parameter across test casesThe addition of the
touchHeadersparameter ingetServerRequestHeaderscalls ensures that thecontentEncodingheader is explicitly accessed when needed for testing. This approach validates the header behavior more accurately and aligns with the PR objective of improving typed header access.Also applies to: 50-50, 71-71, 84-84, 100-100, 114-114, 130-130, 146-146, 174-174
69-69: Improved type flexibility with 'var' instead of explicit 'Headers'Using type inference with
varmakes the code more concise while maintaining type safety. This change is consistent across all test files and improves readability.Also applies to: 82-82, 98-98, 112-112, 128-128, 144-144, 172-172
178-179: Clear exception-based invalid header handlingThe updated assertions properly validate both the accessor behavior and the exception thrown when accessing invalid headers. This ensures the header validation system works as expected throughout the application.
test/headers/typed_headers/te_header_test.dart (3)
28-28: Consistent implementation of touchHeaders parameter across TE header testsThe addition of the
touchHeadersparameter in all test cases ensures that theteheader is explicitly accessed when needed for testing. This consistent implementation aligns with the PR objective of improving typed header access and ensures test precision.Also applies to: 50-50, 72-72, 93-93, 107-107, 124-124, 140-140, 154-154, 170-170, 186-186, 202-202, 230-230, 246-246
91-91: Improved type flexibility with 'var' instead of explicit 'Headers'Using type inference with
varmakes the code more concise while maintaining type safety. This change is consistent with modern Dart practices and improves code readability.Also applies to: 105-105, 122-122, 138-138, 152-152, 168-168, 184-184, 200-200, 228-228, 244-244
234-235: Clear exception-based invalid header handlingThe updated assertions properly test both the low-level accessor behavior (
valueOrNullIfInvalid) and the high-level extension property behavior (throwingInvalidHeaderexception). This ensures proper validation throughout the TE header access chain.Also applies to: 250-251
lib/src/headers/typed/headers/cache_control_header.dart (2)
28-45: Improved type flexibility with IterableChanging from
List<String>toIterable<String>is a good enhancement that makes the code more flexible, allowing it to work with any iterable collection of strings rather than just lists.
128-128: Consistent type flexibility in parse methodUpdating the parameter type from
List<String>toIterable<String>aligns with the change to_validDirectivesand allows the method to accept any iterable collection, following good API design principles.lib/src/message/response.dart (2)
5-8: Improved import organizationThe reorganization of imports, including the addition of standard headers extensions, helps with code organization and makes dependencies clearer.
47-47:Details
❓ Verification inconclusive
Refactored header initialization
Changing from
Headers.response()toHeaders.empty()across all response constructors simplifies header initialization. The transformation approach used in the_redirectconstructor (transform((mh) => mh.location = location)) is more consistent with the new header handling system described in the PR.Some of these changes lack test coverage according to static analysis. Let's verify which response types might need additional tests:
Also applies to: 124-125, 141-141, 163-163, 178-178, 197-197, 215-215, 234-234, 253-253, 272-272, 291-291
🏁 Script executed:
#!/bin/bash # Check for test coverage of Response constructors echo "Looking for tests of Response.noContent and Response.notImplemented..." rg -A 3 "Response.(noContent|notImplemented)" test/Length of output: 204
Attention: Verify Test Coverage for Refactored Header Initialization
The header initialization change (switching from
Headers.response()toHeaders.empty()) in the main response constructor—illustrated by:headers: headers ?? Headers.empty(),—appears to simplify and standardize how headers are set across all response constructors (e.g., via the
_redirectconstructor’stransform((mh) => mh.location = location)transformation). However, our static analysis for the test suite did not return any matches for tests coveringResponse.noContentandResponse.notImplemented. This raises concerns that these (and potentially other) response types may not be adequately tested.Next Steps:
Test Coverage:
- Please verify manually whether tests exist for the following response types:
Response.noContentResponse.notImplemented- Additionally, review any related constructor changes on lines: 124-125, 141-141, 163-163, 178-178, 197-197, 215-215, 234-234, 253-253, 272-272, and 291-291.
Action:
- If tests are missing for any of these response types, please add the necessary coverage to ensure that all header-related refactoring is fully verified through testing.
test/headers/typed_headers/authorization_header_test.dart (4)
1-6: Updated imports for consistencyThe import changes align with the refactored header handling system introduced in this PR.
30-30: Added touchHeaders parameter for explicit header accessThe addition of the
touchHeadersparameter across test cases improves test precision by explicitly specifying which headers should be accessed. This aligns with the PR's goal of allowing typed access to all headers.Also applies to: 51-52, 64-65, 80-81, 99-100, 144-145, 191-192, 214-215, 238-239, 262-263, 286-287, 312-313, 335-336, 359-360, 383-384, 407-408, 430-431, 452-453, 490-491, 506-507
49-53: Simplified variable type declarationsChanging from explicit
Headerstype tovarmakes the code less verbose without affecting functionality. This is a good simplification.Also applies to: 97-101, 142-146, 428-432, 450-454, 488-492, 504-508
494-496: Enhanced invalid header validationThe new approach to checking invalid headers using
valueOrNullIfInvalidand explicitly testing for exceptions withthrowsInvalidHeaderprovides more robust validation. This change is consistent with the PR's goal of improving header handling.Also applies to: 510-512
test/headers/typed_headers/access_control_allow_origin_header_test.dart (4)
1-7: Updated imports for header accessibilityThe changes to imports improve organization and align with the refactored header system.
29-30: Consistent header access with touchHeaders parameterThe consistent use of the
touchHeadersparameter across test cases improves test precision and makes the tests more resilient to changes in the header implementation.Also applies to: 51-52, 73-74, 96-97, 110-111, 127-128, 144-145, 161-162, 175-176, 201-202
94-98: Simplified variable type declarationsChanging from explicit
Headerstype tovarsimplifies the code without affecting functionality, following the same pattern as in other test files.Also applies to: 108-112, 125-129, 142-146, 159-163, 173-177, 199-203
205-208: Enhanced invalid header validationThe new validation approach using
valueOrNullIfInvalidand checking for exceptions withthrowsInvalidHeaderprovides consistent and robust header validation across test files.test/headers/typed_headers/clear_site_data_header_test.dart (10)
1-3: Import changed to include standard headers extensionsThe import statement now includes
standard_headers_extensions.dart, which provides access to header accessors that are used throughout the tests.
28-28: Added touchHeaders parameter to access clearSiteData headerThe
touchHeadersparameter is now used to explicitly access theclearSiteDataheader during tests. This is part of the new header accessor approach where headers are only parsed when accessed.
48-48: Added touchHeaders parameter to access clearSiteData headerSimilar to the previous test, adding the
touchHeadersparameter to trigger header parsing.
68-68: Added touchHeaders parameter to access clearSiteData headerThe
touchHeadersparameter is being added consistently across all tests to ensure the header is properly accessed.
85-88: Changed Headers type to var and added touchHeaders parameterThe explicit
Headerstype declaration is changed tovarfor simpler code maintenance, and thetouchHeadersparameter is added to ensure we're not touching theclearSiteDataheader in this test.
97-100: Changed Headers type to var and added touchHeaders parameterSimilar to previous changes, this simplifies the type declaration and adds explicit header access through the touchHeaders parameter.
115-118: Changed Headers type to var and added touchHeaders parameterConsistent with the pattern of changes applied to all tests in this file.
128-131: Changed Headers type to var and added touchHeaders parameterConsistent application of the same pattern to maintain uniformity across all tests.
152-155: Changed Headers type to var and added touchHeaders parameterSimplified type declaration and added the touchHeaders parameter to avoid accessing the header in this specific test case.
158-159: Updated assertion to use the new header accessor approachThe test now properly checks that the
clearSiteDatavalue is null when accessed via the accessor, and that attempting to directly access it throws an InvalidHeader exception. This reflects the new typed header access design.test/headers/typed_headers/proxy_authorization_header_test.dart (24)
1-5: Import changed to include standard headers extensionsThe import statement now includes
standard_headers_extensions.dart, which provides access to header accessors that are used throughout the tests.
30-31: Added touchHeaders parameter to access proxyAuthorization headerThe
touchHeadersparameter is now used to explicitly access theproxyAuthorizationheader during tests, aligning with the new approach where headers are only parsed when accessed.
49-52: Changed Headers type to var and added touchHeaders parameterThe explicit
Headerstype declaration is changed tovarfor simpler code maintenance, and thetouchHeadersparameter is added with an empty function to ensure we're not touching any headers in this test.
64-68: Changed Headers type to var and updated touchHeaders parameter placementSimplified type declaration and adjusted the parameter order to maintain consistency with other tests.
82-83: Added touchHeaders parameter to access proxyAuthorization headerConsistent application of the touchHeaders parameter pattern across all tests in the file.
99-102: Changed Headers type to var and added touchHeaders parameterSimplified type declaration and added explicit header access through the touchHeaders parameter.
124-125: Added touchHeaders parameter to access proxyAuthorization headerContinuing the consistent pattern of adding the touchHeaders parameter to all tests.
166-167: Added touchHeaders parameter to access proxyAuthorization headerKeeping the touchHeaders parameter consistent across all tests that access the proxyAuthorization header.
191-192: Added touchHeaders parameter to access proxyAuthorization headerMaintaining consistency in the application of the touchHeaders parameter.
214-215: Added touchHeaders parameter to access proxyAuthorization headerConsistent application of the touchHeaders parameter pattern.
238-239: Added touchHeaders parameter to access proxyAuthorization headerContinuing the pattern of adding the touchHeaders parameter to all tests that access the header.
262-263: Added touchHeaders parameter to access proxyAuthorization headerFollowing the established pattern for consistency across tests.
286-287: Added touchHeaders parameter to access proxyAuthorization headerMaintaining the consistent approach to header access in tests.
312-313: Added touchHeaders parameter to access proxyAuthorization headerConsistent with the established pattern across all tests.
335-336: Added touchHeaders parameter to access proxyAuthorization headerContinuing the consistent application of the touchHeaders parameter.
359-360: Added touchHeaders parameter to access proxyAuthorization headerFollowing the established pattern for consistency.
383-384: Added touchHeaders parameter to access proxyAuthorization headerMaintaining consistency in the application of the touchHeaders parameter.
407-408: Added touchHeaders parameter to access proxyAuthorization headerConsistent with the pattern applied throughout the file.
428-431: Changed Headers type to var and added touchHeaders parameterSimplified type declaration and added explicit header access through the touchHeaders parameter, maintaining consistency with other tests.
449-452: Changed Headers type to var and added touchHeaders parameterSimilar to previous changes, simplifying the type declaration and adding explicit header access.
486-489: Changed Headers type to var and added touchHeaders parameterConsistent application of the same changes as in previous tests, with an empty function to ensure we're not touching any headers.
492-493: Updated assertion to use the new header accessor approachThe test now properly checks that the
proxyAuthorizationvalue is null when accessed via the accessor, and that attempting to directly access it throws an InvalidHeader exception. This reflects the new header accessor approach.
502-505: Changed Headers type to var and added touchHeaders parameterConsistent application of the pattern seen throughout the file.
509-510: Updated assertion to use the new header accessor approachSimilar to the previous assertion update, this properly checks the behavior with invalid headers using the new accessor approach.
test/headers/typed_headers/referrer_policy_header_test.dart (8)
1-3: Import changed to include standard headers extensionsThe import statement now includes
standard_headers_extensions.dart, which provides access to header accessors that are used throughout the tests.
27-28: Added touchHeaders parameter to access referrerPolicy headerThe
touchHeadersparameter is now used to explicitly access thereferrerPolicyheader during tests, aligning with the new approach where headers are only parsed when accessed.
46-47: Added touchHeaders parameter to access referrerPolicy headerContinuing the consistent pattern of adding the touchHeaders parameter to all tests that access the header.
63-66: Changed Headers type to var and added touchHeaders parameterThe explicit
Headerstype declaration is changed tovarfor simpler code maintenance, and thetouchHeadersparameter is added with an empty function to ensure we're not touching any headers in this test.
76-79: Changed Headers type to var and added touchHeaders parameterSimplified type declaration and added explicit header access through the touchHeaders parameter.
89-92: Changed Headers type to var and added touchHeaders parameterConsistent application of the same changes as in previous tests.
113-116: Changed Headers type to var and added touchHeaders parameterConsistent application of the pattern seen throughout the file, with an empty function to ensure we're not touching any headers.
119-120: Updated assertion to use the new header accessor approachThe test now properly checks that the
referrerPolicyvalue is null when accessed via the accessor, and that attempting to directly access it throws an InvalidHeader exception. This reflects the new header accessor approach.test/headers/basic/max_forwards_header_test.dart (11)
1-3: Import changed to include standard headers extensionsThe import statement now includes
standard_headers_extensions.dart, which provides access to header accessors that are used throughout the tests.
11-21: Reformatted group declaration and setupThe group declaration and setup have been reformatted for improved readability while maintaining the same functionality.
22-42: Reformatted test for empty Max-Forwards header and added touchHeaders parameterThe test has been reformatted for improved readability and the
touchHeadersparameter has been added to explicitly access themaxForwardsheader during the test.
44-64: Reformatted test for negative Max-Forwards header and added touchHeaders parameterSimilar to the previous test, this has been reformatted and the
touchHeadersparameter has been added for consistency with the new header accessor approach.
66-86: Reformatted test for non-integer Max-Forwards header and added touchHeaders parameterContinuing the pattern of reformatting tests and adding the
touchHeadersparameter for explicit header access.
88-101: Added new test case for invalid Max-Forwards header with touchHeaders parameterThis test ensures that invalid headers don't cause errors if they're not actually accessed, using the new touchHeaders parameter with an empty function.
103-114: Reformatted test for valid Max-Forwards header and added touchHeaders parameterContinuing the consistent pattern of reformatting and adding the touchHeaders parameter.
116-129: Reformatted test for zero Max-Forwards header and added touchHeaders parameterSimilar to previous tests, this has been reformatted and updated to include the touchHeaders parameter.
130-142: Reformatted test for no Max-Forwards header and added touchHeaders parameterFinal test in this group follows the same pattern of reformatting and adding the touchHeaders parameter.
144-153: Added new group for testing with strict flag set to falseThis new group ensures comprehensive testing of the Max-Forwards header behavior when strict validation is disabled.
154-166: Added test for invalid Max-Forwards header with strict flag falseThis test ensures proper handling of invalid headers when strict validation is disabled, using the new header accessor approach.
lib/src/headers/typed/headers/content_language_header.dart (2)
9-9: Type generalization enhances API flexibilityChanging from
List<String>toIterable<String>makes the API more flexible by allowing any iterable collection of strings, not just lists. This follows the interface segregation principle, requiring only the minimum interface needed (iteration).
17-17: Consistent parameter type generalizationThe factory method parameter type change from
List<String>toIterable<String>aligns with the property type change, creating a consistent API. This enables callers to use any iterable collection, improving flexibility while maintaining the internal implementation that converts to a list.test/headers/typed_headers/content_disposition_header_test.dart (4)
1-3: Import updates align with header access refactoringThe addition of
standard_headers_extensions.dartimport provides access to the new header extension methods, supporting the refactored header access approach.
27-27: Explicit header access with touchHeaders parameterThe new
touchHeadersparameter explicitly defines which headers should be accessed during the test. This enables testing the header validation behavior while supporting the lazy header parsing and caching mechanisms introduced in this PR.
44-47: Type inference simplification with intentional empty header touchReplacing explicit
Headerstype withvarsimplifies the code by leveraging Dart's type inference. The emptytouchHeadersfunction ensures no headers are accessed during this test phase, allowing validation of behavior when headers exist but aren't used.
156-158: Updated invalid header validation approachThe validation logic now uses
Headers.contentDisposition[headers].valueOrNullIfInvalidfor checking null values and expects athrowsInvalidHeaderexception when accessing invalid headers directly. This reflects the new exception-based approach to handling invalid headers, improving error handling clarity.test/headers/typed_headers/expect_header_test.dart (3)
1-3: Import updates for header extensionsThe addition of
standard_headers_extensions.dartimport provides access to the new header extension methods, supporting the refactored header access approach.
28-28: Consistent touchHeaders parameter implementationThe new
touchHeadersparameter has been consistently implemented across all test cases, explicitly defining which headers should be accessed during each test. This is part of the broader refactoring to support lazy header parsing and validation with the newHeaderAccessorpattern.Also applies to: 49-49, 67-69, 80-82, 108-109
112-113: Updated invalid header validation approachThe validation logic now uses
Headers.expect[headers].valueOrNullIfInvalidand expects athrowsInvalidHeaderexception when directly accessing invalid headers. This change aligns with the new exception-based invalid header handling throughout the codebase.test/headers/basic/host_header_test.dart (3)
1-3: Import updates for header extensionsReplacing
headers.dartwithstandard_headers_extensions.dartprovides access to the new header extension methods, supporting the refactored header access approach.
29-29: Comprehensive touchHeaders parameter implementationThe
touchHeadersparameter has been thoroughly implemented across all test cases in this file, explicitly controlling which headers are accessed in each test scenario. This supports the new lazy header parsing and caching mechanisms, ensuring headers are properly validated only when explicitly accessed.Also applies to: 51-51, 73-73, 93-95, 107-107, 121-121, 137-137, 150-151, 175-176, 191-192
179-180: Exception-based invalid header handlingThe validation approach now uses
Headers.host[headers].valueOrNullIfInvalidfor checking null values and expects athrowsInvalidHeaderexception when directly accessing invalid headers. This aligns with the new exception-based approach to invalid header handling throughout the codebase.lib/relic.dart (2)
14-15: Broader API exposure enhances header handling flexibilityThese changes remove the restrictive
show Headersclause and add a new export forheader_accessor.dart, exposing the full API surface of the Headers module and introducing the newHeaderAccessorclass. This aligns with the PR objective of treating all headers (both standard and custom) as typed values.
17-18: Enhanced exception handling with consolidated header exceptionsThe export changes consolidate header-related exceptions under a single file and introduce a proper hierarchy with
HeaderExceptionas the base class. This provides better organization and more specific error handling capabilities withInvalidHeaderExceptionandMissingHeaderException.lib/src/headers/typed/headers/access_control_expose_headers_header.dart (2)
10-10: Improved flexibility with broader type acceptanceChanging from
List<String>?toIterable<String>?allows for a wider range of collection types to be accepted. This provides more flexibility and is consistent with the broader header handling refactoring in the PR.
26-26: Consistency improvement in parse method signatureUpdating the
parsemethod to acceptIterable<String>instead ofList<String>maintains consistency with the property type change and allows for more flexible usage patterns when parsing header values.lib/src/headers/mutable_headers.dart (3)
1-11: Good introduction of MutableHeaders with clear relationshipsThe
MutableHeadersclass nicely extendsHeadersBaseand implementsMapMixin<String, Iterable<String>>to provide a mutable headers implementation. The constructors are well-designed, allowing for both creating new instances and building from existing Headers objects.
12-19: Consider addressing the TODO for better object lifecycle managementThe
_freeze()method contains a TODO comment indicating a potential improvement to decouple the backing store from theMutableHeadersobject. This is a good consideration for preventing memory leaks and ensuring proper object lifecycle management.The current implementation still works, but consider implementing the suggested improvement in a future update to prevent potential issues where callers might hold onto mutable headers after freezing.
21-41: Clean implementation of map operations for header managementThe implementation of the Map interface methods is clear and concise. The code correctly handles setting null values by removing the key, and the other operations align well with expected Map behavior.
test/headers/typed_headers/range_header_test.dart (8)
1-3: Appropriate imports for enhanced header handlingAdding the import for
standard_headers_extensions.dartis necessary to support the new header access patterns used in the updated tests.
25-39: Improved test pattern with explicit header touchingThe addition of the
touchHeaders: (h) => h.rangeparameter ensures that the range header is explicitly accessed during testing, which aligns with the new caching mechanism introduced in the PR. This change helps validate that the header accessor properly triggers validation when accessed.
46-59: Consistent test pattern applicationSimilar to the previous test, this update ensures that range header validation is properly triggered when the header is accessed, maintaining consistent testing patterns throughout the file.
67-80: Appropriate validation testing with proper header accessThis test case properly validates the behavior when both start and end ranges are empty, ensuring that the appropriate exception is thrown when the header is accessed.
89-96: Good test for conditional header validationThis test verifies that invalid headers don't cause exceptions when they're not actually accessed, using
touchHeaders: (_) {}to explicitly not touch any headers. This is important for validating the lazy validation behavior in the new header implementation.
103-113: Type simplification with maintained functionalityChanging from explicit
Headerstype tovarsimplifies the code without losing type safety, as the type is inferred from the method return value. Combined with the header touching pattern, this maintains the test's effectiveness.
120-130: Consistent application of the new testing patternThese changes maintain consistency throughout the test file, applying the same pattern of simplified type declarations and explicit header touching for proper validation testing.
Also applies to: 137-147, 153-160, 167-183, 189-197
215-223: Updated assertion pattern for invalid headersThe updated assertions correctly test both the accessor API (
Headers.range[headers].valueOrNullIfInvalid) and direct property access (headers.range), ensuring that invalid headers are properly handled in both cases.test/headers/typed_headers/transfer_encoding_header_test.dart (11)
1-3: Added import for standard_headers_extensions.The addition of this import is needed to support the new typed header functionality, enabling access to the extensions for standard headers.
26-30: Added touchHeaders parameter to properly trigger header validation.The new
touchHeadersparameter ensures that thetransferEncodingheader is accessed during the test, which is essential for triggering the validation logic. This is consistent with the new header accessor pattern introduced in this PR.
46-50: Consistent pattern for testing invalid header values.The touchHeaders parameter is correctly implemented here to test the validation logic for invalid transfer encoding values.
65-68: Testing non-validation when header isn't accessed.This test correctly uses
touchHeaders: (_) {}to verify that invalid headers don't cause errors when they aren't actually accessed during request processing.
78-81: Accessing header for validation during parsing test.The touchHeaders parameter ensures the transferEncoding header is accessed during the test, verifying the correct parsing of encodings.
98-101: Testing header reordering behavior.The touchHeaders parameter ensures the transferEncoding header is accessed during the test, allowing verification of the correct reordering of encodings (chunked must be last).
115-118: Testing duplicate removal behavior.The touchHeaders parameter ensures the transferEncoding header is accessed during the test, allowing verification of duplicate removal functionality.
132-134: Testing chunked encoding detection.The touchHeaders parameter ensures the transferEncoding header is accessed during the test, enabling verification of the chunked encoding detection.
149-151: Testing null case for missing header.The touchHeaders parameter ensures the transferEncoding header is accessed during the test, even when the header isn't present in the request.
175-176: Updated invalid header access pattern.The touchHeaders parameter set to no-op ensures the header isn't accessed during initial parsing, allowing tests for the new invalid header handling mechanism using
Headers.transferEncoding[headers].valueOrNullIfInvalid.
179-181: Testing invalid header exception behavior.The test now properly verifies both the valueOrNullIfInvalid functionality and that accessing an invalid header directly throws an exception.
test/headers/typed_headers/content_range_header_test.dart (12)
1-3: Added import for standard_headers_extensions.The addition of this import is needed to support the new typed header functionality, enabling access to the extensions for standard headers.
28-29: Added touchHeaders parameter to properly trigger header validation.The new
touchHeadersparameter ensures that thecontentRangeheader is accessed during the test, which is essential for triggering the validation logic for empty headers.
50-51: Testing validation of non-numeric characters.The touchHeaders parameter ensures the contentRange header is accessed during the test, triggering validation for invalid format with non-numeric characters.
72-73: Testing validation of negative numbers.The touchHeaders parameter ensures the contentRange header is accessed during the test, triggering validation for invalid format with negative numbers.
94-95: Testing validation of invalid range (start > end).The touchHeaders parameter ensures the contentRange header is accessed during the test, triggering validation for an invalid range where start is greater than end.
113-116: Testing non-validation when header isn't accessed.This test correctly uses
touchHeaders: (_) {}and simplified variable type to verify that invalid headers don't cause errors when they aren't actually accessed during request processing.
127-130: Testing valid byte range parsing.The touchHeaders parameter ensures the contentRange header is accessed during the test, allowing verification of correct parsing for a valid byte range.
144-147: Testing unknown size parsing.The touchHeaders parameter ensures the contentRange header is accessed during the test, allowing verification of correct parsing for a valid byte range with unknown size.
161-164: Testing unsatisfiable range parsing.The touchHeaders parameter ensures the contentRange header is accessed during the test, allowing verification of correct parsing for an unsatisfiable range.
177-180: Testing null case for missing header.The touchHeaders parameter ensures the contentRange header is accessed during the test, even when the header isn't present in the request.
201-204: Updated test for invalid header handling.The test now uses a simpler variable type declaration and the touchHeaders parameter set to no-op, properly setting up the test for the new invalid header handling behavior.
207-208: Testing invalid header exception behavior.The test now properly verifies both the valueOrNullIfInvalid functionality and that accessing an invalid header directly throws an exception, aligning with the new header accessor pattern.
test/headers/typed_headers/content_language_header_test.dart (11)
1-3: Added import for standard_headers_extensions.The addition of this import is needed to support the new typed header functionality, enabling access to the extensions for standard headers.
28-29: Added touchHeaders parameter to properly trigger header validation.The new
touchHeadersparameter ensures that thecontentLanguageheader is accessed during the test, which is essential for triggering the validation logic for empty headers.
49-50: Testing validation of invalid language code.The touchHeaders parameter ensures the contentLanguage header is accessed during the test, triggering validation for invalid language codes.
68-71: Testing non-validation when header isn't accessed.This test correctly uses
touchHeaders: (_) {}and simplified variable type to verify that invalid headers don't cause errors when they aren't actually accessed during request processing.
81-84: Testing valid single language parsing.The touchHeaders parameter ensures the contentLanguage header is accessed during the test, allowing verification of correct parsing for a single valid language.
93-96: Testing multiple languages parsing.The touchHeaders parameter ensures the contentLanguage header is accessed during the test, allowing verification of correct parsing for multiple valid languages.
103-106: Testing whitespace handling in language parsing.The touchHeaders parameter ensures the contentLanguage header is accessed during the test, allowing verification of whitespace handling in language parsing.
115-118: Testing duplicate language handling.The touchHeaders parameter ensures the contentLanguage header is accessed during the test, allowing verification of duplicate removal functionality for languages.
128-131: Testing null case for missing header.The touchHeaders parameter ensures the contentLanguage header is accessed during the test, even when the header isn't present in the request.
152-155: Updated test for invalid header handling.The test now uses a simpler variable type declaration and the touchHeaders parameter set to no-op, properly setting up the test for the new invalid header handling behavior.
158-159: Testing invalid header exception behavior.The test now properly verifies both the valueOrNullIfInvalid functionality and that accessing an invalid header directly throws an exception, aligning with the new header accessor pattern.
lib/src/headers/extension/string_list_extensions.dart (5)
3-3: Broadened extension to work with any iterable of strings.Good change! Modifying the extension to work with
Iterable<String>instead of justList<String>makes it more flexible and usable with a wider variety of string collections (like Sets, custom iterables, etc.).
17-17: Return more flexible Iterable type instead of concrete List.This change aligns with the extension modification, making the method signature return
Iterable<String>rather thanList<String>. This provides more flexibility to callers and better expresses the intent - the method doesn't need to specifically return a List implementation.
24-24: Optimized implementation to return set directly.Improved the implementation by directly returning the
LinkedHashSet(which implementsIterable<String>) rather than first creating a set and then converting it to a list. This is more efficient and matches the new return type.
42-42: Updated StringExtensions for consistency.Changed the return type to
Iterable<String>for consistency with the changes to theStringListExtensionsextension, maintaining a uniform API.
50-50: Simplified return to match new return type.Like the change in the
StringListExtensionsextension, this change directly returns aLinkedHashSetfor improved efficiency.lib/src/relic_server.dart (5)
5-6: Updated imports to support the new header handling architecture.The imports have been updated to include the new header exception handling and standard headers extensions, which aligns with the PR's objective to enhance header handling with typed access.
118-118: Header exception handling has been consolidated.Replaced
InvalidHeaderExceptionwith the more generalHeaderExceptionto catch all header-related exceptions in one place, improving error handling consistency.
155-161: Improved header management with transform method.The header management has been simplified using a transform method instead of conditional checks, making the code more concise and maintainable.
162-162: Consistent header exception handling.Updated to catch the more general
HeaderExceptionin line with the changes to the exception hierarchy.
208-208: Streamlined exception handling for response writing.Updated to use the consolidated
HeaderExceptionwhen writing the HTTP response, maintaining consistency in error handling throughout the code.test/headers/typed_headers/set_cookie_header_test.dart (4)
1-4: Updated imports for the new header architecture.The imports now correctly include the standard headers extensions which are necessary for the new typed access to headers.
26-27: Added touchHeaders parameter for explicit header access.The
touchHeadersparameter has been added to specify which headers should be processed during testing. This is part of the new approach to typed header access, allowing for more explicit testing of header functionality.Also applies to: 48-49, 70-71, 90-91, 111-112, 132-133, 153-154, 174-175, 187-188, 201-202, 225-226
172-176: Updated variable declaration for better flexibility.Changed from explicit
Headers headerstype tovar headersfor better flexibility with the new header accessor pattern.
255-256: Updated to use the new header accessor pattern.The test now uses the new
Headers.setCookie[headers].valueOrNullIfInvalidaccessor pattern and throws anInvalidHeaderexception when trying to access an invalid header directly. This aligns with the PR's objective to enhance typed access to headers.lib/src/headers/typed/headers/access_control_allow_headers_header.dart (2)
10-10: Enhanced flexibility by using Iterable instead of List.Changed the header type from
List<String>?toIterable<String>?to allow for a broader range of collection types, improving the API's flexibility.
26-26: Updated parse method to accept any Iterable.Changed the parameter type of the
parsefactory method fromList<String>toIterable<String>to be consistent with the property type change and enhance flexibility.test/headers/basic/referer_header_test.dart (3)
1-3: Updated imports for the new header architecture.The imports have been updated to include the necessary standard headers extensions, which support the typed header access feature.
11-162: Restructured tests for the new header access pattern.The tests have been restructured to use the new
touchHeadersparameter, which explicitly specifies which headers to process. This ensures consistent testing across the codebase and aligns with the PR's objective to enhance typed access to headers.
183-184: Updated assertions to use the new header accessor pattern.The test now uses the new
Headers.referer[headers].valueOrNullIfInvalidaccessor pattern and checks forthrowsInvalidHeaderwhen trying to access an invalid header directly, which aligns with the PR's goal of improving typed access to custom headers.test/headers/basic/access_control_max_age_header_test.dart (5)
1-2: Appropriate imports for the updated header handling.The imports are correctly updated to include both the main Relic package and the standard headers extensions.
11-21: Well-structured test organization.The group structure follows best practices with clear setup and teardown methods, making the test flow easy to follow.
27-32: Good implementation of touchHeaders parameter.The new
touchHeadersparameter ensures that theaccessControlMaxAgeheader is explicitly accessed during testing, aligning with the new typed header access approach.
93-117: Great test coverage for edge cases.The additional tests for whitespace handling and missing headers improve test coverage and ensure robust behavior.
125-135: Good use of the new header accessor API.This test correctly demonstrates how to use
Headers.accessControlMaxAge[Headers]with the new accessor pattern, showcasing both valueOrNullIfInvalid and proper exception handling.test/headers/typed_headers/accept_ranges_header_test.dart (3)
27-28: Good use of touchHeaders parameter.The touchHeaders parameter correctly accesses the acceptRanges property, which aligns with the new typed header access strategy.
44-48: Appropriate simplification of type declaration.Changing from explicit
Headerstype tovarsimplifies the code while maintaining functionality. The touchHeaders parameter correctly bypasses header validation when appropriate.
115-117: Improved exception handling for invalid headers.The test now correctly expects an exception to be thrown when accessing an invalid header, which is more aligned with the new exception handling approach for headers.
expect(Headers.acceptRanges[headers].valueOrNullIfInvalid, isNull); expect(() => headers.acceptRanges, throwsInvalidHeader);test/headers/typed_headers/if_none_match_header_test.dart (3)
1-3: Correctly updated imports.The imports have been updated to include the needed extensions for standard headers.
28-30: Good implementation of touchHeaders parameter.The touchHeaders parameter correctly accesses the ifNoneMatch property, activating the typed header access for testing.
235-237: Improved exception handling approach.The test now properly checks for both the valueOrNullIfInvalid safe access and that direct access throws an exception, which provides better validation of the error handling behavior.
test/headers/typed_headers/if_match_header_test.dart (3)
1-3: Correctly updated imports.The imports have been properly updated to include the standard headers extensions, which are needed for the new typed header access.
90-94: Good implementation of touchHeaders parameter with simplified type.The code correctly uses
varfor the headers variable and implements touchHeaders to bypass validation when needed, which aligns with the PR's goal of only processing headers that are actually used.
235-237: Improved exception handling for invalid headers.The test correctly checks both the valueOrNullIfInvalid approach for safe access and verifies that direct access throws an exception, providing comprehensive validation of the error handling.
test/headers/basic/allow_header_test.dart (3)
31-31: Approve the new touchHeaders parameterThe addition of the
touchHeadersparameter is a good implementation that explicitly indicates which header is being accessed during testing. This approach aligns with the PR objective of enabling typed access to headers.
66-79: Good test for lazy validationExcellent addition of a test that verifies headers with invalid values don't cause exceptions when they aren't actually used. This validates the lazy validation behavior, which is an important optimization to reduce overhead for unused headers as mentioned in the PR objectives.
152-152: Approve updated header access approachThis change to use
Headers.allow[headers].valueOrNullIfInvalidinstead of direct property access is consistent with the new headers design, utilizing theHeaderAccessor<T>pattern described in the PR objectives.test/headers/basic/content_location_header_test.dart (2)
88-101: Approve test for unused invalid headersWell-structured test case that verifies the server doesn't throw exceptions for invalid headers that aren't accessed. This is consistent with the PR's goal of addressing memory overhead by not processing unused headers.
171-172: Good validation approach with explicit error handlingThe combination of checking
valueOrNullIfInvalidand verifying that direct access throwsthrowsInvalidHeaderprovides complete test coverage for the validation behavior. This dual approach ensures that invalid headers are properly detected while still allowing graceful handling when needed.lib/src/headers/standard_headers_extensions.dart (3)
5-89: Well-structured headers extensionThe
HeadersExextension provides a clean and intuitive API for accessing typed header values. This implementation elegantly supports the goal of treating all headers, both standard and custom, as typed values.
91-195: Good implementation of setter methodsThe
MutableHeadersExextension properly implements setter methods for all header types, maintaining a consistent pattern throughout. This provides a clean API for modifying headers with proper type safety.
196-280: Clear explanation for duplicated gettersThe comment explaining why getter methods need to be duplicated in the
MutableHeadersExextension is helpful and clearly articulates a Dart language constraint. The approach taken is appropriate given this limitation.test/headers/typed_headers/access_control_request_method_header_test.dart (3)
4-4: Approve additional importAdding the import for
standard_headers_extensions.dartis necessary to support the new header access pattern being implemented in this PR.
72-76: Good pattern for testing unused headersUsing
varfor the headers variable and providing an empty callback totouchHeaderscreates a clean test for verifying that invalid headers don't cause issues when not accessed. This is consistent with the PR's optimization goals.
149-152: Approve comprehensive validation testingThe updated validation approach checks both the
valueOrNullIfInvalidproperty and verifies the appropriate exception is thrown when directly accessing the property. This thoroughly tests the behavior of invalid headers with the newHeaderAccessor<T>implementation.test/headers/typed_headers/cross_origin_resource_policy_header_test.dart (7)
1-3: LGTM - Standard headers extension import addedThe import for
standard_headers_extensions.dartis properly added to support the new approach for typed header access.
26-32: Updated test to use the new touchHeaders parameterThe test now correctly uses the
touchHeaderscallback to explicitly access thecrossOriginResourcePolicyheader, which aligns with the new typed header access approach introduced in this PR.
46-51: LGTM - Consistent pattern for header accessThe test properly uses the touchHeaders parameter to explicitly access the header, maintaining consistent pattern across tests.
65-70: Good test for conditional validationThis test correctly verifies that invalid headers don't cause exceptions if they aren't actually accessed, using an empty touchHeaders callback. This aligns with the PR objective of reducing overhead for unused headers.
77-86: LGTM - Type-safe header accessThe test properly uses the new type-safe header accessor pattern to verify the parsed header value.
93-100: LGTM - Proper null handlingThe test correctly verifies that missing headers return null when using the typed accessor.
122-128: LGTM - Consistent non-strict validation handlingTest for non-strict validation mode correctly uses the new pattern for header access, maintaining consistency with the rest of the codebase.
test/headers/basic/user_agent_header_test.dart (6)
1-3: LGTM - Updated importsThe import for
standard_headers_extensions.darthas been properly added to support the new typed header access approach.
26-30: LGTM - Updated to use touchHeaders parameterThe test now correctly uses the
touchHeaderscallback to explicitly access theuserAgentheader, enabling proper validation in the type-safe header system.
47-54: LGTM - Proper pattern for header non-validationThe test uses an empty touchHeaders callback to verify that invalid headers don't cause exceptions when not explicitly accessed, which aligns with the PR objective of reducing overhead for unused headers.
60-64: LGTM - Consistent pattern for header accessThe test maintains the same pattern for accessing headers using the new touchHeaders parameter.
76-80: LGTM - Proper default value handlingThe test correctly verifies default value handling with the new header accessor pattern.
100-108: Improved error handling with separate validationThe test now properly separates the concepts of accessing potentially invalid header values (using
valueOrNullIfInvalid) and throwing exceptions when directly accessing invalid headers. This is a good practice that makes the validation behavior more explicit.lib/src/static/static_handler.dart (5)
9-10: LGTM - Added standard headers extensions importThe import for standard headers extensions has been correctly added to support the new header accessor pattern.
15-16: LGTM - Updated import pathThe import path for mime_type.dart has been updated appropriately.
227-230: LGTM - Improved header construction with builder patternThe code now uses the more maintainable
Headers.buildbuilder pattern instead of direct property assignment, allowing for a cleaner and more functional approach to header construction.
247-248: LGTM - Consistent builder patternThe response headers are now constructed using the same builder pattern, maintaining consistency throughout the codebase.
317-323: LGTM - Using transform instead of copyWithThe code now uses the more functional
transformmethod instead ofcopyWith, which aligns with the new header manipulation approach. This change improves code clarity by explicitly showing which headers are being modified.test/headers/basic/origin_header_test.dart (11)
1-3: LGTM - Updated importsThe import for
standard_headers_extensions.darthas been properly added to support the new typed header access approach.
26-40: LGTM - Updated empty header validationThe test for empty header validation now correctly uses the touchHeaders parameter to explicitly access the header, enabling proper validation in the type-safe header system.
48-61: LGTM - Consistent validation for invalid URI formatThe test for invalid URI format validation follows the same pattern as other tests, maintaining consistency across the test suite.
70-84: LGTM - Proper invalid port validationThe test correctly validates that invalid port numbers trigger appropriate exceptions when the header is accessed.
92-99: LGTM - Verification of unused header behaviorThis test properly verifies that invalid headers don't cause exceptions if they aren't actually accessed, using an empty touchHeaders callback.
105-115: LGTM - Type-safe URI validationThe test properly validates that a valid Origin header is correctly parsed as a URI using the type-safe header accessor.
121-130: LGTM - Proper port number extractionThe test verifies that port numbers are correctly extracted from Origin headers using the new accessor pattern.
137-146: LGTM - Whitespace handling verificationThe test correctly verifies that whitespace is properly handled when parsing Origin headers.
153-160: LGTM - Proper null handling for missing headersThe test correctly verifies that missing headers return null when using the typed accessor.
177-184: LGTM - Improved error handling for non-strict modeThe test for non-strict mode now properly separates accessing potentially invalid header values (using
valueOrNullIfInvalid) and throwing exceptions when directly accessing invalid headers.
192-199: LGTM - Consistent error handling patternThe test maintains the same pattern for validating invalid headers in non-strict mode, ensuring consistency across the test suite.
test/headers/basic/date_header_test.dart (9)
1-3: Import statements have been updated to support new header architectureThe imports have been updated to use
standard_headers_extensions.dartinstead of directly importing headers-related classes. This aligns with the PR's objective to enhance typed access to all headers.Also applies to: 5-5
28-33: AddedtouchHeadersparameter to trigger header accessThe new
touchHeadersparameter helps reduce memory overhead by ensuring the Date header is only parsed when explicitly accessed. This addresses issue #35 mentioned in the PR objectives by avoiding unnecessary parsing of unused headers.
51-55: AddedtouchHeadersparameter to test invalid date handlingSimilar to the previous change, this ensures the Date header is accessed during testing. The parameter is correctly used to target the specific header being tested.
72-76: Added test to verify headers aren't validated when unusedThis test confirms that invalid date formats don't cause exceptions when the header isn't actually accessed, which aligns with the PR's goal of reducing overhead for unused headers.
85-89: AddedtouchHeadersparameter to test valid date parsingEnsures the Date header is accessed during testing, which triggers the parsing logic being tested.
101-105: AddedtouchHeadersparameter to test whitespace handlingSimilar to other changes, this ensures the Date header with whitespace is properly accessed and tested.
117-124: AddedtouchHeadersparameter to test null Date headerThis change ensures that the absence of a Date header is properly tested with the new header access mechanism.
142-150: Updated test for empty Date header with non-strict validationThe test now uses
Headers.date[headers].valueOrNullIfInvalidto check the raw value and expects an exception when accessing the typed value withheaders.date. This aligns with the PR's objective to provide both raw and typed access to headers.
158-166: Updated test for invalid Date header with non-strict validationSimilar to the previous test, this checks both raw value access (which returns null) and typed access (which throws an exception). This consistent approach across all header tests ensures proper handling of invalid headers.
test/headers/basic/via_header_test.dart (8)
1-3: Updated imports to use standard_headers_extensions.dartThe imports have been updated to use
standard_headers_extensions.dartinstead of direct header imports, aligning with the new header architecture.
27-27: AddedtouchHeadersparameter to test empty Via headerThe new parameter ensures that the Via header is accessed during testing, which is necessary to trigger validation in the new header access mechanism.
45-49: AddedtouchHeadersparameter to test header non-usageThis change ensures that the test correctly verifies that headers aren't validated when not accessed, supporting the PR's goal of reducing overhead for unused headers.
58-62: AddedtouchHeadersparameter to test valid Via headerThis change ensures the Via header is accessed during testing, activating the parsing logic being tested.
71-75: AddedtouchHeadersparameter to test whitespace handlingSimilar to previous changes, this ensures the Via header with whitespace is properly accessed and tested.
85-89: AddedtouchHeadersparameter to test duplicate valuesThis ensures the Via header with duplicate values is properly accessed and tested for deduplication.
98-102: AddedtouchHeadersparameter to test null Via headerThis change ensures that the absence of a Via header is properly tested with the new header access mechanism.
122-130: Updated test for empty Via header with non-strict validationThe test now uses
Headers.via[headers].valueOrNullIfInvalidto check the raw value and expects an exception when accessing the typed value. This approach provides a clear distinction between raw and typed access to headers.test/headers/typed_headers/cross_origin_embedder_policy_header_test.dart (7)
1-3: Updated imports to use standard_headers_extensions.dartThe imports have been updated to use
standard_headers_extensions.dartinstead of direct header imports, aligning with the new header architecture.
27-31: AddedtouchHeadersparameter to test empty Cross-Origin-Embedder-Policy headerThis ensures the Cross-Origin-Embedder-Policy header is accessed during testing, activating validation in the new header access mechanism.
45-50: AddedtouchHeadersparameter to test invalid header valueSimilar to other header tests, this ensures that invalid values are properly validated when the header is accessed.
65-70: AddedtouchHeadersparameter to test header non-usageThis verifies that headers aren't validated when not accessed, supporting the goal of reducing overhead for unused headers.
77-81: AddedtouchHeadersparameter to test valid header valueEnsures the header is accessed during testing, activating the parsing logic being tested.
90-101: Added test for when no header is passedThis test ensures that the absence of a Cross-Origin-Embedder-Policy header returns null when accessed.
105-130: Added tests for non-strict validationThis new group of tests covers the behavior when the strict flag is set to false, ensuring that empty headers return null without throwing exceptions. This provides complete test coverage for both strict and non-strict validation modes.
test/headers/typed_headers/if_range_header_test.dart (9)
1-4: Updated imports to use standard_headers_extensions.dartThe imports have been updated to use
standard_headers_extensions.dartinstead of direct header imports, aligning with the new header architecture.
29-29: AddedtouchHeadersparameter to test empty If-Range headerThis ensures the If-Range header is accessed during testing, triggering validation in the new header access mechanism.
50-50: AddedtouchHeadersparameter to test invalid ETag formatThis change ensures that invalid ETag formats are properly validated when the header is accessed.
69-73: AddedtouchHeadersparameter to test header non-usageThis verifies that headers aren't validated when not accessed, supporting the PR's goal of reducing overhead for unused headers.
82-86: AddedtouchHeadersparameter to test valid ETagEnsures the If-Range header with a valid ETag is accessed during testing, activating the parsing logic.
97-101: AddedtouchHeadersparameter to test weak ETagSimilar to the previous change, this ensures the If-Range header with a weak ETag is properly accessed and tested.
112-116: AddedtouchHeadersparameter to test HTTP date formatThis ensures the If-Range header with an HTTP date is properly accessed and tested.
129-133: AddedtouchHeadersparameter to test null If-Range headerThis change ensures that the absence of an If-Range header is properly tested with the new header access mechanism.
153-161: Updated test for invalid If-Range header with non-strict validationThe test now uses
Headers.ifRange[headers].valueOrNullIfInvalidto check the raw value and expects an exception when accessing the typed value. This consistent pattern across all header tests ensures proper handling of invalid headers.test/headers/basic/access_control_request_headers_heder_test.dart (3)
1-6: Updated imports to align with the new header handling approach.The import changes reflect the new organization of header-related code, particularly the addition of
standard_headers_extensions.dartwhich likely contains the typed header accessors needed for the tests.
31-32: LGTM: Consistent introduction of touchHeaders parameter.The addition of the
touchHeadersparameter across all test cases is a well-structured approach that aligns with the PR's objective to enhance typed access to custom headers. This parameter explicitly specifies which headers should be accessed during testing, ensuring that headers are only processed when they're actually used.Also applies to: 51-52, 69-70, 89-90, 109-110, 126-127
157-160: Updated header validation approach to use the new accessor pattern.The test now correctly uses
Headers.accessControlRequestHeaders[headers].valueOrNullIfInvalidto check for null values and expects an exception when directly accessing an invalid header throughheaders.accessControlRequestHeaders. This aligns with the new design for header handling.test/headers/typed_headers/proxy_authenticate_header_test.dart (3)
1-3: Updated imports to support the new header handling approach.The import changes align with the restructured header-related code organization.
26-27: LGTM: Consistently implemented touchHeaders parameter.The consistent application of the
touchHeadersparameter throughout all test cases ensures proper testing of the new header access mechanism, where headers are only processed when explicitly accessed.Also applies to: 45-46, 57-58, 67-68, 84-85, 97-98, 115-116, 133-134, 151-152, 172-173
199-200: Updated header validation to use the new accessor pattern.The test now correctly uses
Headers.proxyAuthenticate[headers].valueOrNullIfInvalidto check for null values and expects an exception when directly accessing an invalid header throughheaders.proxyAuthenticate. This is consistent with the new header access design.test/headers/typed_headers/retry_after_header_test.dart (3)
1-4: Updated imports to align with new header handling.The import changes reflect the reorganized header-related code structure.
28-29: LGTM: Consistent application of touchHeaders parameter.The
touchHeadersparameter has been consistently added to all test cases, ensuring that the tests properly validate the new behavior where headers are only processed when they're explicitly accessed.Also applies to: 47-48, 59-60, 69-70, 80-81, 95-96, 111-112, 124-125, 138-139, 155-156, 178-179
182-183: Updated header validation to use the new accessor pattern.The test now correctly uses
Headers.retryAfter[headers].valueOrNullIfInvalidto check for null values and expects an exception when directly accessing an invalid header throughheaders.retryAfter. This change aligns with the new header access design.lib/src/headers/exception/header_exception.dart (2)
1-27: Well-designed base exception class with clear documentation.The
HeaderExceptionclass provides a solid foundation for the header exception hierarchy. The class is properly documented with clear explanations of its purpose and usage. The sealed class modifier is a good choice here to restrict inheritance to only the defined subclasses within this file.
29-48: LGTM: Clear implementation of InvalidHeaderException.The
InvalidHeaderExceptionclass is well-implemented with proper inheritance from the base class and clear documentation. The overridden methods provide appropriate behavior specific to invalid header scenarios.lib/src/headers/typed/headers/etag_condition_header.dart (1)
38-38: Improved API flexibility by accepting any iterable collection.Changing the parameter type from
List<String>toIterable<String>is a good enhancement that allows these methods to accept a broader range of collection types while maintaining the same functionality.Also applies to: 75-75
test/headers/typed_headers/cache_control_header_test.dart (21)
28-29: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter is consistent with the PR's goal of minimizing memory overhead by only processing headers when they're actually accessed.
49-50: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and validates that invalid directives are properly handled.
70-71: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and validates that invalid directives are properly handled.
91-92: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and validates that both public and private directives cannot be used together.
112-113: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and validates that max-age and stale-while-revalidate cannot be used together.
135-138: Updated test to avoid accessing headers when not needed.The test now uses an empty lambda for
touchHeadersto avoid triggering header validation when testing that invalid headers don't cause errors if not accessed.
148-151: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parsed when valid directives are provided.
163-166: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the max-age directive.
176-179: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the s-maxage directive.
189-192: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the stale-while-revalidate directive.
202-205: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the stale-if-error directive.
215-218: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the max-stale directive.
228-231: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the min-fresh directive.
241-244: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the public directive.
254-257: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the private directive.
267-270: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the no-transform directive.
280-283: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the only-if-cached directive.
293-296: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the immutable directive.
306-309: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed and properly parses the must-understand directive.
319-322: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the cache control header is accessed, and the test properly validates that it returns null when no header is provided.
343-350: Updated error handling validation in tests.The test now correctly validates the new exception handling mechanism using
Headers.cacheControl[headers].valueOrNullIfInvalidand thethrowsInvalidHeadermatcher, aligning with the new header accessor design.test/headers/typed_headers/accept_language_test.dart (14)
11-21: Improved test organization with clear grouping.Restructuring the tests with explicit grouping based on the strictness flag improves readability and organization.
28-40: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the accept-language header is accessed and properly validates empty headers.
50-62: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the accept-language header is accessed and properly validates invalid quality values.
71-84: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the accept-language header is accessed and properly validates that wildcards cannot be used with other values.
88-107: Added test for empty language validation.Good addition of a test case to verify proper handling of empty language values, ensuring the header accessor correctly rejects invalid inputs.
115-122: Updated test to avoid accessing headers when not needed.The test now uses an empty lambda for
touchHeadersto avoid triggering header validation when testing that invalid headers don't cause errors if not accessed.
129-138: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the accept-language header is accessed and properly parses language values.
146-155: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the accept-language header is accessed and properly assigns default quality values.
163-172: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the accept-language header is accessed and properly handles case normalization.
179-186: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the accept-language header is accessed and properly returns null when no header is provided.
192-200: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the accept-language header is accessed and properly handles wildcard values.
207-220: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the accept-language header is accessed and properly handles wildcards with quality values.
224-326: Added comprehensive test cases for multiple accept-language headers.Excellent addition of multiple test cases to verify proper handling of various scenarios:
- Multiple languages
- Quality values
- Duplicate values removal
- Whitespace handling
This significantly improves test coverage and ensures robustness.
364-412: Added test cases for non-strict header validation.Good addition of test cases for non-strict mode to verify that invalid headers result in null values when accessed through the accessor API and throw appropriate exceptions when accessed directly.
test/headers/basic/if_unmodified_since_header_test.dart (9)
11-21: Improved test organization with clear grouping.Restructuring the tests with explicit grouping based on the strictness flag improves readability and organization.
27-41: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the if-unmodified-since header is accessed and properly validates empty headers.
44-64: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the if-unmodified-since header is accessed and properly validates invalid date formats.
66-79: Updated test to avoid accessing headers when not needed.The test now uses an empty lambda for
touchHeadersto avoid triggering header validation when testing that invalid headers don't cause errors if not accessed.
85-94: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the if-unmodified-since header is accessed and properly parses valid date formats.
101-111: Updated test to use the new header accessor pattern.The addition of the
touchHeadersparameter ensures that the if-unmodified-since header is accessed and properly handles whitespace in date values.
129-137: Improved test organization for non-strict mode.Well-structured test group with appropriate setup and teardown for testing non-strict header validation.
142-151: Updated error handling validation in tests.The test now correctly validates the new exception handling mechanism using
Headers.ifUnmodifiedSince[headers].valueOrNullIfInvalidand thethrowsInvalidHeadermatcher, aligning with the new header accessor design.
159-168: Updated error handling validation for invalid date formats.The test now correctly validates the new exception handling mechanism for invalid date formats, using the accessor API and appropriate exception checks.
test/headers/basic/x_powered_by_header_test.dart (5)
1-3: Properly adapted import statements for typed header supportThe changes correctly update the import to use the more specific
standard_headers_extensions.dartinstead of the general headers import, aligning with the PR's goal of supporting typed access to custom headers.
11-21: Test group structure improved with clearer formattingThe test group structure has been reformatted for better readability while maintaining the same functionality. The setup and teardown methods are appropriately preserved.
30-30: Properly implemented header accessor with touchHeaders parameterThe addition of the
touchHeadersparameter demonstrates the new way to access typed headers, ensuring that the header is properly accessed and parsed during testing.
47-47: Consistent use of touchHeaders parameterThe touchHeaders parameter is correctly applied here as well, maintaining consistency throughout the tests and explicitly showing which header is being tested.
56-68: Added comprehensive test coverage with strict flag falseGood addition of a test group for when the strict flag is false, even though it's currently skipped. The skip message clearly explains why: "x-powered-by is a response header (stripped on get request)".
lib/src/headers/typed/headers/accept_header.dart (2)
18-18: More flexible parameter type for AcceptHeader.parseChanging the parameter type from
List<String>toIterable<String>improves API flexibility, allowing any iterable collection to be passed. This is a good enhancement that aligns with the PR objective of supporting more flexible header handling.
59-60: Improved safety with explicit collection conversionThe changes make the code more robust by:
- Explicitly converting the iterable to a list with
.toList()- Using
.firstinstead of[0]to access the first elementThis prevents potential runtime errors when working with non-list iterables and makes the code more idiomatic.
test/headers/typed_headers/content_security_policy_header_test.dart (5)
1-3: Updated imports to match new header implementationThe import change from
headers.darttostandard_headers_extensions.dartcorrectly aligns with the PR's updated header handling approach.
27-28: Added touchHeaders parameter for explicit header accessThe addition of the
touchHeadersparameter explicitly indicates which header is being tested and ensures it gets parsed properly, aligning with the PR's goal of supporting typed access to headers.
44-48: Simplified type declaration and added touchHeaders parameterChanged from explicit
Headers headerstovar headerstype inference, which is cleaner. ThetouchHeaders: (_) {}parameter indicates that in this test case, we're intentionally not accessing any header properties.
57-63: Consistent application of touchHeaders parameterSimilar to previous changes, this applies the touchHeaders pattern consistently. The no-op function
(_) {}indicates that we don't need to explicitly access the header in this test case - we'll access it later in line 65.
131-133: Updated assertion pattern for invalid headersThe assertion pattern has been updated to:
- Check that the valueOrNullIfInvalid is null when accessing via the header accessor
- Verify that directly accessing the property throws an InvalidHeader exception
This is more precise than the previous approach and better demonstrates how invalid headers are handled in the new implementation.
test/headers/typed_headers/strict_transport_security_header_test.dart (6)
1-3: Updated imports to match new header implementationThe import change from
headers.darttostandard_headers_extensions.dartcorrectly aligns with the PR's updated header handling approach.
28-31: Added touchHeaders parameter for explicit header accessThe touchHeaders parameter is added to explicitly specify which header property is being accessed during the test, aligning with the PR's goal of improving header access patterns.
41-79: Improved test cases with clear error messagesThe test cases for invalid headers have been enhanced with more specific error messages and test descriptions, making it clearer what each test is validating. The tests now explicitly check for:
- Empty header values
- Invalid max-age values
- Missing max-age directive
This provides better test coverage for the error handling in the header implementation.
96-126: Comprehensive testing of valid header parsingThese test cases thoroughly validate that the header is correctly parsed with different combinations of directives:
- With includeSubDomains
- Without includeSubDomains
This ensures the header implementation correctly handles all valid use cases.
128-141: Added test for preload directiveGood addition of a test case for the preload directive, ensuring comprehensive coverage of all header directives. This makes the test suite more complete.
178-180: Updated assertion pattern for invalid headersThe assertion pattern has been improved to:
- Check that
valueOrNullIfInvalidis null when accessing through the header accessor- Verify that directly accessing the property throws an
InvalidHeaderexceptionThis is more precise than the previous approach and better demonstrates how invalid headers are handled in the new implementation.
test/headers/basic/server_header_test.dart (7)
1-3: Looks good - Import update adds support for standard headers extensions.The new import for
standard_headers_extensions.dartaligns with the PR's objective to enhance header handling through typed access.
21-40: Improved test structure with touchHeaders parameter.The addition of the
touchHeadersparameter allows explicitly specifying which header should be accessed during test execution, making failures more predictable and easier to debug. This is consistent with the PR's goal of providing typed access to headers.
43-56: Good addition - Tests that empty headers don't cause failures when unused.This new test case verifies an important behavior: headers with invalid values should not cause validation errors if they are not actively used. This improves the robustness of the header handling system by only validating headers that are actually accessed.
58-69: Consistent use of touchHeaders parameter for valid header test.The test has been updated to include the touchHeaders parameter with a no-op function, maintaining a consistent testing pattern across all test cases.
71-82: Good update - Added touchHeaders parameter to the whitespace test.The test now explicitly accesses the header value through the touchHeaders callback, ensuring that whitespace handling is properly tested during header access.
84-95: Test for absent header correctly updated with touchHeaders parameter.The test now explicitly tries to access the server header, ensuring the behavior is correctly tested when the header is missing.
118-119: Updated assertion method to use the new header accessor API.The test now uses
Headers.server[headers].valueOrNullIfInvalidto access the header value, followed by an expectation that directly accessingheaders.serverwill throw an exception. This is consistent with the PR's goal of providing typed access to headers.test/headers/basic/access_control_allow_credentials_header_test.dart (7)
1-2: Import updates align with the new header implementation.Adding the import for standard_headers_extensions.dart supports the PR's goal of providing typed access to headers.
28-47: Test for empty header correctly updated with touchHeaders parameter.The test now explicitly tries to access the accessControlAllowCredentials header through the touchHeaders callback, ensuring the validation happens at the right time.
50-69: Improved test for invalid header with touchHeaders parameter.The test structure has been updated to explicitly access the header, ensuring validation is properly triggered for invalid values.
71-91: Test for 'false' value updated with explicit header access.The test now clearly demonstrates that the header value must be 'true' or null by explicitly accessing the header through touchHeaders.
93-106: Good addition - Tests that invalid headers don't cause failures when unused.This new test case verifies that headers with invalid values don't cause validation errors if they're not actively accessed, which is an important aspect of the new headers implementation.
108-132: Tests for valid value and absent header updated consistently.Both tests now explicitly access the accessControlAllowCredentials header through touchHeaders, ensuring proper validation.
153-163: Updated assertion to use the new header accessor API.The test now first accesses the header via
Headers.accessControlAllowCredentials[headers]before checking its properties. This is a more robust approach that aligns with the new implementation's design.test/headers/basic/location_header_test.dart (6)
1-3: Import update supports access to standard headers extensions.The new import aligns with the PR's objective to enhance header handling through typed access to all headers.
22-42: Empty location header test updated with explicit validation trigger.The test now explicitly accesses the location header through touchHeaders, ensuring validation is properly triggered for empty values.
44-86: Tests for invalid URI and port updated with the touchHeaders parameter.Both tests now explicitly access the location header to trigger validation, maintaining consistency with the new implementation approach.
88-101: Good addition - Tests that invalid headers don't fail when unused.This new test case verifies that headers with invalid values don't cause validation errors if they're not actively accessed, supporting the memory efficiency goal mentioned in the PR description.
103-148: Tests for valid URIs updated to use the touchHeaders parameter consistently.All tests for valid location values now explicitly access the header through touchHeaders, ensuring validation occurs consistently. This maintains the pattern established across all header tests.
174-186: Updated assertion to use the new header accessor API.The test now uses
Headers.location[headers].valueOrNullIfInvalidto check for null when an invalid URI is provided, followed by a validation that direct access throws an exception. This approach is consistent with the new header implementation.test/headers/basic/expires_header_test.dart (8)
1-4: Import alignment with the new header implementation.Adding the import for standard_headers_extensions.dart supports the PR's goal of providing typed access to all headers.
22-42: Empty expires header test updated with explicit validation trigger.The test now explicitly accesses the expires header through touchHeaders, ensuring validation is properly triggered for empty values.
44-64: Test for invalid date format updated with touchHeaders parameter.The test now explicitly accesses the expires header to trigger validation for invalid date formats, maintaining consistency with the new implementation approach.
66-79: Good addition - Tests that invalid date formats don't fail when unused.This important new test case verifies that headers with invalid date formats don't cause validation errors if they're not actively accessed, supporting the memory efficiency goal in the PR.
81-111: Tests for valid date formats updated to use touchHeaders consistently.Both tests for valid expires dates now explicitly access the header through touchHeaders, ensuring validation occurs consistently across test cases.
113-124: Test for absent header updated with touchHeaders parameter.The test now explicitly attempts to access the expires header, ensuring proper behavior when the header is missing.
137-149: Updated assertion to use the new header accessor API for empty header.The test now uses
Headers.expires[headers].valueOrNullIfInvalidto check for null when an empty value is provided, followed by validation that direct access throws an exception. This approach is consistent with the new header implementation.
153-165: Updated assertion to use the new header accessor API for invalid header.Similar to the empty header test, this test now uses the new accessor approach to verify behavior with invalid date formats, maintaining consistency across the test suite.
test/headers/header_test.dart (16)
1-3: Imports appear correct and consistent.
These lines cleanly bring in necessary packages fromrelicand local utility files without any redundant references.Also applies to: 6-7
12-13: Good test for initial Headers state.
UsingHeaders.empty()and verifying it is empty properly ensures the default state behaves as expected.
25-29: Solid test for header removal.
Usingtransform((mh) => mh.remove(...))ensures an immutable pattern while verifying removal. Clear and concise.
33-37: Case-insensitive header checks are correct.
This covers an essential contract of HTTP headers. The usage of multiple casing variations in asserts is commendable.
42-50: Clear coverage of transformation and copying.
Ensuringremoveand new additions on a copy is key to verifying immutability. This test effectively demonstrates correct behavior.
55-60: Response header application is valid.
The approach of building headers and confirming they appear in the response is straightforward and helps ensure correct integration withResponse.ok.
65-69: Large header test is thorough.
Creating a 10,000-character header value verifies that the system can handle long inputs gracefully.
72-73: Managed header removal test is concise.
Verifying a null assignment effectively removes the date header fromMutableHeaders.
78-83: Updating a managed header is well-tested.
Ensuring the new date overwrote the old value validates the immutability approach and correctness.
86-104: Comprehensive parameterized tests for all headers.
UsingparameterizedGroupis an excellent approach to systematically validate each header accessor. This block is thorough in testing set/clear operations and type checks.
106-121: Edge-case coverage for missing raw values.
These tests confirm that headers remain unset and invalid when no raw value is provided. Good guard.
123-141: Empty raw value checks enhance coverage.
VerifyingisValidis false andvaluethrows is crucial for correctness.
143-155: Testing invalid raw values.
Properly ensures that invalid inputs are not accepted. The coverage is robust across multiple headers.
185-263: Named extension property reading on empty instances.
This block systematically ensures each built-in accessor returnsnullwhen unset. Great coverage.
264-341: Ensuring named extension properties on emptyMutableHeaderscan be read asnull.
This parallels the previous parameterized test and upholds consistency. Nicely done.
343-535: Verifying setting header values to bothnulland valid typed objects.
This final parameterized block is extensive and covers nearly all standard headers. Great demonstration of the typed approach.test/headers/headers_test_utils.dart (3)
6-6: Test imports included.
Bringing inpackage:test/test.dartis necessary for matchers. Looks good.
76-77: Refactored callback-based header handling is sensible.
Replacing the eager parsing approach with thetouchHeaderscallback is a neat solution, allowing flexible modifications. ReturningrequestHeadersensures the function’s original behavior remains.Also applies to: 78-78, 83-83, 104-104
107-108: New matchers for header exceptions.
throwsInvalidHeaderandthrowsMissingHeaderfacilitate testing for typed header logic. This is a clear and reusable approach.lib/src/headers/parser/common_types_parser.dart (4)
60-60: Use ofparseIntforparsePositiveIntis concise.
The removal of duplicate checks is a positive change, but ensure negative values are the only additional check here.
85-85:parsePositiveBoolrelies onparseBool.
This is a simpler approach, but the logic effectively treats “false” as invalid. This matches the doc string, so it's good.
105-105:parseStringList(Iterable<String>...)signature.
Accepting anIterable<String>is more flexible thanList<String>, and finalizing withtoList()ensures consistent output. Nicely done.Also applies to: 110-110
116-116: Enhanced flexibility for parseMethodList.
Similarly, switching fromList<String>toIterable<String>avoids unnecessary conversions upstream.lib/src/headers/header_accessor.dart (1)
1-195: Overall structure looks solid.No further critical findings. The caching strategy with
Expandois a neat approach for avoiding repeated header parsing.test/headers/typed_headers/accept_header_test.dart (13)
27-28: Good approach to trigger strict parsing.Accessing
h.acceptensures the test properly validates an empty Accept header.
47-48: Same logic for strict parsing.
64-67: Skipping Accept usage confirms no error when header is unused.This firmly tests the scenario where invalid headers remain benign if not accessed.
77-80: Ensuring Accept is accessed verifies parsing correctness.
94-97: Same validation approach for parsing correctness.
109-112: Identical acceptance test scenario.
124-127: Strict testing of wildcards in Accept header.
140-143: Confirming null Accept if not provided.
157-158: Quality value validation triggers a bad request.
174-177: Multi-range Accept header with different quality values.
196-199: Verifying correct quality parsing for multiple media ranges.
227-229: Fallback to no strict check.Here, invalid quality remains unused, ensuring no request failure.
233-234: Test covers both graceful fallback and thrown exception.Using
valueOrNullIfInvalidis null while direct access throws an invalid header error. Nicely done!test/headers/typed_headers/cookie_header_test.dart (4)
1-3: New import enhances header extensionsThe addition of the
standard_headers_extensions.dartimport provides access to the new typed header extension methods, which is consistent with the PR's objective to support typed access to all headers.
25-25: Addition of touchHeaders parameter improves test specificityThe new
touchHeadersparameter allows tests to explicitly specify which headers should be accessed during testing. This change aligns with the PR's objective of improving header handling and potentially reducing memory overhead by only parsing headers when they're actually accessed.Also applies to: 46-47, 67-68, 88-89, 109-110, 122-123, 142-143, 162-163, 183-184, 203-204
107-108: Type simplification from Headers to varChanging the type declaration from explicit
Headerstovarsimplifies the code while maintaining type safety through inference. This is a good practice when the type is obvious from the context.Also applies to: 120-121, 140-141, 160-161, 181-182, 201-202, 232-233
238-239: Updated invalid header handling approachThe test now checks both the nullable access method (
valueOrNullIfInvalid) and that direct access throws anInvalidHeaderexception. This change reflects the new consistent exception handling for all headers (both standard and custom) as described in the PR objectives.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
test/headers/basic/content_location_header_test.dart (1)
28-32: Consistent parameter ordering in test functions.The parameter ordering in
getServerRequestHeadersis inconsistent with other test files. Other files listtouchHeadersafter the server parameter, but before the headers parameter, while this file places it after the headers parameter.Consider standardizing the parameter order across all test files to maintain consistency:
getServerRequestHeaders( server: server, - headers: {'content-location': ''}, touchHeaders: (h) => h.contentLocation, + headers: {'content-location': ''}, ),lib/src/headers/header_accessor.dart (3)
13-33: Be mindful of potential memory leaks with_caches.While the design relies on a finite number of const-constructed
HeaderAccessorinstances, if new (non-const) accessors are created dynamically in practice, entries in_cacheswill accumulate indefinitely. Consider documenting safe usage patterns or implementing a more controlled lifecycle for cached items to prevent unbounded growth in long-running applications.
65-82: Consider handling non-Exception throws.Currently,
getValueFromonly catchesException. In Dart, some runtime errors (e.g.,TypeError,AssertionError) are not subclasses ofExceptionand won’t be handled here. If your use case requires gracefully handling or transforming all possible failures, you might catchObjectrather thanException. Otherwise, document that onlyExceptiontypes are handled, letting other errors propagate.
126-153: Clarify naming for “invalid” vs. “missing” cases.
valueOrNullIfInvalidandvalueOrNullboth returnnull, but with subtle differences in what triggers thatnull. It may help to extend the documentation to clarify the difference between a truly missing header vs. a present but invalid one, helping developers to avoid confusion.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (68)
lib/src/headers/header_accessor.dart(1 hunks)lib/src/headers/headers.dart(3 hunks)test/headers/basic/access_control_allow_credentials_header_test.dart(3 hunks)test/headers/basic/access_control_max_age_header_test.dart(1 hunks)test/headers/basic/access_control_request_headers_heder_test.dart(2 hunks)test/headers/basic/age_header_test.dart(1 hunks)test/headers/basic/allow_header_test.dart(1 hunks)test/headers/basic/content_location_header_test.dart(1 hunks)test/headers/basic/date_header_test.dart(1 hunks)test/headers/basic/expires_header_test.dart(1 hunks)test/headers/basic/host_header_test.dart(2 hunks)test/headers/basic/if_modified_since_header_test.dart(9 hunks)test/headers/basic/if_unmodified_since_header_test.dart(1 hunks)test/headers/basic/last_modified_header.dart(9 hunks)test/headers/basic/location_header_test.dart(1 hunks)test/headers/basic/max_forwards_header_test.dart(1 hunks)test/headers/basic/origin_header_test.dart(1 hunks)test/headers/basic/referer_header_test.dart(1 hunks)test/headers/basic/server_header_test.dart(1 hunks)test/headers/basic/trailer_header_test.dart(8 hunks)test/headers/basic/user_agent_header_test.dart(6 hunks)test/headers/basic/via_header_test.dart(8 hunks)test/headers/basic/x_powered_by_header_test.dart(2 hunks)test/headers/mutable_headers_test.dart(1 hunks)test/headers/typed_headers/accept_encoding_header_test.dart(20 hunks)test/headers/typed_headers/accept_header_test.dart(13 hunks)test/headers/typed_headers/accept_language_test.dart(1 hunks)test/headers/typed_headers/accept_ranges_header_test.dart(7 hunks)test/headers/typed_headers/access_control_allow_headers_header_test.dart(8 hunks)test/headers/typed_headers/access_control_allow_methods_header_test.dart(9 hunks)test/headers/typed_headers/access_control_allow_origin_header_test.dart(11 hunks)test/headers/typed_headers/access_control_expose_headers_header_test.dart(10 hunks)test/headers/typed_headers/access_control_request_method_header_test.dart(8 hunks)test/headers/typed_headers/authorization_header_test.dart(23 hunks)test/headers/typed_headers/cache_control_header_test.dart(22 hunks)test/headers/typed_headers/clear_site_data_header_test.dart(9 hunks)test/headers/typed_headers/connection_header_test.dart(9 hunks)test/headers/typed_headers/content_disposition_header_test.dart(8 hunks)test/headers/typed_headers/content_encoding_header_test.dart(10 hunks)test/headers/typed_headers/content_language_header_test.dart(9 hunks)test/headers/typed_headers/content_range_header_test.dart(11 hunks)test/headers/typed_headers/content_security_policy_header_test.dart(7 hunks)test/headers/typed_headers/cookie_header_test.dart(12 hunks)test/headers/typed_headers/cross_origin_embedder_policy_header_test.dart(1 hunks)test/headers/typed_headers/cross_origin_opener_policy_header_test.dart(7 hunks)test/headers/typed_headers/cross_origin_resource_policy_header_test.dart(1 hunks)test/headers/typed_headers/etag_header_test.dart(8 hunks)test/headers/typed_headers/expect_header_test.dart(6 hunks)test/headers/typed_headers/from_header_test.dart(12 hunks)test/headers/typed_headers/if_match_header_test.dart(13 hunks)test/headers/typed_headers/if_none_match_header_test.dart(13 hunks)test/headers/typed_headers/if_range_header_test.dart(9 hunks)test/headers/typed_headers/permissions_policy_header_test.dart(7 hunks)test/headers/typed_headers/proxy_authenticate_header_test.dart(11 hunks)test/headers/typed_headers/proxy_authorization_header_test.dart(23 hunks)test/headers/typed_headers/range_header_test.dart(12 hunks)test/headers/typed_headers/referrer_policy_header_test.dart(7 hunks)test/headers/typed_headers/retry_after_header_test.dart(11 hunks)test/headers/typed_headers/sec_fetch_dest_header_test.dart(7 hunks)test/headers/typed_headers/sec_fetch_mode_header_test.dart(7 hunks)test/headers/typed_headers/sec_fetch_site_header_test.dart(7 hunks)test/headers/typed_headers/set_cookie_header_test.dart(13 hunks)test/headers/typed_headers/strict_transport_security_header_test.dart(2 hunks)test/headers/typed_headers/te_header_test.dart(14 hunks)test/headers/typed_headers/transfer_encoding_header_test.dart(1 hunks)test/headers/typed_headers/upgrade_header_test.dart(8 hunks)test/headers/typed_headers/vary_header_test.dart(9 hunks)test/headers/typed_headers/www_authenticate_header_test.dart(12 hunks)
🚧 Files skipped from review as they are similar to previous changes (56)
- test/headers/mutable_headers_test.dart
- test/headers/typed_headers/sec_fetch_site_header_test.dart
- test/headers/basic/allow_header_test.dart
- test/headers/typed_headers/access_control_expose_headers_header_test.dart
- test/headers/typed_headers/expect_header_test.dart
- test/headers/basic/origin_header_test.dart
- test/headers/typed_headers/sec_fetch_dest_header_test.dart
- test/headers/typed_headers/te_header_test.dart
- test/headers/typed_headers/access_control_allow_headers_header_test.dart
- test/headers/typed_headers/content_language_header_test.dart
- test/headers/typed_headers/range_header_test.dart
- test/headers/typed_headers/etag_header_test.dart
- test/headers/typed_headers/if_range_header_test.dart
- test/headers/typed_headers/access_control_allow_methods_header_test.dart
- test/headers/typed_headers/content_disposition_header_test.dart
- test/headers/basic/if_unmodified_since_header_test.dart
- test/headers/typed_headers/access_control_request_method_header_test.dart
- test/headers/basic/host_header_test.dart
- test/headers/typed_headers/clear_site_data_header_test.dart
- test/headers/basic/referer_header_test.dart
- test/headers/basic/server_header_test.dart
- test/headers/basic/date_header_test.dart
- test/headers/typed_headers/transfer_encoding_header_test.dart
- test/headers/basic/last_modified_header.dart
- test/headers/typed_headers/permissions_policy_header_test.dart
- test/headers/typed_headers/content_security_policy_header_test.dart
- test/headers/typed_headers/accept_encoding_header_test.dart
- test/headers/basic/if_modified_since_header_test.dart
- test/headers/basic/access_control_request_headers_heder_test.dart
- test/headers/basic/age_header_test.dart
- test/headers/typed_headers/proxy_authenticate_header_test.dart
- test/headers/typed_headers/proxy_authorization_header_test.dart
- test/headers/basic/max_forwards_header_test.dart
- test/headers/typed_headers/cross_origin_opener_policy_header_test.dart
- test/headers/basic/expires_header_test.dart
- test/headers/typed_headers/from_header_test.dart
- test/headers/basic/x_powered_by_header_test.dart
- test/headers/typed_headers/cross_origin_resource_policy_header_test.dart
- test/headers/typed_headers/if_none_match_header_test.dart
- test/headers/typed_headers/cross_origin_embedder_policy_header_test.dart
- test/headers/typed_headers/content_encoding_header_test.dart
- test/headers/typed_headers/accept_ranges_header_test.dart
- test/headers/basic/trailer_header_test.dart
- test/headers/basic/user_agent_header_test.dart
- test/headers/basic/access_control_allow_credentials_header_test.dart
- test/headers/typed_headers/connection_header_test.dart
- test/headers/basic/access_control_max_age_header_test.dart
- test/headers/typed_headers/authorization_header_test.dart
- test/headers/basic/location_header_test.dart
- test/headers/typed_headers/if_match_header_test.dart
- test/headers/typed_headers/referrer_policy_header_test.dart
- test/headers/typed_headers/content_range_header_test.dart
- test/headers/typed_headers/set_cookie_header_test.dart
- test/headers/typed_headers/sec_fetch_mode_header_test.dart
- test/headers/typed_headers/accept_header_test.dart
- test/headers/typed_headers/cookie_header_test.dart
🧰 Additional context used
🪛 GitHub Check: codecov/patch
lib/src/headers/headers.dart
[warning] 23-23: lib/src/headers/headers.dart#L23
Added line #L23 was not covered by tests
🔇 Additional comments (77)
test/headers/typed_headers/access_control_allow_origin_header_test.dart (4)
27-30: Good addition oftouchHeadersparameter for explicit header access.The addition of
touchHeaders: (h) => h.accessControlAllowOriginparameter explicitly indicates which header is being accessed during testing. This makes the test more transparent about which headers are being used and provides a clear mechanism for triggering header validation.
49-52: Consistent implementation oftouchHeadersparameter.The
touchHeadersparameter is consistently applied across similar test cases, which helps maintain a uniform testing approach throughout the file.
94-97: Appropriate use of empty function for control tests.Using
touchHeaders: (_) {}in this control test is correct - it ensures the header isn't accessed during the test, which is precisely what you want to verify that invalid headers don't cause issues when not accessed.
205-207: Improved error handling for invalid headers.The updated approach for testing invalid headers is more robust:
- First checking that the value is null when accessed via the index operator
- Then verifying that directly accessing the property throws an appropriate exception
This pattern provides better validation of the error handling mechanism for invalid headers.
test/headers/typed_headers/vary_header_test.dart (3)
1-3: Appropriate imports for header extensions.The addition of the standard_headers_extensions import is appropriate for accessing the header accessor functionality.
25-28: Consistent implementation oftouchHeadersparameter for error cases.The implementation of
touchHeadersfor testing error cases is consistent with the pattern established in other header test files, which is good for maintaining a uniform approach to testing.
155-156: Enhanced error handling validation approach.The two-step validation approach:
expect(Headers.vary[headers].valueOrNullIfInvalid, isNull);expect(() => headers.vary, throwsInvalidHeader);Provides comprehensive validation of the header's error handling behavior when invalid values are encountered.
test/headers/typed_headers/www_authenticate_header_test.dart (3)
24-27: Appropriate header validation for empty WWW-Authenticate header.The test correctly validates that an empty WWW-Authenticate header results in a BadRequestException when accessed through the touchHeaders parameter.
43-46: Good use of control test for unused invalid headers.This test appropriately verifies that invalid headers don't cause issues when they aren't accessed, which is an important scenario to validate in the context of lazy header processing.
229-230: Consistent error handling validation across header tests.The approach to validating error handling for invalid headers is consistent with other header test files, which helps maintain a uniform testing methodology throughout the codebase.
test/headers/basic/content_location_header_test.dart (2)
93-97: Good implementation of control test for unused headers.The test appropriately verifies that invalid headers don't cause issues when they aren't accessed, using the
touchHeaders: (_) {}pattern consistently with other test files.
171-172: Consistent two-step validation for invalid headers.The validation approach for invalid headers is consistent with other header test files, validating both that:
- The value is null when accessed via the index operator with
valueOrNullIfInvalid- Accessing the property directly throws the expected exception
This consistency across different header types is good for maintaining a uniform testing approach.
test/headers/typed_headers/upgrade_header_test.dart (7)
1-3: Updated imports to support the new header architecture.The imports have been updated to include the standard headers extensions, aligning with the new architecture for typed access to headers.
25-28: Added touchHeaders parameter to explicitly access upgrade header.The
touchHeadersparameter is now used to explicitly activate the parsing and validation of the upgrade header. This change supports the lazy loading of header values, reducing memory overhead for unused headers.
45-48: Added touchHeaders parameter to validate upgrade header with invalid protocol.Similar to the previous test, this change adds the touchHeaders parameter to explicitly validate the upgrade header containing an invalid protocol.
64-67: Using var type inference and empty touchHeaders callback.Changed from explicit
Headerstype tovarfor type inference, and added an empty touchHeaders callback to avoid parsing the header since this test verifies the server doesn't respond with bad request when headers are not used.
77-80: Added touchHeaders parameter with empty callback for null check test.Similar pattern as previous test - using type inference and an empty callback since we're just checking that upgrade is null when no header is provided.
93-96: Added touchHeaders parameter to verify invalid protocol version handling.Consistent with the pattern throughout the file - explicitly touching the upgrade header to verify validation behavior with invalid protocol versions.
110-113: Implemented touchHeaders parameter for parsing multiple protocols.Both test cases implement the touchHeaders callback to ensure the upgrade header is properly parsed and validated when multiple protocols (including duplicate protocols) are provided.
Also applies to: 129-132
test/headers/typed_headers/accept_language_test.dart (9)
1-2: Updated imports to support the new header architecture.The imports have been updated to include the standard headers extensions instead of directly importing the headers file, aligning with the new typed header architecture.
11-21: Improved test structure with clearer group naming and organization.The test organization has been improved with clearer group naming and better indentation, making the test structure more readable.
28-40: Added touchHeaders parameter for explicit header validation.The touchHeaders parameter has been added to explicitly validate the accept-language header, supporting the new lazy loading mechanism that reduces memory overhead for unused headers.
50-62: Consistent implementation of touchHeaders across validation tests.All validation test cases now consistently implement the touchHeaders parameter to explicitly validate the accept-language header when testing invalid header scenarios, maintaining a uniform testing approach.
Also applies to: 71-84, 93-106
115-122: Added touchHeaders parameter with empty callback for header bypass test.Using an empty callback in touchHeaders allows testing that the server doesn't throw errors when invalid headers aren't actually accessed, supporting the lazy loading behavior.
129-139: Implemented touchHeaders parameter for various header parsing scenarios.All header parsing tests now consistently use the touchHeaders parameter to explicitly activate header parsing, ensuring the typed header values are correctly initialized and validated.
Also applies to: 146-156, 163-173, 179-186
192-200: Added touchHeaders for wildcard parsing test.The wildcard parsing test now explicitly activates the accept-language header processing through touchHeaders, demonstrating the correct handling of wildcard values.
224-360: Added comprehensive tests for multiple accept-language headers.This new test group significantly improves test coverage by adding tests for:
- Multiple languages in a single header
- Quality values parsing
- Duplicate value handling
- Whitespace handling
These tests ensure the typed header implementation correctly handles all valid variations of the accept-language header.
364-412: Added tests for non-strict header validation.This new test group verifies the behavior when strict validation is disabled, ensuring that:
- Invalid headers return null from valueOrNullIfInvalid
- Accessing the typed property throws InvalidHeader exceptions
This supports the new error handling approach for invalid headers.
test/headers/basic/via_header_test.dart (5)
1-3: Updated imports to support the new header architecture.The import statement has been updated to use standard_headers_extensions.dart instead of headers.dart, aligning with the new typed header architecture.
24-28: Added touchHeaders parameter to explicitly validate via header.The touchHeaders parameter has been added to explicitly validate the via header when testing empty values, supporting the lazy loading mechanism that reduces memory overhead for unused headers.
45-49: Using type inference and empty touchHeaders callback for bypass test.Changed from explicit
Headerstype tovarfor type inference, and added an empty touchHeaders callback to test that the server doesn't respond with bad request when headers aren't actually accessed.
58-62: Implemented touchHeaders parameter consistently across parsing tests.All header parsing tests now consistently use the touchHeaders parameter to explicitly activate the via header parsing, ensuring the typed header values are correctly initialized and validated.
Also applies to: 71-75, 85-89, 98-102
122-130: Updated error handling for non-strict validation.The test now verifies that:
- Invalid headers return null from valueOrNullIfInvalid
- Accessing the typed property throws an InvalidHeader exception
This supports the new error handling approach for invalid headers in non-strict mode.
test/headers/typed_headers/cache_control_header_test.dart (5)
1-3: Updated imports to support the new header architecture.The imports have been updated to include the standard headers extensions instead of the headers file directly, aligning with the new typed header architecture.
26-30: Added touchHeaders parameter consistently to validation tests.All validation tests now consistently use the touchHeaders parameter to explicitly activate the cache-control header parsing, ensuring proper validation of directives.
Also applies to: 47-51, 68-72, 89-93, 110-116
135-139: Updated header bypass test to use empty callback and headers.The test now uses an empty touchHeaders callback and empty headers object to verify that the server doesn't respond with bad request when headers aren't actually accessed.
148-152: Implemented touchHeaders parameter consistently across directive parsing tests.All directive parsing tests now consistently use the touchHeaders parameter to explicitly activate the cache-control header parsing, ensuring the typed header values are correctly initialized and validated for each specific directive.
Also applies to: 163-167, 176-180, 189-193, 202-206, 215-219, 228-232, 241-245, 254-258, 267-271, 280-284, 293-297, 306-310, 319-323
343-350: Updated error handling for non-strict validation.The test now verifies that:
- Invalid headers return null from valueOrNullIfInvalid
- Accessing the typed property throws an InvalidHeader exception
This supports the new error handling approach for invalid headers in non-strict mode.
test/headers/typed_headers/retry_after_header_test.dart (13)
1-4: Imports are updated for typed headers.These new imports are consistent with the typed header approach and appear correct.
26-28: Ensuring the header is parsed explicitly.Calling
touchHeaders: (h) => h.retryAfterforces parsing of the header value, enhancing test coverage for strict scenarios.
45-47: Skipping 'touchHeaders' to test unused header scenario.This approach verifies that an invalid header does not trigger a bad request if never accessed.
57-59: Positive integer scenario test.Good use of
touchHeadersto confirm correct parsing when accessed.
67-69: Whitespace handling test.Verifies that leading/trailing spaces are trimmed correctly for the
retryAfterheader.
78-80: Negative delay test.Ensures the strict mode rejects negative values.
93-95: Non-integer case test.Correctly verifies that decimal values trigger a bad request in strict mode.
109-111: Valid date parsing test.Confirms that the
retryAfteraccessor handles well-formed HTTP dates properly.
122-124: Whitespace date test.Checks parsing resilience for date strings with extra spaces.
136-138: Invalid date format test.Correctly triggers a bad request when the date format is unrecognized.
153-155: Missing header test.Testing behavior for absent
retry-afterconfirms the accessor returns null as expected.
176-178: Invalid non-strict scenario test.Demonstrates the header won't raise an error if parsing is never requested.
182-183: ValueOrNullIfInvalid vs. accessor test.Validates that attempting to read an invalid header accessor throws, but calling
valueOrNullIfInvalidreturns null.test/headers/typed_headers/strict_transport_security_header_test.dart (11)
1-3: Added imports for typed header logic.Including
standard_headers_extensions.dartis aligned with the shift to typed headers.
11-21: Group setup for strict flag = true.This creates a scoped environment to test strict HSTS behavior. The approach is well-structured.
22-38: Empty header test.Correctly checks that an empty Strict-Transport-Security header yields a bad request under strict mode.
41-59: Invalid max-age test.Confirms the server rejects malformed numerical directives and raises a descriptive error.
61-79: Missing max-age test.Ensures that omitting mandatory directives triggers a bad request in strict mode.
81-94: Unused header scenario.Verifies no error is thrown if the invalid header is never accessed, consistent with typed approach.
96-111: Valid header with includeSubDomains.Correctly parses
max-ageandincludeSubDomainsfrom a structured directive string.
113-126: Valid header without includeSubDomains.Checks that
includeSubDomainsdefaults to false if not present, ensuring correctness of typed parsing.
128-142: Valid header with preload.Properly confirms that
preloaddirective is recognized and parsed as expected.
143-155: No header scenario.Verifies that the typed accessor returns null when no Strict-Transport-Security header is supplied.
172-179: Strict flag = false + invalid header test.Ensures that in non-strict mode, invalid values do not cause a server error, but the typed accessor throws when forced. Good coverage.
lib/src/headers/headers.dart (11)
1-2: Imports with a TODO to removedart:io.Acknowledging the planned decoupling is acceptable. Refer to the existing TODO process or open an issue if it's a priority.
7-9: Parser and method imports.These are aligned with the new typed approach for header parsing.
10-10: Part directive for mutable_headers.Separating the mutable logic is a solid design choice for clarity and maintainability.
14-16:HeadersBaseunmodifiable wrapper.Wrapping a case-insensitive map ensures robust and consistent header lookups.
19-23:Headers.fromMapfactory handles null or empty maps.Coverage is lacking for the
return _emptyHeaders;branch on line 23.To improve code coverage, add a test that calls
Headers.fromMap(null)directly to confirm_emptyHeadersis returned.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 23-23: lib/src/headers/headers.dart#L23
Added line #L23 was not covered by tests
31-35:Headers.empty()andHeaders.build(...).Facilitates flexible creation of headers, allowing transformation via
MutableHeaders.
36-47: Private constructors for_empty()and_fromEntries(...).Efficiently building immutable headers from given entries.
48-52:transformmethod for in-place updates.Creating a new immutable instance after mutation respects functional style.
54-64:fromHttpRequestwith TODO to removedart:io.Pulling headers in strict or relaxed mode from an IO request is helpful. The plan to remove
dart:iois noted.
66-488: Typed header accessors.Comprehensive set of header accessors ensure typed reading for standard and modern headers. Implementation appears consistent with the new architecture.
575-575: Global_emptyHeadersinstance.Promotes a canonical empty headers object to minimize allocations.
lib/src/headers/header_accessor.dart (4)
84-101: No concerns found here.These utility methods (
isSetIn,isValidIn, operator[],setValueOn,removeFrom) appear both correct and concise, adhering to clean, readable design.
103-104: Internal helper is fine.
_returnNullis a minimal helper function for optional parsing fallback. It fits well within the design and is unlikely to cause issues.
105-124: Verify that edge cases are tested.
HeaderDecoderclasses correctly parse single-valued and multi-valued headers, but ensure exhaustive testing:
- Parsing empty or malformed input.
- Confirming correct handling of multiple values in
HeaderDecoderMulti.- Edge cases with invalid array lengths or data types.
Would you like me to generate a script or additional test stubs to verify coverage for these scenarios?
155-202: Double-check user-provided data handling in_setValue.While converting unknown object types to
toString()is standard practice for HTTP headers, malicious or unexpected data (e.g., newline injection) could lead to undesired behavior. If necessary, consider sanitizing or validating user-provided strings before storing them in headers, depending on your security requirements.
Description
All headers are created equal
This PR allows any header to be typed. We no longer distinguishes between standard and custom headers in any way.
Both can be handled as raw or typed values.
The PR also reduces the overhead associated with headers that are never used. Previously instances of the
Headersclass would for each standard header keep track of aT?, abool, and a reference to an initializer function for parsing, even if none of these where ever used. The parsing would happen lazy, but the memory cost was paid up front.Instead typed headers are handled using const constructed flyweights objects (
HeaderAccessor<T>) that avoids duplicated initializer references, and cache parsed values on theHeadersinstance usingExpandoobjects.Related Issues
Pre-Launch Checklist
Please ensure that your PR meets the following requirements before submitting:
///), ensuring consistency with existing project documentation.Breaking Changes
The public api of the
Headersclass changes.Additional Notes
Include any additional information or context about the PR here, if needed.
Summary by CodeRabbit
Improvements
Bug Fixes
Tests & Maintenance