|
@@ -38,6 +38,8 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
|
38
|
38
|
@interface RNFetchBlobNetwork ()
|
39
|
39
|
{
|
40
|
40
|
BOOL * respFile;
|
|
41
|
+ BOOL isNewPart;
|
|
42
|
+ NSMutableData * partBuffer;
|
41
|
43
|
NSString * destPath;
|
42
|
44
|
NSOutputStream * writeStream;
|
43
|
45
|
long bodyLength;
|
|
@@ -222,6 +224,26 @@ NSOperationQueue *taskQueue;
|
222
|
224
|
{
|
223
|
225
|
NSDictionary *headers = [httpResponse allHeaderFields];
|
224
|
226
|
NSString * respCType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases:@"Content-Type" fromHeaders:headers] lowercaseString];
|
|
227
|
+ if(self.isServerPush == NO)
|
|
228
|
+ {
|
|
229
|
+ self.isServerPush = [[respCType lowercaseString] RNFBContainsString:@"multipart/x-mixed-replace;"];
|
|
230
|
+ }
|
|
231
|
+ if(self.isServerPush)
|
|
232
|
+ {
|
|
233
|
+ if(partBuffer != nil)
|
|
234
|
+ {
|
|
235
|
+ [self.bridge.eventDispatcher
|
|
236
|
+ sendDeviceEventWithName:EVENT_SERVER_PUSH
|
|
237
|
+ body:@{
|
|
238
|
+ @"taskId": taskId,
|
|
239
|
+ @"chunk": [partBuffer base64EncodedStringWithOptions:0],
|
|
240
|
+ }
|
|
241
|
+ ];
|
|
242
|
+ }
|
|
243
|
+ partBuffer = [[NSMutableData alloc] init];
|
|
244
|
+ completionHandler(NSURLSessionResponseAllow);
|
|
245
|
+ return;
|
|
246
|
+ }
|
225
|
247
|
if(respCType != nil)
|
226
|
248
|
{
|
227
|
249
|
NSArray * extraBlobCTypes = [options objectForKey:CONFIG_EXTRA_BLOB_CTYPE];
|
|
@@ -311,9 +333,17 @@ NSOperationQueue *taskQueue;
|
311
|
333
|
completionHandler(NSURLSessionResponseAllow);
|
312
|
334
|
}
|
313
|
335
|
|
|
336
|
+
|
314
|
337
|
// download progress handler
|
315
|
338
|
- (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
|
316
|
339
|
{
|
|
340
|
+ // For #143 handling multipart/x-mixed-replace response
|
|
341
|
+ if(self.isServerPush)
|
|
342
|
+ {
|
|
343
|
+ [partBuffer appendData:data];
|
|
344
|
+ return ;
|
|
345
|
+ }
|
|
346
|
+
|
317
|
347
|
NSNumber * received = [NSNumber numberWithLong:[data length]];
|
318
|
348
|
receivedBytes += [received longValue];
|
319
|
349
|
if(respFile == NO)
|
|
@@ -349,6 +379,7 @@ NSOperationQueue *taskQueue;
|
349
|
379
|
session = nil;
|
350
|
380
|
}
|
351
|
381
|
|
|
382
|
+
|
352
|
383
|
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
|
353
|
384
|
{
|
354
|
385
|
|