Skip to content

refactor: Introduce WildcardListHeader<T> base-class - #159

Merged
nielsenko merged 11 commits into
serverpod:mainfrom
nielsenko:wildcard-header-list
Sep 10, 2025
Merged

nielsenko merged 11 commits into
serverpod:mainfrom
nielsenko:wildcard-header-list

Conversation

@nielsenko

@nielsenko nielsenko commented Sep 9, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Refactors HTTP header classes to use a generic WildcardListHeader<T> base class. Moves parsing logic to factory constructors and encoding logic to instance methods on quality classes. Unifies the implementation pattern across all wildcard headers including Accept-Encoding, Accept-Language, Access-Control headers, Clear-Site-Data, and ETag condition headers.

Related Issues

N/A

Pre-Launch Checklist

  • This update focuses on a single feature or bug fix.
  • 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, ensuring consistency with existing project documentation.
  • I have added new tests to verify the changes.
  • All existing and new tests pass successfully.
  • I have documented any breaking changes below.

Breaking Changes

  • Includes breaking changes.

ETagConditionHeader constructors are no longer const due to base class constraints.

Additional Notes

All wildcard headers now follow consistent inheritance pattern. Test coverage maintained.

Summary by CodeRabbit

  • New Features

    • Unified wildcard/list handling across multiple headers for consistent parsing and encoding.
    • Added encode helpers and new parse/encode methods for encoding and language quality values.
  • Bug Fixes

    • Stricter validation: reject mixing wildcard (*) with other values; improved trimming, deduplication, and q-value checks.
    • More accurate, standardized header encoding.
  • Refactor

    • Headers now use a common base with simplified constructors and getters replacing fields.
  • Tests

    • Updated expectations and constructor usage to match new behaviors.

@coderabbitai

coderabbitai Bot commented Sep 9, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Refactors multiple typed headers to extend a new generic WildcardListHeader, centralizing wildcard/list parsing and encoding. Each header’s codec now uses private _parse/_encode helpers. Several classes replace stored fields with getters backed by the base class. Tests are updated for constructor const-ness and error message text.

Changes

