From 760549f3e7c60d561bd31423eac5f0b88ac1f69d Mon Sep 17 00:00:00 2001 From: matteo Date: Wed, 31 Jan 2018 16:52:13 -0500 Subject: [PATCH 1/2] Added custom URL Session configuration --- .../PFCommandURLRequestConstructor.m | 6 ++++++ .../URLSession/PFURLSessionCommandRunner.m | 10 +++++++++- .../Internal/ParseClientConfiguration_Private.h | 1 + Parse/Parse/ParseClientConfiguration.h | 14 ++++++++++++-- Parse/Parse/ParseClientConfiguration.m | 2 ++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m b/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m index c95fd65da..b489bc368 100644 --- a/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m +++ b/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m @@ -51,6 +51,12 @@ + (instancetype)constructorWithDataSource:(id @@ -261,7 +262,8 @@ - (BFTask *)_performCommandRunningBlock:(nonnull id (^)(void))block + (NSURLSessionConfiguration *)_urlSessionConfigurationForApplicationId:(NSString *)applicationId clientKey:(nullable NSString *)clientKey { - NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; + NSURLSessionConfiguration *customConfiguration = Parse._currentManager.configuration.URLSessionConfiguration; + NSURLSessionConfiguration *configuration = customConfiguration ?: [NSURLSessionConfiguration defaultSessionConfiguration]; // No cookies, they are bad for you. configuration.HTTPCookieAcceptPolicy = NSHTTPCookieAcceptPolicyNever; @@ -276,6 +278,12 @@ + (NSURLSessionConfiguration *)_urlSessionConfigurationForApplicationId:(NSStrin NSDictionary *headers = [PFCommandURLRequestConstructor defaultURLRequestHeadersForApplicationId:applicationId clientKey:clientKey bundle:bundle]; + if (configuration && [configuration.HTTPAdditionalHeaders count]) { + NSMutableDictionary *counpoundHeaders = [configuration.HTTPAdditionalHeaders mutableCopy]; + [counpoundHeaders addEntriesFromDictionary:headers]; + headers = counpoundHeaders; + } + configuration.HTTPAdditionalHeaders = headers; return configuration; diff --git a/Parse/Parse/Internal/ParseClientConfiguration_Private.h b/Parse/Parse/Internal/ParseClientConfiguration_Private.h index 4af07fe86..fca4a5957 100644 --- a/Parse/Parse/Internal/ParseClientConfiguration_Private.h +++ b/Parse/Parse/Internal/ParseClientConfiguration_Private.h @@ -25,6 +25,7 @@ extern NSString *const _ParseDefaultServerURLString; @property (nullable, nonatomic, copy, readwrite) NSString *applicationGroupIdentifier; @property (nullable, nonatomic, copy, readwrite) NSString *containingApplicationBundleIdentifier; +@property (nullable, nonatomic, copy, readwrite) NSURLSessionConfiguration *URLSessionConfiguration; @property (nonatomic, assign, readwrite) NSUInteger networkRetryAttempts; diff --git a/Parse/Parse/ParseClientConfiguration.h b/Parse/Parse/ParseClientConfiguration.h index 9795976b2..a0a9d35be 100644 --- a/Parse/Parse/ParseClientConfiguration.h +++ b/Parse/Parse/ParseClientConfiguration.h @@ -87,9 +87,14 @@ NS_ASSUME_NONNULL_BEGIN @property (nullable, nonatomic, copy) NSString *containingApplicationBundleIdentifier PF_TV_UNAVAILABLE PF_WATCH_UNAVAILABLE; ///-------------------------------------- -#pragma mark - Other Properties +#pragma mark - Network Properties ///-------------------------------------- +/** + A custom NSURLSessionConfiguration configuration + */ +@property (nullable, nonatomic, copy) NSURLSessionConfiguration *URLSessionConfiguration; + /** The maximum number of retry attempts to make upon a failed network request. */ @@ -163,9 +168,14 @@ NS_ASSUME_NONNULL_BEGIN @property (nullable, nonatomic, copy, readonly) NSString *containingApplicationBundleIdentifier; ///-------------------------------------- -#pragma mark - Other Properties +#pragma mark - Network Properties ///-------------------------------------- +/** + A custom NSURLSessionConfiguration configuration + */ +@property (nullable, nonatomic, copy, readonly) NSURLSessionConfiguration *URLSessionConfiguration; + /** The maximum number of retry attempts to make upon a failed network request. */ diff --git a/Parse/Parse/ParseClientConfiguration.m b/Parse/Parse/ParseClientConfiguration.m index c2be76c78..5ceb8883f 100644 --- a/Parse/Parse/ParseClientConfiguration.m +++ b/Parse/Parse/ParseClientConfiguration.m @@ -116,6 +116,7 @@ - (BOOL)isEqual:(id)object { self.localDatastoreEnabled == other.localDatastoreEnabled && [PFObjectUtilities isObject:self.applicationGroupIdentifier equalToObject:other.applicationGroupIdentifier] && [PFObjectUtilities isObject:self.containingApplicationBundleIdentifier equalToObject:other.containingApplicationBundleIdentifier] && + [PFObjectUtilities isObject:self.URLSessionConfiguration equalToObject:other.URLSessionConfiguration] && self.networkRetryAttempts == other.networkRetryAttempts); } @@ -134,6 +135,7 @@ - (instancetype)copyWithZone:(NSZone *)zone { configuration->_applicationGroupIdentifier = [self->_applicationGroupIdentifier copy]; configuration->_containingApplicationBundleIdentifier = [self->_containingApplicationBundleIdentifier copy]; configuration->_networkRetryAttempts = self->_networkRetryAttempts; + configuration->_URLSessionConfiguration = [self->_URLSessionConfiguration copy]; }]; } From ea007d54af55988f4d8f4afa976d11fa78888b2d Mon Sep 17 00:00:00 2001 From: matteo Date: Wed, 31 Jan 2018 17:49:47 -0500 Subject: [PATCH 2/2] Set the URLSesssionConfiguration to the default one. --- .../PFCommandURLRequestConstructor.m | 10 +++++----- .../URLSession/PFURLSessionCommandRunner.m | 9 ++++----- .../Parse/Internal/ParseClientConfiguration_Private.h | 2 +- Parse/Parse/ParseClientConfiguration.h | 10 ++++++---- Parse/Parse/ParseClientConfiguration.m | 3 ++- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m b/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m index b489bc368..157db303e 100644 --- a/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m +++ b/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m @@ -51,11 +51,11 @@ + (instancetype)constructorWithDataSource:(id_applicationGroupIdentifier = [self->_applicationGroupIdentifier copy]; configuration->_containingApplicationBundleIdentifier = [self->_containingApplicationBundleIdentifier copy]; configuration->_networkRetryAttempts = self->_networkRetryAttempts; - configuration->_URLSessionConfiguration = [self->_URLSessionConfiguration copy]; + configuration->_URLSessionConfiguration = self->_URLSessionConfiguration; }]; }