taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 4b3d3bcbf389fbdc5d92f027940be54b84e8395e
parent 0c0a4092043ca8cd4660b541d26e112bc6741b3c
Author: Sebastian <sebasjm@gmail.com>
Date:   Wed, 23 Apr 2025 12:25:57 -0300

preference to turn off request compression

Diffstat:
Mpackages/aml-backoffice-ui/src/App.tsx | 3+++
Mpackages/aml-backoffice-ui/src/hooks/preferences.ts | 6++++++
Mpackages/taler-util/src/http-client/exchange.ts | 7+++++--
Mpackages/web-util/src/context/exchange-api.ts | 7+++++--
4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/packages/aml-backoffice-ui/src/App.tsx b/packages/aml-backoffice-ui/src/App.tsx @@ -38,6 +38,7 @@ import { UiSettings, fetchUiSettings } from "./context/ui-settings.js"; import { UiFormsProvider } from "./context/ui-forms.js"; import { revalidateAccountDecisions } from "./hooks/decisions.js"; import { revalidateAccountInformation } from "./hooks/account.js"; +import { usePreferences } from "./hooks/preferences.js"; const WITH_LOCAL_STORAGE_CACHE = false; @@ -48,6 +49,7 @@ export function App(): VNode { }, []); if (!settings) return <Loading />; + const [{ preventCompression }] = usePreferences(); const baseUrl = getInitialBackendBaseURL(settings.backendBaseURL); return ( <UiSettingsProvider value={settings}> @@ -64,6 +66,7 @@ export function App(): VNode { evictors={{ exchange: evictExchangeSwrCache, }} + preventCompression={preventCompression} > <SWRConfig value={{ diff --git a/packages/aml-backoffice-ui/src/hooks/preferences.ts b/packages/aml-backoffice-ui/src/hooks/preferences.ts @@ -31,6 +31,7 @@ interface Preferences { allowInsecurePassword: boolean; keepSessionAfterReload: boolean; testingDialect: boolean; + preventCompression: boolean; } export const codecForPreferences = (): Codec<Preferences> => @@ -39,6 +40,7 @@ export const codecForPreferences = (): Codec<Preferences> => .property("showDebugInfo", codecForBoolean()) .property("testingDialect", codecForBoolean()) .property("keepSessionAfterReload", codecForBoolean()) + .property("preventCompression", codecForBoolean()) .build("Preferences"); const defaultPreferences: Preferences = { @@ -46,6 +48,7 @@ const defaultPreferences: Preferences = { showDebugInfo: false, testingDialect: false, keepSessionAfterReload: false, + preventCompression: false, }; const PREFERENCES_KEY = buildStorageKey( @@ -79,6 +82,7 @@ export function getAllBooleanPreferences(): Array<keyof Preferences> { "allowInsecurePassword", "keepSessionAfterReload", "testingDialect", + "preventCompression" ]; } @@ -95,5 +99,7 @@ export function getLabelForPreferences( return i18n.str`Allow Insecure password`; case "keepSessionAfterReload": return i18n.str`Keep session after reload`; + case "preventCompression": + return i18n.str`Don't compress request`; } } diff --git a/packages/taler-util/src/http-client/exchange.ts b/packages/taler-util/src/http-client/exchange.ts @@ -100,14 +100,17 @@ export class TalerExchangeHttpClient { httpLib: HttpRequestLibrary; public readonly PROTOCOL_VERSION = "21:0:0"; cacheEvictor: CacheEvictor<TalerExchangeCacheEviction>; + preventCompression: boolean; constructor( readonly baseUrl: string, httpClient?: HttpRequestLibrary, cacheEvictor?: CacheEvictor<TalerExchangeCacheEviction>, + preventCompression?: boolean, ) { this.httpLib = httpClient ?? createPlatformHttpLib(); this.cacheEvictor = cacheEvictor ?? nullEvictor; + this.preventCompression = !!preventCompression; } isCompatible(version: string): boolean { @@ -748,7 +751,7 @@ export class TalerExchangeHttpClient { const resp = await this.httpLib.fetch(url.href, { method: "POST", body, - compress: "deflate", + compress: this.preventCompression ? undefined : "deflate", }); switch (resp.status) { @@ -1016,7 +1019,7 @@ export class TalerExchangeHttpClient { ), }, body, - compress: "deflate", + compress: this.preventCompression ? undefined : "deflate", }); switch (resp.status) { diff --git a/packages/web-util/src/context/exchange-api.ts b/packages/web-util/src/context/exchange-api.ts @@ -94,17 +94,19 @@ export const ExchangeApiProvider = ({ children, evictors = {}, frameOnError, + preventCompression, }: { baseUrl: URL; evictors?: Evictors; children: ComponentChildren; frameOnError: FunctionComponent<{ children: ComponentChildren }>; + preventCompression?: boolean; }): VNode => { const [checked, setChecked] = useState<ConfigResult<KeysAndConfigType>>(); const { i18n } = useTranslationContext(); const { getRemoteConfig, VERSION, lib, cancelRequest, onActivity } = - buildExchangeApiClient(baseUrl, evictors); + buildExchangeApiClient(baseUrl, evictors, !!preventCompression); useEffect(() => { let keepRetrying = true; @@ -177,6 +179,7 @@ export const ExchangeApiProvider = ({ function buildExchangeApiClient( url: URL, evictors: Evictors, + preventCompression: boolean, ): APIClient<ExchangeLib, KeysAndConfigType> { const httpFetch = new BrowserFetchHttpLib({ enableThrottling: true, @@ -190,7 +193,7 @@ function buildExchangeApiClient( }, }); - const ex = new TalerExchangeHttpClient(url.href, httpLib, evictors.exchange); + const ex = new TalerExchangeHttpClient(url.href, httpLib, evictors.exchange, preventCompression); async function getRemoteConfig(): Promise<KeysAndConfigType> { const configResp = await ex.getConfig();