Skip to content

feat: add HTTP_PROXY/HTTPS_PROXY support#101

Open
draix wants to merge 1 commit intoMiniMax-AI:mainfrom
draix:fix/96-proxy-env-vars
Open

feat: add HTTP_PROXY/HTTPS_PROXY support#101
draix wants to merge 1 commit intoMiniMax-AI:mainfrom
draix:fix/96-proxy-env-vars

Conversation

@draix
Copy link
Copy Markdown

@draix draix commented Apr 15, 2026

Summary

Node.js native fetch() does not respect HTTP_PROXY/HTTPS_PROXY environment variables, preventing users behind corporate proxies from using the CLI.

This PR adds a proxy-aware fetch wrapper using undici's ProxyAgent that transparently routes requests through the configured proxy.

Changes

New module: src/client/proxy.ts

A centralized proxy-aware fetch function that:

  • Detects HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy env vars
  • Respects NO_PROXY/no_proxy for bypassing proxy on specific hosts
  • Supports wildcard patterns in NO_PROXY (e.g., *.internal.com, .local)
  • Caches the ProxyAgent instance for performance
  • Falls back to native fetch when no proxy is configured

Updated files

All fetch() calls throughout the codebase have been updated to use proxyFetch():

  • src/client/http.ts (main API client)
  • src/auth/oauth.ts (OAuth token exchange)
  • src/auth/refresh.ts (token refresh)
  • src/config/detect-region.ts (region detection)
  • src/files/download.ts (file downloads)
  • src/update/checker.ts (update checks)
  • src/update/self-update.ts (self-update downloads)
  • src/commands/vision/describe.ts (image fetching)

Dependencies

Added undici as a dependency. While Node.js uses undici internally for its native fetch, the ProxyAgent API is not exposed through the global fetch. The undici package provides the necessary ProxyAgent class to enable proxy support.

Tests

Added tests in test/client/proxy.test.ts covering:

  • Environment variable detection (uppercase and lowercase variants)
  • HTTPS_PROXY precedence over HTTP_PROXY
  • NO_PROXY recognition
  • proxyFetch function behavior

Usage

Users can now configure proxy settings via environment variables:

# Set proxy
export HTTPS_PROXY=http://proxy.corp.com:8080

# Bypass proxy for specific hosts
export NO_PROXY=localhost,127.0.0.1,.internal.corp.com

# Run mmx commands - they will automatically use the proxy
mmx chat "Hello"

Closes #96

Node.js native fetch() does not respect HTTP_PROXY/HTTPS_PROXY environment
variables, preventing users behind corporate proxies from using the CLI.

This commit adds a proxy-aware fetch wrapper using undici's ProxyAgent that:
- Detects HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy env vars
- Respects NO_PROXY/no_proxy for bypassing proxy on specific hosts
- Supports wildcard patterns in NO_PROXY (e.g., *.internal.com, .local)
- Caches the ProxyAgent instance for performance
- Falls back to native fetch when no proxy is configured

All fetch() calls throughout the codebase have been updated to use proxyFetch():
- src/client/http.ts (main API client)
- src/auth/oauth.ts (OAuth token exchange)
- src/auth/refresh.ts (token refresh)
- src/config/detect-region.ts (region detection)
- src/files/download.ts (file downloads)
- src/update/checker.ts (update checks)
- src/update/self-update.ts (self-update downloads)
- src/commands/vision/describe.ts (image fetching)

Closes MiniMax-AI#96
@RyanLee-Dev
Copy link
Copy Markdown
Collaborator

why need proxy?

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.

mmx CLI does not respect HTTP_PROXY / HTTPS_PROXY environment variables

3 participants