usebruno/bruno · error · Error
Invalid system http_proxy
Error message
Invalid system http_proxy
What it means
In system-proxy mode for a plain-HTTP request, the loader constructs `new URL(http_proxy)` from the detected system proxy. If the value is not a valid absolute URL, the URL constructor throws and is rewrapped as 'Invalid system http_proxy'.
Source
Thrown at packages/bruno-requests/src/utils/http-https-agents.ts:572
if (pac_url && requestUrl) {
try {
const result = await resolveAgentsFromPac({ pacSource: pac_url, requestUrl, requestProtocol: isHttpsRequest ? 'https' : 'http', tlsOptions, timeline, disableCache, hostname });
if (result.httpAgent) httpAgent = result.httpAgent;
if (result.httpsAgent) httpsAgent = result.httpsAgent;
} catch {
}
} else {
const shouldUseSystemProxy = shouldUseProxy(requestUrl, no_proxy || '');
if (shouldUseSystemProxy) {
try {
if (http_proxy?.length && !isHttpsRequest) {
const parsedHttpProxy = new URL(http_proxy);
const isHttpsSystemProxy = parsedHttpProxy.protocol === 'https:';
const systemHttpProxyAgentOptions = isHttpsSystemProxy ? { keepAlive: true, ...tlsOptions } : { keepAlive: true };
httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: systemHttpProxyAgentOptions as any, proxyUri: http_proxy, timeline: timeline || null, disableCache, hostname });
}
} catch (error) {
throw new Error('Invalid system http_proxy');
}
try {
if (https_proxy?.length && isHttpsRequest) {
new URL(https_proxy);
httpsAgent = getOrCreateHttpsAgent({ AgentClass: PatchedHttpsProxyAgent, options: tlsOptions as any, proxyUri: https_proxy, timeline: timeline || null, disableCache, hostname }) as HttpsAgent;
}
} catch (error) {
throw new Error('Invalid system https_proxy');
}
}
}
}
if (!httpAgent && !httpsAgent) {
if (isHttpsRequest) {
httpsAgent = getOrCreateHttpsAgent({ AgentClass: https.Agent, options: tlsOptions as any, timeline: timeline || null, disableCache, hostname }) as HttpsAgent;
} else {
httpAgent = getOrCreateHttpAgent({ AgentClass: http.Agent, options: { keepAlive: true }, timeline: timeline || null, disableCache, hostname });View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Set http_proxy with a full scheme: export http_proxy='http://proxy.corp:8080'.
- In GNOME: gsettings set org.gnome.system.proxy mode manual and set host/port so the resolver emits a complete URL.
- Strip whitespace and verify with `new URL(value)` in a REPL before relying on it.
Example fix
// before process.env.http_proxy = 'proxy.corp:8080'; // new URL throws -> 'Invalid system http_proxy' // after process.env.http_proxy = 'http://proxy.corp:8080';
Defensive patterns
Strategy: validation
Validate before calling
function ensureValidProxyUrl(value, label) {
if (!value) return;
let u; try { u = new URL(value); } catch { throw new Error(`Invalid system ${label}`); }
if (!u.protocol || !u.hostname) throw new Error(`Invalid system ${label}`);
}
ensureValidProxyUrl(http_proxy, 'http_proxy');
ensureValidProxyUrl(https_proxy, 'https_proxy'); Type guard
function isAbsoluteProxyUrl(v): v is string { try { const u = new URL(v); return !!u.protocol && !!u.hostname; } catch { return false; } } Try / catch
try { const agent = buildSystemHttpAgent(http_proxy); } catch (e) { if (/Invalid system http_proxy/.test(e.message)) { /* fall back to direct connection */ } else throw e; } Prevention
- Always set http_proxy/https_proxy with a full scheme (http://, https://, socks5://).
- Strip whitespace from proxy env vars before parsing.
- Test the value with `new URL(...)` in a REPL before relying on it.
When it happens
Trigger: proxyMode='system', the OS-reported http_proxy is non-empty but malformed (missing scheme, stray characters, bare hostname without protocol), and the request is HTTP (not HTTPS).
Common situations: Environment/export http_proxy='proxy.corp:8080' (no scheme); gsettings stored host without protocol; copy-paste introduced whitespace or a leading space; URL contains illegal characters.
Related errors
- Invalid token URL: ${requestConfig.url}
- Unsupported platform: ${this.osPlatform}
- No Linux proxy configuration found
- Linux proxy detection failed: ${error instanceof Error ? err
- macOS proxy detection failed: ${error instanceof Error ? err
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/a3aafea21e14659c.
Report an issue: GitHub.