Skip to content

feat!: Support typed access to custom headers - #38

Merged
nielsenko merged 39 commits into
serverpod:mainfrom
nielsenko:refactor-typed-headers
Apr 2, 2025
Merged

nielsenko merged 39 commits into
serverpod:mainfrom
nielsenko:refactor-typed-headers

Conversation

@nielsenko

@nielsenko nielsenko commented Mar 20, 2025 •

Copy link
Copy Markdown
Collaborator

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 Headers class would for each standard header keep track of a T?, a bool, 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 the Headers instance using Expando objects.

Related Issues

Pre-Launch Checklist

Please ensure that your PR meets the following requirements before submitting:

  • This update focuses on a single feature or bug fix. (For multiple fixes, please submit separate PRs.)
  • I have read and followed the Dart Style Guide and formatted the code using dart format.
  • I have referenced at least one issue this PR fixes or is related to.
  • I have updated/added relevant documentation (doc comments with ///), ensuring consistency with existing project documentation.
  • I have added new tests to verify the changes.
  • All existing and new tests pass successfully. (But some skipped)
  • I have documented any breaking changes below.

Breaking Changes

  • Includes breaking changes.
  • No breaking changes.

The public api of the Headers class changes.

Additional Notes

Include any additional information or context about the PR here, if needed.

Summary by CodeRabbit

  • Improvements

    • Consolidated HTTP header management improves consistency and reliability in request–response handling.
    • Enhanced validation and error messaging deliver more predictable interactions.
    • New functionality for managing headers, including better handling of exceptions and streamlined header processing.
  • Bug Fixes

    • Corrected header naming and parsing issues for more robust behavior.
    • Improved error handling for invalid headers ensures exceptions are thrown as expected.
  • Tests & Maintenance

    • Extensive test suite refinements ensure robust header validation.
    • Minor dependency updates enhance the overall development environment.
    • Introduced new test cases and parameters for more precise header manipulation during tests.

@coderabbitai

coderabbitai Bot commented Mar 20, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This 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 touchHeaders parameter) to streamline header construction, parsing, and validation.

Changes

File(s) Change Summary
lib/relic.dart, lib/src/headers/exception/invalid_header_exception.dart Updated export statements: removed show clauses and replaced export of invalid_header_exception.dart with consolidated export from header_exception.dart.
lib/src/extensions/http_response_extension.dart Simplified header application by removing an intermediate map and null check; added import for standard header extensions.
lib/src/handler/pipeline.dart Made _Pipeline constructor constant to allow compile-time instantiation.
lib/src/headers/custom/custom_headers.dart File deleted: Removed the custom headers implementation and related utility functions.
lib/src/headers/exception/header_exception.dart New file: Introduced a sealed base class HeaderException with subclasses for invalid and missing headers.
lib/src/headers/extension/string_list_extensions.dart Changed extension from operating on List<String> to Iterable<String>; updated return type from List<String> to Iterable<String>.
lib/src/headers/header_accessor.dart New file: Added HeaderAccessor class with caching via Expando plus header decoder classes and an extension type Header for strongly-typed header access.
lib/src/headers/headers.dart Refactored the Headers class: now a concrete implementation with multiple factory constructors (e.g., fromMap, empty, build); uses a case-insensitive backing store and updates header naming (e.g., renaming proxyAuthenticationHeader).
lib/src/headers/mutable_headers.dart New class MutableHeaders introduced to allow dynamic manipulation of headers with methods for freezing (converting to immutable state).
lib/src/headers/parser/common_types_parser.dart Streamlined parser functions (e.g., parsePositiveInt, parsePositiveBool) by removing redundant error handling and changing parameter types from List to Iterable; removed parseCustomHeaders.
lib/src/headers/parser/headers_parser.dart Updated import: now using HeaderException instead of InvalidHeaderException.
lib/src/headers/standard_headers_extensions.dart New file: Provided extensions on Headers and MutableHeaders to simplify access to standard HTTP header fields.
Multiple files under lib/src/headers/typed/headers/ Updated factory method signatures and property types across many typed header classes to accept Iterable<String> instead of List<String>, ensuring consistency and flexibility.
lib/src/message/request.dart & lib/src/message/response.dart Updated default header values from Headers.request() or Headers.response() to Headers.empty(); modified header transformation logic in redirection.
lib/src/relic_server.dart Refactored exception handling: replaced usage of InvalidHeaderException with HeaderException; enhanced header management logic via a transformation method for setting headers.
lib/src/static/static_handler.dart Changed header construction in file serving handlers from using direct constructor calls to the Headers.build method with transformation closures; updated dependencies.
pubspec.yaml Added a new dev dependency: meta: ^1.9.1.
Test Files (various under test/) Updated and refactored tests across header exception, handler, basic header tests, and extensive typed header tests. Changes include reorganizing imports (e.g., using standard_headers_extensions.dart), replacing custom headers with direct header access, introducing a touchHeaders callback in getServerRequestHeaders to streamline header manipulation, and updating assertions to check for exceptions via properties like valueOrNullIfInvalid.

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)
Loading

