mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-19 02:18:10 +00:00
Merge pull request #958 from lightpanda-io/http_request_done_notification
Emits a http_request_done internal notification.
This commit is contained in:
@@ -36,6 +36,7 @@ pub fn processMessage(cmd: anytype) !void {
|
||||
setCookie,
|
||||
setCookies,
|
||||
getCookies,
|
||||
getResponseBody,
|
||||
}, cmd.input.action) orelse return error.UnknownMethod;
|
||||
|
||||
switch (action) {
|
||||
@@ -49,6 +50,7 @@ pub fn processMessage(cmd: anytype) !void {
|
||||
.setCookie => return setCookie(cmd),
|
||||
.setCookies => return setCookies(cmd),
|
||||
.getCookies => return getCookies(cmd),
|
||||
.getResponseBody => return getResponseBody(cmd),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +204,19 @@ fn getCookies(cmd: anytype) !void {
|
||||
try cmd.sendResult(.{ .cookies = writer }, .{});
|
||||
}
|
||||
|
||||
fn getResponseBody(cmd: anytype) !void {
|
||||
const params = (try cmd.params(struct {
|
||||
requestId: []const u8, // "REQ-{d}"
|
||||
})) orelse return error.InvalidParams;
|
||||
|
||||
_ = params;
|
||||
|
||||
try cmd.sendResult(.{
|
||||
.body = "TODO",
|
||||
.base64Encoded = false,
|
||||
}, .{});
|
||||
}
|
||||
|
||||
pub fn httpRequestFail(arena: Allocator, bc: anytype, data: *const Notification.RequestFail) !void {
|
||||
// It's possible that the request failed because we aborted when the client
|
||||
// sent Target.closeTarget. In that case, bc.session_id will be cleared
|
||||
@@ -264,6 +279,22 @@ pub fn httpHeadersDone(arena: Allocator, bc: anytype, data: *const Notification.
|
||||
}, .{ .session_id = session_id });
|
||||
}
|
||||
|
||||
pub fn httpRequestDone(arena: Allocator, bc: anytype, data: *const Notification.RequestDone) !void {
|
||||
// Isn't possible to do a network request within a Browser (which our
|
||||
// notification is tied to), without a page.
|
||||
std.debug.assert(bc.session.page != null);
|
||||
|
||||
var cdp = bc.cdp;
|
||||
|
||||
// all unreachable because we _have_ to have a page.
|
||||
const session_id = bc.session_id orelse unreachable;
|
||||
|
||||
try cdp.sendEvent("Network.loadingFinished", .{
|
||||
.requestId = try std.fmt.allocPrint(arena, "REQ-{d}", .{data.transfer.id}),
|
||||
.encodedDataLength = data.transfer.bytes_received,
|
||||
}, .{ .session_id = session_id });
|
||||
}
|
||||
|
||||
pub const TransferAsRequestWriter = struct {
|
||||
transfer: *Transfer,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user