Lightpanda: the headless browser designed for AI and automation
chore: sync request always gets content-type
Karl Seguin7312ba008b6b
diff --git a/src/browser/Frame.zig b/src/browser/Frame.zigindex b44988899..22d6e0acb 100644--- a/src/browser/Frame.zig+++ b/src/browser/Frame.zig@@ -2763,7 +2763,7 @@ pub fn loadExternalStylesheet(self: *Frame, link: *Element.Html.Link, href: []cosm.is_evaluating = true;defer sm.endEvaluationWindow(was_evaluating);- var response = transfer.submitSync(.{ .copy_headers = true }) catch |err| {+ var response = transfer.submitSync(.{}) catch |err| {log.debug(.http, "external stylesheet fetch", .{ .err = err, .url = resolved });return self.fireElementEvent(element, comptime .wrap("error"));};@@ -2807,7 +2807,7 @@ pub fn loadExternalStylesheet(self: *Frame, link: *Element.Html.Link, href: []co// scratch-list pattern in `CSSStyleSheet.replaceSync`. Keeping// `_href` consistent with what the sheet actually contains is the// minimum.- const content_type: ?Mime = if (HttpClient.findHeader(response.headers, "content-type")) |value|+ const content_type: ?Mime = if (response.content_type) |value|Mime.parse(value) catch nullelsenull;diff --git a/src/browser/ScriptManager.zig b/src/browser/ScriptManager.zigindex e29736d47..42be5547b 100644--- a/src/browser/ScriptManager.zig+++ b/src/browser/ScriptManager.zig@@ -396,13 +396,13 @@ pub fn addFromElement(self: *ScriptManager, comptime from_parser: bool, script_etry frame.headersForRequest(transfer, .{});}- const response = try transfer.submitSync(.{ .copy_headers = true });+ const response = try transfer.submitSync(.{});// Take the body's arena rather than releasing it: `source`// has to outlive this call, up to script.deinit().script.source_arena = response.arena;script.source = .{ .remote = response.body };- script.setContentType(HttpClient.findHeader(response.headers, "content-type"));+ script.setContentType(response.content_type);script.status = response.status;script.complete = true;}diff --git a/src/network/HttpClient.zig b/src/network/HttpClient.zigindex 685345822..d362a34f0 100644--- a/src/network/HttpClient.zig+++ b/src/network/HttpClient.zig@@ -1464,6 +1464,7 @@ const SyncContext = struct {status_text: http.StatusText = .{},body: std.ArrayList(u8),headers: std.ArrayList(http.Header) = .empty,+ content_type: ?[]const u8 = null,// Acquired on the first byte we have to buffer.// Ownership moves to the SyncResponse.@@ -1485,6 +1486,10 @@ const SyncContext = struct {try self.body.ensureTotalCapacityPrecise(allocator, body_len);}+ if (transfer.contentType()) |content_type| {+ self.content_type = try allocator.dupe(u8, content_type);+ }+if (self.options.copy_headers) {for (transfer.responseHeaders()) |hdr| {try self.headers.append(allocator, .{@@ -2236,7 +2241,8 @@ const SyncResponse = struct {status: u16,body: std.ArrayList(u8),status_text: http.StatusText,- headers: []const http.Header,+ headers: []const http.Header, // only captured when copy_headers = true+ content_type: ?[]const u8, // always captured (most callers need it)arena: ?*lp.Arena, // need only if there's a body, or we're copying the headerspub fn deinit(self: *SyncResponse) void {@@ -2880,6 +2886,7 @@ pub const Transfer = struct {.status_text = sync_ctx.status_text,.body = sync_ctx.body,.headers = sync_ctx.headers.items,+ .content_type = sync_ctx.content_type,.arena = sync_ctx.arena,},.err => |e| return e,