Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/browser/browser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -435,24 +435,19 @@ pub const Page = struct {

log.info("GET {any} {d}", .{ url, header.status });

const ct = blk: {
break :blk header.get("content-type") orelse {
// no content type in HTTP headers.
// TODO try to sniff mime type from the body.
log.info("no content-type HTTP header", .{});

// Assume it's HTML for now.
break :blk "text/html; charset=utf-8";
};
};
const content_type = header.get("content-type");

log.debug("header content-type: {s}", .{ct});
var mime = try Mime.parse(arena, ct);
const mime: Mime = blk: {
if (content_type) |ct| {
break :blk try Mime.parse(arena, ct);
}
break :blk Mime.sniff(try response.peek());
} orelse .unknown;

if (mime.isHTML()) {
try self.loadHTMLDoc(&response, mime.charset orelse "utf-8");
} else {
log.info("non-HTML document: {s}", .{ct});
log.info("non-HTML document: {s}", .{content_type orelse "null"});
var arr: std.ArrayListUnmanaged(u8) = .{};
while (try response.next()) |data| {
try arr.appendSlice(arena, try arena.dupe(u8, data));
Expand Down
Loading
Loading