@@ -21,7 +21,7 @@ import {
2121 ɵRuntimeError as RuntimeError ,
2222} from '@angular/core' ;
2323import { Observable , of } from 'rxjs' ;
24- import { concatMap } from 'rxjs/operators' ;
24+ import { tap } from 'rxjs/operators' ;
2525
2626import { RuntimeErrorCode } from './errors' ;
2727import { 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