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 Jul 23, 2024
1 parent 04d9d36 commit cccd622
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions modules/juce_gui_extra/native/juce_WebBrowserComponent_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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 @@ -329,7 +332,8 @@ class WebKitSymbols final : public DeletedAtShutdown
makeSymbolBinding (juce_webkit_uri_scheme_response_new, "webkit_uri_scheme_response_new"),
makeSymbolBinding (juce_webkit_uri_scheme_response_set_http_headers, "webkit_uri_scheme_response_set_http_headers"),
makeSymbolBinding (juce_webkit_uri_scheme_response_set_status, "webkit_uri_scheme_response_set_status"),
makeSymbolBinding (juce_webkit_uri_scheme_request_finish_with_response, "webkit_uri_scheme_request_finish_with_response"));
makeSymbolBinding (juce_webkit_uri_scheme_request_finish_with_response, "webkit_uri_scheme_request_finish_with_response"),
makeSymbolBinding (juce_webkit_web_view_load_request, "webkit_web_view_load_request"));
}

bool loadGtkSymbols()
Expand Down Expand Up @@ -801,8 +805,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 cccd622

Please sign in to comment.