@@ -137,9 +137,11 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
137137
138138
139139 NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration ];
140- if ([options valueForKey: @" timeout" ] != nil )
140+ float timeout = [options valueForKey: @" timeout" ] == nil ? -1 : [[options valueForKey: @" timeout" ] floatValue ];
141+ NSLog (@" timeout = %f " ,timeout);
142+ if (timeout > 0 )
141143 {
142- defaultConfigObject.timeoutIntervalForRequest = [[options valueForKey: @" timeout" ] floatValue ] /1000 ;
144+ defaultConfigObject.timeoutIntervalForRequest = timeout/1000 ;
143145 }
144146 defaultConfigObject.HTTPMaximumConnectionsPerHost = 10 ;
145147 session = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: taskQueue];
@@ -196,21 +198,30 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
196198
197199 NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
198200 NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode ];
201+ NSString * respType = @" " ;
199202 respStatus = statusCode;
200203 if ([response respondsToSelector: @selector (allHeaderFields )])
201204 {
202205 NSDictionary *headers = [httpResponse allHeaderFields ];
203- NSString * respType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases: @" content-type "
206+ NSString * respCType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases: @" Content-Type "
204207 fromHeaders: headers]
205208 lowercaseString ];
206- if ([headers valueForKey: @" Content-Type " ] != nil )
209+ if (respCType != nil )
207210 {
208211 NSArray * extraBlobCTypes = [options objectForKey: CONFIG_EXTRA_BLOB_CTYPE];
212+ if ([respCType containsString: @" text/" ])
213+ {
214+ respType = @" text" ;
215+ }
216+ else if ([respCType containsString: @" application/json" ])
217+ {
218+ respType = @" json" ;
219+ }
209220 // If extra blob content type is not empty, check if response type matches
210- if ( extraBlobCTypes != nil ) {
221+ else if ( extraBlobCTypes != nil ) {
211222 for (NSString * substr in extraBlobCTypes)
212223 {
213- if ([[respType lowercaseString ] containsString: [substr lowercaseString ]])
224+ if ([respCType containsString: [substr lowercaseString ]])
214225 {
215226 respType = @" blob" ;
216227 respFile = YES ;
@@ -219,14 +230,6 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
219230 }
220231 }
221232 }
222- else if ([respType containsString: @" text/" ])
223- {
224- respType = @" text" ;
225- }
226- else if ([respType containsString: @" application/json" ])
227- {
228- respType = @" json" ;
229- }
230233 else
231234 {
232235 respType = @" blob" ;
@@ -238,7 +241,7 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
238241 }
239242 }
240243 else
241- respType = @" " ;
244+ respType = @" text " ;
242245 respInfo = @{
243246 @" taskId" : taskId,
244247 @" state" : @" 2" ,
@@ -255,6 +258,8 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
255258 headers = nil ;
256259 respInfo = nil ;
257260 }
261+ else
262+ NSLog (@" oops" );
258263
259264 if (respFile == YES )
260265 {
@@ -319,20 +324,20 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCom
319324 self.error = error;
320325 NSString * errMsg = [NSNull null ];
321326 NSString * respStr = [NSNull null ];
322- NSString * respType = [respInfo valueForKey: @" respType" ];
323327
324328 [[UIApplication sharedApplication ] setNetworkActivityIndicatorVisible: NO ];
325- if (error != nil )
326- {
327- errMsg = [error localizedDescription ];
328- }
329+
329330 if (respInfo == nil )
330331 {
331332 respInfo = [NSNull null ];
332333 }
333334
335+ if (error != nil )
336+ {
337+ errMsg = [error localizedDescription ];
338+ }
334339 // Fix #72 response with status code 200 ~ 299 considered as success
335- if (respStatus> 299 || respStatus < 200 )
340+ else if (respStatus> 299 || respStatus < 200 )
336341 {
337342 errMsg = [NSString stringWithFormat: @" Request failed, status %d " , respStatus];
338343 }
0 commit comments