2626
2727@interface OPTLYHTTPRequestManager ()
2828
29+ - (NSURLSession *)session ;
30+
2931// Use this flag to deterine if we are running a unit test
3032// The flag is needed to track some values for unit test
3133@property (nonatomic , assign ) BOOL isRunningTest;
@@ -35,6 +37,13 @@ @interface OPTLYHTTPRequestManager()
3537
3638@implementation OPTLYHTTPRequestManager
3739
40+ - (NSURLSession *)session {
41+ NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration: [NSURLSessionConfiguration ephemeralSessionConfiguration ]];
42+ ephemeralSession.configuration .TLSMinimumSupportedProtocol = kTLSProtocol12 ;
43+
44+ return ephemeralSession;
45+ }
46+
3847# pragma mark - Object Initializers
3948
4049- (id )init
@@ -83,9 +92,9 @@ - (void)GETWithParameters:(NSDictionary *)parameters
8392 url : (NSURL *)url
8493 completionHandler : (OPTLYHTTPRequestManagerResponse)completion
8594{
86- NSURLSession *ephemeralSession = [ NSURLSession sessionWithConfiguration: [ NSURLSessionConfiguration ephemeralSessionConfiguration ]];
95+
8796 NSURL *urlWithParameterQuery = [self buildQueryURL: url withParameters: parameters];
88- NSURLSessionDataTask *downloadTask = [ephemeralSession dataTaskWithURL: urlWithParameterQuery
97+ NSURLSessionDataTask *downloadTask = [self .session dataTaskWithURL: urlWithParameterQuery
8998 completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
9099 if (completion) {
91100 completion (data, response, error);
@@ -178,8 +187,7 @@ - (void)GETIfModifiedSince:(NSString *)lastModifiedDate
178187 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url];
179188 [request setValue: lastModifiedDate forHTTPHeaderField: @" If-Modified-Since" ];
180189
181- NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration: [NSURLSessionConfiguration ephemeralSessionConfiguration ]];
182- NSURLSessionDataTask *dataTask = [ephemeralSession dataTaskWithRequest: request completionHandler: ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
190+ NSURLSessionDataTask *dataTask = [self .session dataTaskWithRequest: request completionHandler: ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
183191 if (completion) {
184192 completion (data, response, error);
185193 }
@@ -272,7 +280,6 @@ - (void)POSTWithParameters:(NSDictionary *)parameters
272280 url : (NSURL *)url
273281 completionHandler : (OPTLYHTTPRequestManagerResponse)completion
274282{
275- NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration: [NSURLSessionConfiguration ephemeralSessionConfiguration ]];
276283 NSMutableURLRequest *request = [[NSMutableURLRequest alloc ] initWithURL: url];
277284 [request setHTTPMethod: kHTTPRequestMethodPost ];
278285
@@ -288,7 +295,7 @@ - (void)POSTWithParameters:(NSDictionary *)parameters
288295
289296 [request addValue: kHTTPHeaderFieldValueApplicationJSON forHTTPHeaderField: kHTTPHeaderFieldContentType ];
290297
291- NSURLSessionUploadTask *uploadTask = [ephemeralSession uploadTaskWithRequest: request
298+ NSURLSessionUploadTask *uploadTask = [self .session uploadTaskWithRequest: request
292299 fromData: data
293300 completionHandler: ^(NSData *data,NSURLResponse *response,NSError *error) {
294301 if (completion) {
0 commit comments