react-native-windows 0.69.0-preview.2 → 0.69.0-preview.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Directory.Build.props +4 -0
- package/Folly/Folly.vcxproj +4 -5
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/Network/RCTNetworkingWinShared.js +7 -0
- package/Libraries/Utilities/codegenNativeComponent.js +5 -6
- package/Libraries/Utilities/useColorScheme.js +9 -15
- package/Microsoft.ReactNative/Base/CoreNativeModules.cpp +3 -1
- package/Microsoft.ReactNative/IReactContext.cpp +17 -0
- package/Microsoft.ReactNative/IReactContext.h +2 -0
- package/Microsoft.ReactNative/IReactContext.idl +27 -0
- package/Microsoft.ReactNative/JsiApi.cpp +9 -0
- package/Microsoft.ReactNative/JsiApi.h +1 -0
- package/Microsoft.ReactNative/JsiApi.idl +1 -0
- package/Microsoft.ReactNative.Cxx/JSI/JsiAbiApi.cpp +3 -5
- package/Microsoft.ReactNative.Cxx/JSI/JsiAbiApi.h +1 -1
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.cpp +31 -9
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.h +48 -0
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +2 -2
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +1 -1
- package/Microsoft.ReactNative.Managed/packages.lock.json +57 -2
- package/PropertySheets/Generated/PackageVersion.g.props +1 -1
- package/PropertySheets/JSEngine.props +2 -2
- package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +9 -5
- package/Shared/CreateModules.h +17 -2
- package/Shared/InspectorPackagerConnection.cpp +6 -7
- package/Shared/InspectorPackagerConnection.h +1 -1
- package/Shared/JSI/ChakraRuntime.cpp +5 -0
- package/Shared/JSI/ChakraRuntime.h +1 -0
- package/Shared/JSI/NapiJsiV8RuntimeHolder.cpp +72 -2
- package/Shared/JSI/NapiJsiV8RuntimeHolder.h +2 -0
- package/Shared/Modules/BlobModule.cpp +376 -0
- package/Shared/Modules/BlobModule.h +153 -0
- package/Shared/Modules/CxxModuleUtilities.cpp +19 -0
- package/Shared/Modules/CxxModuleUtilities.h +23 -0
- package/Shared/Modules/FileReaderModule.cpp +156 -0
- package/Shared/Modules/FileReaderModule.h +54 -0
- package/Shared/Modules/HttpModule.cpp +72 -69
- package/Shared/Modules/HttpModule.h +8 -1
- package/Shared/Modules/IBlobPersistor.h +30 -0
- package/Shared/Modules/IHttpModuleProxy.h +30 -0
- package/Shared/Modules/IRequestBodyHandler.h +52 -0
- package/Shared/Modules/IResponseHandler.h +27 -0
- package/Shared/Modules/IUriHandler.h +37 -0
- package/Shared/Modules/IWebSocketModuleContentHandler.h +26 -0
- package/Shared/Modules/IWebSocketModuleProxy.h +22 -0
- package/Shared/Modules/NetworkingModule.cpp +1 -1
- package/Shared/Modules/WebSocketModule.cpp +92 -22
- package/Shared/Modules/WebSocketModule.h +27 -1
- package/Shared/Networking/IHttpResource.h +50 -2
- package/Shared/Networking/WinRTHttpResource.cpp +169 -51
- package/Shared/Networking/WinRTHttpResource.h +27 -8
- package/Shared/Networking/WinRTTypes.h +5 -2
- package/Shared/OInstance.cpp +22 -5
- package/Shared/OInstance.h +8 -4
- package/Shared/RuntimeOptions.cpp +6 -3
- package/Shared/RuntimeOptions.h +14 -3
- package/Shared/Shared.vcxitems +13 -0
- package/Shared/Shared.vcxitems.filters +40 -1
- package/fmt/fmt.vcxproj +4 -5
- package/package.json +14 -12
- package/template/cs-app-WinAppSDK/proj/NuGet.Config +3 -1
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/JSCRuntime.cpp +0 -1480
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/decorator.h +0 -753
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/jsi.h +0 -1331
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#include "WinRTHttpResource.h"
|
|
5
5
|
|
|
6
6
|
#include <CppRuntimeOptions.h>
|
|
7
|
+
#include <ReactPropertyBag.h>
|
|
7
8
|
#include <Utils/CppWinrtLessExceptions.h>
|
|
8
9
|
#include <Utils/WinRTConversions.h>
|
|
9
10
|
#include <utilities.h>
|
|
@@ -17,10 +18,14 @@
|
|
|
17
18
|
#include <winrt/Windows.Storage.Streams.h>
|
|
18
19
|
#include <winrt/Windows.Web.Http.Headers.h>
|
|
19
20
|
|
|
21
|
+
using folly::dynamic;
|
|
22
|
+
|
|
20
23
|
using std::function;
|
|
21
24
|
using std::scoped_lock;
|
|
22
25
|
using std::shared_ptr;
|
|
23
26
|
using std::string;
|
|
27
|
+
using std::vector;
|
|
28
|
+
using std::weak_ptr;
|
|
24
29
|
|
|
25
30
|
using winrt::fire_and_forget;
|
|
26
31
|
using winrt::hresult_error;
|
|
@@ -45,29 +50,25 @@ namespace Microsoft::React::Networking {
|
|
|
45
50
|
|
|
46
51
|
#pragma region WinRTHttpResource
|
|
47
52
|
|
|
48
|
-
// TODO: Check for multi-thread issues if there are multiple instances.
|
|
49
|
-
/*static*/ int64_t WinRTHttpResource::s_lastRequestId = 0;
|
|
50
|
-
|
|
51
53
|
WinRTHttpResource::WinRTHttpResource(IHttpClient &&client) noexcept : m_client{std::move(client)} {}
|
|
52
54
|
|
|
53
|
-
WinRTHttpResource::WinRTHttpResource() noexcept : WinRTHttpResource(winrt::Windows::Web::Http::HttpClient
|
|
55
|
+
WinRTHttpResource::WinRTHttpResource() noexcept : WinRTHttpResource(winrt::Windows::Web::Http::HttpClient{}) {}
|
|
54
56
|
|
|
55
57
|
#pragma region IHttpResource
|
|
56
58
|
|
|
57
59
|
void WinRTHttpResource::SendRequest(
|
|
58
60
|
string &&method,
|
|
59
61
|
string &&url,
|
|
62
|
+
int64_t requestId,
|
|
60
63
|
Headers &&headers,
|
|
61
|
-
|
|
64
|
+
dynamic &&data,
|
|
62
65
|
string &&responseType,
|
|
63
66
|
bool useIncrementalUpdates,
|
|
64
67
|
int64_t timeout,
|
|
65
68
|
bool withCredentials,
|
|
66
69
|
std::function<void(int64_t)> &&callback) noexcept /*override*/ {
|
|
67
|
-
auto requestId = ++s_lastRequestId;
|
|
68
|
-
|
|
69
70
|
// Enforce supported args
|
|
70
|
-
assert(responseType == "text" || responseType == "base64");
|
|
71
|
+
assert(responseType == "text" || responseType == "base64" | responseType == "blob");
|
|
71
72
|
|
|
72
73
|
if (callback) {
|
|
73
74
|
callback(requestId);
|
|
@@ -82,10 +83,10 @@ void WinRTHttpResource::SendRequest(
|
|
|
82
83
|
auto concreteArgs = args.as<RequestArgs>();
|
|
83
84
|
concreteArgs->RequestId = requestId;
|
|
84
85
|
concreteArgs->Headers = std::move(headers);
|
|
85
|
-
concreteArgs->
|
|
86
|
+
concreteArgs->Data = std::move(data);
|
|
86
87
|
concreteArgs->IncrementalUpdates = useIncrementalUpdates;
|
|
87
88
|
concreteArgs->WithCredentials = withCredentials;
|
|
88
|
-
concreteArgs->
|
|
89
|
+
concreteArgs->ResponseType = std::move(responseType);
|
|
89
90
|
concreteArgs->Timeout = timeout;
|
|
90
91
|
|
|
91
92
|
PerformSendRequest(std::move(request), args);
|
|
@@ -126,8 +127,8 @@ void WinRTHttpResource::ClearCookies() noexcept /*override*/ {
|
|
|
126
127
|
// NOT IMPLEMENTED
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
void WinRTHttpResource::
|
|
130
|
-
|
|
130
|
+
void WinRTHttpResource::SetOnRequestSuccess(function<void(int64_t requestId)> &&handler) noexcept /*override*/ {
|
|
131
|
+
m_onRequestSuccess = std::move(handler);
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
void WinRTHttpResource::SetOnResponse(function<void(int64_t requestId, Response &&response)> &&handler) noexcept
|
|
@@ -140,6 +141,12 @@ void WinRTHttpResource::SetOnData(function<void(int64_t requestId, string &&resp
|
|
|
140
141
|
m_onData = std::move(handler);
|
|
141
142
|
}
|
|
142
143
|
|
|
144
|
+
void WinRTHttpResource::SetOnData(function<void(int64_t requestId, dynamic &&responseData)> &&handler) noexcept
|
|
145
|
+
/*override*/
|
|
146
|
+
{
|
|
147
|
+
m_onDataDynamic = std::move(handler);
|
|
148
|
+
}
|
|
149
|
+
|
|
143
150
|
void WinRTHttpResource::SetOnError(function<void(int64_t requestId, string &&errorMessage)> &&handler) noexcept
|
|
144
151
|
/*override*/ {
|
|
145
152
|
m_onError = std::move(handler);
|
|
@@ -167,6 +174,28 @@ fire_and_forget WinRTHttpResource::PerformSendRequest(HttpRequestMessage &&reque
|
|
|
167
174
|
// Ensure background thread
|
|
168
175
|
co_await winrt::resume_background();
|
|
169
176
|
|
|
177
|
+
// If URI handler is available, it takes over request processing.
|
|
178
|
+
if (auto uriHandler = self->m_uriHandler.lock()) {
|
|
179
|
+
auto uri = winrt::to_string(coRequest.RequestUri().ToString());
|
|
180
|
+
try {
|
|
181
|
+
if (uriHandler->Supports(uri, coReqArgs->ResponseType)) {
|
|
182
|
+
auto blob = uriHandler->Fetch(uri);
|
|
183
|
+
if (self->m_onDataDynamic && self->m_onRequestSuccess) {
|
|
184
|
+
self->m_onDataDynamic(coReqArgs->RequestId, std::move(blob));
|
|
185
|
+
self->m_onRequestSuccess(coReqArgs->RequestId);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
co_return;
|
|
189
|
+
}
|
|
190
|
+
} catch (const hresult_error &e) {
|
|
191
|
+
if (self->m_onError)
|
|
192
|
+
co_return self->m_onError(coReqArgs->RequestId, Utilities::HResultToString(e));
|
|
193
|
+
} catch (const std::exception &e) {
|
|
194
|
+
if (self->m_onError)
|
|
195
|
+
co_return self->m_onError(coReqArgs->RequestId, e.what());
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
170
199
|
HttpMediaTypeHeaderValue contentType{nullptr};
|
|
171
200
|
string contentEncoding;
|
|
172
201
|
string contentLength;
|
|
@@ -201,20 +230,44 @@ fire_and_forget WinRTHttpResource::PerformSendRequest(HttpRequestMessage &&reque
|
|
|
201
230
|
}
|
|
202
231
|
|
|
203
232
|
IHttpContent content{nullptr};
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
233
|
+
auto &data = coReqArgs->Data;
|
|
234
|
+
if (!data.isNull()) {
|
|
235
|
+
auto bodyHandler = self->m_requestBodyHandler.lock();
|
|
236
|
+
if (bodyHandler && bodyHandler->Supports(data)) {
|
|
237
|
+
auto contentTypeString = contentType ? winrt::to_string(contentType.ToString()) : "";
|
|
238
|
+
dynamic blob;
|
|
239
|
+
try {
|
|
240
|
+
blob = bodyHandler->ToRequestBody(data, contentTypeString);
|
|
241
|
+
} catch (const std::invalid_argument &e) {
|
|
242
|
+
if (self->m_onError) {
|
|
243
|
+
self->m_onError(coReqArgs->RequestId, e.what());
|
|
244
|
+
}
|
|
245
|
+
co_return;
|
|
246
|
+
}
|
|
247
|
+
auto bytes = blob["bytes"];
|
|
248
|
+
auto byteVector = vector<uint8_t>(bytes.size());
|
|
249
|
+
for (auto &byte : bytes) {
|
|
250
|
+
byteVector.push_back(static_cast<uint8_t>(byte.asInt()));
|
|
251
|
+
}
|
|
252
|
+
auto view = winrt::array_view<uint8_t>{byteVector};
|
|
253
|
+
auto buffer = CryptographicBuffer::CreateFromByteArray(view);
|
|
254
|
+
content = HttpBufferContent{std::move(buffer)};
|
|
255
|
+
} else if (!data["string"].empty()) {
|
|
256
|
+
content = HttpStringContent{to_hstring(data["string"].asString())};
|
|
257
|
+
} else if (!data["base64"].empty()) {
|
|
258
|
+
auto buffer = CryptographicBuffer::DecodeFromBase64String(to_hstring(data["base64"].asString()));
|
|
259
|
+
content = HttpBufferContent{std::move(buffer)};
|
|
260
|
+
} else if (!data["uri"].empty()) {
|
|
261
|
+
auto file = co_await StorageFile::GetFileFromApplicationUriAsync(Uri{to_hstring(data["uri"].asString())});
|
|
262
|
+
auto stream = co_await file.OpenReadAsync();
|
|
263
|
+
content = HttpStreamContent{std::move(stream)};
|
|
264
|
+
} else if (!data["form"].empty()) {
|
|
265
|
+
// #9535 - HTTP form data support
|
|
266
|
+
// winrt::Windows::Web::Http::HttpMultipartFormDataContent()
|
|
267
|
+
} else {
|
|
268
|
+
// Assume empty request body.
|
|
269
|
+
// content = HttpStringContent{L""};
|
|
270
|
+
}
|
|
218
271
|
}
|
|
219
272
|
|
|
220
273
|
if (content != nullptr) {
|
|
@@ -224,12 +277,13 @@ fire_and_forget WinRTHttpResource::PerformSendRequest(HttpRequestMessage &&reque
|
|
|
224
277
|
}
|
|
225
278
|
if (!contentEncoding.empty()) {
|
|
226
279
|
if (!content.Headers().ContentEncoding().TryParseAdd(to_hstring(contentEncoding))) {
|
|
227
|
-
if (m_onError)
|
|
228
|
-
m_onError(coReqArgs->RequestId, "Failed to parse Content-Encoding");
|
|
229
|
-
|
|
280
|
+
if (self->m_onError)
|
|
281
|
+
self->m_onError(coReqArgs->RequestId, "Failed to parse Content-Encoding");
|
|
282
|
+
|
|
230
283
|
co_return;
|
|
231
284
|
}
|
|
232
285
|
}
|
|
286
|
+
|
|
233
287
|
if (!contentLength.empty()) {
|
|
234
288
|
const auto contentLengthHeader = _atoi64(contentLength.c_str());
|
|
235
289
|
content.Headers().ContentLength(contentLengthHeader);
|
|
@@ -255,7 +309,7 @@ fire_and_forget WinRTHttpResource::PerformSendRequest(HttpRequestMessage &&reque
|
|
|
255
309
|
auto response = sendRequestOp.GetResults();
|
|
256
310
|
if (response) {
|
|
257
311
|
if (self->m_onResponse) {
|
|
258
|
-
|
|
312
|
+
auto url = to_string(response.RequestMessage().RequestUri().AbsoluteUri());
|
|
259
313
|
|
|
260
314
|
// Gather headers for both the response content and the response itself
|
|
261
315
|
// See Invoke-WebRequest PowerShell cmdlet or Chromium response handling
|
|
@@ -278,30 +332,54 @@ fire_and_forget WinRTHttpResource::PerformSendRequest(HttpRequestMessage &&reque
|
|
|
278
332
|
auto inputStream = co_await response.Content().ReadAsInputStreamAsync();
|
|
279
333
|
auto reader = DataReader{inputStream};
|
|
280
334
|
|
|
281
|
-
if (coReqArgs->IsText) {
|
|
282
|
-
reader.UnicodeEncoding(UnicodeEncoding::Utf8);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
335
|
// #9510 - 10mb limit on fetch
|
|
286
336
|
co_await reader.LoadAsync(10 * 1024 * 1024);
|
|
287
|
-
auto length = reader.UnconsumedBufferLength();
|
|
288
337
|
|
|
289
|
-
if
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
338
|
+
// Let response handler take over, if set
|
|
339
|
+
if (auto responseHandler = self->m_responseHandler.lock()) {
|
|
340
|
+
if (responseHandler->Supports(coReqArgs->ResponseType)) {
|
|
341
|
+
auto bytes = vector<uint8_t>(reader.UnconsumedBufferLength());
|
|
342
|
+
reader.ReadBytes(bytes);
|
|
343
|
+
auto blob = responseHandler->ToResponseData(std::move(bytes));
|
|
344
|
+
|
|
345
|
+
if (self->m_onDataDynamic && self->m_onRequestSuccess) {
|
|
346
|
+
self->m_onDataDynamic(coReqArgs->RequestId, std::move(blob));
|
|
347
|
+
self->m_onRequestSuccess(coReqArgs->RequestId);
|
|
348
|
+
}
|
|
293
349
|
|
|
294
|
-
|
|
295
|
-
self->m_onData(coReqArgs->RequestId, std::move(responseData));
|
|
350
|
+
co_return;
|
|
296
351
|
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
auto isText = coReqArgs->ResponseType == "text";
|
|
355
|
+
if (isText) {
|
|
356
|
+
reader.UnicodeEncoding(UnicodeEncoding::Utf8);
|
|
357
|
+
}
|
|
301
358
|
|
|
302
|
-
|
|
303
|
-
|
|
359
|
+
// #9510 - We currently accumulate all incoming request data in 10MB chunks.
|
|
360
|
+
uint32_t segmentSize = 10 * 1024 * 1024;
|
|
361
|
+
string responseData;
|
|
362
|
+
winrt::Windows::Storage::Streams::IBuffer buffer;
|
|
363
|
+
uint32_t length;
|
|
364
|
+
do {
|
|
365
|
+
co_await reader.LoadAsync(segmentSize);
|
|
366
|
+
length = reader.UnconsumedBufferLength();
|
|
367
|
+
|
|
368
|
+
if (isText) {
|
|
369
|
+
auto data = std::vector<uint8_t>(length);
|
|
370
|
+
reader.ReadBytes(data);
|
|
371
|
+
|
|
372
|
+
responseData += string(Common::Utilities::CheckedReinterpretCast<char *>(data.data()), data.size());
|
|
373
|
+
} else {
|
|
374
|
+
buffer = reader.ReadBuffer(length);
|
|
375
|
+
auto data = CryptographicBuffer::EncodeToBase64String(buffer);
|
|
376
|
+
|
|
377
|
+
responseData += to_string(std::wstring_view(data));
|
|
304
378
|
}
|
|
379
|
+
} while (length > 0);
|
|
380
|
+
|
|
381
|
+
if (self->m_onData) {
|
|
382
|
+
self->m_onData(coReqArgs->RequestId, std::move(responseData));
|
|
305
383
|
}
|
|
306
384
|
} else {
|
|
307
385
|
if (self->m_onError) {
|
|
@@ -323,23 +401,63 @@ fire_and_forget WinRTHttpResource::PerformSendRequest(HttpRequestMessage &&reque
|
|
|
323
401
|
}
|
|
324
402
|
|
|
325
403
|
self->UntrackResponse(coReqArgs->RequestId);
|
|
404
|
+
} // PerformSendRequest
|
|
405
|
+
|
|
406
|
+
#pragma region IHttpModuleProxy
|
|
407
|
+
|
|
408
|
+
void WinRTHttpResource::AddUriHandler(shared_ptr<IUriHandler> /*uriHandler*/) noexcept /*override*/
|
|
409
|
+
{
|
|
410
|
+
// TODO: Implement custom URI handling.
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
void WinRTHttpResource::AddRequestBodyHandler(shared_ptr<IRequestBodyHandler> requestBodyHandler) noexcept /*override*/
|
|
414
|
+
{
|
|
415
|
+
m_requestBodyHandler = weak_ptr<IRequestBodyHandler>(requestBodyHandler);
|
|
326
416
|
}
|
|
327
417
|
|
|
418
|
+
void WinRTHttpResource::AddResponseHandler(shared_ptr<IResponseHandler> responseHandler) noexcept /*override*/
|
|
419
|
+
{
|
|
420
|
+
m_responseHandler = weak_ptr<IResponseHandler>(responseHandler);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
#pragma endregion IHttpModuleProxy
|
|
424
|
+
|
|
328
425
|
#pragma endregion WinRTHttpResource
|
|
329
426
|
|
|
330
427
|
#pragma region IHttpResource
|
|
331
428
|
|
|
332
|
-
/*static*/ shared_ptr<IHttpResource> IHttpResource::Make(
|
|
429
|
+
/*static*/ shared_ptr<IHttpResource> IHttpResource::Make(
|
|
430
|
+
winrt::Windows::Foundation::IInspectable const &inspectableProperties) noexcept {
|
|
431
|
+
using namespace winrt::Microsoft::ReactNative;
|
|
432
|
+
using winrt::Windows::Web::Http::HttpClient;
|
|
433
|
+
|
|
434
|
+
shared_ptr<WinRTHttpResource> result;
|
|
435
|
+
|
|
333
436
|
if (static_cast<OriginPolicy>(GetRuntimeOptionInt("Http.OriginPolicy")) == OriginPolicy::None) {
|
|
334
|
-
|
|
437
|
+
result = std::make_shared<WinRTHttpResource>();
|
|
335
438
|
} else {
|
|
336
439
|
auto globalOrigin = GetRuntimeOptionString("Http.GlobalOrigin");
|
|
337
440
|
OriginPolicyHttpFilter::SetStaticOrigin(std::move(globalOrigin));
|
|
338
441
|
auto opFilter = winrt::make<OriginPolicyHttpFilter>();
|
|
339
|
-
auto client =
|
|
442
|
+
auto client = HttpClient{opFilter};
|
|
340
443
|
|
|
341
|
-
|
|
444
|
+
result = std::make_shared<WinRTHttpResource>(std::move(client));
|
|
342
445
|
}
|
|
446
|
+
|
|
447
|
+
// Register resource as HTTP module proxy.
|
|
448
|
+
if (inspectableProperties) {
|
|
449
|
+
auto propId = ReactPropertyId<ReactNonAbiValue<weak_ptr<IHttpModuleProxy>>>{L"HttpModule.Proxy"};
|
|
450
|
+
auto propBag = ReactPropertyBag{inspectableProperties.try_as<IReactPropertyBag>()};
|
|
451
|
+
auto moduleProxy = weak_ptr<IHttpModuleProxy>{result};
|
|
452
|
+
propBag.Set(propId, std::move(moduleProxy));
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/*static*/ shared_ptr<IHttpResource> IHttpResource::Make() noexcept {
|
|
459
|
+
auto inspectableProperties = IInspectable{nullptr};
|
|
460
|
+
return Make(inspectableProperties);
|
|
343
461
|
}
|
|
344
462
|
|
|
345
463
|
#pragma endregion IHttpResource
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
#include "IHttpResource.h"
|
|
7
7
|
|
|
8
|
+
#include <Modules/IHttpModuleProxy.h>
|
|
8
9
|
#include "WinRTTypes.h"
|
|
9
10
|
|
|
10
11
|
// Windows API
|
|
@@ -15,18 +16,24 @@
|
|
|
15
16
|
|
|
16
17
|
namespace Microsoft::React::Networking {
|
|
17
18
|
|
|
18
|
-
class WinRTHttpResource : public IHttpResource,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
class WinRTHttpResource : public IHttpResource,
|
|
20
|
+
public IHttpModuleProxy,
|
|
21
|
+
public std::enable_shared_from_this<WinRTHttpResource> {
|
|
21
22
|
winrt::Windows::Web::Http::IHttpClient m_client;
|
|
22
23
|
std::mutex m_mutex;
|
|
23
24
|
std::unordered_map<int64_t, ResponseOperation> m_responses;
|
|
24
25
|
|
|
25
|
-
std::function<void(int64_t requestId)>
|
|
26
|
+
std::function<void(int64_t requestId)> m_onRequestSuccess;
|
|
26
27
|
std::function<void(int64_t requestId, Response &&response)> m_onResponse;
|
|
27
28
|
std::function<void(int64_t requestId, std::string &&responseData)> m_onData;
|
|
29
|
+
std::function<void(int64_t requestId, folly::dynamic &&responseData)> m_onDataDynamic;
|
|
28
30
|
std::function<void(int64_t requestId, std::string &&errorMessage /*, bool isTimeout*/)> m_onError;
|
|
29
31
|
|
|
32
|
+
// Used for IHttpModuleProxy
|
|
33
|
+
std::weak_ptr<IUriHandler> m_uriHandler;
|
|
34
|
+
std::weak_ptr<IRequestBodyHandler> m_requestBodyHandler;
|
|
35
|
+
std::weak_ptr<IResponseHandler> m_responseHandler;
|
|
36
|
+
|
|
30
37
|
void TrackResponse(int64_t requestId, ResponseOperation response) noexcept;
|
|
31
38
|
|
|
32
39
|
void UntrackResponse(int64_t requestId) noexcept;
|
|
@@ -45,8 +52,9 @@ class WinRTHttpResource : public IHttpResource, public std::enable_shared_from_t
|
|
|
45
52
|
void SendRequest(
|
|
46
53
|
std::string &&method,
|
|
47
54
|
std::string &&url,
|
|
55
|
+
int64_t requestId,
|
|
48
56
|
Headers &&headers,
|
|
49
|
-
|
|
57
|
+
folly::dynamic &&data,
|
|
50
58
|
std::string &&responseType,
|
|
51
59
|
bool useIncrementalUpdates,
|
|
52
60
|
int64_t timeout,
|
|
@@ -55,13 +63,24 @@ class WinRTHttpResource : public IHttpResource, public std::enable_shared_from_t
|
|
|
55
63
|
void AbortRequest(int64_t requestId) noexcept override;
|
|
56
64
|
void ClearCookies() noexcept override;
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
void SetOnRequest(std::function<void(int64_t requestId)> &&handler) noexcept override;
|
|
66
|
+
void SetOnRequestSuccess(std::function<void(int64_t requestId)> &&handler) noexcept override;
|
|
61
67
|
void SetOnResponse(std::function<void(int64_t requestId, Response &&response)> &&handler) noexcept override;
|
|
62
68
|
void SetOnData(std::function<void(int64_t requestId, std::string &&responseData)> &&handler) noexcept override;
|
|
69
|
+
void SetOnData(std::function<void(int64_t requestId, folly::dynamic &&responseData)> &&handler) noexcept override;
|
|
63
70
|
void SetOnError(std::function<void(int64_t requestId, std::string &&errorMessage /*, bool isTimeout*/)>
|
|
64
71
|
&&handler) noexcept override;
|
|
72
|
+
|
|
73
|
+
#pragma endregion IHttpResource
|
|
74
|
+
|
|
75
|
+
#pragma region IHttpModuleProxy
|
|
76
|
+
|
|
77
|
+
void AddUriHandler(std::shared_ptr<IUriHandler> uriHandler) noexcept override;
|
|
78
|
+
|
|
79
|
+
void AddRequestBodyHandler(std::shared_ptr<IRequestBodyHandler> requestBodyHandler) noexcept override;
|
|
80
|
+
|
|
81
|
+
void AddResponseHandler(std::shared_ptr<IResponseHandler> responseHandler) noexcept override;
|
|
82
|
+
|
|
83
|
+
#pragma endregion IHttpModuleProxy
|
|
65
84
|
};
|
|
66
85
|
|
|
67
86
|
} // namespace Microsoft::React::Networking
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
#include "IHttpResource.h"
|
|
7
7
|
|
|
8
|
+
// Folly
|
|
9
|
+
#include <folly/dynamic.h>
|
|
10
|
+
|
|
8
11
|
// Windows API
|
|
9
12
|
#include <winrt/Windows.Web.Http.h>
|
|
10
13
|
|
|
@@ -16,10 +19,10 @@ namespace Microsoft::React::Networking {
|
|
|
16
19
|
struct RequestArgs : public winrt::implements<RequestArgs, winrt::Windows::Foundation::IInspectable> {
|
|
17
20
|
int64_t RequestId;
|
|
18
21
|
IHttpResource::Headers Headers;
|
|
19
|
-
|
|
22
|
+
folly::dynamic Data;
|
|
20
23
|
bool IncrementalUpdates;
|
|
21
24
|
bool WithCredentials;
|
|
22
|
-
|
|
25
|
+
std::string ResponseType;
|
|
23
26
|
int64_t Timeout;
|
|
24
27
|
};
|
|
25
28
|
|
package/Shared/OInstance.cpp
CHANGED
|
@@ -67,14 +67,16 @@ using namespace facebook;
|
|
|
67
67
|
using namespace Microsoft::JSI;
|
|
68
68
|
|
|
69
69
|
using std::make_shared;
|
|
70
|
+
using winrt::Microsoft::ReactNative::ReactPropertyBagHelper;
|
|
70
71
|
|
|
71
72
|
namespace Microsoft::React {
|
|
72
73
|
|
|
73
|
-
/*extern*/ std::unique_ptr<facebook::xplat::module::CxxModule> CreateHttpModule(
|
|
74
|
+
/*extern*/ std::unique_ptr<facebook::xplat::module::CxxModule> CreateHttpModule(
|
|
75
|
+
winrt::Windows::Foundation::IInspectable const &inspectableProperties) noexcept {
|
|
74
76
|
if (GetRuntimeOptionBool("Http.UseMonolithicModule")) {
|
|
75
77
|
return std::make_unique<NetworkingModule>();
|
|
76
78
|
} else {
|
|
77
|
-
return std::make_unique<HttpModule>();
|
|
79
|
+
return std::make_unique<HttpModule>(inspectableProperties);
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -541,18 +543,21 @@ InstanceImpl::~InstanceImpl() {
|
|
|
541
543
|
std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules(
|
|
542
544
|
std::shared_ptr<MessageQueueThread> nativeQueue) {
|
|
543
545
|
std::vector<std::unique_ptr<NativeModule>> modules;
|
|
546
|
+
auto transitionalProps{ReactPropertyBagHelper::CreatePropertyBag()};
|
|
544
547
|
|
|
545
548
|
modules.push_back(std::make_unique<CxxNativeModule>(
|
|
546
549
|
m_innerInstance,
|
|
547
550
|
Microsoft::React::GetHttpModuleName(),
|
|
548
|
-
[nativeQueue]() -> std::unique_ptr<xplat::module::CxxModule> {
|
|
551
|
+
[nativeQueue, transitionalProps]() -> std::unique_ptr<xplat::module::CxxModule> {
|
|
552
|
+
return Microsoft::React::CreateHttpModule(transitionalProps);
|
|
553
|
+
},
|
|
549
554
|
nativeQueue));
|
|
550
555
|
|
|
551
556
|
modules.push_back(std::make_unique<CxxNativeModule>(
|
|
552
557
|
m_innerInstance,
|
|
553
558
|
Microsoft::React::GetWebSocketModuleName(),
|
|
554
|
-
[nativeQueue]() -> std::unique_ptr<xplat::module::CxxModule> {
|
|
555
|
-
return Microsoft::React::CreateWebSocketModule();
|
|
559
|
+
[nativeQueue, transitionalProps]() -> std::unique_ptr<xplat::module::CxxModule> {
|
|
560
|
+
return Microsoft::React::CreateWebSocketModule(transitionalProps);
|
|
556
561
|
},
|
|
557
562
|
nativeQueue));
|
|
558
563
|
|
|
@@ -614,6 +619,18 @@ std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules
|
|
|
614
619
|
[]() { return std::make_unique<StatusBarManagerModule>(); },
|
|
615
620
|
nativeQueue));
|
|
616
621
|
|
|
622
|
+
modules.push_back(std::make_unique<CxxNativeModule>(
|
|
623
|
+
m_innerInstance,
|
|
624
|
+
Microsoft::React::GetBlobModuleName(),
|
|
625
|
+
[transitionalProps]() { return Microsoft::React::CreateBlobModule(transitionalProps); },
|
|
626
|
+
nativeQueue));
|
|
627
|
+
|
|
628
|
+
modules.push_back(std::make_unique<CxxNativeModule>(
|
|
629
|
+
m_innerInstance,
|
|
630
|
+
Microsoft::React::GetFileReaderModuleName(),
|
|
631
|
+
[transitionalProps]() { return Microsoft::React::CreateFileReaderModule(transitionalProps); },
|
|
632
|
+
nativeQueue));
|
|
633
|
+
|
|
617
634
|
return modules;
|
|
618
635
|
}
|
|
619
636
|
|
package/Shared/OInstance.h
CHANGED
|
@@ -5,14 +5,18 @@
|
|
|
5
5
|
|
|
6
6
|
#pragma once
|
|
7
7
|
|
|
8
|
+
#include <ReactPropertyBag.h>
|
|
9
|
+
#include <TurboModuleManager.h>
|
|
10
|
+
#include "InstanceManager.h"
|
|
11
|
+
|
|
12
|
+
// React Native
|
|
13
|
+
#include <cxxreact/Instance.h>
|
|
14
|
+
|
|
15
|
+
// Standard Libriary
|
|
8
16
|
#include <memory>
|
|
9
17
|
#include <string>
|
|
10
18
|
#include <vector>
|
|
11
19
|
|
|
12
|
-
#include <TurboModuleManager.h>
|
|
13
|
-
#include <cxxreact/Instance.h>
|
|
14
|
-
#include "InstanceManager.h"
|
|
15
|
-
|
|
16
20
|
namespace facebook {
|
|
17
21
|
namespace react {
|
|
18
22
|
|
|
@@ -94,7 +94,7 @@ void __cdecl MicrosoftReactSetRuntimeOptionString(const char *name, const char *
|
|
|
94
94
|
g_runtimeOptionStrings.erase(name);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
bool __cdecl MicrosoftReactGetRuntimeOptionBool(const char *name) noexcept {
|
|
98
98
|
scoped_lock lock{g_runtimeOptionsMutex};
|
|
99
99
|
auto itr = g_runtimeOptionInts.find(name);
|
|
100
100
|
if (itr != g_runtimeOptionInts.end())
|
|
@@ -103,7 +103,7 @@ const bool __cdecl MicrosoftReactGetRuntimeOptionBool(const char *name) noexcept
|
|
|
103
103
|
return false;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
int32_t __cdecl MicrosoftReactGetRuntimeOptionInt(const char *name) noexcept {
|
|
107
107
|
scoped_lock lock{g_runtimeOptionsMutex};
|
|
108
108
|
auto itr = g_runtimeOptionInts.find(name);
|
|
109
109
|
if (itr != g_runtimeOptionInts.end())
|
|
@@ -112,7 +112,10 @@ const int32_t __cdecl MicrosoftReactGetRuntimeOptionInt(const char *name) noexce
|
|
|
112
112
|
return 0;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
void MicrosoftReactGetRuntimeOptionString(
|
|
115
|
+
void __cdecl MicrosoftReactGetRuntimeOptionString(
|
|
116
|
+
const char *name,
|
|
117
|
+
MicrosoftReactGetStringCallback callBack,
|
|
118
|
+
void *state) {
|
|
116
119
|
scoped_lock lock{g_runtimeOptionsMutex};
|
|
117
120
|
auto itr = g_runtimeOptionStrings.find(name);
|
|
118
121
|
if (itr != g_runtimeOptionStrings.cend()) {
|
package/Shared/RuntimeOptions.h
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
#pragma once
|
|
5
5
|
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
extern "C" {
|
|
8
|
+
#endif
|
|
9
|
+
|
|
6
10
|
/// <summary>
|
|
7
11
|
/// Sets a global boolean value identified by an arbitrary string.
|
|
8
12
|
/// </summary>
|
|
@@ -26,14 +30,14 @@ void __cdecl MicrosoftReactSetRuntimeOptionString(const char *name, const char *
|
|
|
26
30
|
/// </summary>
|
|
27
31
|
/// <param name="name">Global boolean key</param>
|
|
28
32
|
/// <returns>Value stored for the given key, or false if the entry doesn't exist (default)</returns>
|
|
29
|
-
|
|
33
|
+
bool __cdecl MicrosoftReactGetRuntimeOptionBool(const char *name) noexcept;
|
|
30
34
|
|
|
31
35
|
/// <summary>
|
|
32
36
|
/// Retrieves a global boolean value for the given key.
|
|
33
37
|
/// </summary>
|
|
34
38
|
/// <param name="name">Global key</param>
|
|
35
39
|
/// <returns>Value stored for the given key, or 0 if the entry doesn't exist (default)</returns>
|
|
36
|
-
|
|
40
|
+
int32_t __cdecl MicrosoftReactGetRuntimeOptionInt(const char *name) noexcept;
|
|
37
41
|
|
|
38
42
|
/// <param name="buffer">String contents. nullptr if none found</param>
|
|
39
43
|
/// <param name="length">String length. 0 if none found</param>
|
|
@@ -46,4 +50,11 @@ typedef void(__cdecl *MicrosoftReactGetStringCallback)(const char *buffer, size_
|
|
|
46
50
|
/// <param name="name">Global key</param>
|
|
47
51
|
/// <param name="callBack">Handler used to access the obtained string</param>
|
|
48
52
|
/// <param name="state">Arbitrary data to pass on to or retrieve from callBack</param>
|
|
49
|
-
void MicrosoftReactGetRuntimeOptionString(
|
|
53
|
+
void __cdecl MicrosoftReactGetRuntimeOptionString(
|
|
54
|
+
const char *name,
|
|
55
|
+
MicrosoftReactGetStringCallback callBack,
|
|
56
|
+
void *state);
|
|
57
|
+
|
|
58
|
+
#ifdef __cplusplus
|
|
59
|
+
}
|
|
60
|
+
#endif
|
package/Shared/Shared.vcxitems
CHANGED
|
@@ -44,7 +44,10 @@
|
|
|
44
44
|
<ClCompile Include="$(MSBuildThisFileDirectory)Modules\AsyncStorageModuleWin32.cpp">
|
|
45
45
|
<ExcludedFromBuild Condition="'$(ApplicationType)' == ''">true</ExcludedFromBuild>
|
|
46
46
|
</ClCompile>
|
|
47
|
+
<ClCompile Include="$(MSBuildThisFileDirectory)Modules\BlobModule.cpp" />
|
|
48
|
+
<ClCompile Include="$(MSBuildThisFileDirectory)Modules\CxxModuleUtilities.cpp" />
|
|
47
49
|
<ClCompile Include="$(MSBuildThisFileDirectory)Modules\ExceptionsManagerModule.cpp" />
|
|
50
|
+
<ClCompile Include="$(MSBuildThisFileDirectory)Modules\FileReaderModule.cpp" />
|
|
48
51
|
<ClCompile Include="$(MSBuildThisFileDirectory)Modules\HttpModule.cpp" />
|
|
49
52
|
<ClCompile Include="$(MSBuildThisFileDirectory)Modules\I18nModule.cpp" />
|
|
50
53
|
<ClCompile Include="$(MSBuildThisFileDirectory)Modules\NetworkingModule.cpp" />
|
|
@@ -87,6 +90,16 @@
|
|
|
87
90
|
<ClInclude Include="$(MSBuildThisFileDirectory)JSI\NapiJsiV8RuntimeHolder.h" />
|
|
88
91
|
<ClInclude Include="$(MSBuildThisFileDirectory)JSI\RuntimeHolder.h" />
|
|
89
92
|
<ClInclude Include="$(MSBuildThisFileDirectory)JSI\ScriptStore.h" />
|
|
93
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\BlobModule.h" />
|
|
94
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\CxxModuleUtilities.h" />
|
|
95
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\FileReaderModule.h" />
|
|
96
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\IBlobPersistor.h" />
|
|
97
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\IHttpModuleProxy.h" />
|
|
98
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\IRequestBodyHandler.h" />
|
|
99
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\IResponseHandler.h" />
|
|
100
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\IUriHandler.h" />
|
|
101
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\IWebSocketModuleContentHandler.h" />
|
|
102
|
+
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\IWebSocketModuleProxy.h" />
|
|
90
103
|
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\HttpModule.h" />
|
|
91
104
|
<ClInclude Include="$(MSBuildThisFileDirectory)Modules\NetworkingModule.h" />
|
|
92
105
|
<ClInclude Include="$(MSBuildThisFileDirectory)Networking\IHttpResource.h" />
|