|
@@ -86,6 +86,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
|
86
|
86
|
NSInteger respStatus;
|
87
|
87
|
NSMutableArray * redirects;
|
88
|
88
|
ResponseFormat responseFormat;
|
|
89
|
+ BOOL * followRedirect;
|
89
|
90
|
}
|
90
|
91
|
|
91
|
92
|
@end
|
|
@@ -214,6 +215,7 @@ NSOperationQueue *taskQueue;
|
214
|
215
|
self.expectedBytes = 0;
|
215
|
216
|
self.receivedBytes = 0;
|
216
|
217
|
self.options = options;
|
|
218
|
+ followRedirect = [options valueForKey:@"followRedirect"] == nil ? YES : [[options valueForKey:@"followRedirect"] boolValue];
|
217
|
219
|
isIncrement = [options valueForKey:@"increment"] == nil ? NO : [[options valueForKey:@"increment"] boolValue];
|
218
|
220
|
redirects = [[NSMutableArray alloc] init];
|
219
|
221
|
if(req.URL != nil)
|
|
@@ -236,8 +238,15 @@ NSOperationQueue *taskQueue;
|
236
|
238
|
bodyLength = contentLength;
|
237
|
239
|
|
238
|
240
|
// the session trust any SSL certification
|
239
|
|
-// NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
|
240
|
|
- NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId];
|
|
241
|
+ NSURLSessionConfiguration *defaultConfigObject;
|
|
242
|
+ if(!followRedirect)
|
|
243
|
+ {
|
|
244
|
+ defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
|
|
245
|
+ }
|
|
246
|
+ else
|
|
247
|
+ {
|
|
248
|
+ NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:taskId];
|
|
249
|
+ }
|
241
|
250
|
|
242
|
251
|
// set request timeout
|
243
|
252
|
float timeout = [options valueForKey:@"timeout"] == nil ? -1 : [[options valueForKey:@"timeout"] floatValue];
|
|
@@ -275,7 +284,7 @@ NSOperationQueue *taskQueue;
|
275
|
284
|
respData = [[NSMutableData alloc] init];
|
276
|
285
|
respFile = NO;
|
277
|
286
|
}
|
278
|
|
-
|
|
287
|
+
|
279
|
288
|
__block NSURLSessionDataTask * task = [session dataTaskWithRequest:req];
|
280
|
289
|
[taskTable setObject:task forKey:taskId];
|
281
|
290
|
[task resume];
|
|
@@ -284,7 +293,7 @@ NSOperationQueue *taskQueue;
|
284
|
293
|
if([[options objectForKey:CONFIG_INDICATOR] boolValue] == YES)
|
285
|
294
|
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
|
286
|
295
|
__block UIApplication * app = [UIApplication sharedApplication];
|
287
|
|
-
|
|
296
|
+
|
288
|
297
|
// #115 handling task expired when application entering backgound for a long time
|
289
|
298
|
UIBackgroundTaskIdentifier tid = [app beginBackgroundTaskWithName:taskId expirationHandler:^{
|
290
|
299
|
NSLog([NSString stringWithFormat:@"session %@ expired", taskId ]);
|
|
@@ -292,7 +301,6 @@ NSOperationQueue *taskQueue;
|
292
|
301
|
[app endBackgroundTask:tid];
|
293
|
302
|
}];
|
294
|
303
|
|
295
|
|
-
|
296
|
304
|
}
|
297
|
305
|
|
298
|
306
|
// #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled
|
|
@@ -575,7 +583,7 @@ NSOperationQueue *taskQueue;
|
575
|
583
|
respStr = [respData base64EncodedStringWithOptions:0];
|
576
|
584
|
}
|
577
|
585
|
}
|
578
|
|
- }
|
|
586
|
+ }
|
579
|
587
|
|
580
|
588
|
|
581
|
589
|
callback(@[ errMsg, rnfbRespType, respStr]);
|
|
@@ -644,9 +652,17 @@ NSOperationQueue *taskQueue;
|
644
|
652
|
|
645
|
653
|
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler
|
646
|
654
|
{
|
647
|
|
- if(request.URL != nil)
|
648
|
|
- [redirects addObject:[request.URL absoluteString]];
|
649
|
|
- completionHandler(request);
|
|
655
|
+
|
|
656
|
+ if(followRedirect)
|
|
657
|
+ {
|
|
658
|
+ if(request.URL != nil)
|
|
659
|
+ [redirects addObject:[request.URL absoluteString]];
|
|
660
|
+ completionHandler(request);
|
|
661
|
+ }
|
|
662
|
+ else
|
|
663
|
+ {
|
|
664
|
+ completionHandler(nil);
|
|
665
|
+ }
|
650
|
666
|
}
|
651
|
667
|
|
652
|
668
|
@end
|