Skip to content

Commit 7eb3371

Browse files
Revert "fix(http): correctly cache blob responses in transfer cache (#67002)"
This reverts commit 1f057af.
1 parent 9e64147 commit 7eb3371

File tree

3 files changed

+144
-205
lines changed

3 files changed

+144
-205
lines changed

packages/common/http/src/transfer_cache.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
ɵRuntimeError as RuntimeError,
2222
} from '@angular/core';
2323
import {Observable, of} from 'rxjs';
24-
import {concatMap} from 'rxjs/operators';
24+
import {tap} from 'rxjs/operators';
2525

2626
import {RuntimeErrorCode} from './errors';
2727
import {HttpHeaders} from './headers';
@@ -267,32 +267,21 @@ export function transferCacheInterceptorFn(
267267
if (typeof ngServerMode !== 'undefined' && ngServerMode) {
268268
// Request not found in cache. Make the request and cache it if on the server.
269269
return event$.pipe(
270-
concatMap(async (event: HttpEvent<unknown>) => {
270+
tap((event: HttpEvent<unknown>) => {
271271
// Only cache successful HTTP responses.
272272
if (event instanceof HttpResponse) {
273-
let body = event.body;
274-
if (req.responseType === 'blob') {
275-
// Note: Blob is converted to ArrayBuffer because Uint8Array constructor
276-
// doesn't accept Blob directly, which would result in an empty array.
277-
// Type assertion is safe here: when responseType is 'blob', the body is guaranteed to be a Blob
278-
const arrayBuffer = await (event.body as Blob).arrayBuffer();
279-
body = toBase64(arrayBuffer);
280-
} else if (req.responseType === 'arraybuffer') {
281-
// For arraybuffer, convert to base64; for other types (json, text), store as-is.
282-
// Type assertion is safe here: when responseType is 'arraybuffer', the body is
283-
// guaranteed to be an ArrayBuffer
284-
body = toBase64(event.body as ArrayBufferLike);
285-
}
286273
transferState.set<TransferHttpResponse>(storeKey, {
287-
[BODY]: body,
274+
[BODY]:
275+
req.responseType === 'arraybuffer' || req.responseType === 'blob'
276+
? toBase64(event.body as ArrayBufferLike)
277+
: event.body,
288278
[HEADERS]: getFilteredHeaders(event.headers, headersToInclude),
289279
[STATUS]: event.status,
290280
[STATUS_TEXT]: event.statusText,
291281
[REQ_URL]: requestUrl,
292282
[RESPONSE_TYPE]: req.responseType,
293283
});
294284
}
295-
return event;
296285
}),
297286
);
298287
}

0 commit comments

Comments
 (0)