Skip to content

Commit 319d2d1

Browse files
committed
simplify cloning of Req/Resp
1 parent 2f0603d commit 319d2d1

File tree

4 files changed

+14
-36
lines changed

4 files changed

+14
-36
lines changed

src/browser/fetch/Headers.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ pub fn constructor(_init: ?HeadersInit, page: *Page) !Headers {
107107
};
108108
}
109109

110-
pub fn clone(self: *const Headers, allocator: std.mem.Allocator) !Headers {
111-
return Headers{
112-
.headers = try self.headers.clone(allocator),
113-
};
114-
}
115-
116110
pub fn append(self: *Headers, name: []const u8, value: []const u8, allocator: std.mem.Allocator) !void {
117111
const gop = try self.headers.getOrPut(allocator, name);
118112

src/browser/fetch/Request.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,23 @@ pub fn get_url(self: *const Request) []const u8 {
173173
return self.url;
174174
}
175175

176-
pub fn _clone(self: *Request, page: *Page) !Request {
176+
pub fn _clone(self: *Request) !Request {
177177
// Not allowed to clone if the body was used.
178178
if (self.body_used) {
179179
return error.TypeError;
180180
}
181181

182-
const arena = page.arena;
183-
182+
// OK to just return the same fields BECAUSE
183+
// all of these fields are read-only and can't be modified.
184184
return Request{
185-
.body = if (self.body) |body| try arena.dupe(u8, body) else null,
185+
.body = self.body,
186186
.body_used = self.body_used,
187187
.cache = self.cache,
188188
.credentials = self.credentials,
189-
.headers = try self.headers.clone(arena),
189+
.headers = self.headers,
190190
.method = self.method,
191-
.integrity = try arena.dupe(u8, self.integrity),
192-
.url = try arena.dupeZ(u8, self.url),
191+
.integrity = self.integrity,
192+
.url = self.url,
193193
};
194194
}
195195

src/browser/fetch/Response.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,21 @@ pub fn get_url(self: *const Response) []const u8 {
109109
return self.url;
110110
}
111111

112-
pub fn _clone(self: *const Response, page: *Page) !Response {
112+
pub fn _clone(self: *const Response) !Response {
113113
if (self.body_used) {
114114
return error.TypeError;
115115
}
116116

117-
const arena = page.arena;
118-
117+
// OK to just return the same fields BECAUSE
118+
// all of these fields are read-only and can't be modified.
119119
return Response{
120-
.body = try arena.dupe(u8, self.body),
120+
.body = self.body,
121121
.body_used = self.body_used,
122-
.mime = if (self.mime) |mime| try mime.clone(arena) else null,
123-
.headers = try self.headers.clone(arena),
122+
.mime = self.mime,
123+
.headers = self.headers,
124124
.redirected = self.redirected,
125125
.status = self.status,
126-
.url = try arena.dupe(u8, self.url),
126+
.url = self.url,
127127
};
128128
}
129129

src/browser/mime.zig

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,6 @@ pub const Mime = struct {
290290
fn trimRight(s: []const u8) []const u8 {
291291
return std.mem.trimRight(u8, s, &std.ascii.whitespace);
292292
}
293-
294-
pub fn clone(self: *const Mime, allocator: Allocator) !Mime {
295-
return Mime{
296-
.content_type = blk: {
297-
switch (self.content_type) {
298-
.other => |data| break :blk ContentType{ .other = .{
299-
.type = try allocator.dupe(u8, data.type),
300-
.sub_type = try allocator.dupe(u8, data.sub_type),
301-
} },
302-
else => break :blk self.content_type,
303-
}
304-
},
305-
.params = try allocator.dupe(u8, self.params),
306-
.charset = if (self.charset) |charset| try allocator.dupeZ(u8, charset) else null,
307-
};
308-
}
309293
};
310294

311295
const testing = @import("../testing.zig");

0 commit comments

Comments
 (0)