Assessment against linked issues

Objective (Linked Issues) Addressed Explanation
Extensible Typed Headers for Custom Implementations (#9, #41) ✅ Refactored typed header architecture and introduced extensible utilities (e.g., HeaderAccessor, extension type Header) facilitating custom implementations.
Adopt Extension Types and Class Modifiers for Header Design (#11) ✅ Added extension types (e.g., Header<T>) and used sealed classes (e.g., HeaderException) to control header behavior.
Refactoring Typed Headers for Flexibility and Efficiency (#33) ✅ Updated typed header classes to use iterables, streamlined parsing, and removed legacy lazy initialization approaches.
Refactor Lazy Parsing (#35) ✅ Simplified parsing functions and integrated caching mechanisms via HeaderAccessor to reduce overhead.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nielsenko nielsenko changed the title Use fly-weight pattern for typed headers feat!: Use fly-weight pattern for typed headers Mar 20, 2025
@nielsenko
nielsenko force-pushed the refactor-typed-headers branch 5 times, most recently from 54ec86c to febe642 Compare March 25, 2025 11:09
@nielsenko
nielsenko force-pushed the refactor-typed-headers branch from febe642 to 7b59f10 Compare March 25, 2025 11:15
@codecov

codecov Bot commented Mar 25, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.14512% with 17 lines in your changes missing coverage. Please review.

Project coverage is 78.43%. Comparing base (39deca6) to head (8ec8adb).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/src/headers/header_accessor.dart 88.33% 7 Missing ⚠️
lib/src/headers/exception/header_exception.dart 63.63% 4 Missing ⚠️
lib/src/headers/headers.dart 91.66% 2 Missing ⚠️
lib/src/message/response.dart 83.33% 2 Missing ⚠️
lib/src/relic_server.dart 71.42% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nielsenko nielsenko self-assigned this Mar 25, 2025
@SandPod SandPod removed this from Relic Roadmap Mar 25, 2025
@nielsenko
nielsenko force-pushed the refactor-typed-headers branch from 077f136 to 16d04be Compare March 25, 2025 15:08
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
@nielsenko
nielsenko force-pushed the refactor-typed-headers branch 2 times, most recently from 7902ecd to aaf51e2 Compare March 27, 2025 08:57
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
@nielsenko
nielsenko force-pushed the refactor-typed-headers branch from 2507e1f to 2da9997 Compare April 2, 2025 10:26

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

Given that the "invalid" and named arguments for SingleTest are removed :)

@nielsenko nielsenko changed the title feat!: Use fly-weight pattern for typed headers feat!: Support typed access to custom headers Apr 2, 2025
@nielsenko
nielsenko force-pushed the refactor-typed-headers branch from a8da619 to 1f3cbca Compare April 2, 2025 16:24
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Apr 2, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 2, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

1 similar comment
@coderabbitai

coderabbitai Bot commented Apr 2, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: Use Headers.build for consistency (optional suggestion).
While Headers.fromMap is valid for quick instantiations, consider using Headers.build for 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 _caches is a static container, consider clarifying its lifecycle and concurrency implications. Even though Expando doesn'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

📥 Commits

Reviewing files that changed from the base of the PR and between 7566f31 and f44ebbc.

📒 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 added

This 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: Added touchHeaders parameter to header tests

The addition of the touchHeaders parameter 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, touchHeaders is 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: Changed Headers headers to var headers

The change from explicit type declaration to using var simplifies 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 pattern

This 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 added

This 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: Added touchHeaders parameter to header tests

The addition of the touchHeaders parameter 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, touchHeaders is 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: Changed Headers headers to var headers

The change from explicit type declaration to using var simplifies 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 dependency

The addition of the meta package (^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 consistency

Moving the package:relic/relic.dart import 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 List

The parameter type change from List<String> to Iterable<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 constructor

Adding the const keyword to the _Pipeline constructor 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 structure

Updating the import to use header_exception.dart instead of the previous import aligns with the broader consolidation of exception handling in the PR. This suggests that InvalidHeaderException is now part of a hierarchy under HeaderException, 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 List

The parameter type change from List<String> to Iterable<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> to Iterable<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> to Iterable<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> to Iterable<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> to Iterable<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.build execution 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> to Iterable<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> to Iterable<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> to Iterable<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 flexibility

Changing from List<String> to Iterable<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 the join() 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 touchHeaders

The addition of the touchHeaders parameter 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 readability

Switching from explicit Headers type declarations to var leverages 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 welcome

Changing from request.headers.custom['header'] to directly accessing request.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 straightforward

Using Headers.build with direct assignments to the map is a cleaner approach than the previous implementation using Headers.response with a CustomHeaders object. 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 extensions

The 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 quality

The change from creating a mapped version of headers and checking for non-null values to directly iterating over headers.entries simplifies 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 touchHeaders parameter 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 for ifModifiedSince.

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 Headers to var for better flexibility, and a no-op function was added for touchHeaders. 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:

  1. Access via the accessor's valueOrNullIfInvalid property returns null for invalid headers
  2. Direct property access throws an InvalidHeader exception

This 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.dart which 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 touchHeaders parameter specifies which header should be processed during testing, in this case accessing secFetchSite. 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 Headers to var, and a no-op function is added for touchHeaders. 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: New touchHeaders parameter ensures header validation is properly triggered.

The addition of the touchHeaders parameter specifying (h) => h.acceptEncoding ensures 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].valueOrNullIfInvalid to check that invalid headers return null, followed by verifying that headers.acceptEncoding throws 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:

  • _anInt for single integer values using HeaderDecoderSingle
  • _someStrings for lists of strings using HeaderDecoderMulti

This demonstrates the type-safety capabilities of the new HeaderAccessor class.


18-25: Clean extension methods for typed header access.

The extensions on Headers and MutableHeaders provide 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:

  1. Single values are correctly parsed to their expected type (int)
  2. 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/isSet and isValidIn/isValid)
  • Verifying raw value access returns null
  • Ensuring value throws 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
  • valueOrNullIfInvalid safely returns null

This ensures robust error handling for malformed headers.


94-132: Thorough tests for header modification operations.

The tests verify:

  1. Setting headers in mutable collections works correctly
  2. Removing headers by setting to null works correctly
  3. Removing headers using the explicit removeFrom method works correctly
  4. 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.dart makes dependencies clearer.


29-29: Added touchHeaders parameter ensures proper header validation.

The addition of the touchHeaders parameter 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:

  1. Valid headers are correctly parsed
  2. Duplicate methods are properly handled
  3. Wildcard headers are correctly identified
  4. 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: Added touchHeaders parameter maintains consistent pattern across tests.

The addition of the touchHeaders parameter 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:

  1. Single policies with simple values
  2. Multiple policies with complex values
  3. 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].valueOrNullIfInvalid to check that invalid headers return null, followed by verifying that headers.permissionsPolicy throws 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 secFetchMode header, 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 secFetchMode through 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 headers to var headers simplifies 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 var for 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 lastModified header, 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:

  1. A no-op touchHeaders function to avoid triggering validation during header retrieval
  2. The new Headers.lastModified[headers].valueOrNullIfInvalid syntax to check the raw value
  3. An expectation that accessing headers.lastModified throws an InvalidHeader exception

This 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 var instead of Headers simplifies 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 var and 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:

  1. Uses a no-op touchHeaders function to avoid triggering validation during header retrieval
  2. Checks the raw value using Headers.connection[headers].valueOrNullIfInvalid
  3. Expects that accessing headers.connection throws an InvalidHeader exception

This 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.dart and the specific standard_headers_extensions.dart file.

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 touchHeaders parameter 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.dart and standard_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() to Headers.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 dart

Length of output: 113


Default Headers Initialization Change Verified

The change to initialize default headers using Headers.empty() is correct. The shell script output confirms that Headers.empty() is defined as intended in lib/src/headers/headers.dart (line containing factory 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.dart contains the proper definition for Headers.empty().
  • Affected File: lib/src/message/request.dart at line 137 where headers ?? 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:

  1. Uses touchHeaders with an empty callback
  2. Validates using Headers.etag[headers].valueOrNullIfInvalid instead of checking failedHeadersToParse
  3. 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 cases

The addition of the touchHeaders parameter in all getServerRequestHeaders calls enhances test precision by explicitly specifying when the Access-Control-Expose-Headers header 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 Headers type to var simplifies 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 handling

The updated assertions properly test both the low-level accessor behavior (valueOrNullIfInvalid) and the high-level extension property behavior (throwing InvalidHeader exception). 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 property

Changing fields from List<String>? to Iterable<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 method

Updating the parse method to accept Iterable<String> instead of List<String> maintains consistency with the fields property and provides more flexibility in how header values can be provided to the parser.


29-54: LGTM - Implementation adapts well to the new Iterable type

The implementation correctly handles the Iterable type 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 cases

The addition of the touchHeaders parameter in getServerRequestHeaders calls ensures that the contentEncoding header 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 var makes 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 handling

The 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 tests

The addition of the touchHeaders parameter in all test cases ensures that the te header 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 var makes 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 handling

The updated assertions properly test both the low-level accessor behavior (valueOrNullIfInvalid) and the high-level extension property behavior (throwing InvalidHeader exception). 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 Iterable

Changing from List<String> to Iterable<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 method

Updating the parameter type from List<String> to Iterable<String> aligns with the change to _validDirectives and allows the method to accept any iterable collection, following good API design principles.

lib/src/message/response.dart (2)

5-8: Improved import organization

The 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() to Headers.empty() across all response constructors simplifies header initialization. The transformation approach used in the _redirect constructor (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() to Headers.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 _redirect constructor’s transform((mh) => mh.location = location) transformation). However, our static analysis for the test suite did not return any matches for tests covering Response.noContent and Response.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.noContent
      • Response.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 consistency

The import changes align with the refactored header handling system introduced in this PR.


30-30: Added touchHeaders parameter for explicit header access

The addition of the touchHeaders parameter 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 declarations

Changing from explicit Headers type to var makes 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 validation

The new approach to checking invalid headers using valueOrNullIfInvalid and explicitly testing for exceptions with throwsInvalidHeader provides 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 accessibility

The changes to imports improve organization and align with the refactored header system.


29-30: Consistent header access with touchHeaders parameter

The consistent use of the touchHeaders parameter 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 declarations

Changing from explicit Headers type to var simplifies 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 validation

The new validation approach using valueOrNullIfInvalid and checking for exceptions with throwsInvalidHeader provides 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 extensions

The 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 header

The touchHeaders parameter is now used to explicitly access the clearSiteData header 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 header

Similar to the previous test, adding the touchHeaders parameter to trigger header parsing.


68-68: Added touchHeaders parameter to access clearSiteData header

The touchHeaders parameter is being added consistently across all tests to ensure the header is properly accessed.


85-88: Changed Headers type to var and added touchHeaders parameter

The explicit Headers type declaration is changed to var for simpler code maintenance, and the touchHeaders parameter is added to ensure we're not touching the clearSiteData header in this test.


97-100: Changed Headers type to var and added touchHeaders parameter

Similar 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 parameter

Consistent with the pattern of changes applied to all tests in this file.


128-131: Changed Headers type to var and added touchHeaders parameter

Consistent application of the same pattern to maintain uniformity across all tests.


152-155: Changed Headers type to var and added touchHeaders parameter

Simplified 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 approach

The test now properly checks that the clearSiteData value 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 extensions

The 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 header

The touchHeaders parameter is now used to explicitly access the proxyAuthorization header during tests, aligning with the new approach where headers are only parsed when accessed.


49-52: Changed Headers type to var and added touchHeaders parameter

The explicit Headers type declaration is changed to var for simpler code maintenance, and the touchHeaders parameter 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 placement

Simplified type declaration and adjusted the parameter order to maintain consistency with other tests.


82-83: Added touchHeaders parameter to access proxyAuthorization header

Consistent application of the touchHeaders parameter pattern across all tests in the file.


99-102: Changed Headers type to var and added touchHeaders parameter

Simplified type declaration and added explicit header access through the touchHeaders parameter.


124-125: Added touchHeaders parameter to access proxyAuthorization header

Continuing the consistent pattern of adding the touchHeaders parameter to all tests.


166-167: Added touchHeaders parameter to access proxyAuthorization header

Keeping the touchHeaders parameter consistent across all tests that access the proxyAuthorization header.


191-192: Added touchHeaders parameter to access proxyAuthorization header

Maintaining consistency in the application of the touchHeaders parameter.


214-215: Added touchHeaders parameter to access proxyAuthorization header

Consistent application of the touchHeaders parameter pattern.


238-239: Added touchHeaders parameter to access proxyAuthorization header

Continuing the pattern of adding the touchHeaders parameter to all tests that access the header.


262-263: Added touchHeaders parameter to access proxyAuthorization header

Following the established pattern for consistency across tests.


286-287: Added touchHeaders parameter to access proxyAuthorization header

Maintaining the consistent approach to header access in tests.


312-313: Added touchHeaders parameter to access proxyAuthorization header

Consistent with the established pattern across all tests.


335-336: Added touchHeaders parameter to access proxyAuthorization header

Continuing the consistent application of the touchHeaders parameter.


359-360: Added touchHeaders parameter to access proxyAuthorization header

Following the established pattern for consistency.


383-384: Added touchHeaders parameter to access proxyAuthorization header

Maintaining consistency in the application of the touchHeaders parameter.


407-408: Added touchHeaders parameter to access proxyAuthorization header

Consistent with the pattern applied throughout the file.


428-431: Changed Headers type to var and added touchHeaders parameter

Simplified 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 parameter

Similar to previous changes, simplifying the type declaration and adding explicit header access.


486-489: Changed Headers type to var and added touchHeaders parameter

Consistent 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 approach

The test now properly checks that the proxyAuthorization value 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 parameter

Consistent application of the pattern seen throughout the file.


509-510: Updated assertion to use the new header accessor approach

Similar 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 extensions

The 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 header

The touchHeaders parameter is now used to explicitly access the referrerPolicy header during tests, aligning with the new approach where headers are only parsed when accessed.


46-47: Added touchHeaders parameter to access referrerPolicy header

Continuing 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 parameter

The explicit Headers type declaration is changed to var for simpler code maintenance, and the touchHeaders parameter 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 parameter

Simplified type declaration and added explicit header access through the touchHeaders parameter.


89-92: Changed Headers type to var and added touchHeaders parameter

Consistent application of the same changes as in previous tests.


113-116: Changed Headers type to var and added touchHeaders parameter

Consistent 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 approach

The test now properly checks that the referrerPolicy value 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 extensions

The 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 setup

The 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 parameter

The test has been reformatted for improved readability and the touchHeaders parameter has been added to explicitly access the maxForwards header during the test.


44-64: Reformatted test for negative Max-Forwards header and added touchHeaders parameter

Similar to the previous test, this has been reformatted and the touchHeaders parameter has been added for consistency with the new header accessor approach.


66-86: Reformatted test for non-integer Max-Forwards header and added touchHeaders parameter

Continuing the pattern of reformatting tests and adding the touchHeaders parameter for explicit header access.


88-101: Added new test case for invalid Max-Forwards header with touchHeaders parameter

This 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 parameter

Continuing the consistent pattern of reformatting and adding the touchHeaders parameter.


116-129: Reformatted test for zero Max-Forwards header and added touchHeaders parameter

Similar 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 parameter

Final 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 false

This 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 false

This 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 flexibility

Changing from List<String> to Iterable<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 generalization

The factory method parameter type change from List<String> to Iterable<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 refactoring

The addition of standard_headers_extensions.dart import provides access to the new header extension methods, supporting the refactored header access approach.


27-27: Explicit header access with touchHeaders parameter

The new touchHeaders parameter 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 touch

Replacing explicit Headers type with var simplifies the code by leveraging Dart's type inference. The empty touchHeaders function 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 approach

The validation logic now uses Headers.contentDisposition[headers].valueOrNullIfInvalid for checking null values and expects a throwsInvalidHeader exception 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 extensions

The addition of standard_headers_extensions.dart import provides access to the new header extension methods, supporting the refactored header access approach.


28-28: Consistent touchHeaders parameter implementation

The new touchHeaders parameter 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 new HeaderAccessor pattern.

Also applies to: 49-49, 67-69, 80-82, 108-109


112-113: Updated invalid header validation approach

The validation logic now uses Headers.expect[headers].valueOrNullIfInvalid and expects a throwsInvalidHeader exception 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 extensions

Replacing headers.dart with standard_headers_extensions.dart provides access to the new header extension methods, supporting the refactored header access approach.


29-29: Comprehensive touchHeaders parameter implementation

The touchHeaders parameter 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 handling

The validation approach now uses Headers.host[headers].valueOrNullIfInvalid for checking null values and expects a throwsInvalidHeader exception 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 flexibility

These changes remove the restrictive show Headers clause and add a new export for header_accessor.dart, exposing the full API surface of the Headers module and introducing the new HeaderAccessor class. 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 exceptions

The export changes consolidate header-related exceptions under a single file and introduce a proper hierarchy with HeaderException as the base class. This provides better organization and more specific error handling capabilities with InvalidHeaderException and MissingHeaderException.

lib/src/headers/typed/headers/access_control_expose_headers_header.dart (2)

10-10: Improved flexibility with broader type acceptance

Changing from List<String>? to Iterable<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 signature

Updating the parse method to accept Iterable<String> instead of List<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 relationships

The MutableHeaders class nicely extends HeadersBase and implements MapMixin<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 management

The _freeze() method contains a TODO comment indicating a potential improvement to decouple the backing store from the MutableHeaders object. 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 management

The 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 handling

Adding the import for standard_headers_extensions.dart is necessary to support the new header access patterns used in the updated tests.


25-39: Improved test pattern with explicit header touching

The addition of the touchHeaders: (h) => h.range parameter 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 application

Similar 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 access

This 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 validation

This 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 functionality

Changing from explicit Headers type to var simplifies 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 pattern

These 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 headers

The 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 touchHeaders parameter ensures that the transferEncoding header 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 touchHeaders parameter ensures that the contentRange header 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 touchHeaders parameter ensures that the contentLanguage header 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 just List<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 than List<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 implements Iterable<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 the StringListExtensions extension, maintaining a uniform API.


50-50: Simplified return to match new return type.

Like the change in the StringListExtensions extension, this change directly returns a LinkedHashSet for 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 InvalidHeaderException with the more general HeaderException to 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 HeaderException in line with the changes to the exception hierarchy.


208-208: Streamlined exception handling for response writing.

Updated to use the consolidated HeaderException when 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 touchHeaders parameter 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 headers type to var headers for 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].valueOrNullIfInvalid accessor pattern and throws an InvalidHeader exception 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>? to Iterable<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 parse factory method from List<String> to Iterable<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 touchHeaders parameter, 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].valueOrNullIfInvalid accessor pattern and checks for throwsInvalidHeader when 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 touchHeaders parameter ensures that the accessControlMaxAge header 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 Headers type to var simplifies 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 var for 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 parameter

