@@ -1060,6 +1060,7 @@ winrt::fire_and_forget RNFetchBlob::fetchBlob(
1060
1060
{
1061
1061
filter.IgnorableServerCertificateErrors ().Append (Cryptography::Certificates::ChainValidationResult::Untrusted);
1062
1062
}
1063
+ RNFetchBlobState eventState;
1063
1064
1064
1065
winrt::Windows::Web::Http::HttpClient httpClient{ filter };
1065
1066
@@ -1186,11 +1187,9 @@ winrt::fire_and_forget RNFetchBlob::fetchBlob(
1186
1187
}
1187
1188
}
1188
1189
1189
- RNFetchBlobState eventState;
1190
-
1191
1190
co_await m_tasks.Add (taskId, ProcessRequestAsync (taskId, filter, requestMessage, config, callback, eventState));
1192
1191
1193
- m_tasks.Cancel (taskId);
1192
+ m_tasks.Cancel (taskId);
1194
1193
{
1195
1194
std::scoped_lock lock{ m_mutex };
1196
1195
uploadProgressMap.extract (taskId);
@@ -1375,19 +1374,6 @@ winrt::fire_and_forget RNFetchBlob::fetchBlobForm(
1375
1374
}
1376
1375
}
1377
1376
}
1378
-
1379
- // TODO, set a timeout for cancellation
1380
-
1381
- // Create EVENT_STATE_CHANGE
1382
- /*
1383
- taskId, // DO NOT STORE
1384
- @"state": @"2", // store
1385
- @"headers": headers, // store
1386
- @"redirects": redirects, //check how to track
1387
- @"respType" : respType, // store
1388
- @"timeout" : @NO, // do not store
1389
- @"status": [NSNumber numberWithInteger:statusCode] // store
1390
- */
1391
1377
1392
1378
RNFetchBlobState eventState;
1393
1379
@@ -1505,13 +1491,36 @@ try
1505
1491
if (config.followRedirect ) {
1506
1492
while (status >= 300 && status < 400 ) {
1507
1493
auto redirect{ response.Headers ().Location ().ToString () };
1508
- eventState.redirects .push_back (winrt::to_string (redirect));
1494
+ eventState.redirects .push_back (Microsoft::ReactNative::JSValue ( winrt::to_string (redirect) ));
1509
1495
httpRequestMessage.RequestUri (Uri{ redirect });
1510
1496
response = co_await httpClient.SendRequestAsync (httpRequestMessage, winrt::Windows::Web::Http::HttpCompletionOption::ResponseHeadersRead);
1511
1497
status = static_cast <int >(response.StatusCode ());
1512
1498
}
1513
1499
}
1514
1500
1501
+ eventState.status = static_cast <int >(response.StatusCode ());
1502
+
1503
+ for (const auto header : response.Content ().Headers ().GetView ()) {
1504
+ eventState.headers [winrt::to_string (header.Key ())] = winrt::to_string (header.Value ());
1505
+ }
1506
+
1507
+ if (response.Content ().Headers ().ContentType () != nullptr ) {
1508
+ eventState.respType = winrt::to_string (response.Content ().Headers ().ContentType ().ToString ());
1509
+ }
1510
+
1511
+ eventState.state = winrt::to_string (response.ReasonPhrase ());
1512
+
1513
+ m_reactContext.CallJSFunction (L" RCTDeviceEventEmitter" , L" emit" , L" RNFetchBlobState" ,
1514
+ Microsoft::ReactNative::JSValueObject{
1515
+ { " taskId" , taskId },
1516
+ { " state" , eventState.state },
1517
+ { " headers" , std::move (eventState.headers ) },
1518
+ { " redirects" , std::move (eventState.redirects ) },
1519
+ { " respType" , eventState.respType },
1520
+ { " status" , eventState.status },
1521
+ { " timeout" , false },
1522
+ });
1523
+
1515
1524
IReference<uint64_t > contentLength{ response.Content ().Headers ().ContentLength () };
1516
1525
1517
1526
IOutputStream outputStream;
@@ -1604,18 +1613,6 @@ try
1604
1613
}
1605
1614
}
1606
1615
}
1607
-
1608
- eventState.status = static_cast <int >(response.StatusCode ());
1609
-
1610
- for (const auto header : response.Content ().Headers ().GetView ()) {
1611
- eventState.headers [winrt::to_string (header.Key ())] = winrt::to_string (header.Value ());
1612
- }
1613
-
1614
- if (response.Content ().Headers ().ContentType () != nullptr ) {
1615
- eventState.respType = winrt::to_string (response.Content ().Headers ().ContentType ().ToString ());
1616
- }
1617
-
1618
- eventState.state = winrt::to_string (response.ReasonPhrase ());
1619
1616
1620
1617
if (writeToFile) {
1621
1618
callback (" " , " path" , config.path );
0 commit comments