property
BunFetchRequestInit.proxy
proxy?: FetchProxyOption
The proxy to send the request through, overriding the http_proxy, HTTPS_PROXY and ALL_PROXY environment variables. Accepts a URL string, a URL instance, or an object with url and optional headers and respectNoProxy.
false connects directly, ignoring the proxy environment variables.
Hosts listed in NO_PROXY bypass the proxy unless respectNoProxy is false.
If a Proxy-Authorization header is provided in proxy.headers, it takes precedence over credentials parsed from the proxy URL.
Not part of the Fetch API specification.
// String format
const response = await fetch("http://example.com", {
proxy: "https://username:password@127.0.0.1:8080"
});
// Object format with custom headers sent to the proxy
const response = await fetch("http://example.com", {
proxy: {
url: "https://127.0.0.1:8080",
headers: {
"Proxy-Authorization": "Bearer token",
"X-Custom-Proxy-Header": "value"
}
}
});
// Never use a proxy for this request
const direct = await fetch("http://example.com", { proxy: false });