@@ -160,27 +160,6 @@ fn isHostChar(c: u8) bool {
160160 };
161161}
162162
163- // Note: Chrome does not apply rules like removing a leading `.` from the domain.
164- fn percentEncodedDomain (allocator : Allocator , default_url : ? []const u8 , domain : ? []const u8 ) ! ? []const u8 {
165- if (domain ) | domain_ | {
166- return try allocator .dupe (u8 , domain_ );
167- } else if (default_url ) | url | {
168- const uri = std .Uri .parse (url ) catch return error .InvalidParams ;
169-
170- switch (uri .host orelse return error .InvalidParams ) {
171- .raw = > | str | {
172- var list = std .ArrayList (u8 ).init (allocator );
173- try list .ensureTotalCapacity (str .len ); // Expect no precents needed
174- try std .Uri .Component .percentEncode (list .writer (), str , isHostChar );
175- return list .items ; // @memory retains memory used before growing
176- },
177- .percent_encoded = > | str | {
178- return try allocator .dupe (u8 , str );
179- },
180- }
181- } else return null ;
182- }
183-
184163const CdpCookie = struct {
185164 name : []const u8 ,
186165 value : []const u8 ,
@@ -254,6 +233,31 @@ fn setCdpCookie(cookie_jar: *CookieJar, param: CdpCookie) !void {
254233 try cookie_jar .add (cookie , std .time .timestamp ());
255234}
256235
236+ // Note: Chrome does not apply rules like removing a leading `.` from the domain.
237+ fn percentEncodedDomain (allocator : Allocator , default_url : ? []const u8 , domain : ? []const u8 ) ! ? []const u8 {
238+ const toLower = @import ("../../browser/storage/cookie.zig" ).toLower ;
239+ if (domain ) | domain_ | {
240+ const output = try allocator .dupe (u8 , domain_ );
241+ return toLower (output );
242+ } else if (default_url ) | url | {
243+ const uri = std .Uri .parse (url ) catch return error .InvalidParams ;
244+
245+ var output : []u8 = undefined ;
246+ switch (uri .host orelse return error .InvalidParams ) {
247+ .raw = > | str | {
248+ var list = std .ArrayList (u8 ).init (allocator );
249+ try list .ensureTotalCapacity (str .len ); // Expect no precents needed
250+ try std .Uri .Component .percentEncode (list .writer (), str , isHostChar );
251+ output = list .items ; // @memory retains memory used before growing
252+ },
253+ .percent_encoded = > | str | {
254+ output = try allocator .dupe (u8 , str );
255+ },
256+ }
257+ return toLower (output );
258+ } else return null ;
259+ }
260+
257261// Upsert a header into the headers array.
258262// returns true if the header was added, false if it was updated
259263fn putAssumeCapacity (headers : * std .ArrayListUnmanaged (std.http.Header ), extra : std .http .Header ) bool {
0 commit comments