Repository navigation
[release/10.0.1xx] [Foundation] Implement NSUrlSessionHandler proxy support. Fixes #14632 - #26858
Conversation
#26021) The `Proxy` setter previously threw `PlatformNotSupportedException`, and `UseProxy`/`SupportsProxy` didn't allow any custom proxy configuration. This implements custom proxy support: * `Proxy` is now a real `IWebProxy` property. Since NSUrlSession applies proxy settings per-session (not per-request), the proxy returned by `IWebProxy.GetProxy` for the first request is translated into the session's `ConnectionProxyDictionary` and the session is recreated before the first request is sent (mirroring the `UseCookies` pattern). * `UseProxy` is now a real settable bool. Setting it to `false` applies an empty connection proxy dictionary, which overrides any proxy configured in the OS. * `SupportsProxy` now returns `true`. * Proxy authentication is wired up: `DefaultProxyCredentials` is a real property, and proxy authentication challenges (`IsProxy` protection spaces) use `Proxy.Credentials ?? DefaultProxyCredentials`. Added an in-process HTTP forwarding proxy test server and tests covering proxy routing, proxy authentication (via `Proxy.Credentials` and `DefaultProxyCredentials`) and the proxy-related property behavior. Fixes #14632. Fixes #18635. 🤖 Pull request created by Copilot --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
CredentialCache proxy authentication can use the wrong URI scheme for HTTPS CONNECT challenges.
1 open finding
What changed in this PR
Backports custom proxy routing and authentication support for NSUrlSessionHandler.
Changes:
- Configures per-session HTTP proxies and proxy disabling.
- Handles proxy credentials and authentication challenges.
- Adds local proxy/TLS infrastructure and regression tests.
| File | Description |
|---|---|
src/Foundation/NSUrlSessionHandler.cs |
Implements proxy configuration and authentication. |
tests/monotouch-test/System.Net.Http/NSUrlSessionHandlerTest.cs |
Tests proxy routing, authentication, and properties. |
tests/monotouch-test/System.Net.Http/ProxyTestServer.cs |
Adds an HTTP forwarding proxy test server. |
tests/monotouch-test/System.Net.Http/TlsTestServer.cs |
Adds reusable local TLS infrastructure. |
tests/monotouch-test/System.Net.Http/MessageHandlers.cs |
Uses the shared TLS test server. |
🧠 Review effort: Balanced
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🚀 [CI Build #a06dd61] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 200 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |

The
Proxysetter previously threwPlatformNotSupportedException, andUseProxy/SupportsProxydidn't allow any custom proxy configuration.This implements custom proxy support:
Proxyis now a realIWebProxyproperty. Since NSUrlSession applies proxy settings per-session (not per-request), the proxy returned byIWebProxy.GetProxyfor the first request is translated into the session'sConnectionProxyDictionaryand the session is recreated before the first request is sent (mirroring theUseCookiespattern).UseProxyis now a real settable bool. Setting it tofalseapplies an empty connection proxy dictionary, which overrides any proxy configured in the OS.SupportsProxynow returnstrue.DefaultProxyCredentialsis a real property, and proxy authentication challenges (IsProxyprotection spaces) useProxy.Credentials ?? DefaultProxyCredentials.Added an in-process HTTP forwarding proxy test server and tests covering proxy routing, proxy authentication (via
Proxy.CredentialsandDefaultProxyCredentials) and the proxy-related property behavior.Fixes #14632.
Fixes #18635.
🤖 Pull request created by Copilot
Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com
Backport of #26021.