From b14e75dd6cd4887202940bb99f649540ab3d7a1f Mon Sep 17 00:00:00 2001
From: Timothy Jaeryang Baek <tim@openwebui.com>
Date: Fri, 21 Feb 2025 13:40:11 -0800
Subject: [PATCH] feat: added Trust Proxy Environment switch in Web Search
 admin settings tab.

Co-Authored-By: harry zhou <67385896+harryzhou2000@users.noreply.github.com>
---
 backend/open_webui/routers/retrieval.py            |  1 +
 src/lib/components/admin/Settings/WebSearch.svelte | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py
index 9611051b3..c2cb68c5d 100644
--- a/backend/open_webui/routers/retrieval.py
+++ b/backend/open_webui/routers/retrieval.py
@@ -403,6 +403,7 @@ async def get_rag_config(request: Request, user=Depends(get_admin_user)):
                 "bing_search_v7_subscription_key": request.app.state.config.BING_SEARCH_V7_SUBSCRIPTION_KEY,
                 "exa_api_key": request.app.state.config.EXA_API_KEY,
                 "result_count": request.app.state.config.RAG_WEB_SEARCH_RESULT_COUNT,
+                "trust_env": request.app.state.config.RAG_WEB_SEARCH_TRUST_ENV,
                 "concurrent_requests": request.app.state.config.RAG_WEB_SEARCH_CONCURRENT_REQUESTS,
                 "domain_filter_list": request.app.state.config.RAG_WEB_SEARCH_DOMAIN_FILTER_LIST,
             },
diff --git a/src/lib/components/admin/Settings/WebSearch.svelte b/src/lib/components/admin/Settings/WebSearch.svelte
index 84e9d0e5a..84729117b 100644
--- a/src/lib/components/admin/Settings/WebSearch.svelte
+++ b/src/lib/components/admin/Settings/WebSearch.svelte
@@ -130,6 +130,19 @@
 					</div>
 				</div>
 
+				<div class=" py-0.5 flex w-full justify-between">
+					<div class=" self-center text-xs font-medium">{$i18n.t('Trust Proxy Environment')}</div>
+					<div class="flex items-center relative">
+						<Tooltip
+							content={webConfig.search.trust_env
+								? 'Use proxy designated by http_proxy and https_proxy environment variables to fetch page contents'
+								: 'Use no proxy to fetch page contents.'}
+						>
+							<Switch bind:state={webConfig.search.trust_env} />
+						</Tooltip>
+					</div>
+				</div>
+
 				{#if webConfig.search.engine !== ''}
 					<div class="mt-1.5">
 						{#if webConfig.search.engine === 'searxng'}