diff --git a/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m b/Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m index c95fd65da..157db303e 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,7 @@ - (BFTask *)_performCommandRunningBlock:(nonnull id (^)(void))block + (NSURLSessionConfiguration *)_urlSessionConfigurationForApplicationId:(NSString *)applicationId clientKey:(nullable NSString *)clientKey { - NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; + NSURLSessionConfiguration *configuration = Parse._currentManager.configuration.URLSessionConfiguration; // No cookies, they are bad for you. configuration.HTTPCookieAcceptPolicy = NSHTTPCookieAcceptPolicyNever; @@ -276,6 +277,12 @@ + (NSURLSessionConfiguration *)_urlSessionConfigurationForApplicationId:(NSStrin NSDictionary *headers = [PFCommandURLRequestConstructor defaultURLRequestHeadersForApplicationId:applicationId clientKey:clientKey bundle:bundle]; + if (configuration && [configuration.HTTPAdditionalHeaders count]) { + NSMutableDictionary *sessionConfigurationHeaders = [configuration.HTTPAdditionalHeaders mutableCopy]; + [sessionConfigurationHeaders addEntriesFromDictionary:headers]; + headers = sessionConfigurationHeaders; + } + configuration.HTTPAdditionalHeaders = headers; return configuration; diff --git a/Parse/Parse/Internal/ParseClientConfiguration_Private.h b/Parse/Parse/Internal/ParseClientConfiguration_Private.h index 4af07fe86..08e80aca8 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 (nonatomic, strong, readwrite) NSURLSessionConfiguration *URLSessionConfiguration; @property (nonatomic, assign, readwrite) NSUInteger networkRetryAttempts; diff --git a/Parse/Parse/ParseClientConfiguration.h b/Parse/Parse/ParseClientConfiguration.h index 9795976b2..7e2c27e11 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 that will be used from the SDK. + */ +@property (nonatomic, strong) NSURLSessionConfiguration *URLSessionConfiguration; + /** The maximum number of retry attempts to make upon a failed network request. */ @@ -163,9 +168,16 @@ NS_ASSUME_NONNULL_BEGIN @property (nullable, nonatomic, copy, readonly) NSString *containingApplicationBundleIdentifier; ///-------------------------------------- -#pragma mark - Other Properties +#pragma mark - Network Properties ///-------------------------------------- +/** + The NSURLSessionConfiguration configuration used by the SDK. + + The default value is NSURLSessionConfiguration.defaultSessionConfiguration + */ +@property (nonatomic, strong, 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..1bd9040fa 100644 --- a/Parse/Parse/ParseClientConfiguration.m +++ b/Parse/Parse/ParseClientConfiguration.m @@ -34,6 +34,7 @@ - (instancetype)initEmpty { if (!self) return nil; _networkRetryAttempts = PFCommandRunningDefaultMaxAttemptsCount; + _URLSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; _server = [_ParseDefaultServerURLString copy]; return self; @@ -116,6 +117,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 +136,7 @@ - (instancetype)copyWithZone:(NSZone *)zone { configuration->_applicationGroupIdentifier = [self->_applicationGroupIdentifier copy]; configuration->_containingApplicationBundleIdentifier = [self->_containingApplicationBundleIdentifier copy]; configuration->_networkRetryAttempts = self->_networkRetryAttempts; + configuration->_URLSessionConfiguration = self->_URLSessionConfiguration; }]; }