Lightpanda: the headless browser designed for AI and automation
webapi: WebSocket (webapi) ignores connect header
Karl Seguinacc12dea4fd1
diff --git a/src/browser/webapi/net/WebSocket.zig b/src/browser/webapi/net/WebSocket.zigindex 37333fb32..20141bd1c 100644--- a/src/browser/webapi/net/WebSocket.zig+++ b/src/browser/webapi/net/WebSocket.zig@@ -242,6 +242,9 @@ fn connect(self: *WebSocket, protocols: []const []const u8) !void {try conn.setURL(resolved_url);try conn.setConnectOnly(false);+ // receivedHeaderCallback reads the first status line as the upgrade's,+ // so a proxy's CONNECT response must not reach it.+ try conn.setSuppressConnectHeaders();try conn.setReadCallback(sendDataCallback, true);try conn.setWriteCallback(receivedDataCallback);diff --git a/src/network/http.zig b/src/network/http.zigindex aa7a9b711..082eae9b3 100644--- a/src/network/http.zig+++ b/src/network/http.zig@@ -404,6 +404,12 @@ pub const Connection = struct {try libcurl.curl_easy_setopt(self._easy, .connect_only, value);}+ // Keep a proxy's CONNECT response out of the header callback, so it only+ // sees the origin's.+ pub fn setSuppressConnectHeaders(self: *const Connection) !void {+ try libcurl.curl_easy_setopt(self._easy, .suppress_connect_headers, true);+ }+// Close this connection when the transfer ends instead of returning it to// libcurl's keepalive pool. Read by libcurl when the transfer completes,// so it can be set while the response is being received.diff --git a/src/sys/libcurl.zig b/src/sys/libcurl.zigindex 746ca6c41..97b09f0c6 100644--- a/src/sys/libcurl.zig+++ b/src/sys/libcurl.zig@@ -226,6 +226,7 @@ const CurlOption = enum(c.CURLoption) {read_data = c.CURLOPT_READDATA,read_function = c.CURLOPT_READFUNCTION,connect_only = c.CURLOPT_CONNECT_ONLY,+ suppress_connect_headers = c.CURLOPT_SUPPRESS_CONNECT_HEADERS,forbid_reuse = c.CURLOPT_FORBID_REUSE,pipewait = c.CURLOPT_PIPEWAIT,upload = c.CURLOPT_UPLOAD,@@ -628,6 +629,7 @@ pub fn curl_easy_setopt(easy: *Curl, comptime option: CurlOption, value: anytype.pipewait,.no_body,.forbid_reuse,+ .suppress_connect_headers,.ssl_verify_peer,.proxy_ssl_verify_peer,=> @as(c_long, @intFromBool(value)),