// // RNFetchBlobNetwork.m // RNFetchBlob // // Created by wkh237 on 2016/6/6. // Copyright © 2016 wkh237. All rights reserved. // #import "RCTConvert.h" #import "RCTLog.h" #import #import "RCTBridge.h" #import "RCTEventDispatcher.h" #import "RNFetchBlobFS.h" #import "RNFetchBlobNetwork.h" #import "RNFetchBlobConst.h" #import "RNFetchBlobReqBuilder.h" #import //////////////////////////////////////// // // HTTP request handler // //////////////////////////////////////// NSMutableDictionary * taskTable; @interface RNFetchBlobNetwork () { BOOL * respFile; NSString * destPath; NSOutputStream * writeStream; long bodyLength; NSMutableDictionary * respInfo; } @end @implementation RNFetchBlobNetwork NSOperationQueue *taskQueue; @synthesize taskId; @synthesize expectedBytes; @synthesize receivedBytes; @synthesize respData; @synthesize callback; @synthesize bridge; @synthesize options; @synthesize fileTaskCompletionHandler; @synthesize dataTaskCompletionHandler; @synthesize error; // constructor - (id)init { self = [super init]; if(taskQueue == nil) { taskQueue = [[NSOperationQueue alloc] init]; taskQueue.maxConcurrentOperationCount = 10; } if(taskTable == nil) { taskTable = [[NSMutableDictionary alloc] init]; } return self; } // removing case from headers + (NSMutableDictionary *) normalizeHeaders:(NSDictionary *)headers { NSMutableDictionary * mheaders = [[NSMutableDictionary alloc]init]; for(NSString * key in headers) { [mheaders setValue:[headers valueForKey:key] forKey:[key lowercaseString]]; } return mheaders; } - (NSString *)md5:(NSString *)input { const char* str = [input UTF8String]; unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5(str, (CC_LONG)strlen(str), result); NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2]; for(int i = 0; i