-
Notifications
You must be signed in to change notification settings - Fork 288
Document cookie #529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Document cookie #529
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
37340dc
dom: implement document.cookie
krichprollsch c88bc65
cookie: use a ; w/o space for cookie separator in requests
krichprollsch 0310192
dom: assume we are using an arena for cookie
krichprollsch ee6382e
dom: use cookie jar's allocator to parse cookie
krichprollsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,7 +145,7 @@ pub const Jar = struct { | |
| if (first) { | ||
| first = false; | ||
| } else { | ||
| try writer.writeAll(", "); | ||
| try writer.writeAll("; "); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with unit test: the test asserts the wrong behavior. Nice catch :) |
||
| } | ||
| try writeCookie(cookie, writer); | ||
| } | ||
|
|
@@ -563,8 +563,8 @@ test "Jar: forRequest" { | |
| try jar.add(try Cookie.parse(testing.allocator, &test_uri_2, "domain1=9;domain=test.lightpanda.io"), now); | ||
|
|
||
| // nothing fancy here | ||
| try expectCookies("global1=1, global2=2", &jar, test_uri, .{}); | ||
| try expectCookies("global1=1, global2=2", &jar, test_uri, .{ .origin_uri = &test_uri, .navigation = false }); | ||
| try expectCookies("global1=1; global2=2", &jar, test_uri, .{}); | ||
| try expectCookies("global1=1; global2=2", &jar, test_uri, .{ .origin_uri = &test_uri, .navigation = false }); | ||
|
|
||
| // We have a cookie where Domain=lightpanda.io | ||
| // This should _not_ match xyxlightpanda.io | ||
|
|
@@ -573,47 +573,47 @@ test "Jar: forRequest" { | |
| }); | ||
|
|
||
| // matching path without trailing / | ||
| try expectCookies("global1=1, global2=2, path1=3", &jar, try std.Uri.parse("http://lightpanda.io/about"), .{ | ||
| try expectCookies("global1=1; global2=2; path1=3", &jar, try std.Uri.parse("http://lightpanda.io/about"), .{ | ||
| .origin_uri = &test_uri, | ||
| }); | ||
|
|
||
| // incomplete prefix path | ||
| try expectCookies("global1=1, global2=2", &jar, try std.Uri.parse("http://lightpanda.io/abou"), .{ | ||
| try expectCookies("global1=1; global2=2", &jar, try std.Uri.parse("http://lightpanda.io/abou"), .{ | ||
| .origin_uri = &test_uri, | ||
| }); | ||
|
|
||
| // path doesn't match | ||
| try expectCookies("global1=1, global2=2", &jar, try std.Uri.parse("http://lightpanda.io/aboutus"), .{ | ||
| try expectCookies("global1=1; global2=2", &jar, try std.Uri.parse("http://lightpanda.io/aboutus"), .{ | ||
| .origin_uri = &test_uri, | ||
| }); | ||
|
|
||
| // path doesn't match cookie directory | ||
| try expectCookies("global1=1, global2=2", &jar, try std.Uri.parse("http://lightpanda.io/docs"), .{ | ||
| try expectCookies("global1=1; global2=2", &jar, try std.Uri.parse("http://lightpanda.io/docs"), .{ | ||
| .origin_uri = &test_uri, | ||
| }); | ||
|
|
||
| // exact directory match | ||
| try expectCookies("global1=1, global2=2, path2=4", &jar, try std.Uri.parse("http://lightpanda.io/docs/"), .{ | ||
| try expectCookies("global1=1; global2=2; path2=4", &jar, try std.Uri.parse("http://lightpanda.io/docs/"), .{ | ||
| .origin_uri = &test_uri, | ||
| }); | ||
|
|
||
| // sub directory match | ||
| try expectCookies("global1=1, global2=2, path2=4", &jar, try std.Uri.parse("http://lightpanda.io/docs/more"), .{ | ||
| try expectCookies("global1=1; global2=2; path2=4", &jar, try std.Uri.parse("http://lightpanda.io/docs/more"), .{ | ||
| .origin_uri = &test_uri, | ||
| }); | ||
|
|
||
| // secure | ||
| try expectCookies("global1=1, global2=2, secure=5", &jar, try std.Uri.parse("https://lightpanda.io/"), .{ | ||
| try expectCookies("global1=1; global2=2; secure=5", &jar, try std.Uri.parse("https://lightpanda.io/"), .{ | ||
| .origin_uri = &test_uri, | ||
| }); | ||
|
|
||
| // navigational cross domain, secure | ||
| try expectCookies("global1=1, global2=2, secure=5, sitenone=6, sitelax=7", &jar, try std.Uri.parse("https://lightpanda.io/x/"), .{ | ||
| try expectCookies("global1=1; global2=2; secure=5; sitenone=6; sitelax=7", &jar, try std.Uri.parse("https://lightpanda.io/x/"), .{ | ||
| .origin_uri = &(try std.Uri.parse("https://example.com/")), | ||
| }); | ||
|
|
||
| // navigational cross domain, insecure | ||
| try expectCookies("global1=1, global2=2, sitelax=7", &jar, try std.Uri.parse("http://lightpanda.io/x/"), .{ | ||
| try expectCookies("global1=1; global2=2; sitelax=7", &jar, try std.Uri.parse("http://lightpanda.io/x/"), .{ | ||
| .origin_uri = &(try std.Uri.parse("https://example.com/")), | ||
| }); | ||
|
|
||
|
|
@@ -630,18 +630,18 @@ test "Jar: forRequest" { | |
| }); | ||
|
|
||
| // non-navigational same origin | ||
| try expectCookies("global1=1, global2=2, sitelax=7, sitestrict=8", &jar, try std.Uri.parse("http://lightpanda.io/x/"), .{ | ||
| try expectCookies("global1=1; global2=2; sitelax=7; sitestrict=8", &jar, try std.Uri.parse("http://lightpanda.io/x/"), .{ | ||
| .origin_uri = &(try std.Uri.parse("https://lightpanda.io/")), | ||
| .navigation = false, | ||
| }); | ||
|
|
||
| // exact domain match + suffix | ||
| try expectCookies("global2=2, domain1=9", &jar, try std.Uri.parse("http://test.lightpanda.io/"), .{ | ||
| try expectCookies("global2=2; domain1=9", &jar, try std.Uri.parse("http://test.lightpanda.io/"), .{ | ||
| .origin_uri = &test_uri, | ||
| }); | ||
|
|
||
| // domain suffix match + suffix | ||
| try expectCookies("global2=2, domain1=9", &jar, try std.Uri.parse("http://1.test.lightpanda.io/"), .{ | ||
| try expectCookies("global2=2; domain1=9", &jar, try std.Uri.parse("http://1.test.lightpanda.io/"), .{ | ||
| .origin_uri = &test_uri, | ||
| }); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a problem, the cookie has to outlive the arena (cookies live for the duration of the session, the arena is for the page). You can parse with
userctx.cookie_jar.allocatorinstead ofarena.Not the first case where I think most web apis need the page_arena, but a few places need something with a longer lifetime. In
jsuruntime, there is no special parameter for Allocator (or Loop), there's simply asession_state.arena. We could add asession_state.session_arenaand/or asession_state.allocatorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 👍
Did you see other places in that case in web api implementations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat related, we see this problem with XHR, where the page_arena is disposed of, clearing out the XHR object, but there are still inflight IO events. It crashes the app. It happens if the page load is slow, and the CDP client disconnects due to a timeout. It's on my radar.
The only other thing which I think currently outlives the page is the storage shed, but I just looked at the code again, and it seems OK as it's using the Session's arena.