mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-17 08:48:58 +00:00
http_headers_done_receiving
This commit is contained in:
@@ -247,6 +247,7 @@ fn makeTransfer(self: *Client, req: Request) !*Transfer {
|
||||
.req = req,
|
||||
.ctx = req.ctx,
|
||||
.client = self,
|
||||
.notification = &self.notification,
|
||||
};
|
||||
return transfer;
|
||||
}
|
||||
@@ -549,6 +550,8 @@ pub const Transfer = struct {
|
||||
|
||||
_redirecting: bool = false,
|
||||
|
||||
notification: *?*Notification, // Points to the Client's notification. TBD if a Browser can remove the notification before all Transfers are gone.
|
||||
|
||||
fn deinit(self: *Transfer) void {
|
||||
self.req.headers.deinit();
|
||||
if (self._handle) |handle| {
|
||||
@@ -673,12 +676,26 @@ pub const Transfer = struct {
|
||||
// returning < buf_len terminates the request
|
||||
return 0;
|
||||
};
|
||||
if (transfer.notification.*) |notification| { // TBD before or after callback?
|
||||
notification.dispatch(.http_headers_done_receiving, &.{
|
||||
.transfer = transfer,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (transfer.req.header_callback) |cb| {
|
||||
cb(transfer, header) catch |err| {
|
||||
log.err(.http, "header_callback", .{ .err = err, .req = transfer });
|
||||
return 0;
|
||||
};
|
||||
if (transfer.notification.*) |notification| { // TBD before or after callback?
|
||||
if (Http.Headers.parseHeader(header)) |hdr_name_value| {
|
||||
notification.dispatch(.http_header_received, &.{
|
||||
.request_id = transfer.id,
|
||||
.status = hdr.status,
|
||||
.header = hdr_name_value,
|
||||
});
|
||||
} else log.err(.http, "invalid header", .{ .line = header });
|
||||
}
|
||||
}
|
||||
}
|
||||
return buf_len;
|
||||
|
||||
@@ -244,8 +244,8 @@ pub const Headers = struct {
|
||||
return list;
|
||||
}
|
||||
|
||||
fn parseHeader(header_str: []const u8) ?struct { name: []const u8, value: []const u8 } {
|
||||
const colon_pos = std.mem.indexOf(u8, header_str, ":") orelse return null;
|
||||
pub fn parseHeader(header_str: []const u8) ?std.http.Header {
|
||||
const colon_pos = std.mem.indexOfScalar(u8, header_str, ':') orelse return null;
|
||||
|
||||
const name = std.mem.trim(u8, header_str[0..colon_pos], " \t");
|
||||
const value = std.mem.trim(u8, header_str[colon_pos + 1 ..], " \t");
|
||||
|
||||
Reference in New Issue
Block a user