mirror of
				https://github.com/lightpanda-io/browser.git
				synced 2025-10-30 15:41:48 +00:00 
			
		
		
		
	simplify cloning of Req/Resp
This commit is contained in:
		| @@ -107,12 +107,6 @@ pub fn constructor(_init: ?HeadersInit, page: *Page) !Headers { | ||||
|     }; | ||||
| } | ||||
|  | ||||
| pub fn clone(self: *const Headers, allocator: std.mem.Allocator) !Headers { | ||||
|     return Headers{ | ||||
|         .headers = try self.headers.clone(allocator), | ||||
|     }; | ||||
| } | ||||
|  | ||||
| pub fn append(self: *Headers, name: []const u8, value: []const u8, allocator: std.mem.Allocator) !void { | ||||
|     const gop = try self.headers.getOrPut(allocator, name); | ||||
|  | ||||
|   | ||||
| @@ -173,23 +173,23 @@ pub fn get_url(self: *const Request) []const u8 { | ||||
|     return self.url; | ||||
| } | ||||
|  | ||||
| pub fn _clone(self: *Request, page: *Page) !Request { | ||||
| pub fn _clone(self: *Request) !Request { | ||||
|     // Not allowed to clone if the body was used. | ||||
|     if (self.body_used) { | ||||
|         return error.TypeError; | ||||
|     } | ||||
|  | ||||
|     const arena = page.arena; | ||||
|  | ||||
|     // OK to just return the same fields BECAUSE | ||||
|     // all of these fields are read-only and can't be modified. | ||||
|     return Request{ | ||||
|         .body = if (self.body) |body| try arena.dupe(u8, body) else null, | ||||
|         .body = self.body, | ||||
|         .body_used = self.body_used, | ||||
|         .cache = self.cache, | ||||
|         .credentials = self.credentials, | ||||
|         .headers = try self.headers.clone(arena), | ||||
|         .headers = self.headers, | ||||
|         .method = self.method, | ||||
|         .integrity = try arena.dupe(u8, self.integrity), | ||||
|         .url = try arena.dupeZ(u8, self.url), | ||||
|         .integrity = self.integrity, | ||||
|         .url = self.url, | ||||
|     }; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -109,21 +109,21 @@ pub fn get_url(self: *const Response) []const u8 { | ||||
|     return self.url; | ||||
| } | ||||
|  | ||||
| pub fn _clone(self: *const Response, page: *Page) !Response { | ||||
| pub fn _clone(self: *const Response) !Response { | ||||
|     if (self.body_used) { | ||||
|         return error.TypeError; | ||||
|     } | ||||
|  | ||||
|     const arena = page.arena; | ||||
|  | ||||
|     // OK to just return the same fields BECAUSE | ||||
|     // all of these fields are read-only and can't be modified. | ||||
|     return Response{ | ||||
|         .body = try arena.dupe(u8, self.body), | ||||
|         .body = self.body, | ||||
|         .body_used = self.body_used, | ||||
|         .mime = if (self.mime) |mime| try mime.clone(arena) else null, | ||||
|         .headers = try self.headers.clone(arena), | ||||
|         .mime = self.mime, | ||||
|         .headers = self.headers, | ||||
|         .redirected = self.redirected, | ||||
|         .status = self.status, | ||||
|         .url = try arena.dupe(u8, self.url), | ||||
|         .url = self.url, | ||||
|     }; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -290,22 +290,6 @@ pub const Mime = struct { | ||||
|     fn trimRight(s: []const u8) []const u8 { | ||||
|         return std.mem.trimRight(u8, s, &std.ascii.whitespace); | ||||
|     } | ||||
|  | ||||
|     pub fn clone(self: *const Mime, allocator: Allocator) !Mime { | ||||
|         return Mime{ | ||||
|             .content_type = blk: { | ||||
|                 switch (self.content_type) { | ||||
|                     .other => |data| break :blk ContentType{ .other = .{ | ||||
|                         .type = try allocator.dupe(u8, data.type), | ||||
|                         .sub_type = try allocator.dupe(u8, data.sub_type), | ||||
|                     } }, | ||||
|                     else => break :blk self.content_type, | ||||
|                 } | ||||
|             }, | ||||
|             .params = try allocator.dupe(u8, self.params), | ||||
|             .charset = if (self.charset) |charset| try allocator.dupeZ(u8, charset) else null, | ||||
|         }; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| const testing = @import("../testing.zig"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Muki Kiboigo
					Muki Kiboigo