The addition of the touchHeaders parameter 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 validation

Excellent 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 approach

This change to use Headers.allow[headers].valueOrNullIfInvalid instead of direct property access is consistent with the new headers design, utilizing the HeaderAccessor<T> pattern described in the PR objectives.

test/headers/basic/content_location_header_test.dart (2)

88-101: Approve test for unused invalid headers

Well-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 handling

The combination of checking valueOrNullIfInvalid and verifying that direct access throws throwsInvalidHeader provides 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 extension

The HeadersEx extension 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 methods

The MutableHeadersEx extension 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 getters

The comment explaining why getter methods need to be duplicated in the MutableHeadersEx extension 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 import

Adding the import for standard_headers_extensions.dart is necessary to support the new header access pattern being implemented in this PR.


72-76: Good pattern for testing unused headers

Using var for the headers variable and providing an empty callback to touchHeaders creates 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 testing

The updated validation approach checks both the valueOrNullIfInvalid property and verifies the appropriate exception is thrown when directly accessing the property. This thoroughly tests the behavior of invalid headers with the new HeaderAccessor<T> implementation.

test/headers/typed_headers/cross_origin_resource_policy_header_test.dart (7)

1-3: LGTM - Standard headers extension import added

The import for standard_headers_extensions.dart is properly added to support the new approach for typed header access.


