26
26
27
27
@interface OPTLYHTTPRequestManager ()
28
28
29
+ - (NSURLSession *)session ;
30
+
29
31
// Use this flag to deterine if we are running a unit test
30
32
// The flag is needed to track some values for unit test
31
33
@property (nonatomic , assign ) BOOL isRunningTest;
@@ -35,6 +37,13 @@ @interface OPTLYHTTPRequestManager()
35
37
36
38
@implementation OPTLYHTTPRequestManager
37
39
40
+ - (NSURLSession *)session {
41
+ NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration: [NSURLSessionConfiguration ephemeralSessionConfiguration ]];
42
+ ephemeralSession.configuration .TLSMinimumSupportedProtocol = kTLSProtocol12 ;
43
+
44
+ return ephemeralSession;
45
+ }
46
+
38
47
# pragma mark - Object Initializers
39
48
40
49
- (id )init
@@ -83,9 +92,9 @@ - (void)GETWithParameters:(NSDictionary *)parameters
83
92
url : (NSURL *)url
84
93
completionHandler : (OPTLYHTTPRequestManagerResponse)completion
85
94
{
86
- NSURLSession *ephemeralSession = [ NSURLSession sessionWithConfiguration: [ NSURLSessionConfiguration ephemeralSessionConfiguration ]];
95
+
87
96
NSURL *urlWithParameterQuery = [self buildQueryURL: url withParameters: parameters];
88
- NSURLSessionDataTask *downloadTask = [ephemeralSession dataTaskWithURL: urlWithParameterQuery
97
+ NSURLSessionDataTask *downloadTask = [self .session dataTaskWithURL: urlWithParameterQuery
89
98
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
90
99
if (completion) {
91
100
completion (data, response, error);
@@ -178,8 +187,7 @@ - (void)GETIfModifiedSince:(NSString *)lastModifiedDate
178
187
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url];
179
188
[request setValue: lastModifiedDate forHTTPHeaderField: @" If-Modified-Since" ];
180
189
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) {
183
191
if (completion) {
184
192
completion (data, response, error);
185
193
}
@@ -272,7 +280,6 @@ - (void)POSTWithParameters:(NSDictionary *)parameters
272
280
url : (NSURL *)url
273
281
completionHandler : (OPTLYHTTPRequestManagerResponse)completion
274
282
{
275
- NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration: [NSURLSessionConfiguration ephemeralSessionConfiguration ]];
276
283
NSMutableURLRequest *request = [[NSMutableURLRequest alloc ] initWithURL: url];
277
284
[request setHTTPMethod: kHTTPRequestMethodPost ];
278
285
@@ -288,7 +295,7 @@ - (void)POSTWithParameters:(NSDictionary *)parameters
288
295
289
296
[request addValue: kHTTPHeaderFieldValueApplicationJSON forHTTPHeaderField: kHTTPHeaderFieldContentType ];
290
297
291
- NSURLSessionUploadTask *uploadTask = [ephemeralSession uploadTaskWithRequest: request
298
+ NSURLSessionUploadTask *uploadTask = [self .session uploadTaskWithRequest: request
292
299
fromData: data
293
300
completionHandler: ^(NSData *data,NSURLResponse *response,NSError *error) {
294
301
if (completion) {
0 commit comments