Skip to content

Commit 045debf

Browse files
authored
fix(cognito-identity): honor provided configuration headers (#5124)
1 parent e838cd6 commit 045debf

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

AWSCore/CognitoIdentity/AWSCognitoIdentityService.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,15 @@ - (instancetype)initWithConfiguration:(AWSServiceConfiguration *)configuration {
231231

232232
_configuration.baseURL = _configuration.endpoint.URL;
233233
_configuration.retryHandler = [[AWSCognitoIdentityRequestRetryHandler alloc] initWithMaximumRetryCount:_configuration.maxRetryCount];
234-
_configuration.headers = @{@"Content-Type" : @"application/x-amz-json-1.1"};
235-
234+
235+
if (_configuration.headers == nil) {
236+
_configuration.headers = @{@"Content-Type" : @"application/x-amz-json-1.1"};
237+
} else {
238+
NSMutableDictionary *headers = [[NSMutableDictionary alloc] initWithDictionary:_configuration.headers];
239+
headers[@"Content-Type"] = @"application/x-amz-json-1.1";
240+
_configuration.headers = headers;
241+
}
242+
236243
_networking = [[AWSNetworking alloc] initWithConfiguration:_configuration];
237244
}
238245

AWSCoreUnitTests/AWSGeneralCognitoIdentityTests.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,25 @@ - (void)testCreateIdentityPoolCompletionHandler {
105105
[AWSCognitoIdentity removeCognitoIdentityForKey:key];
106106
}
107107

108+
- (void)testCreateIdentityPoolWithSuppliedHeaders {
109+
AWSServiceConfiguration *configuration = [AWSTestUtility getDefaultServiceConfiguration];
110+
configuration.headers = @{@"foo": @"bar"};
111+
id key = @"test-with-headers";
112+
[AWSCognitoIdentity registerCognitoIdentityWithConfiguration:configuration forKey:key];
113+
AWSCognitoIdentity *cognitoIdentity = [AWSCognitoIdentity CognitoIdentityForKey:key];
114+
NSDictionary *expected = @{@"foo": @"bar", @"Content-Type": @"application/x-amz-json-1.1"};
115+
XCTAssertEqualObjects(cognitoIdentity.configuration.headers, expected, @"expected provided headers to be included in configuration object");
116+
}
117+
118+
- (void)testCreateIdentityPoolNoSuppliedHeaders {
119+
AWSServiceConfiguration *configuration = [AWSTestUtility getDefaultServiceConfiguration];
120+
id key = @"test-without-headers";
121+
[AWSCognitoIdentity registerCognitoIdentityWithConfiguration:configuration forKey:key];
122+
AWSCognitoIdentity *cognitoIdentity = [AWSCognitoIdentity CognitoIdentityForKey:key];
123+
NSDictionary *expected = @{@"Content-Type": @"application/x-amz-json-1.1"};
124+
XCTAssertEqualObjects(cognitoIdentity.configuration.headers, expected, @"expected Content-Type header to be included");
125+
}
126+
108127
- (void)testDeleteIdentities {
109128
NSString *key = @"testDeleteIdentities";
110129
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil];

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
## Unreleased
66

7+
### Bug Fixes
8+
9+
- **CognitoIdentity**
10+
- Don't overwrite AWSServiceConfiguration provided headers.
11+
712
### Misc. Updates
813

914
- Model updates for the following services

0 commit comments

Comments
 (0)