Skip to content

fix: honor proxy env vars in web search HTTP calls#228

Open
serhiizghama wants to merge 2 commits into
danny-avila:mainfrom
serhiizghama:fix/search-proxy-env-support
Open

fix: honor proxy env vars in web search HTTP calls#228
serhiizghama wants to merge 2 commits into
danny-avila:mainfrom
serhiizghama:fix/search-proxy-env-support

Conversation

@serhiizghama

Copy link
Copy Markdown

Problem

The web search pipeline's HTTP calls (Tavily search/extract, Serper search/scrape, SearXNG, Firecrawl, Jina and Cohere rerankers) go through axios without any proxy handling. In corporate/enterprise deployments where outbound traffic must pass through a forward proxy, these calls bypass the proxy and fail with 502:

error: Error in search: Tavily API request failed: Request failed with status code 502

Reported in danny-avila/LibreChat#13483. Notably, axios' built-in env-var proxy support doesn't help here because it does not establish a CONNECT tunnel for HTTPS targets — the standard workaround is HttpsProxyAgent with axios' own proxy handling disabled (proxy: false), which the reporter verified works in their environment.

Solution

  • New getAxiosProxyOptions(url) helper in src/tools/search/proxy.ts:
    • honors the PROXY variable first — same convention as the existing HttpsProxyAgent usage in ToolSearch, CodeExecutor, and BashExecutor
    • falls back to the standard HTTPS_PROXY/HTTP_PROXY/NO_PROXY variables via proxy-from-env, so self-hosted endpoints (SearXNG, Firecrawl) can be excluded with NO_PROXY exactly like MCP connections already allow
    • only applies to https: URLs — plain-HTTP targets keep axios' default behavior, which handles HTTP proxying correctly
  • Spread the resolved options into all eight axios call sites in src/tools/search/
  • https-proxy-agent was already a dependency; proxy-from-env is added (it's tiny and already in the tree as an axios dependency)

Testing

  • npx jest src/tools/search/ — 56 tests pass, including new coverage for: no-proxy default, PROXY precedence over HTTPS_PROXY, empty-string handling, NO_PROXY exclusions, and non-HTTPS passthrough
  • npx tsc --noEmit and npx eslint clean, npm run build succeeds

Closes danny-avila/LibreChat#13483 (the affected code lives here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web Search: Tavily/Jina/Cohere HTTP calls via axios do not respect HTTP_PROXY/HTTPS_PROXY environment variables

1 participant