diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/exchanges.ts | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index 253801e93..6afafd9f5 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -122,29 +122,39 @@ interface ExchangeTosDownloadResult { tosText: string; tosEtag: string; tosContentType: string; + tosContentLanguage: string | undefined; } async function downloadExchangeWithTermsOfService( exchangeBaseUrl: string, http: HttpRequestLibrary, timeout: Duration, - contentType: string, + acceptFormat: string, + acceptLanguage: string | undefined, ): Promise<ExchangeTosDownloadResult> { - logger.trace(`downloading exchange tos (type ${contentType})`); + logger.trace(`downloading exchange tos (type ${acceptFormat})`); const reqUrl = new URL("terms", exchangeBaseUrl); - const headers = { - Accept: contentType, + const headers: { + Accept: string; + "Accept-Language"?: string; + } = { + Accept: acceptFormat, }; + if (acceptLanguage) { + headers["Accept-Language"] = acceptLanguage; + } + const resp = await http.fetch(reqUrl.href, { headers, timeout, }); const tosText = await readSuccessResponseTextOrThrow(resp); const tosEtag = resp.headers.get("etag") || "unknown"; + const tosContentLanguage = resp.headers.get("content-language") || undefined; const tosContentType = resp.headers.get("content-type") || "text/plain"; - return { tosText, tosEtag, tosContentType }; + return { tosText, tosEtag, tosContentType, tosContentLanguage }; } /** @@ -572,9 +582,10 @@ async function downloadTosFromAcceptedFormat( baseUrl: string, timeout: Duration, acceptedFormat?: string[], + acceptLanguage?: string, ): Promise<ExchangeTosDownloadResult> { let tosFound: ExchangeTosDownloadResult | undefined; - //Remove this when exchange supports multiple content-type in accept header + // Remove this when exchange supports multiple content-type in accept header if (acceptedFormat) for (const format of acceptedFormat) { const resp = await downloadExchangeWithTermsOfService( @@ -582,6 +593,7 @@ async function downloadTosFromAcceptedFormat( ws.http, timeout, format, + acceptLanguage, ); if (resp.tosContentType === format) { tosFound = resp; @@ -597,6 +609,7 @@ async function downloadTosFromAcceptedFormat( ws.http, timeout, "text/plain", + acceptLanguage, ); } @@ -1144,6 +1157,7 @@ export async function getExchangeTos( ws: InternalWalletState, exchangeBaseUrl: string, acceptedFormat?: string[], + acceptLanguage?: string, ): Promise<GetExchangeTosResult> { // FIXME: download ToS in acceptable format if passed! const { exchange, exchangeDetails } = await fetchFreshExchange( @@ -1156,6 +1170,7 @@ export async function getExchangeTos( exchangeBaseUrl, getExchangeRequestTimeout(), acceptedFormat, + acceptLanguage, ); await ws.db @@ -1173,6 +1188,7 @@ export async function getExchangeTos( currentEtag: tosDownload.tosEtag, content: tosDownload.tosText, contentType: tosDownload.tosContentType, + contentLanguage: tosDownload.tosContentLanguage, tosStatus: getExchangeTosStatusFromRecord(exchange), }; } |