Serve PAC file to selectively proxy only watched hosts
- Dominant language
- C#
- Stars
- 832
- Forks
- 89
- Avg merge
- 12h 1m
- Merged PRs (30d)
- 23
Description
Currently, when Dev Proxy runs as a system proxy, _all_ HTTP/HTTPS traffic flows through it. Dev Proxy filters requests internally based on `urlsToWatch`, but unrelated traffic still takes the detour through the proxy. This can cause issues with services that are sensitive to proxying (e.g., Azure Functions startup, Teams auth) and adds unnecessary latency to non-watched traffic.
**Proposal:** Have Dev Proxy serve a [PAC (Proxy Auto-Config)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_PAC_file) file that routes only watched hosts through the proxy. All other traffic goes direct.
**How it would work:**
1. Dev Proxy generates a `FindProxyForURL()` script from the configured `urlsToWatch` hosts
2. Serves it at an endpoint like `http://127.0.0.1:{port}/proxy.pac` with MIME type `application/x-ns-proxy-autoconfig`
3. Instead of setting the system HTTP/HTTPS proxy, sets the system's auto-config URL to point to this PAC file
- macOS: `networksetup -setautoproxyurl http://127.0.0.1:{port}/proxy.pac`
- Windows: set `AutoConfigURL` registry key or use the proxy library equivalent
**Example generated PAC file** for `urlsToWatch: ["https://graph.microsoft.com/*", "https://api.contoso.com/*"]`:
```javascript
function FindProxyForURL(url, host) {
if (shExpMatch(host, "graph.microsoft.com") ||
shExpMatch(host, "api.contoso.com")) {
return "PROXY 127.0.0.1:8000";
}
return "DIRECT";
}
```
**Limitations:**
- PAC files operate at the host level, not URL-path level. Fine-grained URL matching still happens inside the proxy as it does today.
- Linux doesn't have a standard system-wide auto-config URL mechanism (same limitation as the current system proxy setup).
**Benefits:**
- Non-watched traffic never touches the proxy — faster, fewer side effects
- Could resolve issues with Azure Functions, Teams auth, and other services that break when proxied
- Minimal implementation surface — Dev Proxy already has an API controller and already toggles system proxy settings
Derived from https://github.com/dotnet/dev-proxy/issues/1368.
Contributor guide
Assessment
This issue has not been assessed yet.