aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-01-30 15:06:14 +0100
committerFlorian Dold <florian@dold.me>2024-01-30 15:06:14 +0100
commit673b56488e3a07eb6bee6ab6972be46891889d4a (patch)
tree93aee8f436d5fdd33fc0695f3e563eab4cf10021
parent0e79a79e6b9f159b3aebc39f2e278f062c4d4410 (diff)
downloadwallet-core-673b56488e3a07eb6bee6ab6972be46891889d4a.tar.xz
-missing copyright header
-rw-r--r--packages/taler-util/src/http-client/utils.ts41
1 files changed, 33 insertions, 8 deletions
diff --git a/packages/taler-util/src/http-client/utils.ts b/packages/taler-util/src/http-client/utils.ts
index e4b874c2f..7abedae63 100644
--- a/packages/taler-util/src/http-client/utils.ts
+++ b/packages/taler-util/src/http-client/utils.ts
@@ -1,3 +1,22 @@
+/*
+ This file is part of GNU Taler
+ (C) 2022-2024 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+ * Imports.
+ */
import { base64FromArrayBuffer } from "../base64.js";
import { stringToBytes } from "../taler-crypto.js";
import { AccessToken, LongPollParams, PaginationParams } from "./types.js";
@@ -5,7 +24,10 @@ import { AccessToken, LongPollParams, PaginationParams } from "./types.js";
/**
* Helper function to generate the "Authorization" HTTP header.
*/
-export function makeBasicAuthHeader(username: string, password: string): string {
+export function makeBasicAuthHeader(
+ username: string,
+ password: string,
+): string {
const auth = `${username}:${password}`;
const authEncoded: string = base64FromArrayBuffer(stringToBytes(auth));
return `Basic ${authEncoded}`;
@@ -13,8 +35,8 @@ export function makeBasicAuthHeader(username: string, password: string): string
/**
* rfc8959
- * @param token
- * @returns
+ * @param token
+ * @returns
*/
export function makeBearerTokenAuthHeader(token: AccessToken): string {
return `Bearer secret-token:${token}`;
@@ -26,17 +48,20 @@ export function makeBearerTokenAuthHeader(token: AccessToken): string {
export function addPaginationParams(url: URL, pagination?: PaginationParams) {
if (!pagination) return;
if (pagination.offset) {
- url.searchParams.set("start", pagination.offset)
+ url.searchParams.set("start", pagination.offset);
}
- const order = !pagination || pagination.order === "asc" ? 1 : -1
- const limit = !pagination || !pagination.limit || pagination.limit === 0 ? 5 : Math.abs(pagination.limit)
+ const order = !pagination || pagination.order === "asc" ? 1 : -1;
+ const limit =
+ !pagination || !pagination.limit || pagination.limit === 0
+ ? 5
+ : Math.abs(pagination.limit);
//always send delta
- url.searchParams.set("delta", String(order * limit))
+ url.searchParams.set("delta", String(order * limit));
}
export function addLongPollingParam(url: URL, param?: LongPollParams) {
if (!param) return;
if (param.timeoutMs) {
- url.searchParams.set("long_poll_ms", String(param.timeoutMs))
+ url.searchParams.set("long_poll_ms", String(param.timeoutMs));
}
}