@hkdigital/lib-sveltekit 0.0.68 → 0.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,14 @@
|
|
8
8
|
* @throws {Error} internal server error
|
9
9
|
*/
|
10
10
|
export function expectResponseOk(response: object, url: string): Promise<void>;
|
11
|
+
/**
|
12
|
+
* Get the response size from the content-length response header
|
13
|
+
*
|
14
|
+
* @param {Response} response
|
15
|
+
*
|
16
|
+
* @returns {number} response size or 0 if unknown
|
17
|
+
*/
|
18
|
+
export function getResponseSize(response: Response): number;
|
11
19
|
/**
|
12
20
|
* Wait for a response and check if the response is ok
|
13
21
|
*
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ResponseError } from '../../constants/errors/index.js';
|
2
2
|
import * as expect from '../expect/index.js';
|
3
3
|
|
4
|
-
import { WWW_AUTHENTICATE } from '../../constants/http/headers.js';
|
4
|
+
import { WWW_AUTHENTICATE, CONTENT_LENGTH } from '../../constants/http/headers.js';
|
5
5
|
|
6
6
|
import { href } from './url.js';
|
7
7
|
|
@@ -62,6 +62,23 @@ export async function expectResponseOk(response, url) {
|
|
62
62
|
);
|
63
63
|
}
|
64
64
|
|
65
|
+
/**
|
66
|
+
* Get the response size from the content-length response header
|
67
|
+
*
|
68
|
+
* @param {Response} response
|
69
|
+
*
|
70
|
+
* @returns {number} response size or 0 if unknown
|
71
|
+
*/
|
72
|
+
export function getResponseSize(response) {
|
73
|
+
const sizeStr = response.headers.get(CONTENT_LENGTH);
|
74
|
+
|
75
|
+
if (!sizeStr) {
|
76
|
+
return 0;
|
77
|
+
}
|
78
|
+
|
79
|
+
return parseInt(sizeStr, 10);
|
80
|
+
}
|
81
|
+
|
65
82
|
/**
|
66
83
|
* Wait for a response and check if the response is ok
|
67
84
|
*
|