@@ -137,9 +137,11 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
137
137
138
138
139
139
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 )
141
143
{
142
- defaultConfigObject.timeoutIntervalForRequest = [[options valueForKey: @" timeout" ] floatValue ] /1000 ;
144
+ defaultConfigObject.timeoutIntervalForRequest = timeout/1000 ;
143
145
}
144
146
defaultConfigObject.HTTPMaximumConnectionsPerHost = 10 ;
145
147
session = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: taskQueue];
@@ -196,21 +198,30 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
196
198
197
199
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
198
200
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode ];
201
+ NSString * respType = @" " ;
199
202
respStatus = statusCode;
200
203
if ([response respondsToSelector: @selector (allHeaderFields )])
201
204
{
202
205
NSDictionary *headers = [httpResponse allHeaderFields ];
203
- NSString * respType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases: @" content-type "
206
+ NSString * respCType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases: @" Content-Type "
204
207
fromHeaders: headers]
205
208
lowercaseString ];
206
- if ([headers valueForKey: @" Content-Type " ] != nil )
209
+ if (respCType != nil )
207
210
{
208
211
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
+ }
209
220
// If extra blob content type is not empty, check if response type matches
210
- if ( extraBlobCTypes != nil ) {
221
+ else if ( extraBlobCTypes != nil ) {
211
222
for (NSString * substr in extraBlobCTypes)
212
223
{
213
- if ([[respType lowercaseString ] containsString: [substr lowercaseString ]])
224
+ if ([respCType containsString: [substr lowercaseString ]])
214
225
{
215
226
respType = @" blob" ;
216
227
respFile = YES ;
@@ -219,14 +230,6 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
219
230
}
220
231
}
221
232
}
222
- else if ([respType containsString: @" text/" ])
223
- {
224
- respType = @" text" ;
225
- }
226
- else if ([respType containsString: @" application/json" ])
227
- {
228
- respType = @" json" ;
229
- }
230
233
else
231
234
{
232
235
respType = @" blob" ;
@@ -238,7 +241,7 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
238
241
}
239
242
}
240
243
else
241
- respType = @" " ;
244
+ respType = @" text " ;
242
245
respInfo = @{
243
246
@" taskId" : taskId,
244
247
@" state" : @" 2" ,
@@ -255,6 +258,8 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
255
258
headers = nil ;
256
259
respInfo = nil ;
257
260
}
261
+ else
262
+ NSLog (@" oops" );
258
263
259
264
if (respFile == YES )
260
265
{
@@ -319,20 +324,20 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCom
319
324
self.error = error;
320
325
NSString * errMsg = [NSNull null ];
321
326
NSString * respStr = [NSNull null ];
322
- NSString * respType = [respInfo valueForKey: @" respType" ];
323
327
324
328
[[UIApplication sharedApplication ] setNetworkActivityIndicatorVisible: NO ];
325
- if (error != nil )
326
- {
327
- errMsg = [error localizedDescription ];
328
- }
329
+
329
330
if (respInfo == nil )
330
331
{
331
332
respInfo = [NSNull null ];
332
333
}
333
334
335
+ if (error != nil )
336
+ {
337
+ errMsg = [error localizedDescription ];
338
+ }
334
339
// Fix #72 response with status code 200 ~ 299 considered as success
335
- if (respStatus> 299 || respStatus < 200 )
340
+ else if (respStatus> 299 || respStatus < 200 )
336
341
{
337
342
errMsg = [NSString stringWithFormat: @" Request failed, status %d " , respStatus];
338
343
}
0 commit comments