@hkdigital/lib-core 0.4.71 → 0.4.72
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.
|
@@ -403,6 +403,19 @@ export default class IndexedDbCache {
|
|
|
403
403
|
try {
|
|
404
404
|
let responseHeaders = new Headers(entry.headers);
|
|
405
405
|
|
|
406
|
+
// Calculate actual content length from the body and fix Content-Length header
|
|
407
|
+
const bodySize = responseBody instanceof ArrayBuffer ?
|
|
408
|
+
responseBody.byteLength :
|
|
409
|
+
responseBody instanceof Blob ?
|
|
410
|
+
responseBody.size :
|
|
411
|
+
responseBody.length || 0;
|
|
412
|
+
|
|
413
|
+
console.debug(`cache-retrieval: fixing content-length from ${responseHeaders.get('content-length')} to ${bodySize}`);
|
|
414
|
+
console.debug(`cache-retrieval: body type=${typeof responseBody}, constructor=${responseBody?.constructor?.name}, byteLength=${responseBody?.byteLength}`);
|
|
415
|
+
|
|
416
|
+
// Add/fix Content-Length header with actual size
|
|
417
|
+
responseHeaders.set('content-length', bodySize.toString());
|
|
418
|
+
|
|
406
419
|
// Create Response safely
|
|
407
420
|
let response;
|
|
408
421
|
try {
|
|
@@ -69,8 +69,34 @@ export default class MemoryResponseCache {
|
|
|
69
69
|
// Update last accessed time
|
|
70
70
|
entry.lastAccessed = Date.now();
|
|
71
71
|
|
|
72
|
+
// Get body data safely (works with both real Response and mocks)
|
|
73
|
+
let responseBody;
|
|
74
|
+
try {
|
|
75
|
+
responseBody = await entry.response.arrayBuffer();
|
|
76
|
+
} catch (err) {
|
|
77
|
+
// Fallback for test mocks or consumed responses
|
|
78
|
+
responseBody = entry.response.body || new ArrayBuffer(0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Calculate size from body data
|
|
82
|
+
const bodySize = responseBody instanceof ArrayBuffer ?
|
|
83
|
+
responseBody.byteLength :
|
|
84
|
+
responseBody instanceof Blob ?
|
|
85
|
+
responseBody.size :
|
|
86
|
+
responseBody.length || 0;
|
|
87
|
+
|
|
88
|
+
// Create new response with corrected Content-Length header
|
|
89
|
+
const fixedHeaders = new Headers(entry.response.headers);
|
|
90
|
+
fixedHeaders.set('content-length', bodySize.toString());
|
|
91
|
+
|
|
92
|
+
const enhancedResponse = new Response(responseBody, {
|
|
93
|
+
status: entry.response.status,
|
|
94
|
+
statusText: entry.response.statusText,
|
|
95
|
+
headers: fixedHeaders
|
|
96
|
+
});
|
|
97
|
+
|
|
72
98
|
return {
|
|
73
|
-
response:
|
|
99
|
+
response: enhancedResponse,
|
|
74
100
|
metadata: entry.metadata,
|
|
75
101
|
url: entry.url,
|
|
76
102
|
timestamp: entry.timestamp,
|
|
@@ -388,6 +388,7 @@ export async function httpRequest(options) {
|
|
|
388
388
|
if (cachedResponse) {
|
|
389
389
|
console.debug(`http:cache-hit [${url.pathname}]`);
|
|
390
390
|
console.debug(`cached-response has body: ${!!cachedResponse.body}`);
|
|
391
|
+
console.debug(`cached-response content-length: ${cachedResponse.headers.get('content-length')}`);
|
|
391
392
|
return cachedResponse;
|
|
392
393
|
} else {
|
|
393
394
|
console.debug(`http:cache-miss [${url.pathname}]`);
|