mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-15 15:58:57 +00:00
cdp: add mimeType and charset to Network.Response
This commit is contained in:
@@ -53,6 +53,18 @@ pub const Mime = struct {
|
|||||||
other: struct { type: []const u8, sub_type: []const u8 },
|
other: struct { type: []const u8, sub_type: []const u8 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn contentTypeString(mime: *const Mime) [:0]const u8 {
|
||||||
|
return switch (mime.content_type) {
|
||||||
|
.text_xml => "text/xml",
|
||||||
|
.text_html => "text/html",
|
||||||
|
.text_javascript => "application/javascript",
|
||||||
|
.text_plain => "text/plain",
|
||||||
|
.text_css => "text/css",
|
||||||
|
.application_json => "application/json",
|
||||||
|
else => "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the null-terminated charset value.
|
/// Returns the null-terminated charset value.
|
||||||
pub fn charsetString(mime: *const Mime) [:0]const u8 {
|
pub fn charsetString(mime: *const Mime) [:0]const u8 {
|
||||||
return @ptrCast(&mime.charset);
|
return @ptrCast(&mime.charset);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const Allocator = std.mem.Allocator;
|
|||||||
const CdpStorage = @import("storage.zig");
|
const CdpStorage = @import("storage.zig");
|
||||||
const Transfer = @import("../../http/Client.zig").Transfer;
|
const Transfer = @import("../../http/Client.zig").Transfer;
|
||||||
const Notification = @import("../../notification.zig").Notification;
|
const Notification = @import("../../notification.zig").Notification;
|
||||||
|
const Mime = @import("../../browser/mime.zig").Mime;
|
||||||
|
|
||||||
pub fn processMessage(cmd: anytype) !void {
|
pub fn processMessage(cmd: anytype) !void {
|
||||||
const action = std.meta.stringToEnum(enum {
|
const action = std.meta.stringToEnum(enum {
|
||||||
@@ -392,6 +393,20 @@ const TransferAsResponseWriter = struct {
|
|||||||
try jws.write(@as(std.http.Status, @enumFromInt(status)).phrase() orelse "Unknown");
|
try jws.write(@as(std.http.Status, @enumFromInt(status)).phrase() orelse "Unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const mime: Mime = blk: {
|
||||||
|
if (transfer.response_header.?.contentType()) |ct| {
|
||||||
|
break :blk try Mime.parse(ct);
|
||||||
|
}
|
||||||
|
break :blk .unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
try jws.objectField("mimeType");
|
||||||
|
try jws.write(mime.contentTypeString());
|
||||||
|
try jws.objectField("charset");
|
||||||
|
try jws.write(mime.charsetString()[0..]);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// chromedp doesn't like having duplicate header names. It's pretty
|
// chromedp doesn't like having duplicate header names. It's pretty
|
||||||
// common to get these from a server (e.g. for Cache-Control), but
|
// common to get these from a server (e.g. for Cache-Control), but
|
||||||
|
|||||||
Reference in New Issue
Block a user