26-32: Updated test to use the new touchHeaders parameter

The test now correctly uses the touchHeaders callback to explicitly access the crossOriginResourcePolicy header, which aligns with the new typed header access approach introduced in this PR.


46-51: LGTM - Consistent pattern for header access

The test properly uses the touchHeaders parameter to explicitly access the header, maintaining consistent pattern across tests.


65-70: Good test for conditional validation

This 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 access

The test properly uses the new type-safe header accessor pattern to verify the parsed header value.


93-100: LGTM - Proper null handling

The test correctly verifies that missing headers return null when using the typed accessor.


122-128: LGTM - Consistent non-strict validation handling

Test 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 imports

The import for standard_headers_extensions.dart has been properly added to support the new typed header access approach.


26-30: LGTM - Updated to use touchHeaders parameter

The test now correctly uses the touchHeaders callback to explicitly access the userAgent header, enabling proper validation in the type-safe header system.


47-54: LGTM - Proper pattern for header non-validation

The 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 access

The test maintains the same pattern for accessing headers using the new touchHeaders parameter.


76-80: LGTM - Proper default value handling

The test correctly verifies default value handling with the new header accessor pattern.


100-108: Improved error handling with separate validation

The 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 import

The import for standard headers extensions has been correctly added to support the new header accessor pattern.