Cohort / File(s) Summary of changes
Generic wildcard/list base
lib/src/headers/typed/headers/wildcard_list_header.dart
Adds WildcardListHeader with constructors, parse, encode, equality/hash, and toString for headers supporting "*" or a list of values.
Accept-Encoding
lib/src/headers/typed/headers/accept_encoding_header.dart
AcceptEncodingHeader now extends WildcardListHeader; switches to codec with _parse/_encode; replaces field with getter; adds EncodingQuality.parse/encode; updates constructors and helpers.
Accept-Language
lib/src/headers/typed/headers/accept_language_header.dart
AcceptLanguageHeader extends WildcardListHeader; moves to _parse/_encode; replaces field with getter; adds LanguageQuality.parse/encode; removes bespoke overrides.
CORS: Allow-Headers
lib/src/headers/typed/headers/access_control_allow_headers_header.dart
Extends WildcardListHeader; codec uses _parse/_encode; replaces field with getter; constructors delegate to base; adds encodeHeader; removes manual equality/toString.
CORS: Allow-Methods
lib/src/headers/typed/headers/access_control_allow_methods_header.dart
Extends WildcardListHeader; codec uses _parse/_encode; replaces field with getter; constructors delegate; adds encodeHeader; removes overrides.
CORS: Expose-Headers
lib/src/headers/typed/headers/access_control_expose_headers_header.dart
Extends WildcardListHeader; codec uses _parse/_encode; replaces field with getter; constructors delegate; adds encodeHeader; removes overrides.
Clear-Site-Data
lib/src/headers/typed/headers/clear_site_data_header.dart
Extends WildcardListHeader; adds private _parse with tokenization/validation and encodeHeader; codec uses _parse/_encode; replaces field with getter; removes overrides.
ETag conditions (If-Match / If-None-Match)
lib/src/headers/typed/headers/etag_condition_header.dart
ETagConditionHeader extends WildcardListHeader; IfMatch/IfNoneMatch codecs use _parse/_encode; constructors delegate; adds getters and encode helpers; removes overrides and const on etags constructors.
Tests: constructor and messaging tweaks
test/headers/header_test.dart, test/headers/typed/access_control_allow_headers_header_test.dart, test/static/if_none_match_test.dart
Adjust const usage for IfMatch/IfNoneMatch etags; update expected error text for wildcard misuse; minor formatting updates.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Caller
  participant Codec as HeaderCodec
  participant H as TypedHeader (extends WildcardListHeader)
  participant Base as WildcardListHeader<T>

  Note over Client,Codec: Parsing flow
  Client->>Codec: decode(values)
  Codec->>H: _parse(values)
  H->>Base: parse(values, elementParser)
  alt Single "*"
    Base-->>H: wildcard()
  else List of tokens
    Base-->>H: H(values)
  end
  H-->>Codec: instance
  Codec-->>Client: header instance

  Note over Client,Codec: Encoding flow
  Client->>Codec: encode(header)
  Codec->>H: _encode(header)
  H->>H: encodeHeader(header)
  H->>Base: header.encode(elementEncoder)
  Base-->>H: Iterable<String>
  H-->>Codec: List<String>
  Codec-->>Client: encoded values
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Pre-merge checks (1 passed, 2 warnings)

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title misnames the new base class as “WildcardHeaderList” even though the code introduces “WildcardListHeader”, and thus does not accurately summarize the primary change. Rename the title to accurately reference the class as “WildcardListHeader”, for example: “refactor: Introduce WildcardListHeader base class”.
Description Check ⚠️ Warning The description includes all major sections but deviates from the required template: the Breaking Changes section omits the second “No breaking changes” checkbox, and the Related Issues section uses “N/A” instead of linking any relevant issue or explicitly stating none. Add both checkboxes under Breaking Changes per the template and either link any related issues or replace “N/A” with a clear statement that there are no related issues.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description includes all major sections but deviates from the required template: the Breaking Changes section omits the second “No breaking changes” checkbox, and the Related Issues section uses “N/A” instead of linking any relevant issue or explicitly stating none. Add both checkboxes under Breaking Changes per the template and either link any related issues or replace “N/A” with a clear statement that there are no related issues.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title clearly summarizes the primary change of the pull request by concisely indicating the introduction of the new WildcardListHeader<T> base class and uses a single, focused sentence without extraneous details.
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Sep 9, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.84%. Comparing base (0b8098b) to head (725d962).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rc/headers/typed/headers/wildcard_list_header.dart 85.71% 4 Missing ⚠️
...c/headers/typed/headers/etag_condition_header.dart 92.00% 2 Missing ⚠️
.../headers/typed/headers/accept_encoding_header.dart 95.65% 1 Missing ⚠️
.../headers/typed/headers/accept_language_header.dart 95.65% 1 Missing ⚠️
...d/headers/access_control_allow_headers_header.dart 92.30% 1 Missing ⚠️
...d/headers/access_control_allow_methods_header.dart 92.30% 1 Missing ⚠️
.../headers/access_control_expose_headers_header.dart 92.30% 1 Missing ⚠️
.../headers/typed/headers/clear_site_data_header.dart 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #159      +/-   ##
==========================================
- Coverage   92.45%   91.84%   -0.61%     
==========================================
  Files          84       85       +1     
  Lines        3153     3128      -25     
  Branches     1610     1620      +10     
==========================================
- Hits         2915     2873      -42     
- Misses        238      255      +17     

☔ 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 force-pushed the wildcard-header-list branch from 715304e to b3469cb Compare September 9, 2025 09:41
@nielsenko nielsenko self-assigned this Sep 9, 2025
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Sep 9, 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: 2

🧹 Nitpick comments (13)
test/headers/typed/access_control_allow_headers_header_test.dart (1)

41-45: Align test description with new terminology (“values” not “headers”)

Minor copy tweak to mirror the unified error text.

- 'a message that states the wildcard cannot be used with other headers',
+ 'a message that states the wildcard cannot be used with other values',
lib/src/headers/typed/headers/wildcard_list_header.dart (2)

19-23: Enforce non-empty values at runtime, not just in asserts

Asserts are skipped in production; allow-list constructors could slip through with an empty list. Add a runtime guard.

