Automatic proxy detection and configuration based on standard environment variables with intelligent bypass rules for local addresses. The proxy system integrates seamlessly with GitHub Actions runners and supports both HTTP and HTTPS proxies.
Automatically detects proxy configuration from environment variables.
/**
* Get proxy URL for a server URL based on environment variables
* Checks https_proxy/HTTPS_PROXY for HTTPS URLs, http_proxy/HTTP_PROXY for HTTP URLs
* @param serverUrl - Target server URL
* @returns Proxy URL string or empty string if no proxy needed
*/
function getProxyUrl(serverUrl: string): string;Core proxy detection logic working with URL objects. Available from '@actions/http-client/lib/proxy'.
/**
* Internal proxy detection function working with URL objects (from proxy submodule)
* @param reqUrl - Request URL object
* @returns Proxy URL object or undefined if no proxy needed
*/
function getProxyUrl(reqUrl: URL): URL | undefined;Determines if a URL should bypass proxy based on no_proxy configuration. Available from '@actions/http-client/lib/proxy'.
/**
* Check if URL should bypass proxy based on no_proxy/NO_PROXY environment variable
* Supports wildcards, domain matching, and port-specific rules
* @param reqUrl - Request URL to check
* @returns True if URL should bypass proxy
*/
function checkBypass(reqUrl: URL): boolean;Usage Examples:
import { HttpClient, getProxyUrl } from "@actions/http-client";
import { getProxyUrl as getProxyUrlInternal, checkBypass } from "@actions/http-client/lib/proxy";
// Check if proxy is configured for a URL
const proxyUrl = getProxyUrl("https://api.github.com");
if (proxyUrl) {
console.log(`Using proxy: ${proxyUrl}`);
} else {
console.log("No proxy configured");
}
// HttpClient automatically uses proxy
const client = new HttpClient("my-action/1.0");
const response = await client.get("https://api.example.com/data");
// Automatically uses proxy if configured via environment variablesThe proxy system reads standard proxy environment variables:
http_proxy or HTTP_PROXY: Proxy URL for HTTP requestshttps_proxy or HTTPS_PROXY: Proxy URL for HTTPS requestsno_proxy or NO_PROXY: Comma-separated list of hosts to bypass proxyEnvironment Variable Examples:
# Basic proxy configuration
export http_proxy=http://proxy.company.com:8080
export https_proxy=http://proxy.company.com:8080
# Proxy with authentication
export https_proxy=http://username:password@proxy.company.com:8080
# Bypass rules
export no_proxy=localhost,127.0.0.1,.company.com,internal.server:3000
# Complete proxy setup
export http_proxy=http://proxy.company.com:8080
export https_proxy=http://proxy.company.com:8080
export no_proxy=localhost,127.0.0.1,.internal,.company.com,192.168.*The no_proxy environment variable supports various patterns:
localhost, api.internal.com.company.com (matches all subdomains)* (bypasses all requests)127.0.0.1, 192.168.1.1internal.server:3000The following addresses automatically bypass proxy:
localhost, 127.0.0.1, [::1], [0:0:0:0:0:0:0:1][::1] or [0:0:0:0:0:0:0:1]Bypass Examples:
import { checkBypass } from "@actions/http-client/lib/proxy";
// Using internal proxy functions
const url = new URL("https://api.github.com");
const internalProxyUrl = getProxyUrlInternal(url);
const shouldBypass = checkBypass(url);
console.log(`Internal proxy URL:`, internalProxyUrl?.href);
console.log(`Should bypass:`, shouldBypass);
// These will bypass proxy automatically
console.log(checkBypass(new URL("http://localhost:3000"))); // true
console.log(checkBypass(new URL("http://127.0.0.1:8080"))); // true
// With no_proxy=".company.com,internal.server:3000"
console.log(checkBypass(new URL("https://api.company.com"))); // true
console.log(checkBypass(new URL("http://internal.server:3000"))); // true
console.log(checkBypass(new URL("http://internal.server:8080"))); // false
console.log(checkBypass(new URL("https://external.api.com"))); // falseThe HttpClient automatically integrates proxy support:
https_proxy for HTTPS URLs, http_proxy for HTTP URLsno_proxy rules before using proxyIn GitHub Actions runners, proxy configuration is typically handled by the runner environment:
# .github/workflows/action.yml
name: My Action
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run with proxy
env:
http_proxy: ${{ secrets.HTTP_PROXY }}
https_proxy: ${{ secrets.HTTPS_PROXY }}
no_proxy: localhost,127.0.0.1,.company.com
run: |
# Your action code here
# HttpClient will automatically use proxy configurationAdvanced Proxy Usage:
import { HttpClient } from "@actions/http-client";
// Client automatically handles proxy configuration
const client = new HttpClient("my-action/1.0", [], {
// These options work with proxy
keepAlive: true, // Connection pooling through proxy
maxSockets: 50, // Limit concurrent proxy connections
socketTimeout: 30000, // Timeout for proxy connections
allowRetries: true, // Retry through proxy on failure
maxRetries: 3
});
// All requests automatically use proxy if configured
const response1 = await client.get("https://api.github.com/user");
const response2 = await client.get("https://external-api.com/data");
const response3 = await client.get("http://localhost:3000/health"); // Bypasses proxy
// Manual proxy detection for logging
const githubProxy = getProxyUrl("https://api.github.com");
const localProxy = getProxyUrl("http://localhost:3000");
console.log(`GitHub API proxy: ${githubProxy || "none"}`);
console.log(`Local API proxy: ${localProxy || "none"}`);
// Custom proxy configuration (not recommended - use environment variables)
const customClient = new HttpClient("my-action/1.0", [], {
// Note: HttpClient doesn't expose proxy configuration directly
// Always use environment variables for proxy configuration
});Proxy authentication is supported via URL credentials in the proxy environment variables:
# Username and password in proxy URL
export https_proxy=http://username:password@proxy.company.com:8080
# URL-encoded credentials for special characters
export https_proxy=http://user%40domain:p%40ssw0rd@proxy.company.com:8080The client automatically extracts and applies proxy credentials using the DecodedURL class internally, which properly handles URL decoding of usernames and passwords.