15-16: LGTM - Updated import path

The import path for mime_type.dart has been updated appropriately.


227-230: LGTM - Improved header construction with builder pattern

The code now uses the more maintainable Headers.build builder pattern instead of direct property assignment, allowing for a cleaner and more functional approach to header construction.


247-248: LGTM - Consistent builder pattern

The response headers are now constructed using the same builder pattern, maintaining consistency throughout the codebase.


317-323: LGTM - Using transform instead of copyWith

The code now uses the more functional transform method instead of copyWith, 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 imports

The import for standard_headers_extensions.dart has been properly added to support the new typed header access approach.


26-40: LGTM - Updated empty header validation

The 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 format

The 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 validation

The test correctly validates that invalid port numbers trigger appropriate exceptions when the header is accessed.


92-99: LGTM - Verification of unused header behavior

This 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 validation

The 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 extraction

The test verifies that port numbers are correctly extracted from Origin headers using the new accessor pattern.


137-146: LGTM - Whitespace handling verification

The test correctly verifies that whitespace is properly handled when parsing Origin headers.


153-160: LGTM - Proper null handling for missing headers

The test correctly verifies that missing headers return null when using the typed accessor.


177-184: LGTM - Improved error handling for non-strict mode

The 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 pattern

The 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 architecture

The imports have been updated to use standard_headers_extensions.dart instead 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: Added touchHeaders parameter to trigger header access

