Skip to content

Lightpanda: the headless browser designed for AI and automation

send Sec-Ch-Ua-Full-Version-List header

Pierre Tachoirea9611562831e
diff --git a/build.zig b/build.zig
index 7ccff15f7..a07ed01c0 100644
--- a/build.zig
+++ b/build.zig
@@ -86,9 +86,11 @@ pub fn build(b: *Build) !void {
const version_string = b.fmt("{f}", .{version});
const version_encoded = std.mem.replaceOwned(u8, b.allocator, version_string, "+", "%2B") catch @panic("OOM");
+ const version_string_z = b.allocator.dupeZ(u8, version_string) catch @panic("OOM");
var opts = b.addOptions();
opts.addOption([]const u8, "version", version_string);
+ opts.addOption([:0]const u8, "version_z", version_string_z);
opts.addOption([]const u8, "version_encoded", version_encoded);
opts.addOption(?[]const u8, "snapshot_path", snapshot_path);
opts.addOption(bool, "wpt_extensions", wpt_extensions);
diff --git a/src/Config.zig b/src/Config.zig
index 29c8506fc..af54975ff 100644
--- a/src/Config.zig
+++ b/src/Config.zig
@@ -823,13 +823,14 @@ pub const HttpHeaders = struct {
const Brand = struct {
brand: [:0]const u8,
version: [:0]const u8,
+ full_version: [:0]const u8,
};
/// Source of truth for client-hints brand data. Both the Sec-Ch-Ua
/// HTTP header and navigator.userAgentData.brands derive from this
/// list, so the two sides cannot drift.
pub const brands = [_]Brand{
- .{ .brand = "Lightpanda", .version = "1" },
+ .{ .brand = "Lightpanda", .version = "1", .full_version = lp.build_config.version_z },
};
pub const sec_ch_ua: [:0]const u8 = blk: {
@@ -841,6 +842,15 @@ pub const HttpHeaders = struct {
break :blk out;
};
+ pub const sec_ch_ua_full_version_list: [:0]const u8 = blk: {
+ var out: [:0]const u8 = "";
+ for (brands, 0..) |b, i| {
+ const sep = if (i == 0) "" else ", ";
+ out = out ++ sep ++ "\"" ++ b.brand ++ "\";v=\"" ++ b.full_version ++ "\"";
+ }
+ break :blk out;
+ };
+
// Some bot-protection frontends (e.g. Akamai on canada.ca) RST the HTTP/2
// stream when a client sends Accept-Encoding without Accept-Language,
// treating it as a bot signal. Ship a neutral default so we look like a
diff --git a/src/network/HttpClient.zig b/src/network/HttpClient.zig
index 963a7d7f5..b35e8fb00 100644
--- a/src/network/HttpClient.zig
+++ b/src/network/HttpClient.zig
@@ -400,10 +400,11 @@ pub fn getUserAgent(self: *const Client) [:0]const u8 {
}
// Headers _all_ requests include.
-pub fn baselineHeaders(self: *const Client) [3]Transfer.RequestHeader {
+pub fn baselineHeaders(self: *const Client) [4]Transfer.RequestHeader {
return .{
.{ .name = "User-Agent", .value = self.getUserAgent() },
.{ .name = "Sec-Ch-Ua", .value = lp.Config.HttpHeaders.sec_ch_ua, .source = .fixed },
+ .{ .name = "Sec-CH-UA-Full-Version-List", .value = lp.Config.HttpHeaders.sec_ch_ua_full_version_list, .source = .fixed },
// Omitting Accept-Language triggers bot-protection on some CDNs
// (Akamai) when Accept-Encoding is present.
.{ .name = "Accept-Language", .value = lp.Config.HttpHeaders.accept_language },