-  WildcardListHeader(final List<T> values)
-      : assert(values.isNotEmpty, 'Values list cannot be empty'),
-        values = List.unmodifiable(values),
-        isWildcard = false;
+  WildcardListHeader(final List<T> values)
+      : assert(values.isNotEmpty, 'Values list cannot be empty'),
+        values = List.unmodifiable(values),
+        isWildcard = false {
+    if (this.values.isEmpty) {
+      throw ArgumentError('Values list cannot be empty');
+    }
+  }

76-82: Minor generic shadowing in helper

Avoid reusing the class’s type parameter name in the static helper for readability.

-  static bool _listEquals<T>(final List<T> a, final List<T> b) {
+  static bool _listEquals<E>(final List<E> a, final List<E> b) {
lib/src/headers/typed/headers/access_control_expose_headers_header.dart (1)

13-16: Guard against empty header lists at construction

Mirror the base-class runtime check so direct .headers(...) calls can’t create invalid instances in production.

-  AccessControlExposeHeadersHeader.headers(
-      {required final Iterable<String> headers})
-      : super(List.from(headers));
+  AccessControlExposeHeadersHeader.headers(
+      {required final Iterable<String> headers})
+      : super(List.from(headers)) {
+    if (this.headers.isEmpty) {
+      throw ArgumentError('Headers list cannot be empty');
+    }
+  }
lib/src/headers/typed/headers/access_control_allow_methods_header.dart (2)

32-36: Confirm whether '*' is valid for Access-Control-Allow-Methods

Specs commonly require an explicit list of methods; wildcard may be non-compliant. If '*' is not allowed, reject it in parse.

Apply this diff if wildcard must be disallowed:

-    if (parsed.isWildcard) {
-      return const AccessControlAllowMethodsHeader.wildcard();
-    } else {
+    if (parsed.isWildcard) {
+      throw const FormatException("Wildcard '*' is not permitted for Access-Control-Allow-Methods");
+    } else {
       return AccessControlAllowMethodsHeader.methods(methods: parsed.values);
     }

39-46: Encode as a single comma-separated header value for consistency

Most list-type headers are serialized as one field with comma-separated items. Consider emitting one joined value.

-  static List<String> encodeHeader(
-      final AccessControlAllowMethodsHeader header) {
-    return header.encode((final RequestMethod rm) => rm.value).toList();
-  }
+  static List<String> encodeHeader(
+      final AccessControlAllowMethodsHeader header) {
+    return [header.encode((final RequestMethod rm) => rm.value).join(', ')];
+  }
lib/src/headers/typed/headers/accept_language_header.dart (3)

36-42: Prefer a single comma-separated header string

Align encoding with common HTTP list serialization; emit one value instead of many.

-  static List<String> encodeHeader(final AcceptLanguageHeader header) {
-    return header.encode((final LanguageQuality lq) => lq.encode()).toList();
-  }
+  static List<String> encodeHeader(final AcceptLanguageHeader header) {
+    return [header.encode((final LanguageQuality lq) => lq.encode()).join(', ')];
+  }

57-75: Make q-parameter parsing tolerant (case/spacing) and stricter by ABNF

Current split on ';q=' misses variants like '; q=0.8' or uppercase 'Q'. Use a regex to parse robustly and validate precision.

-  factory LanguageQuality.parse(final String value) {
-    final languageParts = value.split(';q=');
-    final language = languageParts[0].trim().toLowerCase();
-    if (language.isEmpty) {
-      throw const FormatException('Invalid language');
-    }
-
-    double? quality;
-    if (languageParts.length > 1) {
-      final qualityValue = double.tryParse(languageParts[1].trim());
-      if (qualityValue == null || qualityValue < 0 || qualityValue > 1) {
-        throw const FormatException('Invalid quality value');
-      }
-      quality = qualityValue;
-    }
-    return LanguageQuality(language, quality);
-  }
+  factory LanguageQuality.parse(final String value) {
+    final re = RegExp(
+        r'^\s*([A-Za-z0-9*-]+)\s*(?:;\s*[qQ]\s*=\s*([0-9](?:\.[0-9]{0,3})?))?\s*$');
+    final m = re.firstMatch(value);
+    if (m == null) {
+      throw const FormatException('Invalid language');
+    }
+    final language = m.group(1)!.toLowerCase();
+    final qStr = m.group(2);
+    double? quality;
+    if (qStr != null) {
+      final q = double.tryParse(qStr);
+      if (q == null || q < 0 || q > 1) {
+        throw const FormatException('Invalid quality value');
+      }
+      quality = q;
+    }
+    return LanguageQuality(language, quality);
+  }

77-81: Normalize q formatting to max 3 decimals and trim trailing zeros

Produces cleaner wire format and aligns with common weighting precision.

-  String encode() {
-    return quality == 1.0 ? language : '$language;q=$quality';
-  }
+  String encode() {
+    final q = quality ?? 1.0;
+    if (q == 1.0) return language;
+    final qStr = q.toStringAsFixed(3).replaceFirst(RegExp(r'\.?0+$'), '');
+    return '$language;q=$qStr';
+  }
lib/src/headers/typed/headers/clear_site_data_header.dart (1)

88-90: Docstring contradicts implementation

Comment claims “returns a custom instance” but code throws. Fix the comment or implement custom values.

-  /// If the value does not match any predefined types, it returns a custom instance.
+  /// If the value does not match any predefined types, a [FormatException] is thrown.
lib/src/headers/typed/headers/access_control_allow_headers_header.dart (1)

39-46: Consider simplifying the encoding delegation.

The double delegation pattern (encodeHeader → _encode) seems unnecessary here. Since _encode simply calls encodeHeader, you could directly use encodeHeader in the codec.

-  static const codec = HeaderCodec(_parse, _encode);
+  static const codec = HeaderCodec(_parse, encodeHeader);

   static List<String> encodeHeader(
       final AccessControlAllowHeadersHeader header) {
     return header.encode((final String str) => str).toList();
   }
-
-  static List<String> _encode(final AccessControlAllowHeadersHeader header) {
-    return encodeHeader(header);
-  }
lib/src/headers/typed/headers/accept_encoding_header.dart (1)

36-42: Consider simplifying the encoding delegation here as well.

Similar to the previous file, the double delegation through _encode appears unnecessary.

-  static const codec = HeaderCodec(_parse, _encode);
+  static const codec = HeaderCodec(_parse, encodeHeader);

   static List<String> encodeHeader(final AcceptEncodingHeader header) {
     return header.encode((final EncodingQuality eq) => eq.encode()).toList();
   }
-
-  static List<String> _encode(final AcceptEncodingHeader header) {
-    return encodeHeader(header);
-  }
lib/src/headers/typed/headers/etag_condition_header.dart (1)

47-53: Apply consistent encoding simplification.

Both IfMatchHeader and IfNoneMatchHeader have the same double delegation pattern that could be simplified.

For IfMatchHeader:

-  static const codec = HeaderCodec(_parse, _encode);
+  static const codec = HeaderCodec(_parse, encodeHeader);

   static List<String> encodeHeader(final IfMatchHeader header) {
     return header.encode((final ETagHeader etag) => etag.encode()).toList();
   }
-
-  static List<String> _encode(final IfMatchHeader header) {
-    return encodeHeader(header);
-  }

For IfNoneMatchHeader:

-  static const codec = HeaderCodec(_parse, _encode);
+  static const codec = HeaderCodec(_parse, encodeHeader);

   static List<String> encodeHeader(final IfNoneMatchHeader header) {
     return header.encode((final ETagHeader etag) => etag.encode()).toList();
   }
-
-  static List<String> _encode(final IfNoneMatchHeader header) {
-    return encodeHeader(header);
-  }

Also applies to: 86-92

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ac8e4e and b3469cb.

📒 Files selected for processing (11)
  • lib/src/headers/typed/headers/accept_encoding_header.dart (2 hunks)
  • lib/src/headers/typed/headers/accept_language_header.dart (2 hunks)
  • lib/src/headers/typed/headers/access_control_allow_headers_header.dart (1 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 (1 hunks)
  • lib/src/headers/typed/headers/clear_site_data_header.dart (2 hunks)
  • lib/src/headers/typed/headers/etag_condition_header.dart (1 hunks)
  • lib/src/headers/typed/headers/wildcard_list_header.dart (1 hunks)
  • test/headers/header_test.dart (1 hunks)
  • test/headers/typed/access_control_allow_headers_header_test.dart (1 hunks)
  • test/static/if_none_match_test.dart (1 hunks)
🔇 Additional comments (20)
test/headers/typed/access_control_allow_headers_header_test.dart (1)

55-56: Updated error message assertion — LGTM

Matches the new shared validation text from WildcardListHeader.

test/headers/header_test.dart (1)

696-699: Remove const on IfMatchHeader.etags — LGTM

Correctly reflects that etag condition headers’ list constructors are no longer const, while keeping inner ETagHeader const.

Run to catch any lingering const usages that would now be invalid:

#!/bin/bash
# Find remaining const uses of list-based ETag condition headers.
rg -nP -S 'const\s+IfNoneMatchHeader\.etags\('
rg -nP -S 'const\s+IfMatchHeader\.etags\('
test/static/if_none_match_test.dart (1)

42-45: Drop const on IfNoneMatchHeader.etags — LGTM

Consistent with the refactor; inner ETagHeader remains const.

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

30-39: Parsing delegation — LGTM

Clean delegation to the generic parser with an identity mapper; wildcard and non-wildcard cases mapped correctly.

lib/src/headers/typed/headers/access_control_allow_methods_header.dart (1)

26-27: Getter replacement looks good

Replacing a public field with a getter backed by the base values is clean and keeps immutability semantics.

lib/src/headers/typed/headers/clear_site_data_header.dart (1)

26-33: Quote stripping and de-duplication look good

Handles multiple header lines, trims quotes, and removes duplicates; default toSet() keeps insertion order in Dart.

lib/src/headers/typed/headers/access_control_allow_headers_header.dart (5)

1-2: LGTM! Clean import consolidation.

The import changes align well with the new base class architecture, replacing multiple utility imports with the single wildcard_list_header.dart import.


8-8: Good architectural improvement with the generic base class.

The refactoring to extend WildcardListHeader<String> provides better code reuse and consistency across header implementations.


25-26: Good API preservation with the headers getter.

The getter maintains backward compatibility while delegating to the base class's values property. This is a clean approach to preserving the public API.


28-37: Well-structured parsing delegation.

The parsing logic properly delegates to WildcardListHeader.parse with appropriate identity function for string values. The conditional construction based on isWildcard is clean and maintainable.


9-9: Verify the codec pattern consistency across all refactored headers.

The codec now uses private static methods _parse and _encode, which is a good encapsulation pattern. Let's verify this pattern is consistently applied across all refactored headers.

#!/bin/bash
# Verify that all header classes following the WildcardListHeader pattern use the same codec structure
rg -A 2 "extends WildcardListHeader" --type dart | head -20
rg "static const codec = HeaderCodec\(_parse, _encode\)" --type dart
lib/src/headers/typed/headers/accept_encoding_header.dart (4)

7-8: Excellent type-safe refactoring with EncodingQuality.

Using WildcardListHeader<EncodingQuality> provides strong typing while maintaining the wildcard functionality. The codec pattern is consistent with other refactored headers.


24-24: Good API preservation for backward compatibility.

The encodings getter maintains the existing public API while internally using the base class's values property.


58-75: Well-implemented parsing with proper validation.

The EncodingQuality.parse factory constructor includes good error handling for empty encodings and invalid quality values (range checking 0-1). The quality value parsing with optional ;q= suffix is correct.


78-80: Clean encoding implementation.

The encode() method correctly handles the default quality value of 1.0 by omitting it from the output, which follows HTTP header best practices.

lib/src/headers/typed/headers/etag_condition_header.dart (5)

6-6: Good use of sealed class for the hierarchy.

Using sealed class for ETagConditionHeader ensures exhaustive matching and prevents external implementations while allowing IfMatchHeader and IfNoneMatchHeader to extend it.


8-11: Note the breaking change: constructors are no longer const.

As mentioned in the PR objectives, the ETagConditionHeader.etags constructor can no longer be const due to base class constraints. This is a necessary trade-off for the unified architecture.


14-14: Consistent API preservation pattern.

The etags getter follows the same pattern as other refactored headers, maintaining backward compatibility.


32-44: Good validation in parsing logic.

Both IfMatchHeader and IfNoneMatchHeader properly validate ETag format before parsing. The use of ETagHeader.isValidETag ensures consistent validation.

Also applies to: 71-83


1-93: Verify the WildcardListHeader base class implementation.

The refactoring looks solid, but we should verify that the WildcardListHeader base class properly handles the common functionality, especially the wildcard validation logic mentioned in test updates.

#!/bin/bash
# Check the WildcardListHeader implementation
fd -e dart "wildcard_list_header.dart" --exec cat {}

# Verify that error messages are consistent
rg "Wildcard.*cannot be used with other values" --type dart

@nielsenko
nielsenko force-pushed the wildcard-header-list branch from b3469cb to 1a98212 Compare September 9, 2025 10:35
@nielsenko
nielsenko marked this pull request as ready for review September 9, 2025 10:37
@nielsenko
nielsenko requested a review from a team September 9, 2025 10:38
@nielsenko nielsenko changed the title refactor: Introduce WildcardHeaderList<T> base-class refactor: Introduce WildcardListHeader <T> base-class Sep 9, 2025
@nielsenko nielsenko changed the title refactor: Introduce WildcardListHeader <T> base-class refactor: Introduce WildcardListHeader<T> base-class Sep 9, 2025
@SandPod SandPod self-assigned this Sep 10, 2025

@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.

Clean refactor. Just one question.

@nielsenko
nielsenko requested a review from SandPod September 10, 2025 09:19
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@SandPod Can we disregard the codecov failure? This PR removes a lot of redundant but tested code, meaning the number of lines and lines covered has been reduced 1:1 causing the overall project coverage to be reduced. The actual patch has higher than project coverage.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

Rebased on main

Add WildcardListHeader<T> to handle common wildcard/list pattern:
- Generic wildcard parsing with '*' validation  
- List management with typed values
- Flexible encoding via function parameter
- No constraints on type parameter T
- Foundation for refactoring Accept headers
…ListHeader

Refactored AcceptEncodingHeader and AcceptLanguageHeader as subclasses of WildcardListHeader
- Fix AccessControlAllowMethodsHeader to use proper uppercase HTTP method names
- RequestMethod.value returns uppercase (e.g. 'GET') while .name returns lowercase
- Convert AccessControlAllowMethodsHeader to extend WildcardListHeader<RequestMethod>
- Use WildcardListHeader.parse for consistent parsing logic
- Remove duplicated wildcard handling code
- Follow same pattern as AcceptEncodingHeader and AcceptLanguageHeader
…ader

- Convert AccessControlExposeHeadersHeader to extend WildcardListHeader<String>
- Use WildcardListHeader.parse for consistent parsing logic
- Remove duplicated wildcard handling code
- Follow same pattern as other wildcard headers
- Convert AccessControlAllowHeadersHeader to extend WildcardListHeader<String>
- Use WildcardListHeader.parse for consistent parsing logic  
- Remove duplicated wildcard handling code
- Update test to use standardized error message 'other values' instead of 'other headers'
- Convert ClearSiteDataHeader to extend WildcardListHeader<ClearSiteDataType>
- Preserve custom quote removal logic for Clear-Site-Data header format
- Use custom parsing instead of WildcardListHeader.parse to handle quotes
- Remove duplicated wildcard handling code
- Follow same pattern as other wildcard headers
- Convert ETagConditionHeader base class to extend WildcardListHeader<ETagHeader>
- Update IfMatchHeader and IfNoneMatchHeader to use base class functionality
- Use WildcardListHeader.parse for consistent parsing logic
- Remove duplicated wildcard handling code from both concrete classes
- Fix const constructor calls in tests (etags constructor is no longer const)
- Follow same pattern as other wildcard headers
@nielsenko

Copy link
Copy Markdown
Collaborator Author

Rebased on main

@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.

🚀

@nielsenko
nielsenko merged commit 44378bc into serverpod:main Sep 10, 2025
@nielsenko
nielsenko deleted the wildcard-header-list branch September 10, 2025 13:22
@coderabbitai coderabbitai Bot mentioned this pull request Jun 12, 2026
7 of 9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants