Send Sec-Ch-Ua http header

This commit is contained in:
Pierre Tachoire
2026-04-07 17:42:31 +02:00
parent ae9b4d3fc6
commit efb2fa9c22
2 changed files with 13 additions and 1 deletions

View File

@@ -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

View File

@@ -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 {