Skip to content

Commit c5e5ef0

Browse files
committed
use proper Headers in fetch()
1 parent 8ccf8e7 commit c5e5ef0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/browser/fetch/fetch.zig

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ const Page = @import("../page.zig").Page;
2626
const Http = @import("../../http/Http.zig");
2727
const HttpClient = @import("../../http/Client.zig");
2828
const Mime = @import("../mime.zig").Mime;
29+
const Headers = @import("Headers.zig");
2930

3031
const RequestInput = @import("Request.zig").RequestInput;
3132
const RequestInit = @import("Request.zig").RequestInit;
3233
const Request = @import("Request.zig");
33-
const Response = @import("./Response.zig");
34+
const Response = @import("Response.zig");
3435

3536
pub const Interfaces = .{
3637
@import("Headers.zig"),
@@ -56,11 +57,22 @@ const FetchContext = struct {
5657
/// We just return the underlying slices used for `headers`
5758
/// and for `body` here to avoid an allocation.
5859
pub fn toResponse(self: *const FetchContext) !Response {
60+
var headers: Headers = .{};
61+
62+
// convert into Headers
63+
for (self.headers.items) |hdr| {
64+
var iter = std.mem.splitScalar(u8, hdr, ':');
65+
const name = iter.next() orelse "";
66+
const value = iter.next() orelse "";
67+
try headers.append(name, value, self.arena);
68+
}
69+
5970
return Response{
6071
.status = self.status,
61-
.headers = self.headers.items,
72+
.headers = headers,
6273
.mime = self.mime,
6374
.body = self.body.items,
75+
.url = self.url,
6476
};
6577
}
6678
};

0 commit comments

Comments
 (0)