@@ -10,8 +10,8 @@ const public_suffix_list = @import("../../data/public_suffix_list.zig").lookup;
1010pub const LookupOpts = struct {
1111 request_time : ? i64 = null ,
1212 origin_uri : ? * const Uri = null ,
13- navigation : bool = true ,
1413 is_http : bool ,
14+ is_navigation : bool = true ,
1515};
1616
1717pub const Jar = struct {
@@ -91,7 +91,7 @@ pub const Jar = struct {
9191
9292 var first = true ;
9393 for (self .cookies .items ) | * cookie | {
94- if (! cookie .appliesTo (& target , same_site , opts .navigation , opts .is_http )) continue ;
94+ if (! cookie .appliesTo (& target , same_site , opts .is_navigation , opts .is_http )) continue ;
9595
9696 // we have a match!
9797 if (first ) {
@@ -103,18 +103,15 @@ pub const Jar = struct {
103103 }
104104 }
105105
106- // @newhttp
107- // pub fn populateFromResponse(self: *Jar, uri: *const Uri, header: *const http.ResponseHeader) !void {
108- // const now = std.time.timestamp();
109- // var it = header.iterate("set-cookie");
110- // while (it.next()) |set_cookie| {
111- // const c = Cookie.parse(self.allocator, uri, set_cookie) catch |err| {
112- // log.warn(.web_api, "cookie parse failed", .{ .raw = set_cookie, .err = err });
113- // continue;
114- // };
115- // try self.add(c, now);
116- // }
117- // }
106+ pub fn populateFromResponse (self : * Jar , uri : * const Uri , set_cookie : []const u8 ) ! void {
107+ const c = Cookie .parse (self .allocator , uri , set_cookie ) catch | err | {
108+ log .warn (.web_api , "cookie parse failed" , .{ .raw = set_cookie , .err = err });
109+ return ;
110+ };
111+
112+ const now = std .time .timestamp ();
113+ try self .add (c , now );
114+ }
118115
119116 fn writeCookie (cookie : * const Cookie , writer : anytype ) ! void {
120117 if (cookie .name .len > 0 ) {
@@ -429,7 +426,7 @@ pub const Cookie = struct {
429426 return .{ name , value , rest };
430427 }
431428
432- pub fn appliesTo (self : * const Cookie , url : * const PreparedUri , same_site : bool , navigation : bool , is_http : bool ) bool {
429+ pub fn appliesTo (self : * const Cookie , url : * const PreparedUri , same_site : bool , is_navigation : bool , is_http : bool ) bool {
433430 if (self .http_only and is_http == false ) {
434431 // http only cookies can be accessed from Javascript
435432 return false ;
@@ -448,7 +445,7 @@ pub const Cookie = struct {
448445 // and cookie.same_site == .lax
449446 switch (self .same_site ) {
450447 .strict = > return false ,
451- .lax = > if (navigation == false ) return false ,
448+ .lax = > if (is_navigation == false ) return false ,
452449 .none = > {},
453450 }
454451 }
@@ -619,7 +616,7 @@ test "Jar: forRequest" {
619616
620617 // nothing fancy here
621618 try expectCookies ("global1=1; global2=2" , & jar , test_uri , .{ .is_http = true });
622- try expectCookies ("global1=1; global2=2" , & jar , test_uri , .{ .origin_uri = & test_uri , .navigation = false , .is_http = true });
619+ try expectCookies ("global1=1; global2=2" , & jar , test_uri , .{ .origin_uri = & test_uri , .is_navigation = false , .is_http = true });
623620
624621 // We have a cookie where Domain=lightpanda.io
625622 // This should _not_ match xyxlightpanda.io
@@ -685,22 +682,22 @@ test "Jar: forRequest" {
685682 // non-navigational cross domain, insecure
686683 try expectCookies ("" , & jar , try std .Uri .parse ("http://lightpanda.io/x/" ), .{
687684 .origin_uri = &(try std .Uri .parse ("https://example.com/" )),
688- .navigation = false ,
689685 .is_http = true ,
686+ .is_navigation = false ,
690687 });
691688
692689 // non-navigational cross domain, secure
693690 try expectCookies ("sitenone=6" , & jar , try std .Uri .parse ("https://lightpanda.io/x/" ), .{
694691 .origin_uri = &(try std .Uri .parse ("https://example.com/" )),
695- .navigation = false ,
696692 .is_http = true ,
693+ .is_navigation = false ,
697694 });
698695
699696 // non-navigational same origin
700697 try expectCookies ("global1=1; global2=2; sitelax=7; sitestrict=8" , & jar , try std .Uri .parse ("http://lightpanda.io/x/" ), .{
701698 .origin_uri = &(try std .Uri .parse ("https://lightpanda.io/" )),
702- .navigation = false ,
703699 .is_http = true ,
700+ .is_navigation = false ,
704701 });
705702
706703 // exact domain match + suffix
0 commit comments