Skip to content

Lightpanda: the headless browser designed for AI and automation

ops: add --http-debug option to turn on libcurl's verbose output

Karl Seguin1a6be93c9f78
diff --git a/src/Config.zig b/src/Config.zig
index 4c97cda62..99943d5e9 100644
--- a/src/Config.zig
+++ b/src/Config.zig
@@ -272,6 +272,7 @@ const CommonOptions = .{
.{ .name = "user_agent_suffix", .type = ?[]const u8 },
.{ .name = "http_cache_dir", .type = ?[]const u8 },
.{ .name = "http_cache_entry_limit", .type = ?u32, .default = 1000 },
+ .{ .name = "http_debug", .type = bool },
.{ .name = "render_font", .type = []const u8, .multiple = true },
.{ .name = "web_bot_auth_key_file", .type = ?[]const u8 },
.{ .name = "web_bot_auth_keyid", .type = ?[]const u8 },
@@ -775,6 +776,13 @@ pub fn httpCacheDir(self: *const Config) ?[]const u8 {
};
}
+pub fn httpDebug(self: *const Config) bool {
+ return switch (self.mode) {
+ inline .serve, .fetch, .mcp, .agent => |opts| opts.http_debug,
+ else => false,
+ };
+}
+
pub fn renderFonts(self: *const Config) []const []const u8 {
return switch (self.mode) {
inline .serve, .fetch, .mcp, .agent => |opts| opts.render_font.items,
diff --git a/src/help.zon b/src/help.zon
index 0398c1aa6..b6cfecd39 100644
--- a/src/help.zon
+++ b/src/help.zon
@@ -454,6 +454,10 @@
\\ Time in ms to establish an HTTP connection before timing out. 0 means
\\ never.
\\ Defaults to 8000.
+ \\ --http-debug
+ \\ Enables libcurl verbose output. Output written directly to stderr
+ \\ by licurl and does not follow the configured log format.
+ \\ Defaults to off (not set).
\\ --http-header <HEADER>
\\ Extra custom header added to every outgoing HTTP request, including redirections,
\\ in "Name: Value" form. Can be passed multiple times. The last one is used.
diff --git a/src/network/http.zig b/src/network/http.zig
index b3771d385..b1e159592 100644
--- a/src/network/http.zig
+++ b/src/network/http.zig
@@ -31,8 +31,6 @@ const repeat = @import("../string.zig").repeat;
const log = lp.log;
const posix = std.posix;
-const ENABLE_DEBUG = false;
-
pub const readfunc_pause = libcurl.curl_readfunc_pause;
pub const writefunc_error = libcurl.curl_writefunc_error;
pub const WsFrameType = libcurl.WsFrameType;
@@ -499,18 +497,16 @@ pub const Connection = struct {
}
}
- // debug
- if (comptime ENABLE_DEBUG) {
+ if (config.httpDebug()) {
try libcurl.curl_easy_setopt(self._easy, .verbose, true);
-
- // Sometimes the default debug output hides some useful data. You can
- // uncomment the following line (BUT KEEP THE LIVE ABOVE AS-IS), to
- // get more control over the data (specifically, the `CURLINFO_TEXT`
- // can include useful data).
-
- // try libcurl.curl_easy_setopt(easy, .debug_function, debugCallback);
}
+ // Sometimes the default debug output hides some useful data. You can
+ // uncomment the following line (BUT KEEP THE LINE ABOVE AS-IS), to
+ // get more control over the data (specifically, the `CURLINFO_TEXT`
+ // can include useful data).
+ // try libcurl.curl_easy_setopt(easy, .debug_function, debugCallback);
+
// default write callback to prevent libcurl from writing to stdout
try self.setWriteCallback(discardBody);