зеркало из https://github.com/nextcloud/talk-ios.git
70 строки
2.7 KiB
Objective-C
70 строки
2.7 KiB
Objective-C
/**
|
|
* @copyright Copyright (c) 2020 Ivan Sein <ivan@nextcloud.com>
|
|
*
|
|
* @author Ivan Sein <ivan@nextcloud.com>
|
|
*
|
|
* @license GNU GPL version 3 or any later version
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
#import "NCImageSessionManager.h"
|
|
|
|
#import "CCCertificate.h"
|
|
|
|
@implementation NCImageSessionManager
|
|
|
|
+ (NCImageSessionManager *)sharedInstance
|
|
{
|
|
static dispatch_once_t once;
|
|
static NCImageSessionManager *sharedInstance;
|
|
dispatch_once(&once, ^{
|
|
sharedInstance = [[self alloc] init];
|
|
});
|
|
return sharedInstance;
|
|
}
|
|
|
|
- (id)init
|
|
{
|
|
// Set ephemeralSessionConfiguration and just use AFAutoPurgingImageCache for caching images.
|
|
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
|
|
self = [super initWithSessionConfiguration:configuration];
|
|
if (self) {
|
|
_userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (iOS) Nextcloud-Talk v%@",
|
|
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
|
|
|
|
self.responseSerializer = [[AFImageResponseSerializer alloc] init];
|
|
self.requestSerializer = [[AFHTTPRequestSerializer alloc] init];
|
|
|
|
AFSecurityPolicy* policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
|
|
self.securityPolicy = policy;
|
|
|
|
self.responseSerializer.acceptableContentTypes = [self.responseSerializer.acceptableContentTypes setByAddingObject:@"image/jpg"];
|
|
[self.requestSerializer setValue:_userAgent forHTTPHeaderField:@"User-Agent"];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
|
|
{
|
|
if ([[CCCertificate sharedManager] checkTrustedChallenge:challenge]) {
|
|
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
|
|
} else {
|
|
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
|
|
}
|
|
}
|
|
|
|
@end
|