Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions QiniuSDK/Http/QNSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
totalBytesSent:(int64_t)totalBytesSent
totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {

_progressBlock(totalBytesSent, totalBytesExpectedToSend);
if (_progressBlock) {
_progressBlock(totalBytesSent, totalBytesExpectedToSend);
}
if (_cancelBlock && _cancelBlock()) {
[_task cancel];
}
Expand All @@ -63,11 +65,12 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
@end

@interface QNSessionManager ()
@property (nonatomic) NSURLSession *httpManager;
@property UInt32 timeout;
@property (nonatomic, strong) QNUrlConvert converter;
@property bool noProxy;
@property (nonatomic,strong) NSDictionary *proxyDict;
@property (nonatomic) QNDnsManager *dns;
@property (nonatomic,strong) NSOperationQueue *delegateQueue;
@end

@implementation QNSessionManager
Expand All @@ -79,13 +82,11 @@ - (instancetype)initWithProxy:(NSDictionary *)proxyDict
if (self = [super init]) {
if (proxyDict != nil) {
_noProxy = NO;
_proxyDict = proxyDict;
} else {
_noProxy = YES;
}
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.connectionProxyDictionary = proxyDict;
_httpManager = [NSURLSession sessionWithConfiguration:configuration delegate:[[QNProgessDelegate alloc] initWithProgress:nil] delegateQueue:[NSOperationQueue currentQueue]];

_delegateQueue = [[NSOperationQueue alloc] init];
_timeout = timeout;
_converter = converter;
_dns = dns;
Expand All @@ -94,12 +95,6 @@ - (instancetype)initWithProxy:(NSDictionary *)proxyDict
return self;
}

- (void)dealloc {
if (self.httpManager) {
[self.httpManager finishTasksAndInvalidate];
}
}

- (instancetype)init {
return [self initWithProxy:nil timeout:60 urlConverter:nil dns:nil];
}
Expand Down Expand Up @@ -196,9 +191,14 @@ - (void)sendRequest2:(NSMutableURLRequest *)request
QNInternalProgressBlock progressBlock2 = ^(long long totalBytesWritten, long long totalBytesExpectedToWrite) {
progressBlock(totalBytesWritten, totalBytesExpectedToWrite);
};
__block QNProgessDelegate *delegate = (QNProgessDelegate *)_httpManager.delegate;
__block QNProgessDelegate *delegate = [[QNProgessDelegate alloc] initWithProgress:nil];
delegate.progressBlock = progressBlock2;
NSURLSessionUploadTask *uploadTask = [_httpManager uploadTaskWithRequest:request fromData:nil completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
if (_proxyDict) {
configuration.connectionProxyDictionary = _proxyDict;
}
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:delegate delegateQueue:_delegateQueue];
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request fromData:nil completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {

NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
double duration = [[NSDate date] timeIntervalSinceDate:startTime];
Expand All @@ -221,6 +221,7 @@ - (void)sendRequest2:(NSMutableURLRequest *)request
delegate.cancelBlock = nil;
delegate.progressBlock = nil;
completeBlock(info, resp);
[session finishTasksAndInvalidate];
}];
delegate.task = uploadTask;
delegate.cancelBlock = cancelBlock;
Expand Down