Refresh HTTP client after network changes - #16370
Open
Khalef Hosany (Khalef1) wants to merge 1 commit into
Open
Conversation
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
Contributor
There was a problem hiding this comment.
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validation
clang-format --dry-run --Werroron the changed C++ filesNetworkInformation::NetworkStatusChangedMicrosoft Reviewers: Open in CodeFlow