Skip to content

Refresh HTTP client after network changes - #16370

Open
Khalef Hosany (Khalef1) wants to merge 1 commit into
0.81-stablefrom
user/khosany/fix-http-proxy-refresh-4995466
Open

Refresh HTTP client after network changes#16370
Khalef Hosany (Khalef1) wants to merge 1 commit into
0.81-stablefrom
user/khosany/fix-http-proxy-refresh-4995466

Conversation

@Khalef1

@Khalef1 Khalef Hosany (Khalef1) commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • invalidate the WinRT HTTP client when Windows reports a network status change
  • lazily rebuild the redirect and origin-policy filter chain before the next request
  • keep in-flight requests on their existing client while refreshing proxy and PAC state for new requests

Validation

  • clang-format --dry-run --Werror on the changed C++ files
  • standalone C++/WinRT compile check for NetworkInformation::NetworkStatusChanged
  • full desktop build not run because this checkout lacks restored dependencies and registry downloads fail with TLS handshake errors
Microsoft Reviewers: Open in CodeFlow

Recreate the WinRT HTTP filter chain before the next request after Windows reports a network status change so proxy and PAC state does not remain stale across sleep or connectivity transitions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2406d9df-f47a-4e33-9d9a-3f734ba117f7
Copilot AI balanced review requested due to automatic review settings August 15, 2026 07:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refreshes WinRT HTTP clients after network changes so new requests use updated proxy/PAC state while in-flight requests continue uninterrupted.

Changes:

  • Monitors Windows network-status changes.
  • Lazily rebuilds HTTP filter chains.
  • Adds package change metadata.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
vnext/Shared/Networking/WinRTHttpResource.h Adds refresh state and network monitoring declarations.
vnext/Shared/Networking/WinRTHttpResource.cpp Implements client invalidation and lazy reconstruction.
change/@office-iss-react-native-win32-91558e86-80c0-4e3b-8fec-3c36d7c4917a.json Records the patch release change.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +419 to +420
auto opFilter = winrt::make<OriginPolicyHttpFilter>(std::string{m_globalOrigin}, redirFilter);
redirFilter.as<RedirectHttpFilter>()->SetRedirectSource(opFilter.as<IRedirectEventSource>());
Comment on lines +438 to +452
void WinRTHttpResource::InitializeNetworkStatusMonitoring() {
{
scoped_lock lock{m_clientMutex};
m_client = CreateClient();
}

m_networkStatusChangedRevoker =
NetworkInformation::NetworkStatusChanged(winrt::auto_revoke, [weakThis = weak_from_this()](auto &&) noexcept {
if (auto strongThis = weakThis.lock()) {
// HttpBaseProtocolFilter caches system proxy state. Recreate it before the next request after a network
// change.
strongThis->m_clientNeedsRefresh.store(true, std::memory_order_release);
}
});
}
Comment on lines +424 to +430
IHttpClient WinRTHttpResource::GetClient() {
scoped_lock lock{m_clientMutex};
if (m_refreshClientOnNetworkChange && m_clientNeedsRefresh.exchange(false, std::memory_order_acq_rel)) {
try {
m_client = CreateClient();
} catch (...) {
m_clientNeedsRefresh.store(true, std::memory_order_release);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants