diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-09-02 12:23:11 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-09-02 12:23:11 +0530 |
commit | 659e9cdbe6defd54d0f4713bb230e4a156262a2c (patch) | |
tree | 1a29245514f9dd5e84617c6ac699ef7a2bf264a5 /packages/taler-wallet-core/src/util/http.ts | |
parent | 0ffea74ad52113aa9036453ff3ea8d4dff61b3d8 (diff) | |
download | wallet-core-659e9cdbe6defd54d0f4713bb230e4a156262a2c.tar.xz |
respect cache header
Diffstat (limited to 'packages/taler-wallet-core/src/util/http.ts')
-rw-r--r-- | packages/taler-wallet-core/src/util/http.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/util/http.ts b/packages/taler-wallet-core/src/util/http.ts index 58b04d455..0977b429e 100644 --- a/packages/taler-wallet-core/src/util/http.ts +++ b/packages/taler-wallet-core/src/util/http.ts @@ -26,7 +26,7 @@ import { Codec } from "./codec"; import { OperationFailedError, makeErrorDetails } from "../operations/errors"; import { TalerErrorCode } from "../TalerErrorCode"; import { Logger } from "./logging"; -import { Duration } from "./time"; +import { Duration, Timestamp, getTimestampNow } from "./time"; const logger = new Logger("http.ts"); @@ -253,3 +253,19 @@ export async function readSuccessResponseTextOrThrow<T>( } throwUnexpectedRequestError(httpResponse, r.talerErrorResponse); } + +/** + * Get the timestamp at which the response's content is considered expired. + */ +export function getExpiryTimestamp(httpResponse: HttpResponse): Timestamp { + const expiryDateMs = new Date( + httpResponse.headers.get("expiry") ?? "", + ).getTime(); + if (Number.isNaN(expiryDateMs)) { + return getTimestampNow(); + } else { + return { + t_ms: expiryDateMs, + } + } +} |