From d0ba61a0e75cfc7b8e6d70d6f323d53295e628ad Mon Sep 17 00:00:00 2001 From: weirdling Date: Mon, 3 May 2021 14:46:24 +0100 Subject: [PATCH] Implement proxy settings --- config.def.h | 3 +++ surf.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/config.def.h b/config.def.h index be168ab..46d164e 100644 --- a/config.def.h +++ b/config.def.h @@ -43,6 +43,9 @@ static Parameter defconfig[ParameterLast] = { [MediaManualPlay] = { { .i = 1 }, }, [Plugins] = { { .i = 1 }, }, [PreferredLanguages] = { { .v = (char *[]){ NULL } }, }, + [ProxyIgnoreHosts] = { { .v = (char *[]){ NULL } }, }, + [ProxyMode] = { { .i = SystemProxy }, }, + [ProxyUrl] = { { .v = (char *) NULL }, }, [RunInFullscreen] = { { .i = 0 }, }, [ScrollBars] = { { .i = 1 }, }, [ShowIndicators] = { { .i = 1 }, }, diff --git a/surf.c b/surf.c index ac832ff..5c74560 100644 --- a/surf.c +++ b/surf.c @@ -50,6 +50,12 @@ enum { OnAny = OnDoc | OnLink | OnImg | OnMedia | OnEdit | OnBar | OnSel, }; +enum { + CustomProxy = WEBKIT_NETWORK_PROXY_MODE_CUSTOM, + SystemProxy = WEBKIT_NETWORK_PROXY_MODE_DEFAULT, + NoProxy = WEBKIT_NETWORK_PROXY_MODE_NO_PROXY, +}; + typedef enum { AcceleratedCanvas, AccessMicrophone, @@ -73,6 +79,9 @@ typedef enum { LoadImages, MediaManualPlay, Plugins, + ProxyIgnoreHosts, + ProxyMode, + ProxyUrl, PreferredLanguages, RunInFullscreen, ScrollBars, @@ -1111,6 +1120,7 @@ newview(Client *c, WebKitWebView *rv) WebKitWebContext *context; WebKitCookieManager *cookiemanager; WebKitUserContentManager *contentmanager; + WebKitNetworkProxySettings *proxysettings; /* Webview */ if (rv) { @@ -1171,6 +1181,28 @@ newview(Client *c, WebKitWebView *rv) webkit_web_context_set_tls_errors_policy(context, curconfig[StrictTLS].val.i ? WEBKIT_TLS_ERRORS_POLICY_FAIL : WEBKIT_TLS_ERRORS_POLICY_IGNORE); + /* proxy */ + switch (curconfig[ProxyMode].val.i) { + case CustomProxy: + proxysettings = webkit_network_proxy_settings_new( + curconfig[ProxyUrl].val.v, + curconfig[ProxyIgnoreHosts].val.v); + webkit_web_context_set_network_proxy_settings(context, + CustomProxy, + proxysettings); + break; + case NoProxy: + webkit_web_context_set_network_proxy_settings(context, + NoProxy, + NULL); + break; + case SystemProxy: + default: + webkit_web_context_set_network_proxy_settings(context, + SystemProxy, + proxysettings); + break; + } /* disk cache */ webkit_web_context_set_cache_model(context, curconfig[DiskCache].val.i ? WEBKIT_CACHE_MODEL_WEB_BROWSER : -- 2.31.1