@@ -32,6 +32,13 @@ pub const Jar = struct {
3232 self .cookies .deinit (self .allocator );
3333 }
3434
35+ pub fn clear (self : * Jar ) void {
36+ for (self .cookies .items ) | c | {
37+ c .deinit ();
38+ }
39+ self .cookies .clearRetainingCapacity ();
40+ }
41+
3542 pub fn add (
3643 self : * Jar ,
3744 cookie : Cookie ,
@@ -173,43 +180,43 @@ pub const Jar = struct {
173180 }
174181};
175182
176- pub const CookieList = struct {
177- _cookies : std .ArrayListUnmanaged (* const Cookie ) = .{},
178-
179- pub fn deinit (self : * CookieList , allocator : Allocator ) void {
180- self ._cookies .deinit (allocator );
181- }
182-
183- pub fn cookies (self : * const CookieList ) []* const Cookie {
184- return self ._cookies .items ;
185- }
186-
187- pub fn len (self : * const CookieList ) usize {
188- return self ._cookies .items .len ;
189- }
190-
191- pub fn write (self : * const CookieList , writer : anytype ) ! void {
192- const all = self ._cookies .items ;
193- if (all .len == 0 ) {
194- return ;
195- }
196- try writeCookie (all [0 ], writer );
197- for (all [1.. ]) | cookie | {
198- try writer .writeAll ("; " );
199- try writeCookie (cookie , writer );
200- }
201- }
202-
203- fn writeCookie (cookie : * const Cookie , writer : anytype ) ! void {
204- if (cookie .name .len > 0 ) {
205- try writer .writeAll (cookie .name );
206- try writer .writeByte ('=' );
207- }
208- if (cookie .value .len > 0 ) {
209- try writer .writeAll (cookie .value );
210- }
211- }
212- };
183+ // pub const CookieList = struct {
184+ // _cookies: std.ArrayListUnmanaged(*const Cookie) = .{},
185+
186+ // pub fn deinit(self: *CookieList, allocator: Allocator) void {
187+ // self._cookies.deinit(allocator);
188+ // }
189+
190+ // pub fn cookies(self: *const CookieList) []*const Cookie {
191+ // return self._cookies.items;
192+ // }
193+
194+ // pub fn len(self: *const CookieList) usize {
195+ // return self._cookies.items.len;
196+ // }
197+
198+ // pub fn write(self: *const CookieList, writer: anytype) !void {
199+ // const all = self._cookies.items;
200+ // if (all.len == 0) {
201+ // return;
202+ // }
203+ // try writeCookie(all[0], writer);
204+ // for (all[1..]) |cookie| {
205+ // try writer.writeAll("; ");
206+ // try writeCookie(cookie, writer);
207+ // }
208+ // }
209+
210+ // fn writeCookie(cookie: *const Cookie, writer: anytype) !void {
211+ // if (cookie.name.len > 0) {
212+ // try writer.writeAll(cookie.name);
213+ // try writer.writeByte('=');
214+ // }
215+ // if (cookie.value.len > 0) {
216+ // try writer.writeAll(cookie.value);
217+ // }
218+ // }
219+ // };
213220
214221fn isCookieExpired (cookie : * const Cookie , now : i64 ) bool {
215222 const ce = cookie .expires orelse return false ;
@@ -660,39 +667,39 @@ test "Jar: forRequest" {
660667 // the 'global2' cookie
661668}
662669
663- test "CookieList: write" {
664- var arr : std .ArrayListUnmanaged (u8 ) = .{};
665- defer arr .deinit (testing .allocator );
666-
667- var cookie_list = CookieList {};
668- defer cookie_list .deinit (testing .allocator );
669-
670- const c1 = try Cookie .parse (testing .allocator , & test_uri , "cookie_name=cookie_value" );
671- defer c1 .deinit ();
672- {
673- try cookie_list ._cookies .append (testing .allocator , & c1 );
674- try cookie_list .write (arr .writer (testing .allocator ));
675- try testing .expectEqual ("cookie_name=cookie_value" , arr .items );
676- }
677-
678- const c2 = try Cookie .parse (testing .allocator , & test_uri , "x84" );
679- defer c2 .deinit ();
680- {
681- arr .clearRetainingCapacity ();
682- try cookie_list ._cookies .append (testing .allocator , & c2 );
683- try cookie_list .write (arr .writer (testing .allocator ));
684- try testing .expectEqual ("cookie_name=cookie_value; x84" , arr .items );
685- }
686-
687- const c3 = try Cookie .parse (testing .allocator , & test_uri , "nope=" );
688- defer c3 .deinit ();
689- {
690- arr .clearRetainingCapacity ();
691- try cookie_list ._cookies .append (testing .allocator , & c3 );
692- try cookie_list .write (arr .writer (testing .allocator ));
693- try testing .expectEqual ("cookie_name=cookie_value; x84; nope=" , arr .items );
694- }
695- }
670+ // test "CookieList: write" {
671+ // var arr: std.ArrayListUnmanaged(u8) = .{};
672+ // defer arr.deinit(testing.allocator);
673+
674+ // var cookie_list = CookieList{};
675+ // defer cookie_list.deinit(testing.allocator);
676+
677+ // const c1 = try Cookie.parse(testing.allocator, &test_uri, "cookie_name=cookie_value");
678+ // defer c1.deinit();
679+ // {
680+ // try cookie_list._cookies.append(testing.allocator, &c1);
681+ // try cookie_list.write(arr.writer(testing.allocator));
682+ // try testing.expectEqual("cookie_name=cookie_value", arr.items);
683+ // }
684+
685+ // const c2 = try Cookie.parse(testing.allocator, &test_uri, "x84");
686+ // defer c2.deinit();
687+ // {
688+ // arr.clearRetainingCapacity();
689+ // try cookie_list._cookies.append(testing.allocator, &c2);
690+ // try cookie_list.write(arr.writer(testing.allocator));
691+ // try testing.expectEqual("cookie_name=cookie_value; x84", arr.items);
692+ // }
693+
694+ // const c3 = try Cookie.parse(testing.allocator, &test_uri, "nope=");
695+ // defer c3.deinit();
696+ // {
697+ // arr.clearRetainingCapacity();
698+ // try cookie_list._cookies.append(testing.allocator, &c3);
699+ // try cookie_list.write(arr.writer(testing.allocator));
700+ // try testing.expectEqual("cookie_name=cookie_value; x84; nope=", arr.items);
701+ // }
702+ // }
696703
697704test "Cookie: parse key=value" {
698705 try expectError (error .Empty , null , "" );
0 commit comments