From 5f76bb3a5f3fc5105f96f3669de88dead86d5916 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 19 Mar 2024 07:53:32 +0000 Subject: [PATCH] fix(http): include transferCache when cloning HttpRequest (#54939) Fixes a bug where HttpRequest.clone() does not include the transferCache property. Fixes #54924. PR Close #54939 --- goldens/public-api/common/http/index.md | 6 ++++++ packages/common/http/src/request.ts | 8 ++++++++ packages/common/http/test/request_spec.ts | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/goldens/public-api/common/http/index.md b/goldens/public-api/common/http/index.md index b09bed56a5494e..b4d903d00b0001 100644 --- a/goldens/public-api/common/http/index.md +++ b/goldens/public-api/common/http/index.md @@ -2099,6 +2099,9 @@ export class HttpRequest { params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; + transferCache?: { + includeHeaders?: string[]; + } | boolean; body?: T | null; method?: string; url?: string; @@ -2117,6 +2120,9 @@ export class HttpRequest { params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; + transferCache?: { + includeHeaders?: string[]; + } | boolean; body?: V | null; method?: string; url?: string; diff --git a/packages/common/http/src/request.ts b/packages/common/http/src/request.ts index 79e46a2511811c..e8fc4682109e16 100644 --- a/packages/common/http/src/request.ts +++ b/packages/common/http/src/request.ts @@ -439,6 +439,7 @@ export class HttpRequest { params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; + transferCache?: {includeHeaders?: string[]} | boolean; body?: T | null; method?: string; url?: string; @@ -452,6 +453,7 @@ export class HttpRequest { params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; + transferCache?: {includeHeaders?: string[]} | boolean; body?: V | null; method?: string; url?: string; @@ -466,6 +468,7 @@ export class HttpRequest { params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; + transferCache?: {includeHeaders?: string[]} | boolean; body?: any | null; method?: string; url?: string; @@ -479,6 +482,10 @@ export class HttpRequest { const url = update.url || this.url; const responseType = update.responseType || this.responseType; + // Carefully handle the transferCache to differentiate between + // `false` and `undefined` in the update args. + const transferCache = update.transferCache ?? this.transferCache; + // The body is somewhat special - a `null` value in update.body means // whatever current body is present is being overridden with an empty // body, whereas an `undefined` value in update.body implies no @@ -526,6 +533,7 @@ export class HttpRequest { reportProgress, responseType, withCredentials, + transferCache, }); } } diff --git a/packages/common/http/test/request_spec.ts b/packages/common/http/test/request_spec.ts index 19bdb32a50d9e6..0114435c05939b 100644 --- a/packages/common/http/test/request_spec.ts +++ b/packages/common/http/test/request_spec.ts @@ -76,6 +76,7 @@ describe('HttpRequest', () => { reportProgress: true, responseType: 'text', withCredentials: true, + transferCache: true, }); it('in the base case', () => { const clone = req.clone(); @@ -87,6 +88,7 @@ describe('HttpRequest', () => { expect(clone.headers.get('Test')).toBe('Test header'); expect(clone.context).toBe(context); + expect(clone.transferCache).toBe(true); }); it('and updates the url', () => { expect(req.clone({url: '/changed'}).url).toBe('/changed'); @@ -101,6 +103,9 @@ describe('HttpRequest', () => { const newContext = new HttpContext(); expect(req.clone({context: newContext}).context).toBe(newContext); }); + it('and updates the transferCache', () => { + expect(req.clone({transferCache: false}).transferCache).toBe(false); + }); }); describe('content type detection', () => { const baseReq = new HttpRequest('POST', '/test', null);