@@ -1060,6 +1060,7 @@ winrt::fire_and_forget RNFetchBlob::fetchBlob(
10601060 {
10611061 filter.IgnorableServerCertificateErrors ().Append (Cryptography::Certificates::ChainValidationResult::Untrusted);
10621062 }
1063+ RNFetchBlobState eventState;
10631064
10641065 winrt::Windows::Web::Http::HttpClient httpClient{ filter };
10651066
@@ -1186,11 +1187,9 @@ winrt::fire_and_forget RNFetchBlob::fetchBlob(
11861187 }
11871188 }
11881189
1189- RNFetchBlobState eventState;
1190-
11911190 co_await m_tasks.Add (taskId, ProcessRequestAsync (taskId, filter, requestMessage, config, callback, eventState));
11921191
1193- m_tasks.Cancel (taskId);
1192+ m_tasks.Cancel (taskId);
11941193 {
11951194 std::scoped_lock lock{ m_mutex };
11961195 uploadProgressMap.extract (taskId);
@@ -1375,19 +1374,6 @@ winrt::fire_and_forget RNFetchBlob::fetchBlobForm(
13751374 }
13761375 }
13771376 }
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- */
13911377
13921378 RNFetchBlobState eventState;
13931379
@@ -1505,13 +1491,36 @@ try
15051491 if (config.followRedirect ) {
15061492 while (status >= 300 && status < 400 ) {
15071493 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) ));
15091495 httpRequestMessage.RequestUri (Uri{ redirect });
15101496 response = co_await httpClient.SendRequestAsync (httpRequestMessage, winrt::Windows::Web::Http::HttpCompletionOption::ResponseHeadersRead);
15111497 status = static_cast <int >(response.StatusCode ());
15121498 }
15131499 }
15141500
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+
15151524 IReference<uint64_t > contentLength{ response.Content ().Headers ().ContentLength () };
15161525
15171526 IOutputStream outputStream;
@@ -1604,18 +1613,6 @@ try
16041613 }
16051614 }
16061615 }
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 ());
16191616
16201617 if (writeToFile) {
16211618 callback (" " , " path" , config.path );
0 commit comments