Webkitgtk+ - Webpageprocess crashes when I try to modify SoupMessageHeaders

68 Views Asked by At

I am using webkit2gtk4 and the webkit extension library. Anyway, I'm trying to write a webkit extension with the following code and link it to the main loop.

#include <webkit2/webkit-web-extension.h>

static gboolean set_http_headers(WebKitWebPage * page, WebKitURIRequest * req, WebKitURIResponse * res)
{

    SoupMessageHeaders * http_headers = webkit_uri_request_get_http_headers(req);

    const gchar * type = webkit_uri_request_get_http_method(req);

    if (strncmp(type, "GET", 3) == 0)
        {
            // ** this is where the crash happens **
            soup_message_headers_replace(http_headers, "Accept-Encoding", "gzip, deflate, br");
            soup_message_headers_replace(http_headers, "Accept-Language", "en-US,en;q=0.5");
        }

    return FALSE;

}

static void wp_handle_cb(WebKitWebExtension * webext, WebKitWebPage * wp, gpointer dummy)
{
    g_signal_connect_object (wp, "send-request", G_CALLBACK(set_http_headers), NULL, 0);
}

G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension * webext)
{
    g_signal_connect (webext, "page-created", G_CALLBACK (wp_handle_cb), NULL);
}

The problem happens with some webpages I load. Since it happens nearly with every website, I am not going to list each webpage it crashes. Here's an example website.

1

There are 1 best solutions below

0
On

As I was writing the question, I found out what was the problem with a final consideration of making sure the question isn't dumb.

Basically, I wasn't making sure that the SoupMessageHeaders wasn't NULL.

if (!http_headers)
    return FALSE;

this works fine, and Im really sad that I spent 12 hours on this