summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/exchanges.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/exchanges.ts32
1 files changed, 25 insertions, 7 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts
index fc776c81f..629957efb 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -278,6 +278,7 @@ async function downloadExchangeWithWireInfo(
export async function updateExchangeFromUrl(
ws: InternalWalletState,
baseUrl: string,
+ acceptedFormat?: string[],
forceNow = false,
): Promise<{
exchange: ExchangeRecord;
@@ -286,7 +287,7 @@ export async function updateExchangeFromUrl(
const onOpErr = (e: TalerErrorDetails): Promise<void> =>
handleExchangeUpdateError(ws, baseUrl, e);
return await guardOperationException(
- () => updateExchangeFromUrlImpl(ws, baseUrl, forceNow),
+ () => updateExchangeFromUrlImpl(ws, baseUrl, acceptedFormat, forceNow),
onOpErr,
);
}
@@ -411,6 +412,7 @@ async function downloadKeysInfo(
async function updateExchangeFromUrlImpl(
ws: InternalWalletState,
baseUrl: string,
+ acceptedFormat?: string[],
forceNow = false,
): Promise<{
exchange: ExchangeRecord;
@@ -468,12 +470,28 @@ async function updateExchangeFromUrlImpl(
logger.info("finished validating exchange /wire info");
- const tosDownload = await downloadExchangeWithTermsOfService(
- baseUrl,
- ws.http,
- timeout,
- "text/plain"
- );
+ let tosFound: ExchangeTosDownloadResult | undefined;
+ //Remove this when exchange supports multiple content-type in accept header
+ if (acceptedFormat) for (const format of acceptedFormat) {
+ const resp = await downloadExchangeWithTermsOfService(
+ baseUrl,
+ ws.http,
+ timeout,
+ format
+ );
+ if (resp.tosContentType === format) {
+ tosFound = resp
+ break
+ }
+ }
+ // If none of the specified format was found try text/plain
+ const tosDownload = tosFound !== undefined ? tosFound :
+ await downloadExchangeWithTermsOfService(
+ baseUrl,
+ ws.http,
+ timeout,
+ "text/plain"
+ );
let recoupGroupId: string | undefined = undefined;