forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): add cache-control header to cognito identity client (aws-a…
- Loading branch information
1 parent
cde60fc
commit dfbabaf
Showing
5 changed files
with
184 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,9 @@ describe('Credentials test', () => { | |
}; | ||
} | ||
}, | ||
middlewareStack: { | ||
add: (next, _) => {}, | ||
}, | ||
}; | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
CognitoIdentityClient, | ||
CognitoIdentityClientConfig, | ||
} from '@aws-sdk/client-cognito-identity'; | ||
import { Provider } from '@aws-sdk/types'; | ||
import { getAmplifyUserAgent } from '../Platform'; | ||
|
||
/** | ||
* Returns a CognitoIdentityClient with middleware | ||
* @param {CognitoIdentityClientConfig} config | ||
* @return {CognitoIdentityClient} | ||
*/ | ||
export function createCognitoIdentityClient( | ||
config: CognitoIdentityClientConfig | ||
): CognitoIdentityClient { | ||
const client = new CognitoIdentityClient({ | ||
region: config.region, | ||
customUserAgent: getAmplifyUserAgent(), | ||
}); | ||
|
||
client.middlewareStack.add( | ||
(next, _) => (args: any) => { | ||
return next(middlewareArgs(args)); | ||
}, | ||
{ | ||
step: 'build', | ||
name: 'cacheControlMiddleWare', | ||
} | ||
); | ||
|
||
return client; | ||
} | ||
|
||
export function middlewareArgs(args: { request: any; input: any }) { | ||
return { | ||
...args, | ||
request: { | ||
...args.request, | ||
headers: { | ||
...args.request.headers, | ||
'cache-control': 'no-store', | ||
}, | ||
}, | ||
}; | ||
} |