Skip to content

Commit

Permalink
Ensure both property and value exist for Blob's HTTP proxy (#12417)
Browse files Browse the repository at this point in the history
* Check HTTP handler property and value exist

* Change files
  • Loading branch information
JunielKatarn committed Nov 18, 2023
1 parent f58718e commit b84ca2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Check HTTP handler property and value exist",
"packageName": "react-native-windows",
"email": "julio.rocha@microsoft.com",
"dependentChangeType": "patch"
}
12 changes: 8 additions & 4 deletions vnext/Shared/Networking/DefaultBlobResource.cpp
Expand Up @@ -140,15 +140,19 @@ void DefaultBlobResource::Release(string &&blobId) noexcept /*override*/ {
void DefaultBlobResource::AddNetworkingHandler() noexcept /*override*/ {
auto propId = msrn::ReactPropertyId<msrn::ReactNonAbiValue<weak_ptr<IHttpModuleProxy>>>{L"HttpModule.Proxy"};

bool handlerAdded = false;
if (auto prop = m_propertyBag.Get(propId)) {
if (auto httpHandler = prop.Value().lock()) {
httpHandler->AddRequestBodyHandler(m_requestBodyHandler);
httpHandler->AddResponseHandler(m_responseHandler);
handlerAdded = true;
}
} else {
// #11439 - The absence of HttpModule.Proxy may be caused by a module initialization race condition.
// Best-effort approach to set up the request/response handlers by exposing this interface to dependents
// (i.e. IHttpResource).
}

// #11439 - The absence of HttpModule.Proxy may be caused by a module initialization race condition.
// Best-effort approach to set up the request/response handlers by exposing this interface to dependents
// (i.e. IHttpResource).
if (!handlerAdded) {
auto propId = msrn::ReactPropertyId<msrn::ReactNonAbiValue<weak_ptr<IBlobResource>>>{L"Blob.Resource"};
m_propertyBag.Set(propId, weak_ptr<IBlobResource>(shared_from_this()));
}
Expand Down

0 comments on commit b84ca2d

Please sign in to comment.