| 
				
			 | 
			
			
				@@ -8,13 +8,10 @@ 
			 | 
		
	
		
			
			| 
				8
			 | 
			
				8
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				9
			 | 
			
				9
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				10
			 | 
			
				10
			 | 
			
			
				 #import <Foundation/Foundation.h> 
			 | 
		
	
		
			
			| 
				11
			 | 
			
				
			 | 
			
			
				-#import "RNFetchBlob.h" 
			 | 
		
	
		
			
			| 
				12
			 | 
			
				
			 | 
			
			
				-#import "RNFetchBlobFS.h" 
			 | 
		
	
		
			
			| 
				13
			 | 
			
				11
			 | 
			
			
				 #import "RNFetchBlobNetwork.h" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				12
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				+#import "RNFetchBlob.h" 
			 | 
		
	
		
			
			| 
				14
			 | 
			
				14
			 | 
			
			
				 #import "RNFetchBlobConst.h" 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				
			 | 
			
			
				-#import "RNFetchBlobReqBuilder.h" 
			 | 
		
	
		
			
			| 
				16
			 | 
			
				
			 | 
			
			
				-#import "IOS7Polyfill.h" 
			 | 
		
	
		
			
			| 
				17
			 | 
			
				
			 | 
			
			
				-#import <CommonCrypto/CommonDigest.h> 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				15
			 | 
			
			
				 #import "RNFetchBlobProgress.h" 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				16
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				20
			 | 
			
				17
			 | 
			
			
				 #if __has_include(<React/RCTAssert.h>) 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -35,132 +32,43 @@ 
			 | 
		
	
		
			
			| 
				35
			 | 
			
				32
			 | 
			
			
				 // 
			 | 
		
	
		
			
			| 
				36
			 | 
			
				33
			 | 
			
			
				 //////////////////////////////////////// 
			 | 
		
	
		
			
			| 
				37
			 | 
			
				34
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				38
			 | 
			
				
			 | 
			
			
				-NSMapTable * taskTable; 
			 | 
		
	
		
			
			| 
				39
			 | 
			
				35
			 | 
			
			
				 NSMapTable * expirationTable; 
			 | 
		
	
		
			
			| 
				40
			 | 
			
				
			 | 
			
			
				-NSMutableDictionary * progressTable; 
			 | 
		
	
		
			
			| 
				41
			 | 
			
				
			 | 
			
			
				-NSMutableDictionary * uploadProgressTable; 
			 | 
		
	
		
			
			| 
				42
			 | 
			
				36
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				43
			 | 
			
				37
			 | 
			
			
				 __attribute__((constructor)) 
			 | 
		
	
		
			
			| 
				44
			 | 
			
				38
			 | 
			
			
				 static void initialize_tables() { 
			 | 
		
	
		
			
			| 
				45
			 | 
			
				
			 | 
			
			
				-    if(expirationTable == nil) 
			 | 
		
	
		
			
			| 
				46
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+    if (expirationTable == nil) { 
			 | 
		
	
		
			
			| 
				47
			 | 
			
				40
			 | 
			
			
				         expirationTable = [[NSMapTable alloc] init]; 
			 | 
		
	
		
			
			| 
				48
			 | 
			
				41
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				49
			 | 
			
				
			 | 
			
			
				-    if(taskTable == nil) 
			 | 
		
	
		
			
			| 
				50
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				51
			 | 
			
				
			 | 
			
			
				-        taskTable = [[NSMapTable alloc] init]; 
			 | 
		
	
		
			
			| 
				52
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				53
			 | 
			
				
			 | 
			
			
				-    if(progressTable == nil) 
			 | 
		
	
		
			
			| 
				54
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				55
			 | 
			
				
			 | 
			
			
				-        progressTable = [[NSMutableDictionary alloc] init]; 
			 | 
		
	
		
			
			| 
				56
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				57
			 | 
			
				
			 | 
			
			
				-    if(uploadProgressTable == nil) 
			 | 
		
	
		
			
			| 
				58
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				59
			 | 
			
				
			 | 
			
			
				-        uploadProgressTable = [[NSMutableDictionary alloc] init]; 
			 | 
		
	
		
			
			| 
				60
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				61
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				62
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				63
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				64
			 | 
			
				
			 | 
			
			
				-typedef NS_ENUM(NSUInteger, ResponseFormat) { 
			 | 
		
	
		
			
			| 
				65
			 | 
			
				
			 | 
			
			
				-    UTF8, 
			 | 
		
	
		
			
			| 
				66
			 | 
			
				
			 | 
			
			
				-    BASE64, 
			 | 
		
	
		
			
			| 
				67
			 | 
			
				
			 | 
			
			
				-    AUTO 
			 | 
		
	
		
			
			| 
				68
			 | 
			
				
			 | 
			
			
				-}; 
			 | 
		
	
		
			
			| 
				69
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				70
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				71
			 | 
			
				
			 | 
			
			
				-@interface RNFetchBlobNetwork () 
			 | 
		
	
		
			
			| 
				72
			 | 
			
				
			 | 
			
			
				-{ 
			 | 
		
	
		
			
			| 
				73
			 | 
			
				
			 | 
			
			
				-    BOOL * respFile; 
			 | 
		
	
		
			
			| 
				74
			 | 
			
				
			 | 
			
			
				-    BOOL isNewPart; 
			 | 
		
	
		
			
			| 
				75
			 | 
			
				
			 | 
			
			
				-    BOOL * isIncrement; 
			 | 
		
	
		
			
			| 
				76
			 | 
			
				
			 | 
			
			
				-    NSMutableData * partBuffer; 
			 | 
		
	
		
			
			| 
				77
			 | 
			
				
			 | 
			
			
				-    NSString * destPath; 
			 | 
		
	
		
			
			| 
				78
			 | 
			
				
			 | 
			
			
				-    NSOutputStream * writeStream; 
			 | 
		
	
		
			
			| 
				79
			 | 
			
				
			 | 
			
			
				-    long bodyLength; 
			 | 
		
	
		
			
			| 
				80
			 | 
			
				
			 | 
			
			
				-    NSMutableDictionary * respInfo; 
			 | 
		
	
		
			
			| 
				81
			 | 
			
				
			 | 
			
			
				-    NSInteger respStatus; 
			 | 
		
	
		
			
			| 
				82
			 | 
			
				
			 | 
			
			
				-    NSMutableArray * redirects; 
			 | 
		
	
		
			
			| 
				83
			 | 
			
				
			 | 
			
			
				-    ResponseFormat responseFormat; 
			 | 
		
	
		
			
			| 
				84
			 | 
			
				
			 | 
			
			
				-    BOOL * followRedirect; 
			 | 
		
	
		
			
			| 
				85
			 | 
			
				
			 | 
			
			
				-    BOOL backgroundTask; 
			 | 
		
	
		
			
			| 
				86
			 | 
			
				42
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				87
			 | 
			
				43
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				88
			 | 
			
				
			 | 
			
			
				-@end 
			 | 
		
	
		
			
			| 
				89
			 | 
			
				44
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				90
			 | 
			
				45
			 | 
			
			
				 @implementation RNFetchBlobNetwork 
			 | 
		
	
		
			
			| 
				91
			 | 
			
				46
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				92
			 | 
			
				
			 | 
			
			
				-NSOperationQueue *taskQueue; 
			 | 
		
	
		
			
			| 
				93
			 | 
			
				
			 | 
			
			
				-@synthesize taskId; 
			 | 
		
	
		
			
			| 
				94
			 | 
			
				
			 | 
			
			
				-@synthesize expectedBytes; 
			 | 
		
	
		
			
			| 
				95
			 | 
			
				
			 | 
			
			
				-@synthesize receivedBytes; 
			 | 
		
	
		
			
			| 
				96
			 | 
			
				
			 | 
			
			
				-@synthesize respData; 
			 | 
		
	
		
			
			| 
				97
			 | 
			
				
			 | 
			
			
				-@synthesize callback; 
			 | 
		
	
		
			
			| 
				98
			 | 
			
				
			 | 
			
			
				-@synthesize bridge; 
			 | 
		
	
		
			
			| 
				99
			 | 
			
				
			 | 
			
			
				-@synthesize options; 
			 | 
		
	
		
			
			| 
				100
			 | 
			
				
			 | 
			
			
				-@synthesize fileTaskCompletionHandler; 
			 | 
		
	
		
			
			| 
				101
			 | 
			
				
			 | 
			
			
				-@synthesize dataTaskCompletionHandler; 
			 | 
		
	
		
			
			| 
				102
			 | 
			
				
			 | 
			
			
				-@synthesize error; 
			 | 
		
	
		
			
			| 
				103
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				104
			 | 
			
				47
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				105
			 | 
			
				
			 | 
			
			
				-// constructor 
			 | 
		
	
		
			
			| 
				106
			 | 
			
				48
			 | 
			
			
				 - (id)init { 
			 | 
		
	
		
			
			| 
				107
			 | 
			
				49
			 | 
			
			
				     self = [super init]; 
			 | 
		
	
		
			
			| 
				108
			 | 
			
				
			 | 
			
			
				-    @synchronized ([RNFetchBlobNetwork class]) { 
			 | 
		
	
		
			
			| 
				109
			 | 
			
				
			 | 
			
			
				-        if (taskQueue == nil) { 
			 | 
		
	
		
			
			| 
				110
			 | 
			
				
			 | 
			
			
				-            taskQueue = [[NSOperationQueue alloc] init]; 
			 | 
		
	
		
			
			| 
				111
			 | 
			
				
			 | 
			
			
				-            taskQueue.maxConcurrentOperationCount = 10; 
			 | 
		
	
		
			
			| 
				112
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+    if (self) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+        self.requestsTable = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableWeakMemory]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+         
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+        self.taskQueue = [[NSOperationQueue alloc] init]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+        self.taskQueue.qualityOfService = NSQualityOfServiceUtility; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+        self.taskQueue.maxConcurrentOperationCount = 10; 
			 | 
		
	
		
			
			| 
				113
			 | 
			
				56
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				114
			 | 
			
				58
			 | 
			
			
				     return self; 
			 | 
		
	
		
			
			| 
				115
			 | 
			
				59
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				116
			 | 
			
				60
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				117
			 | 
			
				
			 | 
			
			
				-+ (void) enableProgressReport:(NSString *) taskId config:(RNFetchBlobProgress *)config 
			 | 
		
	
		
			
			| 
				118
			 | 
			
				
			 | 
			
			
				-{ 
			 | 
		
	
		
			
			| 
				119
			 | 
			
				
			 | 
			
			
				-    @synchronized ([RNFetchBlobNetwork class]) { 
			 | 
		
	
		
			
			| 
				120
			 | 
			
				
			 | 
			
			
				-        if(progressTable == nil) 
			 | 
		
	
		
			
			| 
				121
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				122
			 | 
			
				
			 | 
			
			
				-            progressTable = [[NSMutableDictionary alloc] init]; 
			 | 
		
	
		
			
			| 
				123
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				124
			 | 
			
				
			 | 
			
			
				-        [progressTable setValue:config forKey:taskId]; 
			 | 
		
	
		
			
			| 
				125
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				126
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				127
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				128
			 | 
			
				
			 | 
			
			
				-+ (void) enableUploadProgress:(NSString *) taskId config:(RNFetchBlobProgress *)config 
			 | 
		
	
		
			
			| 
				129
			 | 
			
				
			 | 
			
			
				-{ 
			 | 
		
	
		
			
			| 
				130
			 | 
			
				
			 | 
			
			
				-    @synchronized ([RNFetchBlobNetwork class]) { 
			 | 
		
	
		
			
			| 
				131
			 | 
			
				
			 | 
			
			
				-        if(uploadProgressTable == nil) 
			 | 
		
	
		
			
			| 
				132
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				133
			 | 
			
				
			 | 
			
			
				-            uploadProgressTable = [[NSMutableDictionary alloc] init]; 
			 | 
		
	
		
			
			| 
				134
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				135
			 | 
			
				
			 | 
			
			
				-        [uploadProgressTable setValue:config forKey:taskId]; 
			 | 
		
	
		
			
			| 
				136
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				137
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				138
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				139
			 | 
			
				
			 | 
			
			
				-// removing case from headers 
			 | 
		
	
		
			
			| 
				140
			 | 
			
				
			 | 
			
			
				-+ (NSMutableDictionary *) normalizeHeaders:(NSDictionary *)headers 
			 | 
		
	
		
			
			| 
				141
			 | 
			
				
			 | 
			
			
				-{ 
			 | 
		
	
		
			
			| 
				142
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				143
			 | 
			
				
			 | 
			
			
				-    NSMutableDictionary * mheaders = [[NSMutableDictionary alloc]init]; 
			 | 
		
	
		
			
			| 
				144
			 | 
			
				
			 | 
			
			
				-    for(NSString * key in headers) { 
			 | 
		
	
		
			
			| 
				145
			 | 
			
				
			 | 
			
			
				-        [mheaders setValue:[headers valueForKey:key] forKey:[key lowercaseString]]; 
			 | 
		
	
		
			
			| 
				146
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				147
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				148
			 | 
			
				
			 | 
			
			
				-    return mheaders; 
			 | 
		
	
		
			
			| 
				149
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				150
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				151
			 | 
			
				
			 | 
			
			
				-- (NSString *)md5:(NSString *)input { 
			 | 
		
	
		
			
			| 
				152
			 | 
			
				
			 | 
			
			
				-    const char* str = [input UTF8String]; 
			 | 
		
	
		
			
			| 
				153
			 | 
			
				
			 | 
			
			
				-    unsigned char result[CC_MD5_DIGEST_LENGTH]; 
			 | 
		
	
		
			
			| 
				154
			 | 
			
				
			 | 
			
			
				-    CC_MD5(str, (CC_LONG)strlen(str), result); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				++ (RNFetchBlobNetwork* _Nullable)sharedInstance { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+    static id _sharedInstance = nil; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+    static dispatch_once_t onceToken; 
			 | 
		
	
		
			
			| 
				155
			 | 
			
				64
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				156
			 | 
			
				
			 | 
			
			
				-    NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2]; 
			 | 
		
	
		
			
			| 
				157
			 | 
			
				
			 | 
			
			
				-    for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) { 
			 | 
		
	
		
			
			| 
				158
			 | 
			
				
			 | 
			
			
				-        [ret appendFormat:@"%02x",result[i]]; 
			 | 
		
	
		
			
			| 
				159
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				160
			 | 
			
				
			 | 
			
			
				-    return ret; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				+    dispatch_once(&onceToken, ^{ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+        _sharedInstance = [[self alloc] init]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+    }); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				+    return _sharedInstance; 
			 | 
		
	
		
			
			| 
				161
			 | 
			
				70
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				162
			 | 
			
				71
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				163
			 | 
			
				
			 | 
			
			
				-// send HTTP request 
			 | 
		
	
		
			
			| 
				164
			 | 
			
				72
			 | 
			
			
				 - (void) sendRequest:(__weak NSDictionary  * _Nullable )options 
			 | 
		
	
		
			
			| 
				165
			 | 
			
				73
			 | 
			
			
				        contentLength:(long) contentLength 
			 | 
		
	
		
			
			| 
				166
			 | 
			
				74
			 | 
			
			
				               bridge:(RCTBridge * _Nullable)bridgeRef 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -168,475 +76,80 @@ NSOperationQueue *taskQueue; 
			 | 
		
	
		
			
			| 
				168
			 | 
			
				76
			 | 
			
			
				          withRequest:(__weak NSURLRequest * _Nullable)req 
			 | 
		
	
		
			
			| 
				169
			 | 
			
				77
			 | 
			
			
				             callback:(_Nullable RCTResponseSenderBlock) callback 
			 | 
		
	
		
			
			| 
				170
			 | 
			
				78
			 | 
			
			
				 { 
			 | 
		
	
		
			
			| 
				171
			 | 
			
				
			 | 
			
			
				-    self.taskId = taskId; 
			 | 
		
	
		
			
			| 
				172
			 | 
			
				
			 | 
			
			
				-    self.respData = [[NSMutableData alloc] initWithLength:0]; 
			 | 
		
	
		
			
			| 
				173
			 | 
			
				
			 | 
			
			
				-    self.callback = callback; 
			 | 
		
	
		
			
			| 
				174
			 | 
			
				
			 | 
			
			
				-    self.bridge = bridgeRef; 
			 | 
		
	
		
			
			| 
				175
			 | 
			
				
			 | 
			
			
				-    self.expectedBytes = 0; 
			 | 
		
	
		
			
			| 
				176
			 | 
			
				
			 | 
			
			
				-    self.receivedBytes = 0; 
			 | 
		
	
		
			
			| 
				177
			 | 
			
				
			 | 
			
			
				-    self.options = options; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+    RNFetchBlobRequest *request = [[RNFetchBlobRequest alloc] init]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				+    [request sendRequest:options 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+           contentLength:contentLength 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+                  bridge:bridgeRef 
			 | 
		
	
		
			
			| 
				
			 | 
			
				83
			 | 
			
			
				+                  taskId:taskId 
			 | 
		
	
		
			
			| 
				
			 | 
			
				84
			 | 
			
			
				+             withRequest:req 
			 | 
		
	
		
			
			| 
				
			 | 
			
				85
			 | 
			
			
				+      taskOperationQueue:self.taskQueue 
			 | 
		
	
		
			
			| 
				
			 | 
			
				86
			 | 
			
			
				+                callback:callback]; 
			 | 
		
	
		
			
			| 
				178
			 | 
			
				87
			 | 
			
			
				      
			 | 
		
	
		
			
			| 
				179
			 | 
			
				
			 | 
			
			
				-    backgroundTask = [options valueForKey:@"IOSBackgroundTask"] == nil ? NO : [[options valueForKey:@"IOSBackgroundTask"] boolValue]; 
			 | 
		
	
		
			
			| 
				180
			 | 
			
				
			 | 
			
			
				-    followRedirect = [options valueForKey:@"followRedirect"] == nil ? YES : [[options valueForKey:@"followRedirect"] boolValue]; 
			 | 
		
	
		
			
			| 
				181
			 | 
			
				
			 | 
			
			
				-    isIncrement = [options valueForKey:@"increment"] == nil ? NO : [[options valueForKey:@"increment"] boolValue]; 
			 | 
		
	
		
			
			| 
				182
			 | 
			
				
			 | 
			
			
				-    redirects = [[NSMutableArray alloc] init]; 
			 | 
		
	
		
			
			| 
				183
			 | 
			
				
			 | 
			
			
				-    if(req.URL != nil) 
			 | 
		
	
		
			
			| 
				184
			 | 
			
				
			 | 
			
			
				-        [redirects addObject:req.URL.absoluteString]; 
			 | 
		
	
		
			
			| 
				185
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				186
			 | 
			
				
			 | 
			
			
				-    // set response format 
			 | 
		
	
		
			
			| 
				187
			 | 
			
				
			 | 
			
			
				-    NSString * rnfbResp = [req.allHTTPHeaderFields valueForKey:@"RNFB-Response"]; 
			 | 
		
	
		
			
			| 
				188
			 | 
			
				
			 | 
			
			
				-    if([[rnfbResp lowercaseString] isEqualToString:@"base64"]) 
			 | 
		
	
		
			
			| 
				189
			 | 
			
				
			 | 
			
			
				-        responseFormat = BASE64; 
			 | 
		
	
		
			
			| 
				190
			 | 
			
				
			 | 
			
			
				-    else if([[rnfbResp lowercaseString] isEqualToString:@"utf8"]) 
			 | 
		
	
		
			
			| 
				191
			 | 
			
				
			 | 
			
			
				-        responseFormat = UTF8; 
			 | 
		
	
		
			
			| 
				192
			 | 
			
				
			 | 
			
			
				-    else 
			 | 
		
	
		
			
			| 
				193
			 | 
			
				
			 | 
			
			
				-        responseFormat = AUTO; 
			 | 
		
	
		
			
			| 
				194
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				195
			 | 
			
				
			 | 
			
			
				-    NSString * path = [self.options valueForKey:CONFIG_FILE_PATH]; 
			 | 
		
	
		
			
			| 
				196
			 | 
			
				
			 | 
			
			
				-    NSString * ext = [self.options valueForKey:CONFIG_FILE_EXT]; 
			 | 
		
	
		
			
			| 
				197
			 | 
			
				
			 | 
			
			
				-	NSString * key = [self.options valueForKey:CONFIG_KEY]; 
			 | 
		
	
		
			
			| 
				198
			 | 
			
				
			 | 
			
			
				-    __block NSURLSession * session; 
			 | 
		
	
		
			
			| 
				199
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				200
			 | 
			
				
			 | 
			
			
				-    bodyLength = contentLength; 
			 | 
		
	
		
			
			| 
				201
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				202
			 | 
			
				
			 | 
			
			
				-    // the session trust any SSL certification 
			 | 
		
	
		
			
			| 
				203
			 | 
			
				
			 | 
			
			
				-    NSURLSessionConfiguration *defaultConfigObject; 
			 | 
		
	
		
			
			| 
				204
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				205
			 | 
			
				
			 | 
			
			
				-    defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; 
			 | 
		
	
		
			
			| 
				206
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				207
			 | 
			
				
			 | 
			
			
				-    if(backgroundTask) 
			 | 
		
	
		
			
			| 
				208
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				209
			 | 
			
				
			 | 
			
			
				-        defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId]; 
			 | 
		
	
		
			
			| 
				210
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				211
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				212
			 | 
			
				
			 | 
			
			
				-    // set request timeout 
			 | 
		
	
		
			
			| 
				213
			 | 
			
				
			 | 
			
			
				-    float timeout = [options valueForKey:@"timeout"] == nil ? -1 : [[options valueForKey:@"timeout"] floatValue]; 
			 | 
		
	
		
			
			| 
				214
			 | 
			
				
			 | 
			
			
				-    if(timeout > 0) 
			 | 
		
	
		
			
			| 
				215
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				216
			 | 
			
				
			 | 
			
			
				-        defaultConfigObject.timeoutIntervalForRequest = timeout/1000; 
			 | 
		
	
		
			
			| 
				217
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				218
			 | 
			
				
			 | 
			
			
				-    defaultConfigObject.HTTPMaximumConnectionsPerHost = 10; 
			 | 
		
	
		
			
			| 
				219
			 | 
			
				
			 | 
			
			
				-    session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue]; 
			 | 
		
	
		
			
			| 
				220
			 | 
			
				
			 | 
			
			
				-    if(path != nil || [self.options valueForKey:CONFIG_USE_TEMP]!= nil) 
			 | 
		
	
		
			
			| 
				221
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				222
			 | 
			
				
			 | 
			
			
				-        respFile = YES; 
			 | 
		
	
		
			
			| 
				223
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				224
			 | 
			
				
			 | 
			
			
				-		NSString* cacheKey = taskId; 
			 | 
		
	
		
			
			| 
				225
			 | 
			
				
			 | 
			
			
				-		if (key != nil) { 
			 | 
		
	
		
			
			| 
				226
			 | 
			
				
			 | 
			
			
				-            cacheKey = [self md5:key]; 
			 | 
		
	
		
			
			| 
				227
			 | 
			
				
			 | 
			
			
				-			if (cacheKey == nil) { 
			 | 
		
	
		
			
			| 
				228
			 | 
			
				
			 | 
			
			
				-				cacheKey = taskId; 
			 | 
		
	
		
			
			| 
				229
			 | 
			
				
			 | 
			
			
				-			} 
			 | 
		
	
		
			
			| 
				230
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				231
			 | 
			
				
			 | 
			
			
				-			destPath = [RNFetchBlobFS getTempPath:cacheKey withExtension:[self.options valueForKey:CONFIG_FILE_EXT]]; 
			 | 
		
	
		
			
			| 
				232
			 | 
			
				
			 | 
			
			
				-            if ([[NSFileManager defaultManager] fileExistsAtPath:destPath]) { 
			 | 
		
	
		
			
			| 
				233
			 | 
			
				
			 | 
			
			
				-				callback(@[[NSNull null], RESP_TYPE_PATH, destPath]); 
			 | 
		
	
		
			
			| 
				234
			 | 
			
				
			 | 
			
			
				-                return; 
			 | 
		
	
		
			
			| 
				235
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				236
			 | 
			
				
			 | 
			
			
				-		} 
			 | 
		
	
		
			
			| 
				237
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				238
			 | 
			
				
			 | 
			
			
				-        if(path != nil) 
			 | 
		
	
		
			
			| 
				239
			 | 
			
				
			 | 
			
			
				-            destPath = path; 
			 | 
		
	
		
			
			| 
				240
			 | 
			
				
			 | 
			
			
				-        else 
			 | 
		
	
		
			
			| 
				241
			 | 
			
				
			 | 
			
			
				-            destPath = [RNFetchBlobFS getTempPath:cacheKey withExtension:[self.options valueForKey:CONFIG_FILE_EXT]]; 
			 | 
		
	
		
			
			| 
				242
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				243
			 | 
			
				
			 | 
			
			
				-    else 
			 | 
		
	
		
			
			| 
				244
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				245
			 | 
			
				
			 | 
			
			
				-        respData = [[NSMutableData alloc] init]; 
			 | 
		
	
		
			
			| 
				246
			 | 
			
				
			 | 
			
			
				-        respFile = NO; 
			 | 
		
	
		
			
			| 
				247
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				248
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				249
			 | 
			
				
			 | 
			
			
				-    __block NSURLSessionDataTask * task = [session dataTaskWithRequest:req]; 
			 | 
		
	
		
			
			| 
				250
			 | 
			
				
			 | 
			
			
				-    @synchronized ([RNFetchBlobNetwork class]){ 
			 | 
		
	
		
			
			| 
				251
			 | 
			
				
			 | 
			
			
				-        [taskTable setObject:task forKey:taskId]; 
			 | 
		
	
		
			
			| 
				252
			 | 
			
				
			 | 
			
			
				-        [task resume]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				88
			 | 
			
			
				+    @synchronized([RNFetchBlobNetwork class]) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				89
			 | 
			
			
				+        [self.requestsTable setObject:request forKey:taskId]; 
			 | 
		
	
		
			
			| 
				253
			 | 
			
				90
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				254
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				255
			 | 
			
				
			 | 
			
			
				-    // network status indicator 
			 | 
		
	
		
			
			| 
				256
			 | 
			
				
			 | 
			
			
				-    if([[options objectForKey:CONFIG_INDICATOR] boolValue] == YES) 
			 | 
		
	
		
			
			| 
				257
			 | 
			
				
			 | 
			
			
				-        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 
			 | 
		
	
		
			
			| 
				258
			 | 
			
				
			 | 
			
			
				-    __block UIApplication * app = [UIApplication sharedApplication]; 
			 | 
		
	
		
			
			| 
				259
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				260
			 | 
			
				91
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				261
			 | 
			
				92
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				262
			 | 
			
				
			 | 
			
			
				-// #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled 
			 | 
		
	
		
			
			| 
				263
			 | 
			
				
			 | 
			
			
				-+ (void) emitExpiredTasks 
			 | 
		
	
		
			
			| 
				
			 | 
			
				93
			 | 
			
			
				+- (void) enableProgressReport:(NSString *) taskId config:(RNFetchBlobProgress *)config 
			 | 
		
	
		
			
			| 
				264
			 | 
			
				94
			 | 
			
			
				 { 
			 | 
		
	
		
			
			| 
				265
			 | 
			
				
			 | 
			
			
				-    @synchronized ([RNFetchBlobNetwork class]){ 
			 | 
		
	
		
			
			| 
				266
			 | 
			
				
			 | 
			
			
				-        NSEnumerator * emu =  [expirationTable keyEnumerator]; 
			 | 
		
	
		
			
			| 
				267
			 | 
			
				
			 | 
			
			
				-        NSString * key; 
			 | 
		
	
		
			
			| 
				268
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				269
			 | 
			
				
			 | 
			
			
				-        while((key = [emu nextObject])) 
			 | 
		
	
		
			
			| 
				270
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				271
			 | 
			
				
			 | 
			
			
				-            RCTBridge * bridge = [RNFetchBlob getRCTBridge]; 
			 | 
		
	
		
			
			| 
				272
			 | 
			
				
			 | 
			
			
				-            NSData * args = @{ @"taskId": key }; 
			 | 
		
	
		
			
			| 
				273
			 | 
			
				
			 | 
			
			
				-            [bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args]; 
			 | 
		
	
		
			
			| 
				274
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				275
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				276
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				277
			 | 
			
				
			 | 
			
			
				-        // clear expired task entries 
			 | 
		
	
		
			
			| 
				278
			 | 
			
				
			 | 
			
			
				-        [expirationTable removeAllObjects]; 
			 | 
		
	
		
			
			| 
				279
			 | 
			
				
			 | 
			
			
				-        expirationTable = [[NSMapTable alloc] init]; 
			 | 
		
	
		
			
			| 
				280
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				281
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				282
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				283
			 | 
			
				
			 | 
			
			
				-//////////////////////////////////////// 
			 | 
		
	
		
			
			| 
				284
			 | 
			
				
			 | 
			
			
				-// 
			 | 
		
	
		
			
			| 
				285
			 | 
			
				
			 | 
			
			
				-//  NSURLSession delegates 
			 | 
		
	
		
			
			| 
				286
			 | 
			
				
			 | 
			
			
				-// 
			 | 
		
	
		
			
			| 
				287
			 | 
			
				
			 | 
			
			
				-//////////////////////////////////////// 
			 | 
		
	
		
			
			| 
				288
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				289
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				290
			 | 
			
				
			 | 
			
			
				-#pragma mark NSURLSession delegate methods 
			 | 
		
	
		
			
			| 
				291
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				292
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				293
			 | 
			
				
			 | 
			
			
				-#pragma mark - Received Response 
			 | 
		
	
		
			
			| 
				294
			 | 
			
				
			 | 
			
			
				-// set expected content length on response received 
			 | 
		
	
		
			
			| 
				295
			 | 
			
				
			 | 
			
			
				-- (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler 
			 | 
		
	
		
			
			| 
				296
			 | 
			
				
			 | 
			
			
				-{ 
			 | 
		
	
		
			
			| 
				297
			 | 
			
				
			 | 
			
			
				-    expectedBytes = [response expectedContentLength]; 
			 | 
		
	
		
			
			| 
				298
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				299
			 | 
			
				
			 | 
			
			
				-    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response; 
			 | 
		
	
		
			
			| 
				300
			 | 
			
				
			 | 
			
			
				-    NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode]; 
			 | 
		
	
		
			
			| 
				301
			 | 
			
				
			 | 
			
			
				-    NSString * respType = @""; 
			 | 
		
	
		
			
			| 
				302
			 | 
			
				
			 | 
			
			
				-    respStatus = statusCode; 
			 | 
		
	
		
			
			| 
				303
			 | 
			
				
			 | 
			
			
				-    if ([response respondsToSelector:@selector(allHeaderFields)]) 
			 | 
		
	
		
			
			| 
				304
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				305
			 | 
			
				
			 | 
			
			
				-        NSDictionary *headers = [httpResponse allHeaderFields]; 
			 | 
		
	
		
			
			| 
				306
			 | 
			
				
			 | 
			
			
				-        NSString * respCType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases:@"Content-Type" fromHeaders:headers] lowercaseString]; 
			 | 
		
	
		
			
			| 
				307
			 | 
			
				
			 | 
			
			
				-        if(self.isServerPush == NO) 
			 | 
		
	
		
			
			| 
				308
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				309
			 | 
			
				
			 | 
			
			
				-            self.isServerPush = [[respCType lowercaseString] RNFBContainsString:@"multipart/x-mixed-replace;"]; 
			 | 
		
	
		
			
			| 
				310
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				311
			 | 
			
				
			 | 
			
			
				-        if(self.isServerPush) 
			 | 
		
	
		
			
			| 
				312
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				313
			 | 
			
				
			 | 
			
			
				-            if(partBuffer != nil) 
			 | 
		
	
		
			
			| 
				314
			 | 
			
				
			 | 
			
			
				-            { 
			 | 
		
	
		
			
			| 
				315
			 | 
			
				
			 | 
			
			
				-                [self.bridge.eventDispatcher 
			 | 
		
	
		
			
			| 
				316
			 | 
			
				
			 | 
			
			
				-                 sendDeviceEventWithName:EVENT_SERVER_PUSH 
			 | 
		
	
		
			
			| 
				317
			 | 
			
				
			 | 
			
			
				-                 body:@{ 
			 | 
		
	
		
			
			| 
				318
			 | 
			
				
			 | 
			
			
				-                        @"taskId": taskId, 
			 | 
		
	
		
			
			| 
				319
			 | 
			
				
			 | 
			
			
				-                        @"chunk": [partBuffer base64EncodedStringWithOptions:0], 
			 | 
		
	
		
			
			| 
				320
			 | 
			
				
			 | 
			
			
				-                        } 
			 | 
		
	
		
			
			| 
				321
			 | 
			
				
			 | 
			
			
				-                 ]; 
			 | 
		
	
		
			
			| 
				322
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				323
			 | 
			
				
			 | 
			
			
				-            partBuffer = [[NSMutableData alloc] init]; 
			 | 
		
	
		
			
			| 
				324
			 | 
			
				
			 | 
			
			
				-            completionHandler(NSURLSessionResponseAllow); 
			 | 
		
	
		
			
			| 
				325
			 | 
			
				
			 | 
			
			
				-            return; 
			 | 
		
	
		
			
			| 
				326
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				327
			 | 
			
				
			 | 
			
			
				-        if(respCType != nil) 
			 | 
		
	
		
			
			| 
				328
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				329
			 | 
			
				
			 | 
			
			
				-            NSArray * extraBlobCTypes = [options objectForKey:CONFIG_EXTRA_BLOB_CTYPE]; 
			 | 
		
	
		
			
			| 
				330
			 | 
			
				
			 | 
			
			
				-            if([respCType RNFBContainsString:@"text/"]) 
			 | 
		
	
		
			
			| 
				331
			 | 
			
				
			 | 
			
			
				-            { 
			 | 
		
	
		
			
			| 
				332
			 | 
			
				
			 | 
			
			
				-                respType = @"text"; 
			 | 
		
	
		
			
			| 
				333
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				334
			 | 
			
				
			 | 
			
			
				-            else if([respCType RNFBContainsString:@"application/json"]) 
			 | 
		
	
		
			
			| 
				335
			 | 
			
				
			 | 
			
			
				-            { 
			 | 
		
	
		
			
			| 
				336
			 | 
			
				
			 | 
			
			
				-                respType = @"json"; 
			 | 
		
	
		
			
			| 
				337
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				338
			 | 
			
				
			 | 
			
			
				-            // If extra blob content type is not empty, check if response type matches 
			 | 
		
	
		
			
			| 
				339
			 | 
			
				
			 | 
			
			
				-            else if( extraBlobCTypes !=  nil) { 
			 | 
		
	
		
			
			| 
				340
			 | 
			
				
			 | 
			
			
				-                for(NSString * substr in extraBlobCTypes) 
			 | 
		
	
		
			
			| 
				341
			 | 
			
				
			 | 
			
			
				-                { 
			 | 
		
	
		
			
			| 
				342
			 | 
			
				
			 | 
			
			
				-                    if([respCType RNFBContainsString:[substr lowercaseString]]) 
			 | 
		
	
		
			
			| 
				343
			 | 
			
				
			 | 
			
			
				-                    { 
			 | 
		
	
		
			
			| 
				344
			 | 
			
				
			 | 
			
			
				-                        respType = @"blob"; 
			 | 
		
	
		
			
			| 
				345
			 | 
			
				
			 | 
			
			
				-                        respFile = YES; 
			 | 
		
	
		
			
			| 
				346
			 | 
			
				
			 | 
			
			
				-                        destPath = [RNFetchBlobFS getTempPath:taskId withExtension:nil]; 
			 | 
		
	
		
			
			| 
				347
			 | 
			
				
			 | 
			
			
				-                        break; 
			 | 
		
	
		
			
			| 
				348
			 | 
			
				
			 | 
			
			
				-                    } 
			 | 
		
	
		
			
			| 
				349
			 | 
			
				
			 | 
			
			
				-                } 
			 | 
		
	
		
			
			| 
				350
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				351
			 | 
			
				
			 | 
			
			
				-            else 
			 | 
		
	
		
			
			| 
				352
			 | 
			
				
			 | 
			
			
				-            { 
			 | 
		
	
		
			
			| 
				353
			 | 
			
				
			 | 
			
			
				-                respType = @"blob"; 
			 | 
		
	
		
			
			| 
				354
			 | 
			
				
			 | 
			
			
				-                // for XMLHttpRequest, switch response data handling strategy automatically 
			 | 
		
	
		
			
			| 
				355
			 | 
			
				
			 | 
			
			
				-                if([options valueForKey:@"auto"] == YES) { 
			 | 
		
	
		
			
			| 
				356
			 | 
			
				
			 | 
			
			
				-                    respFile = YES; 
			 | 
		
	
		
			
			| 
				357
			 | 
			
				
			 | 
			
			
				-                    destPath = [RNFetchBlobFS getTempPath:taskId withExtension:@""]; 
			 | 
		
	
		
			
			| 
				358
			 | 
			
				
			 | 
			
			
				-                } 
			 | 
		
	
		
			
			| 
				359
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				360
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				361
			 | 
			
				
			 | 
			
			
				-        else 
			 | 
		
	
		
			
			| 
				362
			 | 
			
				
			 | 
			
			
				-            respType = @"text"; 
			 | 
		
	
		
			
			| 
				363
			 | 
			
				
			 | 
			
			
				-        respInfo = @{ 
			 | 
		
	
		
			
			| 
				364
			 | 
			
				
			 | 
			
			
				-                     @"taskId": taskId, 
			 | 
		
	
		
			
			| 
				365
			 | 
			
				
			 | 
			
			
				-                     @"state": @"2", 
			 | 
		
	
		
			
			| 
				366
			 | 
			
				
			 | 
			
			
				-                     @"headers": headers, 
			 | 
		
	
		
			
			| 
				367
			 | 
			
				
			 | 
			
			
				-                     @"redirects": redirects, 
			 | 
		
	
		
			
			| 
				368
			 | 
			
				
			 | 
			
			
				-                     @"respType" : respType, 
			 | 
		
	
		
			
			| 
				369
			 | 
			
				
			 | 
			
			
				-                     @"timeout" : @NO, 
			 | 
		
	
		
			
			| 
				370
			 | 
			
				
			 | 
			
			
				-                     @"status": [NSNumber numberWithInteger:statusCode] 
			 | 
		
	
		
			
			| 
				371
			 | 
			
				
			 | 
			
			
				-                    }; 
			 | 
		
	
		
			
			| 
				372
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				373
			 | 
			
				
			 | 
			
			
				-#pragma mark - handling cookies 
			 | 
		
	
		
			
			| 
				374
			 | 
			
				
			 | 
			
			
				-        // # 153 get cookies 
			 | 
		
	
		
			
			| 
				375
			 | 
			
				
			 | 
			
			
				-        if(response.URL != nil) 
			 | 
		
	
		
			
			| 
				376
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				377
			 | 
			
				
			 | 
			
			
				-            NSHTTPCookieStorage * cookieStore = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
			 | 
		
	
		
			
			| 
				378
			 | 
			
				
			 | 
			
			
				-            NSArray<NSHTTPCookie *> * cookies = [NSHTTPCookie cookiesWithResponseHeaderFields: headers forURL:response.URL]; 
			 | 
		
	
		
			
			| 
				379
			 | 
			
				
			 | 
			
			
				-            if(cookies != nil && [cookies count] > 0) { 
			 | 
		
	
		
			
			| 
				380
			 | 
			
				
			 | 
			
			
				-                [cookieStore setCookies:cookies forURL:response.URL mainDocumentURL:nil]; 
			 | 
		
	
		
			
			| 
				381
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				382
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				383
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				384
			 | 
			
				
			 | 
			
			
				-        [self.bridge.eventDispatcher 
			 | 
		
	
		
			
			| 
				385
			 | 
			
				
			 | 
			
			
				-         sendDeviceEventWithName: EVENT_STATE_CHANGE 
			 | 
		
	
		
			
			| 
				386
			 | 
			
				
			 | 
			
			
				-         body:respInfo 
			 | 
		
	
		
			
			| 
				387
			 | 
			
				
			 | 
			
			
				-        ]; 
			 | 
		
	
		
			
			| 
				388
			 | 
			
				
			 | 
			
			
				-        headers = nil; 
			 | 
		
	
		
			
			| 
				389
			 | 
			
				
			 | 
			
			
				-        respInfo = nil; 
			 | 
		
	
		
			
			| 
				390
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				391
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				392
			 | 
			
				
			 | 
			
			
				-    else 
			 | 
		
	
		
			
			| 
				393
			 | 
			
				
			 | 
			
			
				-        NSLog(@"oops"); 
			 | 
		
	
		
			
			| 
				394
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				395
			 | 
			
				
			 | 
			
			
				-    if(respFile == YES) 
			 | 
		
	
		
			
			| 
				396
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				397
			 | 
			
				
			 | 
			
			
				-        @try{ 
			 | 
		
	
		
			
			| 
				398
			 | 
			
				
			 | 
			
			
				-            NSFileManager * fm = [NSFileManager defaultManager]; 
			 | 
		
	
		
			
			| 
				399
			 | 
			
				
			 | 
			
			
				-            NSString * folder = [destPath stringByDeletingLastPathComponent]; 
			 | 
		
	
		
			
			| 
				400
			 | 
			
				
			 | 
			
			
				-            if(![fm fileExistsAtPath:folder]) 
			 | 
		
	
		
			
			| 
				401
			 | 
			
				
			 | 
			
			
				-            { 
			 | 
		
	
		
			
			| 
				402
			 | 
			
				
			 | 
			
			
				-                [fm createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:NULL error:nil]; 
			 | 
		
	
		
			
			| 
				403
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				404
			 | 
			
				
			 | 
			
			
				-            BOOL overwrite = [options valueForKey:@"overwrite"] == nil ? YES : [[options valueForKey:@"overwrite"] boolValue]; 
			 | 
		
	
		
			
			| 
				405
			 | 
			
				
			 | 
			
			
				-            BOOL appendToExistingFile = [destPath RNFBContainsString:@"?append=true"]; 
			 | 
		
	
		
			
			| 
				406
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				407
			 | 
			
				
			 | 
			
			
				-            appendToExistingFile = !overwrite; 
			 | 
		
	
		
			
			| 
				408
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				409
			 | 
			
				
			 | 
			
			
				-            // For solving #141 append response data if the file already exists 
			 | 
		
	
		
			
			| 
				410
			 | 
			
				
			 | 
			
			
				-            // base on PR#139 @kejinliang 
			 | 
		
	
		
			
			| 
				411
			 | 
			
				
			 | 
			
			
				-            if(appendToExistingFile) 
			 | 
		
	
		
			
			| 
				412
			 | 
			
				
			 | 
			
			
				-            { 
			 | 
		
	
		
			
			| 
				413
			 | 
			
				
			 | 
			
			
				-                destPath = [destPath stringByReplacingOccurrencesOfString:@"?append=true" withString:@""]; 
			 | 
		
	
		
			
			| 
				414
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				415
			 | 
			
				
			 | 
			
			
				-            if (![fm fileExistsAtPath:destPath]) 
			 | 
		
	
		
			
			| 
				416
			 | 
			
				
			 | 
			
			
				-            { 
			 | 
		
	
		
			
			| 
				417
			 | 
			
				
			 | 
			
			
				-                [fm createFileAtPath:destPath contents:[[NSData alloc] init] attributes:nil]; 
			 | 
		
	
		
			
			| 
				418
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				419
			 | 
			
				
			 | 
			
			
				-            writeStream = [[NSOutputStream alloc] initToFileAtPath:destPath append:appendToExistingFile]; 
			 | 
		
	
		
			
			| 
				420
			 | 
			
				
			 | 
			
			
				-            [writeStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; 
			 | 
		
	
		
			
			| 
				421
			 | 
			
				
			 | 
			
			
				-            [writeStream open]; 
			 | 
		
	
		
			
			| 
				422
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				423
			 | 
			
				
			 | 
			
			
				-        @catch(NSException * ex) 
			 | 
		
	
		
			
			| 
				424
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				425
			 | 
			
				
			 | 
			
			
				-            NSLog(@"write file error"); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				95
			 | 
			
			
				+    if (config) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				96
			 | 
			
			
				+        @synchronized ([RNFetchBlobNetwork class]) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				97
			 | 
			
			
				+            [self.requestsTable objectForKey:taskId].progressConfig = config; 
			 | 
		
	
		
			
			| 
				426
			 | 
			
				98
			 | 
			
			
				         } 
			 | 
		
	
		
			
			| 
				427
			 | 
			
				99
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				428
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				429
			 | 
			
				
			 | 
			
			
				-    completionHandler(NSURLSessionResponseAllow); 
			 | 
		
	
		
			
			| 
				430
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				431
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				432
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				433
			 | 
			
				
			 | 
			
			
				-// download progress handler 
			 | 
		
	
		
			
			| 
				434
			 | 
			
				
			 | 
			
			
				-- (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data 
			 | 
		
	
		
			
			| 
				435
			 | 
			
				
			 | 
			
			
				-{ 
			 | 
		
	
		
			
			| 
				436
			 | 
			
				
			 | 
			
			
				-    // For #143 handling multipart/x-mixed-replace response 
			 | 
		
	
		
			
			| 
				437
			 | 
			
				
			 | 
			
			
				-    if(self.isServerPush) 
			 | 
		
	
		
			
			| 
				438
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				439
			 | 
			
				
			 | 
			
			
				-        [partBuffer appendData:data]; 
			 | 
		
	
		
			
			| 
				440
			 | 
			
				
			 | 
			
			
				-        return ; 
			 | 
		
	
		
			
			| 
				441
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				442
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				443
			 | 
			
				
			 | 
			
			
				-    NSNumber * received = [NSNumber numberWithLong:[data length]]; 
			 | 
		
	
		
			
			| 
				444
			 | 
			
				
			 | 
			
			
				-    receivedBytes += [received longValue]; 
			 | 
		
	
		
			
			| 
				445
			 | 
			
				
			 | 
			
			
				-    NSString * chunkString = @""; 
			 | 
		
	
		
			
			| 
				446
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				447
			 | 
			
				
			 | 
			
			
				-    if(isIncrement == YES) 
			 | 
		
	
		
			
			| 
				448
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				449
			 | 
			
				
			 | 
			
			
				-        chunkString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
			 | 
		
	
		
			
			| 
				450
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				451
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				452
			 | 
			
				
			 | 
			
			
				-    if(respFile == NO) 
			 | 
		
	
		
			
			| 
				453
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				454
			 | 
			
				
			 | 
			
			
				-        [respData appendData:data]; 
			 | 
		
	
		
			
			| 
				455
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				456
			 | 
			
				
			 | 
			
			
				-    else 
			 | 
		
	
		
			
			| 
				457
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				458
			 | 
			
				
			 | 
			
			
				-        [writeStream write:[data bytes] maxLength:[data length]]; 
			 | 
		
	
		
			
			| 
				459
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				460
			 | 
			
				
			 | 
			
			
				-     
			 | 
		
	
		
			
			| 
				461
			 | 
			
				
			 | 
			
			
				-    if(expectedBytes == 0) 
			 | 
		
	
		
			
			| 
				462
			 | 
			
				
			 | 
			
			
				-        return; 
			 | 
		
	
		
			
			| 
				463
			 | 
			
				
			 | 
			
			
				-     
			 | 
		
	
		
			
			| 
				464
			 | 
			
				
			 | 
			
			
				-    RNFetchBlobProgress * pconfig; 
			 | 
		
	
		
			
			| 
				465
			 | 
			
				
			 | 
			
			
				-     
			 | 
		
	
		
			
			| 
				466
			 | 
			
				
			 | 
			
			
				-    @synchronized ([RNFetchBlobNetwork class]){ 
			 | 
		
	
		
			
			| 
				467
			 | 
			
				
			 | 
			
			
				-        pconfig = [progressTable valueForKey:taskId]; 
			 | 
		
	
		
			
			| 
				468
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				469
			 | 
			
				
			 | 
			
			
				-         
			 | 
		
	
		
			
			| 
				470
			 | 
			
				
			 | 
			
			
				-    NSNumber * now =[NSNumber numberWithFloat:((float)receivedBytes/(float)expectedBytes)]; 
			 | 
		
	
		
			
			| 
				471
			 | 
			
				
			 | 
			
			
				-     
			 | 
		
	
		
			
			| 
				472
			 | 
			
				
			 | 
			
			
				-    if(pconfig != nil && [pconfig shouldReport:now]) 
			 | 
		
	
		
			
			| 
				473
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				474
			 | 
			
				
			 | 
			
			
				-        [self.bridge.eventDispatcher 
			 | 
		
	
		
			
			| 
				475
			 | 
			
				
			 | 
			
			
				-         sendDeviceEventWithName:EVENT_PROGRESS 
			 | 
		
	
		
			
			| 
				476
			 | 
			
				
			 | 
			
			
				-         body:@{ 
			 | 
		
	
		
			
			| 
				477
			 | 
			
				
			 | 
			
			
				-                @"taskId": taskId, 
			 | 
		
	
		
			
			| 
				478
			 | 
			
				
			 | 
			
			
				-                @"written": [NSString stringWithFormat:@"%d", receivedBytes], 
			 | 
		
	
		
			
			| 
				479
			 | 
			
				
			 | 
			
			
				-                @"total": [NSString stringWithFormat:@"%d", expectedBytes], 
			 | 
		
	
		
			
			| 
				480
			 | 
			
				
			 | 
			
			
				-                @"chunk": chunkString 
			 | 
		
	
		
			
			| 
				481
			 | 
			
				
			 | 
			
			
				-                } 
			 | 
		
	
		
			
			| 
				482
			 | 
			
				
			 | 
			
			
				-         ]; 
			 | 
		
	
		
			
			| 
				483
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				484
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				485
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				486
			 | 
			
				
			 | 
			
			
				-- (void) URLSession:(NSURLSession *)session didBecomeInvalidWithError:(nullable NSError *)error 
			 | 
		
	
		
			
			| 
				487
			 | 
			
				
			 | 
			
			
				-{ 
			 | 
		
	
		
			
			| 
				488
			 | 
			
				
			 | 
			
			
				-    if([session isEqual:session]) 
			 | 
		
	
		
			
			| 
				489
			 | 
			
				
			 | 
			
			
				-        session = nil; 
			 | 
		
	
		
			
			| 
				490
			 | 
			
				100
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				491
			 | 
			
				101
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				492
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				493
			 | 
			
				
			 | 
			
			
				-- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error 
			 | 
		
	
		
			
			| 
				
			 | 
			
				102
			 | 
			
			
				+- (void) enableUploadProgress:(NSString *) taskId config:(RNFetchBlobProgress *)config 
			 | 
		
	
		
			
			| 
				494
			 | 
			
				103
			 | 
			
			
				 { 
			 | 
		
	
		
			
			| 
				495
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				496
			 | 
			
				
			 | 
			
			
				-    self.error = error; 
			 | 
		
	
		
			
			| 
				497
			 | 
			
				
			 | 
			
			
				-    NSString * errMsg = [NSNull null]; 
			 | 
		
	
		
			
			| 
				498
			 | 
			
				
			 | 
			
			
				-    NSString * respStr = [NSNull null]; 
			 | 
		
	
		
			
			| 
				499
			 | 
			
				
			 | 
			
			
				-    NSString * rnfbRespType = @""; 
			 | 
		
	
		
			
			| 
				500
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				501
			 | 
			
				
			 | 
			
			
				-    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 
			 | 
		
	
		
			
			| 
				502
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				503
			 | 
			
				
			 | 
			
			
				-    if(respInfo == nil) 
			 | 
		
	
		
			
			| 
				504
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				505
			 | 
			
				
			 | 
			
			
				-        respInfo = [NSNull null]; 
			 | 
		
	
		
			
			| 
				506
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				507
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				508
			 | 
			
				
			 | 
			
			
				-    if(error != nil) 
			 | 
		
	
		
			
			| 
				509
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				510
			 | 
			
				
			 | 
			
			
				-        errMsg = [error localizedDescription]; 
			 | 
		
	
		
			
			| 
				511
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				512
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				513
			 | 
			
				
			 | 
			
			
				-    if(respFile == YES) 
			 | 
		
	
		
			
			| 
				514
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				515
			 | 
			
				
			 | 
			
			
				-        [writeStream close]; 
			 | 
		
	
		
			
			| 
				516
			 | 
			
				
			 | 
			
			
				-        rnfbRespType = RESP_TYPE_PATH; 
			 | 
		
	
		
			
			| 
				517
			 | 
			
				
			 | 
			
			
				-        respStr = destPath; 
			 | 
		
	
		
			
			| 
				518
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				519
			 | 
			
				
			 | 
			
			
				-    // base64 response 
			 | 
		
	
		
			
			| 
				520
			 | 
			
				
			 | 
			
			
				-    else { 
			 | 
		
	
		
			
			| 
				521
			 | 
			
				
			 | 
			
			
				-        // #73 fix unicode data encoding issue : 
			 | 
		
	
		
			
			| 
				522
			 | 
			
				
			 | 
			
			
				-        // when response type is BASE64, we should first try to encode the response data to UTF8 format 
			 | 
		
	
		
			
			| 
				523
			 | 
			
				
			 | 
			
			
				-        // if it turns out not to be `nil` that means the response data contains valid UTF8 string, 
			 | 
		
	
		
			
			| 
				524
			 | 
			
				
			 | 
			
			
				-        // in order to properly encode the UTF8 string, use URL encoding before BASE64 encoding. 
			 | 
		
	
		
			
			| 
				525
			 | 
			
				
			 | 
			
			
				-        NSString * utf8 = [[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding]; 
			 | 
		
	
		
			
			| 
				526
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				527
			 | 
			
				
			 | 
			
			
				-        if(responseFormat == BASE64) 
			 | 
		
	
		
			
			| 
				528
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				529
			 | 
			
				
			 | 
			
			
				-            rnfbRespType = RESP_TYPE_BASE64; 
			 | 
		
	
		
			
			| 
				530
			 | 
			
				
			 | 
			
			
				-            respStr = [respData base64EncodedStringWithOptions:0]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				104
			 | 
			
			
				+    if (config) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				105
			 | 
			
			
				+        @synchronized ([RNFetchBlobNetwork class]) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				106
			 | 
			
			
				+            [self.requestsTable objectForKey:taskId].uploadProgressConfig = config; 
			 | 
		
	
		
			
			| 
				531
			 | 
			
				107
			 | 
			
			
				         } 
			 | 
		
	
		
			
			| 
				532
			 | 
			
				
			 | 
			
			
				-        else if (responseFormat == UTF8) 
			 | 
		
	
		
			
			| 
				533
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				534
			 | 
			
				
			 | 
			
			
				-            rnfbRespType = RESP_TYPE_UTF8; 
			 | 
		
	
		
			
			| 
				535
			 | 
			
				
			 | 
			
			
				-            respStr = utf8; 
			 | 
		
	
		
			
			| 
				536
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				537
			 | 
			
				
			 | 
			
			
				-        else 
			 | 
		
	
		
			
			| 
				538
			 | 
			
				
			 | 
			
			
				-        { 
			 | 
		
	
		
			
			| 
				539
			 | 
			
				
			 | 
			
			
				-            if(utf8 != nil) 
			 | 
		
	
		
			
			| 
				540
			 | 
			
				
			 | 
			
			
				-            { 
			 | 
		
	
		
			
			| 
				541
			 | 
			
				
			 | 
			
			
				-                rnfbRespType = RESP_TYPE_UTF8; 
			 | 
		
	
		
			
			| 
				542
			 | 
			
				
			 | 
			
			
				-                respStr = utf8; 
			 | 
		
	
		
			
			| 
				543
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				544
			 | 
			
				
			 | 
			
			
				-            else 
			 | 
		
	
		
			
			| 
				545
			 | 
			
				
			 | 
			
			
				-            { 
			 | 
		
	
		
			
			| 
				546
			 | 
			
				
			 | 
			
			
				-                rnfbRespType = RESP_TYPE_BASE64; 
			 | 
		
	
		
			
			| 
				547
			 | 
			
				
			 | 
			
			
				-                respStr = [respData base64EncodedStringWithOptions:0]; 
			 | 
		
	
		
			
			| 
				548
			 | 
			
				
			 | 
			
			
				-            } 
			 | 
		
	
		
			
			| 
				549
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				550
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				551
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				552
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				553
			 | 
			
				
			 | 
			
			
				-    callback(@[ errMsg, rnfbRespType, respStr]); 
			 | 
		
	
		
			
			| 
				554
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				555
			 | 
			
				
			 | 
			
			
				-    @synchronized ([RNFetchBlobNetwork class]) 
			 | 
		
	
		
			
			| 
				556
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				557
			 | 
			
				
			 | 
			
			
				-        if([taskTable objectForKey:taskId] == nil) 
			 | 
		
	
		
			
			| 
				558
			 | 
			
				
			 | 
			
			
				-            NSLog(@"object released by ARC."); 
			 | 
		
	
		
			
			| 
				559
			 | 
			
				
			 | 
			
			
				-        else 
			 | 
		
	
		
			
			| 
				560
			 | 
			
				
			 | 
			
			
				-            [taskTable removeObjectForKey:taskId]; 
			 | 
		
	
		
			
			| 
				561
			 | 
			
				
			 | 
			
			
				-        [uploadProgressTable removeObjectForKey:taskId]; 
			 | 
		
	
		
			
			| 
				562
			 | 
			
				
			 | 
			
			
				-        [progressTable removeObjectForKey:taskId]; 
			 | 
		
	
		
			
			| 
				563
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				564
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				565
			 | 
			
				
			 | 
			
			
				-    respData = nil; 
			 | 
		
	
		
			
			| 
				566
			 | 
			
				
			 | 
			
			
				-    receivedBytes = 0; 
			 | 
		
	
		
			
			| 
				567
			 | 
			
				
			 | 
			
			
				-    [session finishTasksAndInvalidate]; 
			 | 
		
	
		
			
			| 
				568
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				569
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				570
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				571
			 | 
			
				
			 | 
			
			
				-// upload progress handler 
			 | 
		
	
		
			
			| 
				572
			 | 
			
				
			 | 
			
			
				-- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesWritten totalBytesExpectedToSend:(int64_t)totalBytesExpectedToWrite 
			 | 
		
	
		
			
			| 
				573
			 | 
			
				
			 | 
			
			
				-{ 
			 | 
		
	
		
			
			| 
				574
			 | 
			
				
			 | 
			
			
				-    if(totalBytesExpectedToWrite == 0) 
			 | 
		
	
		
			
			| 
				575
			 | 
			
				
			 | 
			
			
				-        return; 
			 | 
		
	
		
			
			| 
				576
			 | 
			
				
			 | 
			
			
				-     
			 | 
		
	
		
			
			| 
				577
			 | 
			
				
			 | 
			
			
				-    RNFetchBlobProgress * pconfig; 
			 | 
		
	
		
			
			| 
				578
			 | 
			
				
			 | 
			
			
				-     
			 | 
		
	
		
			
			| 
				579
			 | 
			
				
			 | 
			
			
				-    @synchronized ([RNFetchBlobNetwork class]) { 
			 | 
		
	
		
			
			| 
				580
			 | 
			
				
			 | 
			
			
				-        pconfig = [uploadProgressTable valueForKey:taskId]; 
			 | 
		
	
		
			
			| 
				581
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				582
			 | 
			
				
			 | 
			
			
				-     
			 | 
		
	
		
			
			| 
				583
			 | 
			
				
			 | 
			
			
				-    NSNumber * now = [NSNumber numberWithFloat:((float)totalBytesWritten/(float)totalBytesExpectedToWrite)]; 
			 | 
		
	
		
			
			| 
				584
			 | 
			
				
			 | 
			
			
				-    if(pconfig != nil && [pconfig shouldReport:now]) { 
			 | 
		
	
		
			
			| 
				585
			 | 
			
				
			 | 
			
			
				-        [self.bridge.eventDispatcher 
			 | 
		
	
		
			
			| 
				586
			 | 
			
				
			 | 
			
			
				-         sendDeviceEventWithName:EVENT_PROGRESS_UPLOAD 
			 | 
		
	
		
			
			| 
				587
			 | 
			
				
			 | 
			
			
				-         body:@{ 
			 | 
		
	
		
			
			| 
				588
			 | 
			
				
			 | 
			
			
				-                @"taskId": taskId, 
			 | 
		
	
		
			
			| 
				589
			 | 
			
				
			 | 
			
			
				-                @"written": [NSString stringWithFormat:@"%ld", (long) totalBytesWritten], 
			 | 
		
	
		
			
			| 
				590
			 | 
			
				
			 | 
			
			
				-                @"total": [NSString stringWithFormat:@"%ld", (long) totalBytesExpectedToWrite] 
			 | 
		
	
		
			
			| 
				591
			 | 
			
				
			 | 
			
			
				-                } 
			 | 
		
	
		
			
			| 
				592
			 | 
			
				
			 | 
			
			
				-         ]; 
			 | 
		
	
		
			
			| 
				593
			 | 
			
				108
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				594
			 | 
			
				109
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				595
			 | 
			
				110
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				596
			 | 
			
				
			 | 
			
			
				-+ (void) cancelRequest:(NSString *)taskId 
			 | 
		
	
		
			
			| 
				
			 | 
			
				111
			 | 
			
			
				+- (void) cancelRequest:(NSString *)taskId 
			 | 
		
	
		
			
			| 
				597
			 | 
			
				112
			 | 
			
			
				 { 
			 | 
		
	
		
			
			| 
				598
			 | 
			
				113
			 | 
			
			
				     NSURLSessionDataTask * task; 
			 | 
		
	
		
			
			| 
				599
			 | 
			
				114
			 | 
			
			
				      
			 | 
		
	
		
			
			| 
				600
			 | 
			
				115
			 | 
			
			
				     @synchronized ([RNFetchBlobNetwork class]) { 
			 | 
		
	
		
			
			| 
				601
			 | 
			
				
			 | 
			
			
				-        task = [taskTable objectForKey:taskId]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				116
			 | 
			
			
				+        task = [self.requestsTable objectForKey:taskId].task; 
			 | 
		
	
		
			
			| 
				602
			 | 
			
				117
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				603
			 | 
			
				118
			 | 
			
			
				      
			 | 
		
	
		
			
			| 
				604
			 | 
			
				
			 | 
			
			
				-    if(task != nil && task.state == NSURLSessionTaskStateRunning) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				119
			 | 
			
			
				+    if (task && task.state == NSURLSessionTaskStateRunning) { 
			 | 
		
	
		
			
			| 
				605
			 | 
			
				120
			 | 
			
			
				         [task cancel]; 
			 | 
		
	
		
			
			| 
				606
			 | 
			
				
			 | 
			
			
				-} 
			 | 
		
	
		
			
			| 
				607
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				608
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				609
			 | 
			
				
			 | 
			
			
				-- (void) URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable credantial))completionHandler 
			 | 
		
	
		
			
			| 
				610
			 | 
			
				
			 | 
			
			
				-{ 
			 | 
		
	
		
			
			| 
				611
			 | 
			
				
			 | 
			
			
				-    BOOL trusty = [options valueForKey:CONFIG_TRUSTY]; 
			 | 
		
	
		
			
			| 
				612
			 | 
			
				
			 | 
			
			
				-    if(!trusty) 
			 | 
		
	
		
			
			| 
				613
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				614
			 | 
			
				
			 | 
			
			
				-        completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]); 
			 | 
		
	
		
			
			| 
				615
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				616
			 | 
			
				
			 | 
			
			
				-    else 
			 | 
		
	
		
			
			| 
				617
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				618
			 | 
			
				
			 | 
			
			
				-        completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]); 
			 | 
		
	
		
			
			| 
				619
			 | 
			
				121
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				620
			 | 
			
				122
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				621
			 | 
			
				123
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				622
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				623
			 | 
			
				
			 | 
			
			
				-- (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session 
			 | 
		
	
		
			
			| 
				
			 | 
			
				124
			 | 
			
			
				+// removing case from headers 
			 | 
		
	
		
			
			| 
				
			 | 
			
				125
			 | 
			
			
				++ (NSMutableDictionary *) normalizeHeaders:(NSDictionary *)headers 
			 | 
		
	
		
			
			| 
				624
			 | 
			
				126
			 | 
			
			
				 { 
			 | 
		
	
		
			
			| 
				625
			 | 
			
				
			 | 
			
			
				-    NSLog(@"sess done in background"); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				127
			 | 
			
			
				+    NSMutableDictionary * mheaders = [[NSMutableDictionary alloc]init]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				128
			 | 
			
			
				+    for (NSString * key in headers) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				129
			 | 
			
			
				+        [mheaders setValue:[headers valueForKey:key] forKey:[key lowercaseString]]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				130
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				131
			 | 
			
			
				+     
			 | 
		
	
		
			
			| 
				
			 | 
			
				132
			 | 
			
			
				+    return mheaders; 
			 | 
		
	
		
			
			| 
				626
			 | 
			
				133
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				627
			 | 
			
				134
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				628
			 | 
			
				
			 | 
			
			
				-- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler 
			 | 
		
	
		
			
			| 
				
			 | 
			
				135
			 | 
			
			
				+// #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled 
			 | 
		
	
		
			
			| 
				
			 | 
			
				136
			 | 
			
			
				++ (void) emitExpiredTasks 
			 | 
		
	
		
			
			| 
				629
			 | 
			
				137
			 | 
			
			
				 { 
			 | 
		
	
		
			
			| 
				630
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				631
			 | 
			
				
			 | 
			
			
				-    if(followRedirect) 
			 | 
		
	
		
			
			| 
				632
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				633
			 | 
			
				
			 | 
			
			
				-        if(request.URL != nil) 
			 | 
		
	
		
			
			| 
				634
			 | 
			
				
			 | 
			
			
				-            [redirects addObject:[request.URL absoluteString]]; 
			 | 
		
	
		
			
			| 
				635
			 | 
			
				
			 | 
			
			
				-        completionHandler(request); 
			 | 
		
	
		
			
			| 
				636
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				637
			 | 
			
				
			 | 
			
			
				-    else 
			 | 
		
	
		
			
			| 
				638
			 | 
			
				
			 | 
			
			
				-    { 
			 | 
		
	
		
			
			| 
				639
			 | 
			
				
			 | 
			
			
				-        completionHandler(nil); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				138
			 | 
			
			
				+    @synchronized ([RNFetchBlobNetwork class]){ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				139
			 | 
			
			
				+        NSEnumerator * emu =  [expirationTable keyEnumerator]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				140
			 | 
			
			
				+        NSString * key; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				141
			 | 
			
			
				+         
			 | 
		
	
		
			
			| 
				
			 | 
			
				142
			 | 
			
			
				+        while ((key = [emu nextObject])) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				143
			 | 
			
			
				+        { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				144
			 | 
			
			
				+            RCTBridge * bridge = [RNFetchBlob getRCTBridge]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				145
			 | 
			
			
				+            id args = @{ @"taskId": key }; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				146
			 | 
			
			
				+            [bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				147
			 | 
			
			
				+             
			 | 
		
	
		
			
			| 
				
			 | 
			
				148
			 | 
			
			
				+        } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				149
			 | 
			
			
				+         
			 | 
		
	
		
			
			| 
				
			 | 
			
				150
			 | 
			
			
				+        // clear expired task entries 
			 | 
		
	
		
			
			| 
				
			 | 
			
				151
			 | 
			
			
				+        [expirationTable removeAllObjects]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				152
			 | 
			
			
				+        expirationTable = [[NSMapTable alloc] init]; 
			 | 
		
	
		
			
			| 
				640
			 | 
			
				153
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				641
			 | 
			
				154
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				642
			 | 
			
				155
			 | 
			
			
				  
			 |