Skip to content

Commit b84ca2d

Browse files
authored
Ensure both property and value exist for Blob's HTTP proxy (#12417)
* Check HTTP handler property and value exist * Change files
1 parent f58718e commit b84ca2d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Check HTTP handler property and value exist",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Shared/Networking/DefaultBlobResource.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,19 @@ void DefaultBlobResource::Release(string &&blobId) noexcept /*override*/ {
140140
void DefaultBlobResource::AddNetworkingHandler() noexcept /*override*/ {
141141
auto propId = msrn::ReactPropertyId<msrn::ReactNonAbiValue<weak_ptr<IHttpModuleProxy>>>{L"HttpModule.Proxy"};
142142

143+
bool handlerAdded = false;
143144
if (auto prop = m_propertyBag.Get(propId)) {
144145
if (auto httpHandler = prop.Value().lock()) {
145146
httpHandler->AddRequestBodyHandler(m_requestBodyHandler);
146147
httpHandler->AddResponseHandler(m_responseHandler);
148+
handlerAdded = true;
147149
}
148-
} else {
149-
// #11439 - The absence of HttpModule.Proxy may be caused by a module initialization race condition.
150-
// Best-effort approach to set up the request/response handlers by exposing this interface to dependents
151-
// (i.e. IHttpResource).
150+
}
151+
152+
// #11439 - The absence of HttpModule.Proxy may be caused by a module initialization race condition.
153+
// Best-effort approach to set up the request/response handlers by exposing this interface to dependents
154+
// (i.e. IHttpResource).
155+
if (!handlerAdded) {
152156
auto propId = msrn::ReactPropertyId<msrn::ReactNonAbiValue<weak_ptr<IBlobResource>>>{L"Blob.Resource"};
153157
m_propertyBag.Set(propId, weak_ptr<IBlobResource>(shared_from_this()));
154158
}

0 commit comments

Comments
 (0)