From efb2fa9c22aebaba22368d7e1edc5e124e5bfbd6 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 7 Apr 2026 17:42:31 +0200 Subject: [PATCH] Send Sec-Ch-Ua http header --- src/Config.zig | 5 +++++ src/network/http.zig | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Config.zig b/src/Config.zig index c7008810..c037e87a 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -306,6 +306,7 @@ pub const Common = struct { /// Must be initialized with an allocator that outlives all HTTP connections. pub const HttpHeaders = struct { const user_agent_base: [:0]const u8 = "Lightpanda/1.0"; + pub const sec_ch_ua: [:0]const u8 = "Sec-Ch-Ua: \"Lightpanda\";v=\"1\""; user_agent: [:0]const u8, // User agent value (e.g. "Lightpanda/1.0") user_agent_header: [:0]const u8, @@ -411,6 +412,10 @@ pub fn printUsageAndExit(self: *const Config, success: bool) void { \\ http, unknown_prop, event, ... \\ \\--user-agent Override the User-Agent header entirely + \\ User-Agent mustn't impersonate other browser. + \\ Starting the value with "Mozilla/5.0" is forbidden. + \\ The browser will continue to send Sec-Ch-Ua header. + \\ Incompatible with --user-agent-suffix \\ \\--user-agent-suffix \\ Suffix to append to the Lightpanda/X.Y User-Agent diff --git a/src/network/http.zig b/src/network/http.zig index 4bf71ded..ef3dfc65 100644 --- a/src/network/http.zig +++ b/src/network/http.zig @@ -62,7 +62,14 @@ pub const Headers = struct { if (header_list == null) { return error.OutOfMemory; } - return .{ .headers = header_list }; + + // Always add sec-CH-UA header + const updated_headers = libcurl.curl_slist_append(header_list, Config.HttpHeaders.sec_ch_ua); + if (updated_headers == null) { + return error.OutOfMemory; + } + + return .{ .headers = updated_headers }; } pub fn deinit(self: *const Headers) void {