feat: add pluggable cookie jar primitives#11
Conversation
|
Warning Review limit reached
More reviews will be available in 27 minutes and 31 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds ChangesPluggable Cookie Jar Primitives
Sequence Diagram(s)sequenceDiagram
participant App
participant CookieJar
participant CookiePolicy
participant CookieStore
rect rgba(70, 130, 180, 0.5)
Note over App,CookieStore: Save Set-Cookie response headers
App->>CookieJar: save(loginUri, setCookieValues)
CookieJar->>CookieStore: loadCandidates(loginUri)
CookieStore-->>CookieJar: existing StoredCookies
CookieJar->>CookiePolicy: normalizeSetCookie(value, requestUri)
CookiePolicy-->>CookieJar: StoredCookie
CookieJar->>CookieStore: upsert or delete by CookieKey
end
rect rgba(34, 139, 34, 0.5)
Note over App,CookieStore: Build Cookie request header
App->>CookieJar: header(profileUri)
CookieJar->>CookieStore: loadCandidates(profileUri)
CookieStore-->>CookieJar: candidate StoredCookies
CookieJar->>CookiePolicy: matches(cookie, uri, now)
CookieJar->>CookiePolicy: sortForHeader(matched)
CookieJar->>CookiePolicy: toRequestHeaderValue(sorted)
CookieJar-->>App: serialized Cookie header or null
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 39548c650a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
🧹 Nitpick comments (2)
lib/src/cookie_key.dart (1)
29-36: 💤 Low valueRemove redundant
runtimeTypecheck in equality operator.Since
CookieKeyis declared asfinal class(line 4), it cannot be subclassed. TheruntimeType == other.runtimeTypecheck on line 33 is therefore redundant—theother is CookieKeycheck on line 32 already guarantees the type.♻️ Simplify the equality operator
`@override` bool operator ==(Object other) => identical(this, other) || other is CookieKey && - runtimeType == other.runtimeType && name == other.name && domain == other.domain && path == other.path;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/src/cookie_key.dart` around lines 29 - 36, The equality operator in the CookieKey class contains a redundant runtimeType check. Since CookieKey is declared as a final class (line 4), it cannot be subclassed, making the runtimeType == other.runtimeType check on line 33 unnecessary because the other is CookieKey check on line 32 already guarantees the type is correct. Remove the runtimeType == other.runtimeType && portion from the operator == implementation to simplify the equality comparison while maintaining the same logic.lib/src/cookie_jar.dart (1)
202-213: 💤 Low valueRedundant sorting in
header()path.
loadStored()returns cookies already sorted bypolicy.sortForHeader()(line 189), buttoRequestHeaderValue()sorts them again internally (line 69). Consider adding a join-only helper to avoid the redundant O(n log n) work on eachheader()call:♻️ Suggested refactor
+ /// Joins pre-sorted cookies without re-sorting. + String _joinForHeader( + Iterable<StoredCookie> cookies, { + CookieCodec? encode, + }) { + return cookies + .map((cookie) => policy.toRequestCookie(cookie, encode: encode)) + .join('; '); + } + Future<String?> header( Uri uri, { DateTime? now, CookieCodec? encode, }) async { final cookies = await loadStored(uri, now: now); if (cookies.isEmpty) { return null; } - return policy.toRequestHeaderValue(cookies, encode: encode); + return _joinForHeader(cookies, encode: encode); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/src/cookie_jar.dart` around lines 202 - 213, The `header()` method is performing redundant sorting on cookies because `loadStored()` returns cookies already sorted by `policy.sortForHeader()`, yet `toRequestHeaderValue()` internally sorts them again. Create a join-only helper method (or add an optional parameter to `toRequestHeaderValue()`) that skips the sorting step and simply joins the already-sorted cookies. Update the `header()` method to use this new join-only helper instead of calling `toRequestHeaderValue()`, eliminating the unnecessary O(n log n) sorting operation on each `header()` call.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/src/cookie_jar.dart`:
- Around line 202-213: The `header()` method is performing redundant sorting on
cookies because `loadStored()` returns cookies already sorted by
`policy.sortForHeader()`, yet `toRequestHeaderValue()` internally sorts them
again. Create a join-only helper method (or add an optional parameter to
`toRequestHeaderValue()`) that skips the sorting step and simply joins the
already-sorted cookies. Update the `header()` method to use this new join-only
helper instead of calling `toRequestHeaderValue()`, eliminating the unnecessary
O(n log n) sorting operation on each `header()` call.
In `@lib/src/cookie_key.dart`:
- Around line 29-36: The equality operator in the CookieKey class contains a
redundant runtimeType check. Since CookieKey is declared as a final class (line
4), it cannot be subclassed, making the runtimeType == other.runtimeType check
on line 33 unnecessary because the other is CookieKey check on line 32 already
guarantees the type is correct. Remove the runtimeType == other.runtimeType &&
portion from the operator == implementation to simplify the equality comparison
while maintaining the same logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3ef8b670-87de-4100-a5e1-38e1f59dfce6
📒 Files selected for processing (8)
CHANGELOG.mdREADME.mdlib/ocookie.dartlib/src/cookie_jar.dartlib/src/cookie_key.dartlib/src/stored_cookie.darttest/cookie_jar_test.darttest/stored_cookie_test.dart
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8eb46ef25
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Summary
CookiePolicy,CookieStore,MemoryCookieStore,CookieJar, andCookieKeyfor pluggable cookie-jar behaviorStoredCookiewith public rehydration metadata, creation time, last access time, and metadata copy supportCloses #9.
Validation
dart analyzedart testdart pub publish --dry-runSummary by CodeRabbit
New Features
CookiePolicyfor cookie normalization,CookieStoreinterface for custom persistence,MemoryCookieStorefor in-memory storage, andCookieJarfor managing policies and storage.CookieKeyvalue object for cookie identity.Documentation
CookieJarusage examples and component documentation.