The new touchHeaders parameter 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: Added touchHeaders parameter to test invalid date handling

Similar 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 unused

This 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: Added touchHeaders parameter to test valid date parsing

Ensures the Date header is accessed during testing, which triggers the parsing logic being tested.


101-105: Added touchHeaders parameter to test whitespace handling

Similar to other changes, this ensures the Date header with whitespace is properly accessed and tested.


117-124: Added touchHeaders parameter to test null Date header

This 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 validation

The test now uses Headers.date[headers].valueOrNullIfInvalid to check the raw value and expects an exception when accessing the typed value with headers.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 validation

Similar 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.dart

The imports have been updated to use standard_headers_extensions.dart instead of direct header imports, aligning with the new header architecture.


27-27: Added touchHeaders parameter to test empty Via header

The 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: Added touchHeaders parameter to test header non-usage

This 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: Added touchHeaders parameter to test valid Via header

This change ensures the Via header is accessed during testing, activating the parsing logic being tested.


71-75: Added touchHeaders parameter to test whitespace handling

Similar to previous changes, this ensures the Via header with whitespace is properly accessed and tested.


85-89: Added touchHeaders parameter to test duplicate values

This ensures the Via header with duplicate values is properly accessed and tested for deduplication.


98-102: Added touchHeaders parameter to test null Via header

This 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 validation

The test now uses Headers.via[headers].valueOrNullIfInvalid to 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.dart

The imports have been updated to use standard_headers_extensions.dart instead of direct header imports, aligning with the new header architecture.


27-31: Added touchHeaders parameter to test empty Cross-Origin-Embedder-Policy header

This ensures the Cross-Origin-Embedder-Policy header is accessed during testing, activating validation in the new header access mechanism.


45-50: Added touchHeaders parameter to test invalid header value

Similar to other header tests, this ensures that invalid values are properly validated when the header is accessed.


65-70: Added touchHeaders parameter to test header non-usage

This verifies that headers aren't validated when not accessed, supporting the goal of reducing overhead for unused headers.


77-81: Added touchHeaders parameter to test valid header value

Ensures the header is accessed during testing, activating the parsing logic being tested.


90-101: Added test for when no header is passed

This test ensures that the absence of a Cross-Origin-Embedder-Policy header returns null when accessed.


105-130: Added tests for non-strict validation

This 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.dart

The imports have been updated to use standard_headers_extensions.dart instead of direct header imports, aligning with the new header architecture.


29-29: Added touchHeaders parameter to test empty If-Range header

This ensures the If-Range header is accessed during testing, triggering validation in the new header access mechanism.


50-50: Added touchHeaders parameter to test invalid ETag format

This change ensures that invalid ETag formats are properly validated when the header is accessed.


69-73: Added touchHeaders parameter to test header non-usage

This verifies that headers aren't validated when not accessed, supporting the PR's goal of reducing overhead for unused headers.


82-86: Added touchHeaders parameter to test valid ETag

Ensures the If-Range header with a valid ETag is accessed during testing, activating the parsing logic.


97-101: Added touchHeaders parameter to test weak ETag

Similar to the previous change, this ensures the If-Range header with a weak ETag is properly accessed and tested.


112-116: Added touchHeaders parameter to test HTTP date format

This ensures the If-Range header with an HTTP date is properly accessed and tested.


129-133: Added touchHeaders parameter to test null If-Range header

This 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 validation

The test now uses Headers.ifRange[headers].valueOrNullIfInvalid to 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.dart which likely contains the typed header accessors needed for the tests.


31-32: LGTM: Consistent introduction of touchHeaders parameter.

The addition of the touchHeaders parameter 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].valueOrNullIfInvalid to check for null values and expects an exception when directly accessing an invalid header through headers.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 touchHeaders parameter 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].valueOrNullIfInvalid to check for null values and expects an exception when directly accessing an invalid header through headers.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 touchHeaders parameter 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].valueOrNullIfInvalid to check for null values and expects an exception when directly accessing an invalid header through headers.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 HeaderException class 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 InvalidHeaderException class 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> to Iterable<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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders to 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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].valueOrNullIfInvalid and the throwsInvalidHeader matcher, 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders to 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders parameter 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 touchHeaders to 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 touchHeaders parameter 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 touchHeaders parameter 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].valueOrNullIfInvalid and the throwsInvalidHeader matcher, 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 support

The changes correctly update the import to use the more specific standard_headers_extensions.dart instead 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 formatting

The 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 parameter

The addition of the touchHeaders parameter 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 parameter

The 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 false

Good 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.parse

Changing the parameter type from List<String> to Iterable<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 conversion

The changes make the code more robust by:

  1. Explicitly converting the iterable to a list with .toList()
  2. Using .first instead of [0] to access the first element

This 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 implementation

The import change from headers.dart to standard_headers_extensions.dart correctly aligns with the PR's updated header handling approach.


27-28: Added touchHeaders parameter for explicit header access

The addition of the touchHeaders parameter 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 parameter

Changed from explicit Headers headers to var headers type inference, which is cleaner. The touchHeaders: (_) {} parameter indicates that in this test case, we're intentionally not accessing any header properties.


57-63: Consistent application of touchHeaders parameter

Similar 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 headers

The assertion pattern has been updated to:

  1. Check that the valueOrNullIfInvalid is null when accessing via the header accessor
  2. 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 implementation

The import change from headers.dart to standard_headers_extensions.dart correctly aligns with the PR's updated header handling approach.


28-31: Added touchHeaders parameter for explicit header access

The 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 messages

The 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:

  1. Empty header values
  2. Invalid max-age values
  3. Missing max-age directive

This provides better test coverage for the error handling in the header implementation.


96-126: Comprehensive testing of valid header parsing

These test cases thoroughly validate that the header is correctly parsed with different combinations of directives:

  1. With includeSubDomains
  2. Without includeSubDomains
    This ensures the header implementation correctly handles all valid use cases.

128-141: Added test for preload directive

Good 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 headers

The assertion pattern has been improved to:

  1. Check that valueOrNullIfInvalid is null when accessing through the header accessor
  2. 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/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.dart aligns with the PR's objective to enhance header handling through typed access.


21-40: Improved test structure with touchHeaders parameter.

The addition of the touchHeaders parameter 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].valueOrNullIfInvalid to access the header value, followed by an expectation that directly accessing headers.server will 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].valueOrNullIfInvalid to 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].valueOrNullIfInvalid to 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 from relic and local utility files without any redundant references.

Also applies to: 6-7


12-13: Good test for initial Headers state.
Using Headers.empty() and verifying it is empty properly ensures the default state behaves as expected.


25-29: Solid test for header removal.
Using transform((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.
Ensuring remove and 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 with Response.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 from MutableHeaders.


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.
Using parameterizedGroup is 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.
Verifying isValid is false and value throws 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 returns null when unset. Great coverage.


264-341: Ensuring named extension properties on empty MutableHeaders can be read as null.
This parallels the previous parameterized test and upholds consistency. Nicely done.


343-535: Verifying setting header values to both null and 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 in package:test/test.dart is necessary for matchers. Looks good.


76-77: Refactored callback-based header handling is sensible.
Replacing the eager parsing approach with the touchHeaders callback is a neat solution, allowing flexible modifications. Returning requestHeaders ensures the function’s original behavior remains.

Also applies to: 78-78, 83-83, 104-104


107-108: New matchers for header exceptions.
throwsInvalidHeader and throwsMissingHeader facilitate testing for typed header logic. This is a clear and reusable approach.

lib/src/headers/parser/common_types_parser.dart (4)

60-60: Use of parseInt for parsePositiveInt is concise.
The removal of duplicate checks is a positive change, but ensure negative values are the only additional check here.


85-85: parsePositiveBool relies on parseBool.
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 an Iterable<String> is more flexible than List<String>, and finalizing with toList() ensures consistent output. Nicely done.

Also applies to: 110-110


116-116: Enhanced flexibility for parseMethodList.
Similarly, switching from List<String> to Iterable<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 Expando is 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.accept ensures 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 valueOrNullIfInvalid is 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 extensions

The addition of the standard_headers_extensions.dart import 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 specificity

The new touchHeaders parameter 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 var

Changing the type declaration from explicit Headers to var simplifies 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 approach

The test now checks both the nullable access method (valueOrNullIfInvalid) and that direct access throws an InvalidHeader exception. This change reflects the new consistent exception handling for all headers (both standard and custom) as described in the PR objectives.

Comment thread lib/src/headers/headers.dart Resolved
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 2, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getServerRequestHeaders is inconsistent with other test files. Other files list touchHeaders after 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 HeaderAccessor instances, if new (non-const) accessors are created dynamically in practice, entries in _caches will 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, getValueFrom only catches Exception. In Dart, some runtime errors (e.g., TypeError, AssertionError) are not subclasses of Exception and won’t be handled here. If your use case requires gracefully handling or transforming all possible failures, you might catch Object rather than Exception. Otherwise, document that only Exception types are handled, letting other errors propagate.


126-153: Clarify naming for “invalid” vs. “missing” cases.

valueOrNullIfInvalid and valueOrNull both return null, but with subtle differences in what triggers that null. 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

📥 Commits

Reviewing files that changed from the base of the PR and between f44ebbc and 8ec8adb.

📒 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 of touchHeaders parameter for explicit header access.

The addition of touchHeaders: (h) => h.accessControlAllowOrigin parameter 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 of touchHeaders parameter.

The touchHeaders parameter 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:

  1. First checking that the value is null when accessed via the index operator
  2. 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 of touchHeaders parameter for error cases.

The implementation of touchHeaders for 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:

  1. expect(Headers.vary[headers].valueOrNullIfInvalid, isNull);
  2. 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:

  1. The value is null when accessed via the index operator with valueOrNullIfInvalid
  2. 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 touchHeaders parameter 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 Headers type to var for 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:

  1. Multiple languages in a single header
  2. Quality values parsing
  3. Duplicate value handling
  4. 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:

  1. Invalid headers return null from valueOrNullIfInvalid
  2. 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 Headers type to var for 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:

  1. Invalid headers return null from valueOrNullIfInvalid
  2. 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:

  1. Invalid headers return null from valueOrNullIfInvalid
  2. 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.retryAfter forces 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 touchHeaders to confirm correct parsing when accessed.


67-69: Whitespace handling test.

Verifies that leading/trailing spaces are trimmed correctly for the retryAfter header.


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 retryAfter accessor 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-after confirms 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 valueOrNullIfInvalid returns null.

test/headers/typed_headers/strict_transport_security_header_test.dart (11)

1-3: Added imports for typed header logic.

Including standard_headers_extensions.dart is 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-age and includeSubDomains from a structured directive string.


113-126: Valid header without includeSubDomains.

Checks that includeSubDomains defaults to false if not present, ensuring correctness of typed parsing.


128-142: Valid header with preload.

Properly confirms that preload directive 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 remove dart: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: HeadersBase unmodifiable wrapper.

Wrapping a case-insensitive map ensures robust and consistent header lookups.


19-23: Headers.fromMap factory 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 _emptyHeaders is 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() and Headers.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: transform method for in-place updates.

Creating a new immutable instance after mutation respects functional style.


54-64: fromHttpRequest with TODO to remove dart:io.

Pulling headers in strict or relaxed mode from an IO request is helpful. The plan to remove dart:io is 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 _emptyHeaders instance.

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.

_returnNull is 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.

HeaderDecoder classes 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants