Skip to content

Commit 04a2393

Browse files
committed
fetch callback logging
1 parent b1483a7 commit 04a2393

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/browser/fetch/Request.zig

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

1919
const std = @import("std");
20+
const log = @import("../../log.zig");
21+
2022
const URL = @import("../../url.zig").URL;
2123
const Page = @import("../page.zig").Page;
2224

@@ -94,6 +96,8 @@ const FetchContext = struct {
9496
js_ctx: *Env.JsContext,
9597
promise_resolver: v8.Persistent(v8.PromiseResolver),
9698

99+
method: Http.Method,
100+
url: []const u8,
97101
body: std.ArrayListUnmanaged(u8) = .empty,
98102
headers: std.ArrayListUnmanaged([]const u8) = .empty,
99103
status: u16 = 0,
@@ -104,7 +108,7 @@ const FetchContext = struct {
104108
///
105109
/// We just return the underlying slices used for `headers`
106110
/// and for `body` here to avoid an allocation.
107-
pub fn toResponse(self: FetchContext) !Response {
111+
pub fn toResponse(self: *const FetchContext) !Response {
108112
return Response{
109113
.status = self.status,
110114
.headers = self.headers.items,
@@ -131,7 +135,12 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
131135
fetch_ctx.* = .{
132136
.arena = arena,
133137
.js_ctx = page.main_context,
134-
.promise_resolver = v8.Persistent(v8.PromiseResolver).init(page.main_context.isolate, resolver.resolver),
138+
.promise_resolver = v8.Persistent(v8.PromiseResolver).init(
139+
page.main_context.isolate,
140+
resolver.resolver,
141+
),
142+
.method = req.method,
143+
.url = req.url,
135144
};
136145

137146
try client.request(.{
@@ -145,6 +154,7 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
145154
.start_callback = struct {
146155
fn startCallback(transfer: *HttpClient.Transfer) !void {
147156
const self: *FetchContext = @alignCast(@ptrCast(transfer.ctx));
157+
log.debug(.http, "request start", .{ .method = self.method, .url = self.url, .source = "fetch" });
148158
self.transfer = transfer;
149159
}
150160
}.startCallback,
@@ -159,6 +169,12 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
159169
const self: *FetchContext = @alignCast(@ptrCast(transfer.ctx));
160170
const header = &transfer.response_header.?;
161171

172+
log.debug(.http, "request header", .{
173+
.source = "fetch",
174+
.url = self.url,
175+
.status = header.status,
176+
});
177+
162178
if (header.contentType()) |ct| {
163179
self.mime = Mime.parse(ct) catch {
164180
return error.Todo;
@@ -177,6 +193,13 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
177193
.done_callback = struct {
178194
fn doneCallback(ctx: *anyopaque) !void {
179195
const self: *FetchContext = @alignCast(@ptrCast(ctx));
196+
197+
log.info(.http, "request complete", .{
198+
.source = "fetch",
199+
.url = self.url,
200+
.status = self.status,
201+
});
202+
180203
const response = try self.toResponse();
181204
const promise_resolver: Env.PromiseResolver = .{
182205
.js_context = self.js_ctx,

0 commit comments

Comments
 (0)