Skip to content

Commit

Permalink
WebBrowserComponent: Fix adding custom HTTP headers on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgration committed Jan 28, 2024
1 parent 6c32c4d commit b59639d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion modules/juce_gui_extra/native/juce_WebBrowserComponent_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class WebKitSymbols final : public DeletedAtShutdown
JUCE_GENERATE_FUNCTION_WITH_DEFAULT (webkit_web_view_load_uri, juce_webkit_web_view_load_uri,
(WebKitWebView*, const gchar*), void)

JUCE_GENERATE_FUNCTION_WITH_DEFAULT (webkit_web_view_load_request, juce_webkit_web_view_load_request,
(WebKitWebView*, WebKitURIRequest*), void)

JUCE_GENERATE_FUNCTION_WITH_DEFAULT (webkit_policy_decision_use, juce_webkit_policy_decision_use,
(WebKitPolicyDecision*), void)

Expand Down Expand Up @@ -181,6 +184,7 @@ class WebKitSymbols final : public DeletedAtShutdown
makeSymbolBinding (juce_webkit_web_view_stop_loading, "webkit_web_view_stop_loading"),
makeSymbolBinding (juce_webkit_uri_request_get_uri, "webkit_uri_request_get_uri"),
makeSymbolBinding (juce_webkit_web_view_load_uri, "webkit_web_view_load_uri"),
makeSymbolBinding (juce_webkit_web_view_load_request, "webkit_web_view_load_request"),
makeSymbolBinding (juce_webkit_navigation_action_get_request, "webkit_navigation_action_get_request"),
makeSymbolBinding (juce_webkit_navigation_policy_decision_get_frame_name, "webkit_navigation_policy_decision_get_frame_name"),
makeSymbolBinding (juce_webkit_navigation_policy_decision_get_navigation_action, "webkit_navigation_policy_decision_get_navigation_action"),
Expand Down Expand Up @@ -415,8 +419,19 @@ class GtkChildProcess final : private CommandReceiver::Responder
{
static Identifier urlIdentifier ("url");
auto url = params.getProperty (urlIdentifier, var()).toString();
static Identifier headersIdentifier ("headers");
auto headers = params.getProperty (headersIdentifier, var(StringArray {}));

auto request = webkit_uri_request_new(url.toRawUTF8());
auto http_headers = webkit_uri_request_get_http_headers(request);

WebKitSymbols::getInstance()->juce_webkit_web_view_load_uri (webview, url.toRawUTF8());
for (int i = 0; i < headers.size(); i++) {
const String header = headers[i].toString();
auto name = header.upToFirstOccurrenceOf (":", false, false).trim();
auto value = header.fromFirstOccurrenceOf (":", false, false).trim();
soup_message_headers_append(http_headers, name.toRawUTF8(), value.toRawUTF8());
}
WebKitSymbols::getInstance()->juce_webkit_web_view_load_request (webview, request);
}

void handleDecisionResponse (const var& params)
Expand Down

0 comments on commit b59639d

Please sign in to comment.