Skip to content

Commit 5d0341c

Browse files
mt81flovilmart
authored andcommitted
Custom header support. (#1250)
* Added custom URL Session configuration * Set the URLSesssionConfiguration to the default one.
1 parent 61f3320 commit 5d0341c

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ + (instancetype)constructorWithDataSource:(id<PFInstallationIdentifierStoreProvi
5151
path:command.httpPath
5252
query:nil];
5353
NSDictionary *headers = task.result;
54+
NSURLSessionConfiguration *configuration = Parse._currentManager.configuration.URLSessionConfiguration;
55+
if (configuration && [configuration.HTTPAdditionalHeaders count]) {
56+
NSMutableDictionary *sessionConfigurationHeaders = [configuration.HTTPAdditionalHeaders mutableCopy];
57+
[sessionConfigurationHeaders addEntriesFromDictionary:headers];
58+
headers = sessionConfigurationHeaders;
59+
}
5460

5561
NSString *requestMethod = command.httpMethod;
5662
NSDictionary *requestParameters = nil;

Parse/Parse/Internal/Commands/CommandRunner/URLSession/PFURLSessionCommandRunner.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import "PFRESTCommand.h"
3030
#import "PFURLConstructor.h"
3131
#import "PFURLSession.h"
32+
#import "Parse_Private.h"
3233

3334
@interface PFURLSessionCommandRunner () <PFURLSessionDelegate>
3435

@@ -261,7 +262,7 @@ - (BFTask *)_performCommandRunningBlock:(nonnull id (^)(void))block
261262

262263
+ (NSURLSessionConfiguration *)_urlSessionConfigurationForApplicationId:(NSString *)applicationId
263264
clientKey:(nullable NSString *)clientKey {
264-
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
265+
NSURLSessionConfiguration *configuration = Parse._currentManager.configuration.URLSessionConfiguration;
265266

266267
// No cookies, they are bad for you.
267268
configuration.HTTPCookieAcceptPolicy = NSHTTPCookieAcceptPolicyNever;
@@ -276,6 +277,12 @@ + (NSURLSessionConfiguration *)_urlSessionConfigurationForApplicationId:(NSStrin
276277
NSDictionary *headers = [PFCommandURLRequestConstructor defaultURLRequestHeadersForApplicationId:applicationId
277278
clientKey:clientKey
278279
bundle:bundle];
280+
if (configuration && [configuration.HTTPAdditionalHeaders count]) {
281+
NSMutableDictionary *sessionConfigurationHeaders = [configuration.HTTPAdditionalHeaders mutableCopy];
282+
[sessionConfigurationHeaders addEntriesFromDictionary:headers];
283+
headers = sessionConfigurationHeaders;
284+
}
285+
279286
configuration.HTTPAdditionalHeaders = headers;
280287

281288
return configuration;

Parse/Parse/Internal/ParseClientConfiguration_Private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern NSString *const _ParseDefaultServerURLString;
2525

2626
@property (nullable, nonatomic, copy, readwrite) NSString *applicationGroupIdentifier;
2727
@property (nullable, nonatomic, copy, readwrite) NSString *containingApplicationBundleIdentifier;
28+
@property (nonatomic, strong, readwrite) NSURLSessionConfiguration *URLSessionConfiguration;
2829

2930
@property (nonatomic, assign, readwrite) NSUInteger networkRetryAttempts;
3031

Parse/Parse/ParseClientConfiguration.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,14 @@ NS_ASSUME_NONNULL_BEGIN
8787
@property (nullable, nonatomic, copy) NSString *containingApplicationBundleIdentifier PF_TV_UNAVAILABLE PF_WATCH_UNAVAILABLE;
8888

8989
///--------------------------------------
90-
#pragma mark - Other Properties
90+
#pragma mark - Network Properties
9191
///--------------------------------------
9292

93+
/**
94+
A custom NSURLSessionConfiguration configuration that will be used from the SDK.
95+
*/
96+
@property (nonatomic, strong) NSURLSessionConfiguration *URLSessionConfiguration;
97+
9398
/**
9499
The maximum number of retry attempts to make upon a failed network request.
95100
*/
@@ -163,9 +168,16 @@ NS_ASSUME_NONNULL_BEGIN
163168
@property (nullable, nonatomic, copy, readonly) NSString *containingApplicationBundleIdentifier;
164169

165170
///--------------------------------------
166-
#pragma mark - Other Properties
171+
#pragma mark - Network Properties
167172
///--------------------------------------
168173

174+
/**
175+
The NSURLSessionConfiguration configuration used by the SDK.
176+
177+
The default value is NSURLSessionConfiguration.defaultSessionConfiguration
178+
*/
179+
@property (nonatomic, strong, readonly) NSURLSessionConfiguration *URLSessionConfiguration;
180+
169181
/**
170182
The maximum number of retry attempts to make upon a failed network request.
171183
*/

Parse/Parse/ParseClientConfiguration.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ - (instancetype)initEmpty {
3434
if (!self) return nil;
3535

3636
_networkRetryAttempts = PFCommandRunningDefaultMaxAttemptsCount;
37+
_URLSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
3738
_server = [_ParseDefaultServerURLString copy];
3839

3940
return self;
@@ -116,6 +117,7 @@ - (BOOL)isEqual:(id)object {
116117
self.localDatastoreEnabled == other.localDatastoreEnabled &&
117118
[PFObjectUtilities isObject:self.applicationGroupIdentifier equalToObject:other.applicationGroupIdentifier] &&
118119
[PFObjectUtilities isObject:self.containingApplicationBundleIdentifier equalToObject:other.containingApplicationBundleIdentifier] &&
120+
[PFObjectUtilities isObject:self.URLSessionConfiguration equalToObject:other.URLSessionConfiguration] &&
119121
self.networkRetryAttempts == other.networkRetryAttempts);
120122
}
121123

@@ -134,6 +136,7 @@ - (instancetype)copyWithZone:(NSZone *)zone {
134136
configuration->_applicationGroupIdentifier = [self->_applicationGroupIdentifier copy];
135137
configuration->_containingApplicationBundleIdentifier = [self->_containingApplicationBundleIdentifier copy];
136138
configuration->_networkRetryAttempts = self->_networkRetryAttempts;
139+
configuration->_URLSessionConfiguration = self->_URLSessionConfiguration;
137140
}];
138141
}
139142

0 commit comments

Comments
 (0)