|
17 | 17 | #import <React/RCTUtils.h>
|
18 | 18 |
|
19 | 19 | #import <React/RCTHTTPRequestHandler.h>
|
| 20 | +#import <React/RCTFileRequestHandler.h> |
20 | 21 |
|
21 | 22 | #import "RCTNetworkPlugins.h"
|
22 | 23 |
|
@@ -154,6 +155,7 @@ @implementation RCTNetworking
|
154 | 155 | }
|
155 | 156 |
|
156 | 157 | @synthesize methodQueue = _methodQueue;
|
| 158 | +@synthesize moduleRegistry = _moduleRegistry; |
157 | 159 |
|
158 | 160 | RCT_EXPORT_MODULE()
|
159 | 161 |
|
@@ -188,6 +190,14 @@ - (void)invalidate
|
188 | 190 | _responseHandlers = nil;
|
189 | 191 | }
|
190 | 192 |
|
| 193 | +// TODO (T93136931) - Investigate why this is needed. This setter shouldn't be |
| 194 | +// necessary, since moduleRegistry is a property on RCTEventEmitter (which this |
| 195 | +// class inherits from). |
| 196 | +- (void)setModuleRegistry:(RCTModuleRegistry *)moduleRegistry |
| 197 | +{ |
| 198 | + _moduleRegistry = moduleRegistry; |
| 199 | +} |
| 200 | + |
191 | 201 | - (NSArray<NSString *> *)supportedEvents
|
192 | 202 | {
|
193 | 203 | return @[@"didCompleteNetworkResponse",
|
@@ -393,9 +403,9 @@ - (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(nullable NSDictionary
|
393 | 403 | }
|
394 | 404 | NSURLRequest *request = [RCTConvert NSURLRequest:query[@"uri"]];
|
395 | 405 | if (request) {
|
396 |
| - |
397 | 406 | __block RCTURLRequestCancellationBlock cancellationBlock = nil;
|
398 |
| - RCTNetworkTask *task = [self networkTaskWithRequest:request completionBlock:^(NSURLResponse *response, NSData *data, NSError *error) { |
| 407 | + id<RCTURLRequestHandler> handler = [self.moduleRegistry moduleForName:"FileRequestHandler"]; |
| 408 | + RCTNetworkTask *task = [self networkTaskWithRequest:request handler:handler completionBlock:^(NSURLResponse *response, NSData *data, NSError *error) { |
399 | 409 | dispatch_async(self->_methodQueue, ^{
|
400 | 410 | cancellationBlock = callback(error, data ? @{@"body": data, @"contentType": RCTNullIfNil(response.MIMEType)} : nil);
|
401 | 411 | });
|
@@ -676,6 +686,19 @@ - (RCTNetworkTask *)networkTaskWithRequest:(NSURLRequest *)request completionBlo
|
676 | 686 | return task;
|
677 | 687 | }
|
678 | 688 |
|
| 689 | +- (RCTNetworkTask *)networkTaskWithRequest:(NSURLRequest *)request handler:(id<RCTURLRequestHandler>)handler completionBlock:(RCTURLRequestCompletionBlock)completionBlock |
| 690 | +{ |
| 691 | + if (!handler) { |
| 692 | + // specified handler is nil, fall back to generic method |
| 693 | + return [self networkTaskWithRequest:request completionBlock:completionBlock]; |
| 694 | + } |
| 695 | + RCTNetworkTask *task = [[RCTNetworkTask alloc] initWithRequest:request |
| 696 | + handler:handler |
| 697 | + callbackQueue:_methodQueue]; |
| 698 | + task.completionBlock = completionBlock; |
| 699 | + return task; |
| 700 | +} |
| 701 | + |
679 | 702 | #pragma mark - JS API
|
680 | 703 |
|
681 | 704 | RCT_EXPORT_METHOD(sendRequest:(JS::NativeNetworkingIOS::SpecSendRequestQuery &)query
|
|
0 commit comments