Skip to content

Commit cb433af

Browse files
mlz11dylhunn
authored andcommitted
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
1 parent 3cf70e2 commit cb433af

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

goldens/public-api/common/http/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,9 @@ export class HttpRequest<T> {
20992099
params?: HttpParams;
21002100
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
21012101
withCredentials?: boolean;
2102+
transferCache?: {
2103+
includeHeaders?: string[];
2104+
} | boolean;
21022105
body?: T | null;
21032106
method?: string;
21042107
url?: string;
@@ -2117,6 +2120,9 @@ export class HttpRequest<T> {
21172120
params?: HttpParams;
21182121
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
21192122
withCredentials?: boolean;
2123+
transferCache?: {
2124+
includeHeaders?: string[];
2125+
} | boolean;
21202126
body?: V | null;
21212127
method?: string;
21222128
url?: string;

packages/common/http/src/request.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ export class HttpRequest<T> {
439439
params?: HttpParams;
440440
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
441441
withCredentials?: boolean;
442+
transferCache?: {includeHeaders?: string[]} | boolean;
442443
body?: T | null;
443444
method?: string;
444445
url?: string;
@@ -452,6 +453,7 @@ export class HttpRequest<T> {
452453
params?: HttpParams;
453454
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
454455
withCredentials?: boolean;
456+
transferCache?: {includeHeaders?: string[]} | boolean;
455457
body?: V | null;
456458
method?: string;
457459
url?: string;
@@ -466,6 +468,7 @@ export class HttpRequest<T> {
466468
params?: HttpParams;
467469
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
468470
withCredentials?: boolean;
471+
transferCache?: {includeHeaders?: string[]} | boolean;
469472
body?: any | null;
470473
method?: string;
471474
url?: string;
@@ -479,6 +482,10 @@ export class HttpRequest<T> {
479482
const url = update.url || this.url;
480483
const responseType = update.responseType || this.responseType;
481484

485+
// Carefully handle the transferCache to differentiate between
486+
// `false` and `undefined` in the update args.
487+
const transferCache = update.transferCache ?? this.transferCache;
488+
482489
// The body is somewhat special - a `null` value in update.body means
483490
// whatever current body is present is being overridden with an empty
484491
// body, whereas an `undefined` value in update.body implies no
@@ -526,6 +533,7 @@ export class HttpRequest<T> {
526533
reportProgress,
527534
responseType,
528535
withCredentials,
536+
transferCache,
529537
});
530538
}
531539
}

packages/common/http/test/request_spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ describe('HttpRequest', () => {
7676
reportProgress: true,
7777
responseType: 'text',
7878
withCredentials: true,
79+
transferCache: true,
7980
});
8081
it('in the base case', () => {
8182
const clone = req.clone();
@@ -87,6 +88,7 @@ describe('HttpRequest', () => {
8788
expect(clone.headers.get('Test')).toBe('Test header');
8889

8990
expect(clone.context).toBe(context);
91+
expect(clone.transferCache).toBe(true);
9092
});
9193
it('and updates the url', () => {
9294
expect(req.clone({url: '/changed'}).url).toBe('/changed');
@@ -101,6 +103,9 @@ describe('HttpRequest', () => {
101103
const newContext = new HttpContext();
102104
expect(req.clone({context: newContext}).context).toBe(newContext);
103105
});
106+
it('and updates the transferCache', () => {
107+
expect(req.clone({transferCache: false}).transferCache).toBe(false);
108+
});
104109
});
105110
describe('content type detection', () => {
106111
const baseReq = new HttpRequest('POST', '/test', null);

0 commit comments

Comments
 (0)